Smartcar Shield
 All Classes Namespaces Files Functions Variables Macros
Public Member Functions | List of all members
DistanceCar Class Reference

A class to programmatically represent a vehicle equipped with odometers. More...

#include <DistanceCar.hpp>

Inheritance diagram for DistanceCar:
Inheritance graph
Collaboration diagram for DistanceCar:
Collaboration graph

Public Member Functions

 DistanceCar (Control &control, Odometer &odometer, Runtime &runtime)
 
 DistanceCar (Control &control, Odometer &odometerLeft, Odometer &odometerRight, Runtime &runtime)
 
long getDistance ()
 Gets the car's travelled distance. More...
 
virtual void setSpeed (float speed) override
 Sets the car's speed in meters per second if cruise control is enabled otherwise as a percentage of the motor speed. More...
 
float getSpeed ()
 Gets the car's current speed in meters per second. More...
 
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. More...
 
virtual void update ()
 Adjusts the cruise control speed. More...
 
void disableCruiseControl ()
 Disable cruise control. More...
 
virtual void overrideMotorSpeed (int firstMotorSpeed, int secondMotorSpeed) override
 Sets the motor speed individually as a percentage of the motors` total power unless cruise control is enabled in which case has no effect. More...
 
- Public Member Functions inherited from SimpleCar
 SimpleCar (Control &control)
 Constructs a simple car. More...
 
virtual ~SimpleCar ()=default
 
virtual void setAngle (int angle) override
 Set the car's driving angle. More...
 
- Public Member Functions inherited from Car
virtual ~Car ()=default
 

Detailed Description

A class to programmatically represent a vehicle equipped with odometers.

Examples:
DistanceCar.ino, manualWithCruiseControl.ino, and PidControllerMonitor.ino.

Definition at line 31 of file DistanceCar.hpp.

Constructor & Destructor Documentation

DistanceCar::DistanceCar ( Control control,
Odometer odometer,
Runtime runtime 
)

Definition at line 17 of file DistanceCar.cpp.

DistanceCar::DistanceCar ( Control control,
Odometer odometerLeft,
Odometer odometerRight,
Runtime runtime 
)

Definition at line 36 of file DistanceCar.cpp.

Member Function Documentation

void DistanceCar::disableCruiseControl ( )

Disable cruise control.

Example:

car.disableCruiseControl();

Definition at line 205 of file DistanceCar.cpp.

void DistanceCar::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.

Parameters
proportionalThe proportional value of the PID controller
integralThe integral value of the PID controller
derivativeThe derivative value of the PID controller
frequencyHow often to adjust the speed using update()

Example:

// Start adjusting the speed using a PID controller with
// P = 2, I = 0.1, D = 0.5 every 80 milliseconds
car.enableCruiseControl(2, 0.1, 0.5, 80);

Definition at line 210 of file DistanceCar.cpp.

long DistanceCar::getDistance ( )

Gets the car's travelled distance.

Returns
The car's travelled distance

Example:

// After we have attached the odometers, we can get the travelled distance
long travelledDistance = car.getDistance();

Definition at line 58 of file DistanceCar.cpp.

Here is the call graph for this function:

float DistanceCar::getSpeed ( )

Gets the car's current speed in meters per second.

Returns
The car's speed

Example:

float currentSpeed = car.getSpeed();

Definition at line 199 of file DistanceCar.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void DistanceCar::overrideMotorSpeed ( int  firstMotorSpeed,
int  secondMotorSpeed 
)
overridevirtual

Sets the motor speed individually as a percentage of the motors` total power unless cruise control is enabled in which case has no effect.

Use with caution.

Parameters
firstMotorSpeedThe speed of the motor passed as first argument argument to the car's control class [-100, 100]
secondMotorSpeedThe speed of the motor passed as second argument argument to the car's control class [-100, 100]

Example:

// Make the car spin around
car.overrideMotorSpeed(100, -100);

Reimplemented from SimpleCar.

Definition at line 232 of file DistanceCar.cpp.

Here is the call graph for this function:

void DistanceCar::setSpeed ( float  speed)
overridevirtual

Sets the car's speed in meters per second if cruise control is enabled otherwise as a percentage of the motor speed.

Sign in both cases determines direction.

Parameters
speedThe car's speed

Example (with cruise control):

car.enableCruiseControl();
float speedInMetersPerSecond = -0.8;
// Set speed to 0.8 meters per second backward
car.setSpeed(speedInMetersPerSecond);

Example (without cruise control):

float speedInPercentageOfMotorPower = 50;
// Set speed to half of the maximum motor speed forward
car.setSpeed(speedInPercentageOfMotorPower);

Reimplemented from SimpleCar.

Definition at line 64 of file DistanceCar.cpp.

Here is the call graph for this function:

void DistanceCar::update ( )
virtual

Adjusts the cruise control speed.

You must have this being executed as often as possible when having cruise control enabled. When cruise control is not enabled this has no effect.

Example:

void loop() {
// Update the car readings as often as possible
car.update();
// Other functionality
}

Reimplemented in SmartCar.

Definition at line 134 of file DistanceCar.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: