diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index d8a5fb9c..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "xmake", - "request": "launch", - "name": "Debug `backend`", - "target": "backend", - "cwd": "${workspaceFolder}/backend" - }, - { - "type": "xmake", - "request": "launch", - "name": "Debug `raspberry-pi`", - "target": "raspberry-pi", - "cwd": "${workspaceFolder}/raspberry-pi" - }, - { - "type": "xmake", - "request": "launch", - "name": "Debug `legacy`", - "target": "legacy", - "cwd": "${workspaceFolder}/legacy" - } - ] -} \ No newline at end of file diff --git a/app/raspberry_pi/src/car/display/CarConsole.cxx b/app/raspberry_pi/src/car/display/CarConsole.cxx index 8dd648ae..4b9a9791 100644 --- a/app/raspberry_pi/src/car/display/CarConsole.cxx +++ b/app/raspberry_pi/src/car/display/CarConsole.cxx @@ -16,12 +16,13 @@ using namespace car::system; using namespace ftxui; namespace car::display { - static auto button_style = ButtonOption::Animated(); + static const ButtonOption button_style = ButtonOption::Animated(); class CarConsole { public: - Component MainComponent(std::function show_exit_modal) { + Component MainComponent(std::function start_car_system, std::function show_exit_modal) { auto component = Container::Vertical({ + Button("Start Car Application", start_car_system, button_style), Button("Quit", show_exit_modal, button_style), }); // Polish how the two buttons are rendered: @@ -69,16 +70,18 @@ namespace car::display { auto show_exit_modal = [&] { exit_modal_shown = true; }; auto hide_exit_modal = [&] { exit_modal_shown = false; }; + + auto start_car_system = [&] { this->car_system->start(); }; + auto exit = screen.ExitLoopClosure(); - auto main_component = MainComponent(show_exit_modal); + auto main_component = MainComponent(start_car_system, show_exit_modal); auto modal_component = ExitModalComponent(hide_exit_modal, exit); main_component |= Modal(modal_component, &exit_modal_shown); Loop loop(&screen, main_component); - this->car_system->initalize(); - this->car_system->start(); + this->car_system->initialize(); // The main loop: while (!loop.HasQuitted()) { this->car_system->update(); diff --git a/app/raspberry_pi/src/car/system/CarSystem.cpp b/app/raspberry_pi/src/car/system/CarSystem.cpp index e41a1f40..ca808e50 100644 --- a/app/raspberry_pi/src/car/system/CarSystem.cpp +++ b/app/raspberry_pi/src/car/system/CarSystem.cpp @@ -1,12 +1,12 @@ #include "CarSystem.h" -namespace car::system { +namespace car::system +{ CarSystem::CarSystem( - const std::string& websocket_url, - std::unique_ptr lidar_device, - std::unique_ptr messaging_system, - std::unique_ptr movement_system - ) : lidar_device(std::move(lidar_device)), messaging_system(std::move(messaging_system)), movement_system(std::move(movement_system)) + const std::string &websocket_url, + std::unique_ptr lidar_device, + std::unique_ptr messaging_system, + std::unique_ptr movement_system) : lidar_device(std::move(lidar_device)), messaging_system(std::move(messaging_system)), movement_system(std::move(movement_system)) { } @@ -15,58 +15,61 @@ namespace car::system { this->terminate(); } - void CarSystem::initalize() + void CarSystem::initialize() { - this->messaging_system->initalize(); + this->messaging_system->initialize(); this->lidar_device->initialize(); - this->messaging_system->move_command_signal.connect([this](const MoveCommand move_command) { - this->move(move_command); - }); + this->messaging_system->move_command_signal.connect([this](const MoveCommand move_command) + { this->move(move_command); }); - this->messaging_system->turn_command_signal.connect([this](const TurnCommand turn_command) { - this->turn(turn_command); - }); + this->messaging_system->turn_command_signal.connect([this](const TurnCommand turn_command) + { this->turn(turn_command); }); } void CarSystem::start() { this->messaging_system->start(); this->lidar_device->start(); + this->running = true; } void CarSystem::update() { + if (!this->running) + { + return; + } json output_json; output_json["data"] = json::array(); std::vector scan = this->lidar_device->scan(); - for (const Measure& measure : scan) + for (const Measure &measure : scan) { output_json["data"].push_back( { - {"distance", measure.distance}, - {"angle", measure.angle}, - } - ); + {"distance", measure.distance}, + {"angle", measure.angle}, + }); } this->messaging_system->sendMessage(output_json.dump()); } void CarSystem::terminate() { - if (!this->terminated) { + if (!this->terminated) + { this->terminated = true; this->lidar_device->terminate(); this->messaging_system->terminate(); } } - void CarSystem::move(const MoveCommand& move_command) + void CarSystem::move(const MoveCommand &move_command) { this->movement_system->move(move_command); } - void CarSystem::turn(const TurnCommand& turn_command) + void CarSystem::turn(const TurnCommand &turn_command) { this->movement_system->turn(turn_command); } diff --git a/app/raspberry_pi/src/car/system/CarSystem.h b/app/raspberry_pi/src/car/system/CarSystem.h index c6d9ad5f..ed3f0e19 100644 --- a/app/raspberry_pi/src/car/system/CarSystem.h +++ b/app/raspberry_pi/src/car/system/CarSystem.h @@ -24,7 +24,7 @@ namespace car::system { CarSystem(const std::string& websocket_url, std::unique_ptr lidar_device, std::unique_ptr messaging_system, std::unique_ptr movement_system); ~CarSystem(); - void initalize(); + void initialize(); void start(); void update(); @@ -38,6 +38,7 @@ namespace car::system { std::unique_ptr messaging_system; std::unique_ptr movement_system; + bool running = false; bool terminated = false; }; } diff --git a/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx b/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx index 86937601..fb4e6ff6 100644 --- a/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx +++ b/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx @@ -29,7 +29,7 @@ namespace car::system::messaging { MessagingSystem(const std::string& websocket_url) : websocket_url(websocket_url) { }; - void initalize() + void initialize() { ix::initNetSystem(); this->websocket.setUrl(websocket_url); diff --git a/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx b/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx index a550f474..37bfce24 100644 --- a/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx +++ b/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx @@ -26,7 +26,7 @@ namespace car::system::movement { MovementSystem() { }; - void initalize() + void initialize() { this->pwm->init(1, 0x40); std::this_thread::sleep_for(std::chrono::milliseconds(100));