Smartcar Shield
AckermanControl.cpp
Go to the documentation of this file.
1 #include "AckermanControl.hpp"
2 
3 #include "../../utilities/Utilities.hpp"
4 
5 using namespace smartcarlib::utils;
6 using namespace smartcarlib::constants::control;
7 using namespace smartcarlib::constants::motor;
8 
10  : mSteering(steering)
11  , mThrottling(throttling)
12 {
13 }
14 
16 {
22  mSteering.setSpeed(speed);
23 }
24 
26 {
28  mThrottling.setSpeed(speed);
29 }
30 
31 void AckermanControl::overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed)
32 {
33  firstMotorSpeed = getConstrain(firstMotorSpeed, kMinMotorSpeed, kMaxMotorSpeed);
34  secondMotorSpeed = getConstrain(secondMotorSpeed, kMinMotorSpeed, kMaxMotorSpeed);
35 
36  mSteering.setSpeed(firstMotorSpeed);
37  mThrottling.setSpeed(secondMotorSpeed);
38 }
AckermanControl::overrideMotorSpeed
void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed) override
Set the motor speed individually as a percentage of the motors` total power.
Definition: AckermanControl.cpp:31
smartcarlib::constants::motor::kMaxMotorSpeed
const int kMaxMotorSpeed
Definition: Motor.hpp:17
smartcarlib::constants::control::kMaxControlAngle
const int kMaxControlAngle
Definition: Control.hpp:15
Motor
Definition: Motor.hpp:22
smartcarlib::utils::getMap
constexpr AnyNumber getMap(AnyNumber valueToMap, AnyNumber fromLow, AnyNumber fromHigh, AnyNumber toLow, AnyNumber toHigh)
Maps a value from a range to another.
Definition: Utilities.hpp:104
smartcarlib::constants::motor
Definition: Motor.hpp:13
AckermanControl::setAngle
void setAngle(int angle) override
Sets the driving angle in degrees [-90, 90].
Definition: AckermanControl.cpp:15
AckermanControl.hpp
AckermanControl::AckermanControl
AckermanControl(Motor &steering, Motor &throttling)
Constructs an Ackerman way of controlling the vehicle.
Definition: AckermanControl.cpp:9
smartcarlib::utils
Definition: Utilities.hpp:9
AckermanControl::setSpeed
void setSpeed(int speed) override
Sets the driving speed as percentage of the total motor speed where the sign represents the direction...
Definition: AckermanControl.cpp:25
smartcarlib::constants::motor::kMinMotorSpeed
const int kMinMotorSpeed
Definition: Motor.hpp:15
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
Motor::setSpeed
virtual void setSpeed(int speed)=0
Sets the motor speed and direction as the percentage of the maximum possible speed,...