mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-23 00:59:54 +08:00
Small updates to endstops & homing
This commit is contained in:
@@ -189,9 +189,9 @@ bool Axis::do_checks() {
|
||||
// controller_.do_checks();
|
||||
|
||||
// Check for endstop presses
|
||||
if (min_endstop_.config_.enabled && min_endstop_.get_state() && !(current_state_ == AXIS_STATE_HOMING)) {
|
||||
if (min_endstop_.config_.enabled && min_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING)) {
|
||||
error_ |= ERROR_MIN_ENDSTOP_PRESSED;
|
||||
} else if (max_endstop_.config_.enabled && max_endstop_.get_state() && !(current_state_ == AXIS_STATE_HOMING)) {
|
||||
} else if (max_endstop_.config_.enabled && max_endstop_.rose() && !(current_state_ == AXIS_STATE_HOMING)) {
|
||||
error_ |= ERROR_MAX_ENDSTOP_PRESSED;
|
||||
}
|
||||
|
||||
@@ -410,6 +410,7 @@ bool Axis::run_homing() {
|
||||
// Avoid integrator windup issues
|
||||
controller_.vel_integrator_torque_ = 0.0f;
|
||||
|
||||
// Driving toward the endstop
|
||||
run_control_loop([this](){
|
||||
// Note that all estimators are updated in the loop prefix in run_control_loop
|
||||
float torque_setpoint;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
void Endstop::update() {
|
||||
debounceTimer_.update();
|
||||
last_state_ = endstop_state_;
|
||||
if (config_.enabled) {
|
||||
bool last_pin_state = pin_state_;
|
||||
|
||||
@@ -19,10 +20,6 @@ void Endstop::update() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Endstop::get_state() {
|
||||
return endstop_state_;
|
||||
}
|
||||
|
||||
bool Endstop::apply_config() {
|
||||
debounceTimer_.reset();
|
||||
if (config_.enabled) {
|
||||
|
||||
@@ -26,11 +26,22 @@ class Endstop {
|
||||
bool apply_config();
|
||||
|
||||
void update();
|
||||
bool get_state();
|
||||
constexpr bool get_state(){
|
||||
return endstop_state_;
|
||||
}
|
||||
|
||||
constexpr bool rose(){
|
||||
return (endstop_state_ != last_state_) && endstop_state_;
|
||||
}
|
||||
|
||||
constexpr bool fell(){
|
||||
return (endstop_state_ != last_state_) && !endstop_state_;
|
||||
}
|
||||
|
||||
bool endstop_state_ = false;
|
||||
|
||||
private:
|
||||
bool last_state_ = false;
|
||||
bool pin_state_ = false;
|
||||
float pos_when_pressed_ = 0.0f;
|
||||
Timer<float> debounceTimer_;
|
||||
|
||||
Reference in New Issue
Block a user