Skip to content

Commit

Permalink
Make initialize and start consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Dec 6, 2023
1 parent f063e65 commit 32d5435
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions raspberry_pi/src/car/display/CarConsole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ namespace car::display {

Loop loop(&screen, main_component);

this->car_system->initalize();
this->car_system->start();
// The main loop:
while (!loop.HasQuitted()) {
this->car_system->update();
Expand Down
2 changes: 1 addition & 1 deletion raspberry_pi/src/car/system/CarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace car::system {
CarSystem::CarSystem(const std::string& websocket_url, std::unique_ptr<LidarDevice> lidar_device, std::unique_ptr<MessagingSystem> messaging_system) : lidar_device(std::move(lidar_device)), messaging_system(std::move(messaging_system))
{
this->initalize();
}

CarSystem::~CarSystem()
Expand All @@ -14,6 +13,7 @@ namespace car::system {
void CarSystem::initalize()
{
this->messaging_system->initalize();
this->lidar_device->initialize();

this->messaging_system->move_command_signal.connect([this](MoveCommand move_command) {
this->move(move_command);
Expand Down
1 change: 1 addition & 0 deletions raspberry_pi/src/car/system/lidar/LidarDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace car::system::lidar {
class LidarDevice
{
public:
virtual void initialize() const = 0;
virtual void start() const = 0;
virtual std::vector<Measure> scan() const = 0;
virtual void terminate() const = 0;
Expand Down
2 changes: 2 additions & 0 deletions raspberry_pi/src/car/system/lidar/LidarDummy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace car::system::lidar {
{
};

void initialize() const override {};

void start() const override {};

std::vector<Measure> scan() const override
Expand Down
16 changes: 8 additions & 8 deletions raspberry_pi/src/car/system/lidar/LidarScanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ namespace car::system::lidar
public:
LidarScanner(const std::string &lidar_port) : lidar(RPLidar::create(lidar_port).value())
{
this->initialize();
};

~LidarScanner()
{
this->terminate();
};

void initialize() const
{
this->lidar->reset();
this->lidar->stop();
this->lidar->stop_motor();
};

void start() const
{
this->lidar->start_motor();
Expand Down Expand Up @@ -59,13 +66,6 @@ namespace car::system::lidar
}

private:
void initialize() const
{
this->lidar->reset();
this->lidar->stop();
this->lidar->stop_motor();
};

std::unique_ptr<RPLidar> lidar;
};
}
Expand Down
1 change: 0 additions & 1 deletion raspberry_pi/src/car/system/messaging/MessagingSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace car::system::messaging {
{
public:
MessagingSystem(const std::string& websocket_url) : websocket_url(websocket_url) {

};

void initalize()
Expand Down

0 comments on commit 32d5435

Please sign in to comment.