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

Dynamic Traction Demonstration State Machine #123

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions run/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ int main(int argc, char *argv[])
demo_state_machine.start();
telemetry.start();

hyped::demo_state_machine::UI UI;
UI.run();
hyped::demo_state_machine::Ui Ui;
Ui.run();

// Join the threads here
brakes.join();
Expand Down
36 changes: 18 additions & 18 deletions src/demo_state_machine/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace hyped::demo_state_machine {

UI::UI()
Ui::Ui()
: system_(utils::System::getSystem()),
log_("UI", utils::System::getSystem().config_.log_level),
data_(data::Data::getInstance())
Expand All @@ -19,7 +19,7 @@ UI::UI()
addQuitCommand();
}

void UI::run()
void Ui::run()
{
printAvailableCommands();
while (system_.isRunning()) {
Expand All @@ -28,15 +28,15 @@ void UI::run()
}
}

void UI::printCurrentState()
void Ui::printCurrentState()
{
auto current_state = data_.getStateMachineData().current_state;
auto const current_state = data_.getStateMachineData().current_state;
std::cout << "Current State: " << ::hyped::data::stateToString(current_state)->c_str()
<< std::endl;
std::cout << "------------------------------" << std::endl;
}

void UI::printAvailableCommands()
void Ui::printAvailableCommands()
{
std::cout << "Available options:" << std::endl;
for (auto &option : commands_) {
Expand All @@ -46,9 +46,9 @@ void UI::printAvailableCommands()
}
}

void UI::readAndHandleCommand()
void Ui::readAndHandleCommand()
{
auto current_state = data_.getStateMachineData().current_state;
auto const current_state = data_.getStateMachineData().current_state;
mifrandir marked this conversation as resolved.
Show resolved Hide resolved
if (current_state == data::State::kPreCalibrating || current_state == data::State::kReady
|| current_state == data::State::kAccelerating || current_state == data::State::kCruising
|| current_state == data::State::kFinished) {
Expand All @@ -64,67 +64,67 @@ void UI::readAndHandleCommand()
}
}

void UI::addCommand(const Command &command)
void Ui::addCommand(const Command &command)
{
commands_.push_back(command);
handlers_by_identifier_.emplace(command.identifier, command.handler);
}

void UI::addQuitCommand()
void Ui::addQuitCommand()
{
addCommand({"quit", "Turn the system off", [this]() { system_.stop(); }});
}

void UI::addHelpCommand()
void Ui::addHelpCommand()
{
addCommand({"help", "Print all options", [this]() { printAvailableCommands(); }});
}

void UI::giveCalibrationCommand()
void Ui::giveCalibrationCommand()
{
telemetry_data_ = data_.getTelemetryData();
telemetry_data_.calibrate_command = true;
data_.setTelemetryData(telemetry_data_);
}

void UI::addCalibrationCommand()
void Ui::addCalibrationCommand()
{
addCommand(
{"calibrate", "Allows pod to enter Calibrating", [this]() { giveCalibrationCommand(); }});
}

void UI::giveLaunchCommand()
void Ui::giveLaunchCommand()
{
telemetry_data_ = data_.getTelemetryData();
telemetry_data_.launch_command = true;
data_.setTelemetryData(telemetry_data_);
}

void UI::addLaunchCommand()
void Ui::addLaunchCommand()
{
addCommand({"launch", "Allows pod to enter Accelerating", [this]() { giveLaunchCommand(); }});
}

void UI::giveBrakingCommand()
void Ui::giveBrakingCommand()
{
telemetry_data_ = data_.getTelemetryData();
telemetry_data_.emergency_stop_command = true;
data_.setTelemetryData(telemetry_data_);
}

void UI::addBrakingCommand()
void Ui::addBrakingCommand()
{
addCommand({"brake", "Allows pod to enter Pre-Braking", [this]() { giveBrakingCommand(); }});
}

void UI::giveShutDownCommand()
void Ui::giveShutDownCommand()
{
telemetry_data_ = data_.getTelemetryData();
telemetry_data_.shutdown_command = true;
data_.setTelemetryData(telemetry_data_);
}

void UI::addShutDownCommand()
void Ui::addShutDownCommand()
{
addCommand({"shut", "Allows pod to turn off", [this]() { giveShutDownCommand(); }});
}
Expand Down
4 changes: 2 additions & 2 deletions src/demo_state_machine/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace hyped::demo_state_machine {

class UI {
class Ui {
public:
using Handler = std::function<void(void)>;
void printAvailableCommands();
Expand All @@ -24,7 +24,7 @@ class UI {
Handler handler;
};

UI();
Ui();

void run();

Expand Down