Smartcar Shield
Loading...
Searching...
No Matches
DistanceCar.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include "../../runtime/Runtime.hpp"
8#include "../../sensors/odometer/Odometer.hpp"
9#include "../simple/SimpleCar.hpp"
10
11namespace smartcarlib
12{
13namespace constants
14{
15namespace car
16{
17const unsigned long kDefaultPidFrequency = 80;
18const float kDefaultProportional = 5.0F;
19const float kDefaultIntegral = 0.0F;
20const float kDefaultDerivative = 10.0F;
22const auto kBreakSpeedScale = 10;
23} // namespace car
24} // namespace constants
25} // namespace smartcarlib
26
27class DistanceCar : virtual public SimpleCar
28{
29public:
49 DistanceCar(Runtime& runtime, Control& control, Odometer& odometer);
50
75 DistanceCar(Runtime& runtime,
76 Control& control,
77 Odometer& odometerLeft,
78 Odometer& odometerRight);
79
90 long getDistance();
91
113 void setSpeed(float speed) override;
114
124 float getSpeed();
125
143 unsigned long frequency
145
160 virtual void update();
161
171
187 void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed) override;
188
189private:
190 Odometer& mOdometerLeft;
191 Odometer& mOdometerRight;
192 Runtime& mRuntime;
193 bool mCruiseControlEnabled{ false };
194 float mProportional{ 0 };
195 float mIntegral{ 0 };
196 float mDerivative{ 0 };
197 unsigned long mFrequency{ 0 };
198 unsigned long mPreviousUpdate{ 0 };
199 float mTargetSpeed{ 0 };
200 float mPreviousControlledSpeed{ 0 };
201 float mIntegratedError{ 0 };
202 float mPreviousError{ 0 };
203
204 bool areOdometersAttached() const;
205 bool areOdometersDirectional() const;
206 float controlMotorSpeed(float previousSpeed, float targetSpeed, float currentSpeed);
207
211 void brake();
212};
213
Interface to generalize all classes that can provide a way to control a Car.
Definition Control.hpp:24
A class to programmatically represent a vehicle equipped with odometers.
long getDistance()
Gets the car's travelled distance.
void overrideMotorSpeed(int firstMotorSpeed, int secondMotorSpeed) override
Sets the motor speed individually as a percentage of the motors` total power unless cruise control is...
virtual void update()
Adjusts the cruise control speed.
void disableCruiseControl()
Disable cruise control.
void setSpeed(float speed) override
Sets the car's speed in meters per second if cruise control is enabled otherwise as a percentage of t...
float getSpeed()
Gets the car's current speed in meters per second.
void enableCruiseControl(float proportional=smartcarlib::constants::car::kDefaultProportional, float integral=smartcarlib::constants::car::kDefaultIntegral, float derivative=smartcarlib::constants::car::kDefaultDerivative, unsigned long frequency=smartcarlib::constants::car::kDefaultPidFrequency)
Enables the car to move with a stable speed using the odometers.
An interface to programmatically represent all odometers.
Definition Odometer.hpp:27
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36
A class to programmatically represent a very basic vehicle with two motors.
Definition SimpleCar.hpp:11
const unsigned long kDefaultPidFrequency