Fix current_state in can_example.py

The documentation, CAN doc file, and firmware all indicate that the current state is only one byte of the heartbeat message. This file used to read four bytes as the state on line 21, but only one byte on line 49. This PR adjusts line 21 so that it only uses one byte, making this example work. Otherwise, it incorrectly reads the flags that occupy the next three bytes as part of the state, which can cause the idle state to never be recognized.
This commit is contained in:
thatcomputerguy0101
2022-03-21 21:28:38 -04:00
committed by GitHub
parent 7ce096e5a8
commit 8b37784e8c

View File

@@ -18,7 +18,7 @@ print("Waiting for calibration to finish...")
while True:
msg = bus.recv()
if msg.arbitration_id == (axisID << 5 | 0x01):
current_state = msg.data[4] | msg.data[5] << 8 | msg.data[6] << 16 | msg.data[7] << 24
current_state = msg.data[4]
if current_state == 0x1:
print("\nAxis has returned to Idle state.")
break
@@ -50,4 +50,4 @@ for msg in bus:
print("Axis has entered closed loop")
else:
print("Axis failed to enter closed loop")
break
break