Getting position data from a function DWM1001 Raspberry Pi

I am using the DWM1001 with my pi and am able to get the location data no problem, however I don’t want a constant stream of data, I just want to retrieve the current position by calling a function, but I’m having trouble doing this. The first call of the function returns the correct data, however when the tag has moved and I call the function again the position data from the tag does not change. Here is my code:

import serial
import time
import datetime
import math

def tagPosition():

data = DWM.readline()


DWM = serial.Serial(port="/dev/ttyACM0", baudrate=115200)
print(“Connected to tag”)

while True:
get = input('get position? ')
if get == 1:
print(‘didnt get’)

1 Like

Your read function doesn’t request the location, all it does is take the next location from the input queue.
If the tag is constantly outputting positions at a fixed rate then your serial data is going to get queued up waiting for you to read it. e.g. If your tag is outputting positions at 1 Hz and you move the tag 30 seconds after start up then the first 30 reads are going to give you the initial position, it doesn’t matter when you do those reads, it could be straight away (in which case your code will block until new data is available since you don’t set a timeout) or after 5 minutes.

You could try closing the serial port and opening it again, that may clear the queue. Or if the python serial library has a flush function that could work (I don’t know it well enough to know if that’s the case or not)

1 Like