Skip to content

Commit

Permalink
Add code for setting wheel variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 9, 2024
1 parent 75ad817 commit c50e890
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/raspberry_pi/src/car/display/CarConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ namespace car::display {
// main thread). Using `screen.Post(task)` is threadsafe.
screen.Post([&]
{
this->car_system->setFrontWheelsAngle({ front_wheel_angle * 1.0f });
this->car_system->setRearWheelsSpeed({ rear_wheel_speed });
this->car_system->update();
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ namespace car::system::movement::wheels
}

// Some of the code was from: https://github.com/chaoticmachinery/pca9685
int setAngle(const int& angle)
void setAngle(const int& angle)
{
this->angle = std::clamp(angle, 0, 180);
const int new_angle = std::clamp(angle, 0, 180);
if (new_angle == this->angle) {
return;
}
this->angle = new_angle;
int analog_angle = getAnalogAngle();
this->pwm->setPWM(channel, 0, analog_angle);
spdlog::info("Channel: {} \tAngle: {} \tAnalog Angle: {}", this->channel, angle, analog_angle);
return (0);
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ namespace car::system::movement::wheels

void setSpeed(const int &speed)
{
this->speed = std::clamp(speed, 0, 100);
const int new_speed = std::clamp(speed, 0, 100);
if (new_speed == this->speed)
{
return;
}
this->speed = new_speed;
const int pulse_wide = (this->speed / 100.0f) * 4095;
this->pwm->setPWM(PWM_A, 0, pulse_wide);
}
Expand Down

0 comments on commit c50e890

Please sign in to comment.