From c594b67c53cc059fdbd1f569f1a06221348b1db8 Mon Sep 17 00:00:00 2001 From: Aaron Tulino <13600347+aaronjamt@users.noreply.github.com> Date: Wed, 22 May 2024 21:49:43 -0700 Subject: [PATCH] Add option to ignore endstops during startup This is useful for devices where the endstop is pressed while power is off, due to gravity, springs, or otherwise. When the ODrive initially starts up, it sees the limit switch(es) pressed and disarms the motor(s) immediately. With this setting enabled, the limit switch will not cause the motor to disarm during inital startup, making the `odrive.axis*.config.startup_*` flags useful again. --- Firmware/MotorControl/axis.cpp | 4 ++-- Firmware/MotorControl/endstop.hpp | 1 + Firmware/odrive-interface.yaml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index 03735ce0d..fd830c593 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -153,9 +153,9 @@ bool Axis::do_checks(uint32_t timestamp) { motor_.do_checks(timestamp); // Check for endstop presses - if (min_endstop_.config_.enabled && min_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING)) { + if (min_endstop_.config_.enabled && min_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING) && !(min_endstop_.config_.ignore_during_startup && current_state_ == AXIS_STATE_UNDEFINED)) { error_ |= ERROR_MIN_ENDSTOP_PRESSED; - } else if (max_endstop_.config_.enabled && max_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING)) { + } else if (max_endstop_.config_.enabled && max_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING) && !(max_endstop_.config_.ignore_during_startup && current_state_ == AXIS_STATE_UNDEFINED)) { error_ |= ERROR_MAX_ENDSTOP_PRESSED; } diff --git a/Firmware/MotorControl/endstop.hpp b/Firmware/MotorControl/endstop.hpp index 21a640c27..2df8cba31 100644 --- a/Firmware/MotorControl/endstop.hpp +++ b/Firmware/MotorControl/endstop.hpp @@ -10,6 +10,7 @@ class Endstop { uint16_t gpio_num = 0; bool enabled = false; bool is_active_high = false; + bool ignore_during_startup = false; // custom setters Endstop* parent = nullptr; diff --git a/Firmware/odrive-interface.yaml b/Firmware/odrive-interface.yaml index 34cb09d06..3d2d717d8 100644 --- a/Firmware/odrive-interface.yaml +++ b/Firmware/odrive-interface.yaml @@ -1409,6 +1409,7 @@ interfaces: enabled: {type: bool, c_setter: set_enabled} offset: {type: float32, unit: turns} is_active_high: bool + ignore_during_startup: bool debounce_ms: {type: uint32, c_setter: set_debounce_ms} ODrive.MechanicalBrake: