Smartcar Shield
Loading...
Searching...
No Matches
AckermanControl.cpp
Go to the documentation of this file.
1#include "AckermanControl.hpp"
2
3#include "../../utilities/Utilities.hpp"
4
5using namespace smartcarlib::utils;
8
10 : mSteering(steering)
11 , mThrottling(throttling)
12{
13}
14
16{
22 mSteering.setSpeed(speed);
23}
24
26{
28 mThrottling.setSpeed(speed);
29}
30
31void 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}
void setAngle(int angle) override
Sets the driving angle in degrees [-90, 90].
void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed) override
Set the motor speed individually as a percentage of the motors` total power.
AckermanControl(Motor &steering, Motor &throttling)
Constructs an Ackerman way of controlling the vehicle.
void setSpeed(int speed) override
Sets the driving speed as percentage of the total motor speed where the sign represents the direction...
Interface programmatically representing any kind of motor.
Definition Motor.hpp:23
virtual void setSpeed(int speed)=0
Sets the motor speed and direction as the percentage of the maximum possible speed,...
constexpr AnyNumber getMap(AnyNumber valueToMap, AnyNumber fromLow, AnyNumber fromHigh, AnyNumber toLow, AnyNumber toHigh)
Maps a value from a range to another.
constexpr AnyNumber getConstrain(AnyNumber number, AnyNumber min, AnyNumber max)
Limit the number between a range.
Definition Utilities.hpp:46