I am trying to work with the create2. In using the "get distance traveled" command (id 142) I am getting back incorrect data. My simple test case logic is
I am working with the Create2_TetheredDrive.py example and adding this
elif k == 'PLUS' or k == 'MINUS': # Move 200mm forward or backward # reset distance measurement by sending request sendCommandASCII('142 19') # ignore/discard the data returned recv_basic(connection) # set velocity mm/s v = 200; if k=='MINUS': v=-v # start moving cmd = struct.pack(">Bhh", 145, v, v) sendCommandRaw(cmd) # pause 1 second time.sleep(1); # stop moving cmd = struct.pack(">Bhh", 145, 0, 0) sendCommandRaw(cmd) # get distance traveled sendCommandASCII('142 19') data = recv_basic(connection) dist = struct.unpack('>h',data) print(dist)
I consistently numbers near -25 for moving forward, and +25 for moving backward. If I wait for 2 seconds, I get -50 for moving forward, and +50 for moving backward. The documentation says it should return the distance traveled in mm, so these numbers seem to be off by a factor of -8.
Anyone have any suggestions? Thanks.
p.s. I had to add this function to the example as well
def recv_basic(the_socket): the_socket.settimeout(0.1) total_data= while True: try: data = the_socket.recv(8192) total_data.append(data) except: break return ''.join(total_data)