Skip to content

Commit

Permalink
⚡ (rc): Move reboot to RC
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Jun 8, 2022
1 parent a6bd955 commit 7308c6c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 0 additions & 6 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,8 @@ namespace robot {

void emergencyStop(const MagicCard &card)
{
static auto emergency_stop_iteration = 0;
if (card == MagicCard::emergency_stop) {
++emergency_stop_iteration;
controller.raiseEmergencyStop();

if (emergency_stop_iteration == 7) {
system_reset();
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class RobotController : public interface::RobotController
stopActuators();
}

void resetEmergencyStopIteration() final { _emergency_stop_iteration = 0; }

void raise(auto event)
{
_event_queue.call([this, &event] { state_machine.process_event(event); });
Expand Down Expand Up @@ -247,7 +249,15 @@ class RobotController : public interface::RobotController
_service_update.onFactoryResetNotification(on_factory_reset_requested);
}

void raiseEmergencyStop() { raise(system::robot::sm::event::emergency_stop {}); }
void raiseEmergencyStop()
{
++_emergency_stop_iteration;
raise(system::robot::sm::event::emergency_stop {});
log_debug("emergency_stop_iteration : %i", _emergency_stop_iteration);
if (_emergency_stop_iteration == 7) {
system_reset();
}
}

void registerEvents()
{
Expand Down Expand Up @@ -379,6 +389,8 @@ class RobotController : public interface::RobotController
&_service_battery, &_service_commands, &_service_device_information,
&_service_monitoring, &_service_file_reception, &_service_update,
};

uint8_t _emergency_stop_iteration {0};
};

} // namespace leka
5 changes: 5 additions & 0 deletions libs/RobotKit/include/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ namespace sm::action {
auto operator()(irc &rc) const { rc.turnOffActuators(); }
};

struct reset_emergency_stop_iteration {
auto operator()(irc &rc) const { rc.resetEmergencyStopIteration(); }
};

} // namespace sm::action

struct StateMachine {
Expand Down Expand Up @@ -195,6 +199,7 @@ struct StateMachine {
, sm::state::updating + boost::sml::on_entry<_> / sm::action::apply_update {}

, sm::state::emergency_stopped + boost::sml::on_entry<_> / sm::action::turn_off_actuators {}
, sm::state::emergency_stopped + boost::sml::on_exit <_> / sm::action::reset_emergency_stop_iteration {}

, sm::state::emergency_stopped + event<sm::event::command_received> [sm::guard::is_not_charging {} && sm::guard::is_connected {}] = sm::state::working
, sm::state::emergency_stopped + event<sm::event::ble_connection> [sm::guard::is_not_charging {}] = sm::state::working
Expand Down
3 changes: 2 additions & 1 deletion libs/RobotKit/include/interface/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class RobotController
virtual auto isReadyToUpdate() -> bool = 0;
virtual void applyUpdate() = 0;

virtual void turnOffActuators() = 0;
virtual void turnOffActuators() = 0;
virtual void resetEmergencyStopIteration() = 0;
};

} // namespace leka::interface

0 comments on commit 7308c6c

Please sign in to comment.