diff --git a/CHANGELOG.md b/CHANGELOG.md index 1257724b..9cef2851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Please add a note of your changes below this heading if you make a Pull Request. * `encoder.config.bandwidth` ### Fixed +* An issue where the axis state machine would jump in and out of idle when there is an error * There is a [bug](https://github.com/ARM-software/CMSIS_5/issues/267) in the arm fast math library, which gives spikes in the output of arm_cos_f32 for input values close to -pi/2. We fixed the bug locally, and hence are using "our_arm_cos_f32". # Releases diff --git a/Firmware/MotorControl/axis.hpp b/Firmware/MotorControl/axis.hpp index b264d1a1..3443b7f6 100644 --- a/Firmware/MotorControl/axis.hpp +++ b/Firmware/MotorControl/axis.hpp @@ -85,17 +85,9 @@ public: bool do_updates(); float get_temp(); + // True if there are no errors bool inline check_for_errors() { - // Maybe we should update this to only trigger on new errors? - // The danger with that is we could fail to bail on uncleared errors that still prevent - // correct opreation. - - // For now: we treat ERROR_INVALID_STATE in idle loop special, or we could never stay - // in idle after this kind of error. - if (current_state_ == AXIS_STATE_IDLE) - return (error_ & ~ERROR_INVALID_STATE) == ERROR_NONE; - else - return error_ == ERROR_NONE; + return error_ == ERROR_NONE; } // @brief Runs the specified update handler at the frequency of the current measurements. @@ -127,8 +119,12 @@ public: // Note: updates run even if checks fail bool updates_ok = do_updates(); - if (!checks_ok || !updates_ok) - break; + if (!checks_ok || !updates_ok) { + // It's not useful to quit idle since that is the safe action + // Also leaving idle would rearm the motors + if (current_state_ != AXIS_STATE_IDLE) + break; + } // Run main loop function, defer quitting for after wait // TODO: change arming logic to arm after waiting diff --git a/Firmware/MotorControl/odrive_main.h b/Firmware/MotorControl/odrive_main.h index 0165c673..776f1590 100644 --- a/Firmware/MotorControl/odrive_main.h +++ b/Firmware/MotorControl/odrive_main.h @@ -1,6 +1,13 @@ #ifndef __ODRIVE_MAIN_H #define __ODRIVE_MAIN_H +// Note on central include scheme by Samuel: +// there are circular dependencies between some of the header files, +// e.g. the Motor header needs a forward declaration of Axis and vice versa +// so I figured I'd make one main header that takes care of +// the forward declarations and right ordering +// btw this pattern is not so uncommon, for instance IIRC the stdlib uses it too + #ifdef __cplusplus #include extern "C" {