Skip to content

Commit

Permalink
Add WheelController and allow compilation on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 5, 2024
1 parent 74d6d8f commit 58da5eb
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Car-Application.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@
"shared_mutex": "cpp",
"cinttypes": "cpp",
"filesystem": "cpp",
"variant": "cpp"
"variant": "cpp",
"complex": "cpp",
"queue": "cpp",
"ranges": "cpp"
}
}
}
28 changes: 10 additions & 18 deletions app/raspberry_pi/src/car/system/movement/MovementSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,26 @@

#include <memory>

#include "PCA9685.h"

#include "../messaging/commands/MoveCommand.cxx"
#include "../messaging/commands/TurnCommand.cxx"

#include "wheels/FrontWheel.cxx"
#include "wheels/RearWheel.cxx"
#include "controller/AbstractWheelController.cxx"

using namespace car::system::movement::controller;
using namespace car::system::messaging::commands;

namespace car::system::movement {
constexpr int MIN_PULSE_WIDTH = 900;
constexpr int MAX_PULSE_WIDTH = 2100;
constexpr int FREQUENCY = 50;

class MovementSystem
class MovementSystem
{
public:
MovementSystem() {
MovementSystem(std::unique_ptr<AbstractWheelController> wheel_controller) : wheel_controller(std::move(wheel_controller))
{
};

void initialize()
{
this->pwm->init(1, 0x40);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
this->pwm->setPWMFreq(FREQUENCY);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
this->wheel_controller->initialize();
}

void start()
{
Expand All @@ -42,18 +34,18 @@ namespace car::system::movement {
}

void move(const MoveCommand& move_command) {

this->wheel_controller->move(move_command);
}

void turn(const TurnCommand& turn_command) {

this->wheel_controller->turn(turn_command);
}

~MovementSystem() {
};

private:
std::unique_ptr<PCA9685> pwm;
std::unique_ptr<AbstractWheelController> wheel_controller;
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ABSTRACTWHEELCONTROLLER_CXX
#define ABSTRACTWHEELCONTROLLER_CXX

#pragma once

#include "../../messaging/commands/MoveCommand.cxx"
#include "../../messaging/commands/TurnCommand.cxx"

using namespace car::system::messaging::commands;

namespace car::system::movement::controller
{
class AbstractWheelController
{
public:
virtual void initialize() = 0;

virtual void move(const MoveCommand &move_command) = 0;
virtual void turn(const TurnCommand &turn_command) = 0;

private:
};
} // namespace car::system::movement::controller

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifdef __linux__
#ifndef CARWHEELCONTROLLER_CXX
#define CARWHEELCONTROLLER_CXX

#pragma once

#include <memory>
#include <thread>
#include <chrono>

#include <PCA9685.h>

#include "AbstractWheelController.cxx"

#include "../wheels/FrontWheel.cxx"
#include "../wheels/RearWheel.cxx"

namespace car::system::movement::controller
{
constexpr int MIN_PULSE_WIDTH = 900;
constexpr int MAX_PULSE_WIDTH = 2100;
constexpr int FREQUENCY = 50;
class CarWheelController : public AbstractWheelController
{
public:
CarWheelController() {};
~CarWheelController() {};

void initialize() override {
this->pwm->init(1, 0x40);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
this->pwm->setPWMFreq(FREQUENCY);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}

void move(const MoveCommand& move_command) override {

}

void turn(const TurnCommand& turn_command) override {

}

private:
std::unique_ptr<PCA9685> pwm;

};
} // namespace car::system::movement::controller

#endif
#endif // __linux__
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef DUMMYWHEELCONTROLLER_CXX
#define DUMMYWHEELCONTROLLER_CXX

#pragma once

#include "AbstractWheelController.cxx"

namespace car::system::movement::controller
{
class DummyWheelController : public AbstractWheelController
{
public:
void initialize(){};

void move(const MoveCommand &move_command){};
void turn(const TurnCommand &turn_command){};

private:
};
} // namespace car::system::movement::controller

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
#ifndef FRONTWHEEL_CXX
#define FRONTWHEEL_CXX

Expand Down Expand Up @@ -58,4 +59,5 @@ namespace car::system::movement::wheels
};
} // namespace car::system::movement::wheels

#endif
#endif
#endif // __linux__
2 changes: 2 additions & 0 deletions app/raspberry_pi/src/car/system/movement/wheels/RearWheel.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
#ifndef REARWHEEL_CXX
#define REARWHEEL_CXX

Expand Down Expand Up @@ -91,4 +92,5 @@ namespace car::system::movement::wheels
};
} // namespace car::system::movement::wheels

#endif
#endif
5 changes: 4 additions & 1 deletion app/raspberry_pi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "car/system/lidar/LidarScanner.cxx"
#include "car/system/lidar/LidarDummy.cxx"

#include "car/system/movement/controller/DummyWheelController.cxx"

std::string getWebSocketUrl()
{
std::optional<int> maybe_port = GET_CONFIG_VALUE(port);
Expand All @@ -33,6 +35,7 @@ int main()
using namespace car::system;
using namespace car::system::lidar;
using namespace car::system::messaging;
using namespace car::system::movement::controller;
using namespace rplidar;

// spdlog::set_level(spdlog::level::off);
Expand All @@ -50,7 +53,7 @@ int main()

std::unique_ptr<MessagingSystem> messaging_system = std::make_unique<MessagingSystem>(websocket_url);

std::unique_ptr<MovementSystem> movement_system = std::make_unique<MovementSystem>();
std::unique_ptr<MovementSystem> movement_system = std::make_unique<MovementSystem>(std::make_unique<DummyWheelController>());

auto car_system = std::make_unique<CarSystem>(
websocket_url,
Expand Down

0 comments on commit 58da5eb

Please sign in to comment.