-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds new brake axis state and an optional fallthrough on watchdog timeout #652
Open
Jonas-Witt
wants to merge
3
commits into
odriverobotics:devel
Choose a base branch
from
Jonas-Witt:add_brake_axis_state
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,16 +169,30 @@ void Axis::watchdog_feed() { | |
|
||
// @brief Check the watchdog timer for expiration. Also sets the watchdog error bit if expired. | ||
bool Axis::watchdog_check() { | ||
if (!config_.enable_watchdog) return true; | ||
|
||
if (!config_.enable_watchdog) { | ||
return true; | ||
} | ||
// explicit check here to ensure that we don't underflow back to UINT32_MAX | ||
if (watchdog_current_value_ > 0) { | ||
watchdog_current_value_--; | ||
return true; | ||
} else { | ||
error_ |= ERROR_WATCHDOG_TIMER_EXPIRED; | ||
return false; | ||
} | ||
// Go to braking state from closed loop control when watchdog times out. | ||
if (current_state_ == AXIS_STATE_CLOSED_LOOP_CONTROL && | ||
config_.enable_brake_state_fallthrough_on_watchdog_timeout) { | ||
//controller_.config_.control_mode = Controller::CONTROL_MODE_VELOCITY_CONTROL; | ||
//controller_.config_.input_mode = Controller::INPUT_MODE_PASSTHROUGH; | ||
//controller_.input_vel_ = 0; | ||
requested_state_ = AXIS_STATE_BRAKE; | ||
return true; | ||
} | ||
// Don't care about timeouts in AXIS_STATE_BRAKE if brake state fallthrough is enabled. | ||
if (current_state_ == AXIS_STATE_BRAKE && | ||
config_.enable_brake_state_fallthrough_on_watchdog_timeout) { | ||
return true; | ||
} | ||
error_ |= ERROR_WATCHDOG_TIMER_EXPIRED; | ||
return false; | ||
} | ||
|
||
bool Axis::run_lockin_spin(const LockinConfig_t &lockin_config, bool remain_armed, | ||
|
@@ -362,6 +376,22 @@ bool Axis::run_closed_loop_control_loop() { | |
return check_for_errors(); | ||
} | ||
|
||
bool Axis::run_brake_loop() { | ||
start_closed_loop_control(); | ||
set_step_dir_active(config_.enable_step_dir); | ||
|
||
while ((requested_state_ == AXIS_STATE_UNDEFINED) && motor_.is_armed_) { | ||
controller_.config_.control_mode = Controller::CONTROL_MODE_VELOCITY_CONTROL; | ||
controller_.input_vel_ = 0.0f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the axis isn't in in |
||
osDelay(1); | ||
} | ||
|
||
set_step_dir_active(config_.enable_step_dir && config_.step_dir_always_on); | ||
stop_closed_loop_control(); | ||
|
||
return check_for_errors(); | ||
} | ||
|
||
|
||
// Slowly drive in the negative direction at homing_speed until the min endstop is pressed | ||
// When pressed, set the linear count to the offset (default 0), and then go to position 0 | ||
|
@@ -578,6 +608,15 @@ void Axis::run_state_machine_loop() { | |
status = run_closed_loop_control_loop(); | ||
} break; | ||
|
||
case AXIS_STATE_BRAKE: { | ||
//if (odrv.any_error()) | ||
// goto invalid_state_label; | ||
if (!motor_.is_calibrated_ || (encoder_.config_.direction==0 && !config_.enable_sensorless_mode)) | ||
goto invalid_state_label; | ||
watchdog_feed(); | ||
status = run_brake_loop(); | ||
} break; | ||
|
||
case AXIS_STATE_IDLE: { | ||
run_idle_loop(); | ||
status = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented code