From ac6c565b305cffd8a4d62c715c8da112657d931f Mon Sep 17 00:00:00 2001 From: riewert Date: Fri, 29 Jan 2021 21:24:26 +0100 Subject: [PATCH] Fixes Added an abort + error, and confirmed to naming convention. --- Firmware/MotorControl/axis.cpp | 9 +++++++-- Firmware/odrive-interface.yaml | 2 ++ tools/odrive/enums.py | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index d255a771..937b7377 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -395,8 +395,13 @@ bool Axis::run_homing() { error_ &= ~ERROR_MIN_ENDSTOP_PRESSED; // clear this error since we deliberately drove into the endstop + + if (encoder_.pos_estimate_.any() == std::nullopt || !encoder_.pos_estimate_.any().has_value()){ + return error_ |= ERROR_UNKNOWN_POSITION, false; + } + // Calculate the desired position after offset. - float inputBuffer = encoder_.pos_estimate_.any().value() + min_endstop_.config_.offset; + float input_buffer = encoder_.pos_estimate_.any().value() + min_endstop_.config_.offset; controller_.config_.control_mode = Controller::CONTROL_MODE_POSITION_CONTROL; controller_.config_.input_mode = Controller::INPUT_MODE_TRAP_TRAJ; @@ -404,7 +409,7 @@ bool Axis::run_homing() { // Initialize closed loop control, and then set the desired location. start_closed_loop_control(); - controller_.input_pos_ = inputBuffer; + controller_.input_pos_ = input_buffer; controller_.input_pos_updated(); while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_ && !controller_.trajectory_done_) { diff --git a/Firmware/odrive-interface.yaml b/Firmware/odrive-interface.yaml index e21e4266..63850344 100644 --- a/Firmware/odrive-interface.yaml +++ b/Firmware/odrive-interface.yaml @@ -414,6 +414,8 @@ interfaces: OVER_TEMP: # unused doc: Check `motor.error` for more details. + UNKNOWN_POSITION: + doc: There isn't a valid position estimate available. step_dir_active: readonly bool last_drv_fault: readonly uint32 current_state: readonly AxisState diff --git a/tools/odrive/enums.py b/tools/odrive/enums.py index a5fa2f00..81a136b3 100644 --- a/tools/odrive/enums.py +++ b/tools/odrive/enums.py @@ -101,6 +101,7 @@ AXIS_ERROR_MAX_ENDSTOP_PRESSED = 0x00002000 AXIS_ERROR_ESTOP_REQUESTED = 0x00004000 AXIS_ERROR_HOMING_WITHOUT_ENDSTOP = 0x00020000 AXIS_ERROR_OVER_TEMP = 0x00040000 +AXIS_ERROR_UNKNOWN_POSITION = 0x00080000 # ODrive.Motor.Error MOTOR_ERROR_NONE = 0x00000000