From 8b37784e8cb0a173e929ffb2cf79408461b94487 Mon Sep 17 00:00:00 2001 From: thatcomputerguy0101 Date: Mon, 21 Mar 2022 21:28:38 -0400 Subject: [PATCH] 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. --- tools/can_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/can_example.py b/tools/can_example.py index f6ce94f2..d44a5033 100644 --- a/tools/can_example.py +++ b/tools/can_example.py @@ -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 \ No newline at end of file + break