Skip to content

Commit

Permalink
Fix alarm race and unhomed glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Jan 8, 2025
1 parent cdb1954 commit c8324a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions FluidNC/src/Machine/Homing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Machine {

uint32_t Homing::_runs;

AxisMask Homing::_unhomed_axes; // Bitmap of axes whose position is unknown
AxisMask Homing::_unhomed_axes = 0; // Bitmap of axes whose position is unknown

bool Homing::axis_is_homed(size_t axis) {
return bitnum_is_false(_unhomed_axes, axis);
Expand All @@ -55,7 +55,9 @@ namespace Machine {
set_bitnum(_unhomed_axes, axis);
}
void Homing::set_all_axes_unhomed() {
_unhomed_axes = Machine::Axes::homingMask;
if (config->_start->_mustHome) {
_unhomed_axes = Machine::Axes::homingMask;
}
}
void Homing::set_all_axes_homed() {
_unhomed_axes = 0;
Expand Down
18 changes: 11 additions & 7 deletions FluidNC/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void polling_loop(void* unused) {
// channels to see if one has a line ready.
activeChannel = pollChannels(activeLine);
} else {
if (state_is(State::Alarm) || state_is(State::ConfigAlarm)) {
if (state_is(State::Alarm) || state_is(State::ConfigAlarm) || state_is(State::Critical)) {
log_debug("Unwinding from Alarm");
Job::abort();
unwind_cause = nullptr;
Expand Down Expand Up @@ -449,9 +449,8 @@ static void protocol_do_start() {
send_alarm(ExecAlarm::Init);
return;
}
Homing::set_all_axes_homed();
if (config->_start->_mustHome && Machine::Axes::homingMask) {
Homing::set_all_axes_unhomed();
Homing::set_all_axes_unhomed();
if (Homing::unhomed_axes()) {
// If there is an axis with homing configured, enter Alarm state on startup
send_alarm(ExecAlarm::Unhomed);
} else {
Expand All @@ -465,20 +464,25 @@ static void protocol_do_alarm(void* alarmVoid) {
if (spindle->_off_on_alarm) {
spindle->stop();
}
alarm_msg(lastAlarm);
// It is important to do set_state() before alarm_msg() because the
// latter can cause a task switch that can introduce a race condition
// whereby polling_loop() does not see the state change.
if (lastAlarm == ExecAlarm::HardLimit || lastAlarm == ExecAlarm::HardStop) {
set_state(State::Critical); // Set system alarm state
report_error_message(Message::CriticalEvent);
protocol_disable_steppers();
Homing::set_all_axes_unhomed();
set_state(State::Critical); // Set system alarm state
alarm_msg(lastAlarm);
report_error_message(Message::CriticalEvent);
return;
}
if (lastAlarm == ExecAlarm::SoftLimit) {
set_state(State::Critical); // Set system alarm state
alarm_msg(lastAlarm);
report_error_message(Message::CriticalEvent);
return;
}
set_state(State::Alarm);
alarm_msg(lastAlarm);
}

static void protocol_start_holding() {
Expand Down

0 comments on commit c8324a7

Please sign in to comment.