Skip to content

Commit

Permalink
Able to change direction of rear wheels via cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 11, 2024
1 parent 97b500a commit e182f8a
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 21 deletions.
54 changes: 52 additions & 2 deletions app/raspberry_pi/src/car/display/CarConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,12 @@ namespace car::display {
if (connected) {
this->car_system->startLidarDevice();
lidar_motor_status = LIDAR_MOTOR_ENABLED_MESSAGE;
lidar_motor_loading_debounce = false;
}
else {
this->car_system->stopLidarDevice();
lidar_motor_status = LIDAR_MOTOR_DISABLED_MESSAGE;
lidar_motor_loading_debounce = false;
}
lidar_motor_loading_debounce = false;
}
);

Expand All @@ -243,6 +242,46 @@ namespace car::display {
auto rear_left_wheel_speed_slider = Slider("Left Rear Wheel Speed:", &rear_left_wheel_speed_slider_value, 0, 100, 1);
auto rear_right_wheel_speed_slider = Slider("Right Rear Wheel Speed:", &rear_right_wheel_speed_slider_value, 0, 100, 1);

static constexpr auto REAR_WHEEL_DIRECTION_FORWARD_MESSAGE = "Rear Wheel Direction: Forward";
static constexpr auto REAR_WHEEL_DIRECTION_BACKWARD_MESSAGE = "Rear Wheel Direction: Backward";

nod::signal<void(bool)> rear_wheel_direction_signal;

bool rear_wheel_direction_debounce = false;
std::string rear_wheel_direction_status = LIDAR_MOTOR_DISABLED_MESSAGE;
bool rear_wheel_direction = true;
auto rear_wheel_direction_checkbox_option = CheckboxOption::Simple();
rear_wheel_direction_checkbox_option.on_change = [&]
{
if (rear_wheel_direction_debounce) {
rear_wheel_direction = !rear_wheel_direction;
return;
}
rear_wheel_direction_debounce = true;
if (rear_wheel_direction) {
rear_wheel_direction_status = REAR_WHEEL_DIRECTION_FORWARD_MESSAGE;
}
else {
rear_wheel_direction_status = REAR_WHEEL_DIRECTION_BACKWARD_MESSAGE;
}
rear_wheel_direction_signal(rear_wheel_direction);
};

rear_wheel_direction_signal.connect([&](bool direction)
{
if (direction) {
this->car_system->setRearWheelDirectionToForwards();
rear_wheel_direction_status = REAR_WHEEL_DIRECTION_FORWARD_MESSAGE;
}
else {
this->car_system->setRearWheelDirectionToBackwards();
rear_wheel_direction_status = REAR_WHEEL_DIRECTION_BACKWARD_MESSAGE;
}
rear_wheel_direction_debounce = false;
}
);
auto rear_wheel_direction_checkbox_component = Checkbox(&rear_wheel_direction_status, &rear_wheel_direction, rear_wheel_direction_checkbox_option);

int previous_front_wheels_angle_slider_value = DEFAULT_FRONT_WHEEL_ANGLE;

int front_wheels_angle_slider_value = DEFAULT_FRONT_WHEEL_ANGLE;
Expand All @@ -253,15 +292,20 @@ namespace car::display {
auto front_left_wheel_angle_slider = Slider("Left Front Wheel Angle:", &front_left_wheel_angle_slider_value, 0, 180, 1);
auto front_right_wheel_angle_slider = Slider("Right Front Wheel Angle:", &front_right_wheel_angle_slider_value, 0, 180, 1);

auto rear_wheel_menu_entry = MenuEntry("Rear Wheel:") | bold;
auto front_wheel_menu_entry = MenuEntry("Front Wheel:") | bold;

auto slider_container =
Container::Horizontal({
Container::Vertical({
rear_wheel_menu_entry,
rear_wheel_speed_slider,
rear_left_wheel_speed_slider,
rear_right_wheel_speed_slider,
rear_wheel_direction_checkbox_component,
}),
Container::Vertical({
front_wheel_menu_entry,
front_wheels_angle_slider,
front_left_wheel_angle_slider,
front_right_wheel_angle_slider,
Expand All @@ -272,16 +316,22 @@ namespace car::display {
return
hbox({
vbox({
rear_wheel_menu_entry->Render(),
separator(),
rear_wheel_speed_slider->Render(),
separator(),
rear_left_wheel_speed_slider->Render(),
rear_right_wheel_speed_slider->Render(),
separator(),
text("Left Rear Wheel Speed: " + std::to_string(rear_left_wheel_speed_slider_value)),
text("Right Rear Wheel Speed: " + std::to_string(rear_right_wheel_speed_slider_value)),
separator(),
rear_wheel_direction_checkbox_component->Render(),
}) | xflex,
separator(),
vbox({
front_wheel_menu_entry->Render(),
separator(),
front_wheels_angle_slider->Render(),
separator(),
front_left_wheel_angle_slider->Render(),
Expand Down
9 changes: 9 additions & 0 deletions app/raspberry_pi/src/car/system/CarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,13 @@ namespace car::system
{
this->movement_system->setFrontRightWheelAngle(angle_command);
}

void CarSystem::setRearWheelDirectionToForwards()
{
this->movement_system->setRearWheelDirectionToForwards();
}
void CarSystem::setRearWheelDirectionToBackwards()
{
this->movement_system->setRearWheelDirectionToBackwards();
}
}
3 changes: 3 additions & 0 deletions app/raspberry_pi/src/car/system/CarSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace car::system {
void setFrontLeftWheelAngle(const AngleCommand& angle_command);
void setFrontRightWheelAngle(const AngleCommand& angle_command);

void setRearWheelDirectionToForwards();
void setRearWheelDirectionToBackwards();

const std::vector<Measure>& getScanData() const { return this->scan_data; }

private:
Expand Down
9 changes: 9 additions & 0 deletions app/raspberry_pi/src/car/system/movement/MovementSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ namespace car::system::movement {
{
this->wheel_controller->setFrontRightWheelAngle(angle_command);
}

void setRearWheelDirectionToForwards()
{
this->wheel_controller->setRearWheelDirectionToForwards();
}
void setRearWheelDirectionToBackwards()
{
this->wheel_controller->setRearWheelDirectionToBackwards();
}
#pragma endregion


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace car::system::movement::controller

virtual void setFrontLeftWheelAngle(const AngleCommand& angle_command) = 0;
virtual void setFrontRightWheelAngle(const AngleCommand& angle_command) = 0;

virtual void setRearWheelDirectionToForwards() = 0;
virtual void setRearWheelDirectionToBackwards() = 0;
};
} // namespace car::system::movement::controller

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ namespace car::system::movement::controller
this->front_right_wheel->setAngle(angle_command.angle);
}

void setRearWheelDirectionToForwards() override {
this->rear_left_wheel->forward();
this->rear_right_wheel->forward();
}

void setRearWheelDirectionToBackwards() override {
this->rear_left_wheel->backward();
this->rear_right_wheel->backward();
}

private:
std::shared_ptr<PCA9685> pwm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,44 @@

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

void setRearWheelsSpeed(const SpeedCommand &speed_command) override {

}
void setRearWheelsSpeed(const SpeedCommand& speed_command) override {

void setFrontWheelsAngle(const AngleCommand &angle_command) override {
}

}
void setFrontWheelsAngle(const AngleCommand& angle_command) override {

void setRearLeftWheelSpeed(const SpeedCommand& speed_command) override {
}

}
void setRearLeftWheelSpeed(const SpeedCommand& speed_command) override {

void setRearRightWheelSpeed(const SpeedCommand& speed_command) override {
}

}
void setRearRightWheelSpeed(const SpeedCommand& speed_command) override {

void setFrontLeftWheelAngle(const AngleCommand& angle_command) override {
}

}
void setFrontLeftWheelAngle(const AngleCommand& angle_command) override {

void setFrontRightWheelAngle(const AngleCommand& angle_command) override {
}

}
private:
};
void setFrontRightWheelAngle(const AngleCommand& angle_command) override {

}

void setRearWheelDirectionToForwards() override {

}

void setRearWheelDirectionToBackwards() override {

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

#endif

0 comments on commit e182f8a

Please sign in to comment.