Smartcar Shield
SimpleCar.cpp
Go to the documentation of this file.
1 #include "SimpleCar.hpp"
2 #include "../../utilities/Utilities.hpp"
3 
4 using namespace smartcarlib::constants::control;
5 using namespace smartcarlib::utils;
6 
8  : mControl(control)
9 {
10 }
11 
12 void SimpleCar::setSpeed(float speed)
13 {
14  mControl.setSpeed(getConstrain(static_cast<int>(speed), kMinControlSpeed, kMaxControlSpeed));
15 }
16 
17 void SimpleCar::setAngle(int angle)
18 {
20 }
21 
22 void SimpleCar::overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed)
23 {
25  getConstrain(secondMotorSpeed, kMinControlSpeed, kMaxControlSpeed));
26 }
smartcarlib::constants::control::kMinControlSpeed
const int kMinControlSpeed
Definition: Control.hpp:16
SimpleCar.hpp
SimpleCar::setAngle
void setAngle(int angle) override
Set the car's driving angle.
Definition: SimpleCar.cpp:17
SimpleCar::SimpleCar
SimpleCar(Control &control)
Constructs a simple car.
Definition: SimpleCar.cpp:7
smartcarlib::constants::control::kMaxControlAngle
const int kMaxControlAngle
Definition: Control.hpp:15
SimpleCar::setSpeed
void setSpeed(float speed) override
Sets the car's driving speed as a percentage of the motors total speed where the sign indicates direc...
Definition: SimpleCar.cpp:12
SimpleCar::overrideMotorSpeed
void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed) override
Set the motor speed individually as a percentage of the motors` total power.
Definition: SimpleCar.cpp:22
Control
Definition: Control.hpp:23
Control::setSpeed
virtual void setSpeed(int speed)=0
Sets the driving speed as percentage of the total motor speed where the sign represents the direction...
smartcarlib::constants::control::kMaxControlSpeed
const int kMaxControlSpeed
Definition: Control.hpp:18
Control::setAngle
virtual void setAngle(int angle)=0
Sets the driving angle in degrees [-90, 90].
smartcarlib::utils
Definition: Utilities.hpp:9
smartcarlib::constants::control::kMinControlAngle
const int kMinControlAngle
Definition: Control.hpp:13
smartcarlib::constants::control
Definition: Control.hpp:11
smartcarlib::utils::getConstrain
constexpr AnyNumber getConstrain(AnyNumber number, AnyNumber min, AnyNumber max)
Limit the number between a range.
Definition: Utilities.hpp:46
Control::overrideMotorSpeed
virtual void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed)=0
Set the motor speed individually as a percentage of the motors` total power.