Trouble with uart.read()
Posted: Wed Aug 05, 2020 2:49 pm
Hi,
I am trying to run consecutive uart.write calls in a row to a motor and return one uart.read that contains multiple messages in it. Specifically, I am using the Pyboard D-series SF6W. The motors that I am writing to are Dynamixel XM430-W210-R motors (https://emanual.robotis.com/docs/en/dxl/x/xm430-w210/). My code looks like this:
def readMotors(self):
self.wrist_pin_out.high()
pyb.udelay(100)
write_time = utime.ticks_us()
self.uart.write(self.final_rot_pos)
self.uart.write(self.final_flex_pos)
self.uart.write(self.final_rot_curr)
self.uart.write(self.final_flex_curr)
print("time in uart.write " + str(utime.ticks_us()-write_time))
pyb.udelay(1000)
self.wrist_pin_out.low()
pyb.udelay(1000)
read_time = utime.ticks_us()
tmp = self.uart.read()
print("time in uart.read: " + str(utime.ticks_us()-read_time))
print("tmp: " + str(tmp))
where self.final_rot_pos, self.final_flex_pos, self.final_rot_curr, and self.final_flex_curr are instructional packets for the motors to know to respond with the correct positions and currents. They are in the correct hexadecimal form (which has been confirmed). The issue lies in the uart.write()/uart.read() sequence. I am not sure if it has to do with delays; however, I am returning readings that has some of the correct bytes. For example, it will return one or two of those readings correctly but then will also include a bunch of random bytes jumbled inside.
Any thoughts?
I am trying to run consecutive uart.write calls in a row to a motor and return one uart.read that contains multiple messages in it. Specifically, I am using the Pyboard D-series SF6W. The motors that I am writing to are Dynamixel XM430-W210-R motors (https://emanual.robotis.com/docs/en/dxl/x/xm430-w210/). My code looks like this:
def readMotors(self):
self.wrist_pin_out.high()
pyb.udelay(100)
write_time = utime.ticks_us()
self.uart.write(self.final_rot_pos)
self.uart.write(self.final_flex_pos)
self.uart.write(self.final_rot_curr)
self.uart.write(self.final_flex_curr)
print("time in uart.write " + str(utime.ticks_us()-write_time))
pyb.udelay(1000)
self.wrist_pin_out.low()
pyb.udelay(1000)
read_time = utime.ticks_us()
tmp = self.uart.read()
print("time in uart.read: " + str(utime.ticks_us()-read_time))
print("tmp: " + str(tmp))
where self.final_rot_pos, self.final_flex_pos, self.final_rot_curr, and self.final_flex_curr are instructional packets for the motors to know to respond with the correct positions and currents. They are in the correct hexadecimal form (which has been confirmed). The issue lies in the uart.write()/uart.read() sequence. I am not sure if it has to do with delays; however, I am returning readings that has some of the correct bytes. For example, it will return one or two of those readings correctly but then will also include a bunch of random bytes jumbled inside.
Any thoughts?