fix homing bug

This commit is contained in:
Samuel Sadok
2021-07-27 17:35:32 +02:00
parent a768e8f715
commit b32193d9dd
2 changed files with 15 additions and 2 deletions
+1
View File
@@ -7,6 +7,7 @@ Please add a note of your changes below this heading if you make a Pull Request.
### Fixed
* ASCII protocol commands with multiline responses (`i`, `h`) now return the expected response (in v0.5.2 the response was corrupted)
* odrivetool no longer shows the message `<Task pending coro=... running at ...>` when closing
* Homing used to erroneously complete with `is_homed == True` even if it failed for some reason
### Added
* `brake_resistor_current` added to interface for reading the commanded brake resistor current
+14 -2
View File
@@ -386,10 +386,14 @@ bool Axis::run_homing() {
homing_.is_homed = false;
error_ &= ~ERROR_MIN_ENDSTOP_PRESSED;
bool done = false;
start_closed_loop_control();
// Driving toward the endstop
while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_ && !min_endstop_.get_state()) {
while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_ && !(done = min_endstop_.get_state())) {
osDelay(1);
}
@@ -397,6 +401,10 @@ bool Axis::run_homing() {
controller_.input_vel_ = 0.0f;
if (!done) {
return false;
}
error_ &= ~ERROR_MIN_ENDSTOP_PRESSED; // clear this error since we deliberately drove into the endstop
std::optional<float> pos_estimate_local = encoder_.pos_estimate_.any();
@@ -415,12 +423,16 @@ bool Axis::run_homing() {
controller_.vel_setpoint_ = 0.0f;
controller_.input_pos_updated();
while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_ && !controller_.trajectory_done_) {
while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_ && !(done = controller_.trajectory_done_)) {
osDelay(1);
}
stop_closed_loop_control();
if (!done) {
return false;
}
// Set the current position to 0.
encoder_.set_linear_count(0);
controller_.input_pos_ = 0;