Skip to content
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

add emergency and fault inputs to operations exe #283

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion exes/operations/inc/details/state_machine_owner_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ auto state_machine_owner<signal_t, slot_t, sml_t>::set_mode(tfc::operation::mode

bool handled{};
switch (new_mode) {
using enum tfc::operation::mode_e;
using enum mode_e;
case unknown:
break;
case stopping:
Expand Down Expand Up @@ -251,6 +251,26 @@ void state_machine_owner<signal_t, slot_t, sml_t>::maintenance_new_state(bool ne
// clang-format off
template <template <typename, typename> typename signal_t, template <typename, typename> typename slot_t, template <typename, typename...> typename sml_t>
// clang-format on
void state_machine_owner<signal_t, slot_t, sml_t>::emergency(bool new_state) {
if (new_state) {
states_->process_event(detail::events::emergency_on{});
} else {
states_->process_event(detail::events::emergency_off{});
}
}
// clang-format off
template <template <typename, typename> typename signal_t, template <typename, typename> typename slot_t, template <typename, typename...> typename sml_t>
// clang-format on
void state_machine_owner<signal_t, slot_t, sml_t>::fault(bool new_state) {
if (new_state) {
states_->process_event(detail::events::fault_on{});
} else {
states_->process_event(detail::events::fault_off{});
}
}
// clang-format off
template <template <typename, typename> typename signal_t, template <typename, typename> typename slot_t, template <typename, typename...> typename sml_t>
// clang-format on
void state_machine_owner<signal_t, slot_t, sml_t>::on_starting_timer_expired(std::error_code const& err) {
if (err) {
return;
Expand Down
7 changes: 7 additions & 0 deletions exes/operations/inc/state_machine_owner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class state_machine_owner {
void cleaning_new_state(bool);
void maintenance_new_state(bool);

void emergency(bool);
void fault(bool);

private:
std::function<void(new_mode, old_mode)> on_new_state_{};
asio::io_context& ctx_;
Expand All @@ -119,6 +122,10 @@ class state_machine_owner {
std::bind_front(&state_machine_owner::cleaning_new_state, this) };
bool_slot_t maintenance_button_{ ctx_, mclient_, "maintenance_button",
std::bind_front(&state_machine_owner::maintenance_new_state, this) };
bool_slot_t emergency_{ ctx_, mclient_, "emergency", "Emergency active input",
std::bind_front(&state_machine_owner::emergency, this) };
bool_slot_t fault_{ ctx_, mclient_, "fault", "Fault active, like trip signal from motor driver",
std::bind_front(&state_machine_owner::fault, this) };
tfc::logger::logger logger_{ "state_machine" };
tfc::confman::config<detail::storage> config_{ ctx_, "state_machine",
detail::storage{ .startup_time = std::chrono::milliseconds{ 0 },
Expand Down