Small updates to endstops & homing

This commit is contained in:
Paul Guenette
2020-10-13 22:41:37 -04:00
parent 75a3cb69d3
commit 101f78dcd9
3 changed files with 16 additions and 7 deletions
+3 -2
View File
@@ -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;
+1 -4
View File
@@ -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) {
+12 -1
View File
@@ -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_;