Robotic Car Controller 1.0
Library to manage a two wheeled robotic vehicle (Stepper Motors)
MD_SmartCar2 Class Reference

#include <MD_SmartCar2.h>

Collaboration diagram for MD_SmartCar2:

Classes

struct  actionItem_t
 

Public Member Functions

Class constructor and destructor.
 MD_SmartCar2 (MD_Stepper *ml, MD_Stepper *mr)
 
 ~MD_SmartCar2 (void)
 
Methods for core object control.
bool begin (uint16_t ppr, uint16_t ppsMax, uint16_t dWheel, uint16_t lBase)
 
void setVehicleParameters (uint16_t ppr, uint16_t ppsMax, uint16_t dWheel, uint16_t lBase)
 
void run (void)
 
bool isRunning (void)
 
bool isRunning (uint8_t mtr)
 
Methods for free running the vehicle.
void drive (int8_t vLinear, int8_t vAngularD)
 
void drive (int8_t vLinear)
 
void drive (int8_t vLinear, float vAngularR)
 
void stop (bool insideSequence=false)
 
void setLinearVelocity (int8_t vel)
 
int8_t getLinearVelocity (void)
 
void setAngularVelocity (float angR)
 
void setAngularVelocity (int8_t angD)
 
float getAngularVelocity (void)
 
void setAccelProfile (uint16_t timebase, uint8_t steps)
 
Methods for precision movements of the vehicle.
void move (float angL, float angR)
 
void move (int16_t angL, int16_t angR)
 
void move (int16_t len)
 
void spin (int16_t fraction)
 
void startSequence (const actionItem_t *actionList)
 
void startSequence (actionItem_t *actionList)
 
void stopSequence (void)
 
bool isSequenceComplete (void)
 
Methods for Configuration Management.
uint16_t getPulsePerRev ()
 
float getDistancePerPulse ()
 
Utility methods.
float deg2rad (int16_t deg)
 
float len2rad (int16_t len)
 

Structures, Enumerated Types and Constants.

enum  actionId_t {
  DRIVE , MOVE , SPIN , PAUSE ,
  STOP , END
}
 
static const uint8_t MAX_MOTOR = 2
 

Detailed Description

Core object for the MD_SmartCar2 library

Member Enumeration Documentation

◆ actionId_t

Enumerated type for Action Items operation

Specifies which operation is being defined in the actionItem_t

Enumerator
DRIVE 

executes drive(); param 0 lin vel, param 1 angular velocity

MOVE 

executes a move(); param 0 left rotate, param 1 right rotate

SPIN 

executes a spin(); param 0 spin percentage

PAUSE 

executes a pause; param 0 milliseconds pause

STOP 

executes a stop()

END 

marks the end of the action list; should always be last item.

Constructor & Destructor Documentation

◆ MD_SmartCar2()

MD_SmartCar2::MD_SmartCar2 ( MD_Stepper *  ml,
MD_Stepper *  mr 
)

Class Constructor

Instantiate a new instance of the class. This variant is for motor controllers that have a PWM input for speed control.

The main function for the core object is to reset the internal shared variables and timers to default values.

Parameters
mlThe MD_Stepper object for controlling the left side motor.
mrThe MD_Stepper object for controlling the right side motor.

◆ ~MD_SmartCar2()

MD_SmartCar2::~MD_SmartCar2 ( void  )

Class Destructor.

Release any allocated memory and clean up anything else.

Member Function Documentation

◆ begin()

bool MD_SmartCar2::begin ( uint16_t  ppr,
uint16_t  ppsMax,
uint16_t  dWheel,
uint16_t  lBase 
)

Initialize the object.

Initialize the object data. This needs to be called during setup() to reset new items that cannot be done during object creation.

Vehicle constants are passed through to the setVehicleParameters() method. See comments for that method for more details.

See also
setVehicleParameters();
Parameters
pprNumber of encoder pulses per wheel revolution.
ppsMaxMaximum number of encoder pulses per second at top speed (100% velocity).
dWheelWheel diameter in mm.
lBaseBase length (distance between wheel centers) in mm
Returns
false if either encoder did not reset, true otherwise.

◆ deg2rad()

float MD_SmartCar2::deg2rad ( int16_t  deg)

Convert degrees to radians.

Convert the degrees measure specified into radians.

Parameters
degthe value in degrees to be converted.
Returns
the converted value

◆ drive() [1/3]

void MD_SmartCar2::drive ( int8_t  vLinear)

Drive the vehicle along a straight path.

Run the vehicle along a straight path with the specified velocity.

The velocity is specified as a percentage of the maximum vehicle velocity [-100..100]. Positive velocity move the vehicle forward, negative moves it in reverse. The speed will be adjusted using the acceleration parameters.

See also
getLinearVelocity(), setAccelProfile()
Parameters
vLinearthe linear velocity as a percentage of full scale [-100..100].

◆ drive() [2/3]

void MD_SmartCar2::drive ( int8_t  vLinear,
float  vAngularR 
)

Drive the vehicle along specified path (radians).

Run the vehicle along a path with the specified velocity and angular orientation.

The velocity is specified as a percentage of the maximum vehicle velocity [-100..100]. Positive velocity move the vehicle forward, negative moves it in reverse. The speed will be adjusted using the acceleration parameters.

Angular velocity direction is specified in radians per second [-pi/2..pi/2]. Positive angle is clockwise rotation.

See also
getLinearVelocity(), getAngularVelocity(), setAccelProfile()
Parameters
vLinearthe linear velocity as a percentage of full scale [-100..100].
vAngularRthe angular velocity in radians per second [-pi/2..pi/2].

◆ drive() [3/3]

void MD_SmartCar2::drive ( int8_t  vLinear,
int8_t  vAngularD 
)

Drive the vehicle along specified path (degrees).

Run the vehicle along a path with the specified velocity and angular orientation.

The velocity is specified as a percentage of the maximum vehicle velocity [0..100]. Positive velocity move the vehicle forward, negative moves it in reverse. The speed will be adjusted using the acceleration parameters.

Angular velocity is specified in degrees per second [-90..90]. Positive angle is clockwise rotation.

See also
getLinearVelocity(), getAngularVelocity(), setAccelProfile()
Parameters
vLinearthe linear velocity as a percentage of full scale [-100..100].
vAngularDthe angular velocity in degrees per second [-90..90].

◆ getAngularVelocity()

float MD_SmartCar2::getAngularVelocity ( void  )

Get the current angular velocity.

Angular velocity is expressed in radians relative to the forward direction [-PI/2..PI/2]. Positive angle is turn to the right, negative left.

See also
drive()
Returns
the current angular speed setting.

◆ getDistancePerPulse()

float MD_SmartCar2::getDistancePerPulse ( )

Read linear length moved per wheel pulse

Returns the distance traveled for each pulse of the motor.

See also
setVehicleParameters()
Returns
The distance travelled with each pulse.

◆ getLinearVelocity()

int8_t MD_SmartCar2::getLinearVelocity ( void  )

Get the current linear velocity.

Linear velocity is expressed as a percentage of the maximum velocity [-100..100]. The Master velocity is used to regulate all the speed functions for the motors.

See also
drive()
Returns
the current linear speed setting.

◆ getPulsePerRev()

uint16_t MD_SmartCar2::getPulsePerRev ( )

Read pulses per wheel revolution

Returns the number of pulses per encoder revolution. This may be needed to change from number of pulses to revolutions and then distance.

See also
setVehicleParameters()
Returns
The number of pulses per revolution.

◆ isRunning() [1/2]

bool MD_SmartCar2::isRunning ( uint8_t  mtr)

Check if specific motor is running

Check if motors are commanded to run. This method is useful to check when drive() or move() have completed their motions.

Parameters
mtrThe motor number being queried [0..MAX_MOTOR-1]
Returns
true if any of the motors are not idle

◆ isRunning() [2/2]

bool MD_SmartCar2::isRunning ( void  )

Check if motors are running

Check if motors are commanded to run. This method is useful to check when drive() or move() have completed their motions.

Returns
true if any of the motors are not idle

◆ isSequenceComplete()

bool MD_SmartCar2::isSequenceComplete ( void  )

Check if the current action sequence has completed.

Once an action sequqnce is started it will automatically execute to completion unless interrupted. This method checks to see if the action sequqnce has completed.

See also
startSequence()
Returns
true if the sequence has finished executing

◆ len2rad()

float MD_SmartCar2::len2rad ( int16_t  len)

Convert a length to angle of wheel rotation.

Convert a length in mm to travel into the radian of wheel rotation required for that travel.

Parameters
lenlength in mm to convert.
Returns
the angle in radians of wheel rotation to achieve that distance.

◆ move() [1/3]

void MD_SmartCar2::move ( float  angL,
float  angR 
)

Precisely move the vehicle (radians).

Controls the movement by counting the encoder pulses rather that PID, which should make it more precise and controlled. This is useful for specific movements run at slow speed.

The call to move() specifies the angle each wheels will turn, independently. This method is designed to allow close movements such as spin-in-place or other short precise motions.

The motion for each wheel is specified as speed as the total angle subtended by the turned by the wheel in radians. Negative angle is a reverse wheel rotation.

See also
drive(), spin(), len2rad()
Parameters
angLleft wheel angle subtended by the motion in radians.
angRright wheel angle subtended by the motion in radians.

◆ move() [2/3]

void MD_SmartCar2::move ( int16_t  angL,
int16_t  angR 
)

Precisely move the vehicle (degrees).

Controls the movement by counting the encoder pulses rather that PID, which should make it more precise and controlled. This is useful for specific movements run at slow speed.

The call to move() specifies the precise motion of the motors, independently. This method is designed to allow close movements such as spin-in-place or other short precise motions.

The motion for each wheel is specified as speed as the total angle subtended by the turned by the wheel in degrees. Negative angle is a reverse wheel rotation.

See also
drive(), spin()
Parameters
angLleft wheel angle subtended by the motion in degrees.
angRright wheel angle subtended by the motion in degrees.

◆ move() [3/3]

void MD_SmartCar2::move ( int16_t  len)

Precisely move the vehicle (millimeter).

Controls the movement by counting the encoder pulses rather that PID, which should make it more precise and controlled. This is useful for specific movements run at slow speed.

The call to move() specifies the precise motion of the motors, independently. This method is designed to allow close movements such as spin-in-place or other short precise motions.

The motion for each wheel will be identical to move the vehicle the required distance. Negative length is a reverse wheel rotation.

See also
drive(), spin()
Parameters
lendistance to move in mm.

◆ run()

void MD_SmartCar2::run ( void  )

Run the Robot Management Services.

This is called every iteration through loop() to run all the required Smart Car Management functions.

◆ setAccelProfile()

void MD_SmartCar2::setAccelProfile ( uint16_t  timebase,
uint8_t  steps 
)

Set the acceleration profile parameters

To make the best use of the stepper motor torque, speed changes are adjusted in incremental steps. The number of stepos is given by the steps parameter and the time between each step is given by the timebase parameter.

The library calculates the difference between the 2 speed (S2 - S1) and divides this by steps. During the acceleration/deceleration, the motor speed is changed by this quantity timebase time period until the new speed is reached.

Default values are the class private constants DEF_ACCEL_TIME and DEF_ACCEL_STEPS.

Parameters
timebasetime between acceleration steps (in milliseconds)
stepsnumber of dicrete steps between start and end speeds

◆ setAngularVelocity() [1/2]

void MD_SmartCar2::setAngularVelocity ( float  angR)

Set the angular velocity (radians).

Sets the angular velocity without changing any other parameters. Useful for adjusting turning when already in motion.

Angular velocity is expressed in radians relative to the forward direction [-PI/2..PI/2]. Positive angle is turn to the right, negative left.

See also
getAngularVelocity(), drive()
Parameters
angRthe new turning rate in radians.

◆ setAngularVelocity() [2/2]

void MD_SmartCar2::setAngularVelocity ( int8_t  angD)

Set the angular velocity (degrees).

Sets the angular velocity without changing any other parameters. Useful for adjusting turning when already in motion.

Angular velocity is expressed in degrees relative to the forward direction [-90..90]. Positive angle is turn to the right, negative left.

See also
getAngularVelocity(), drive()
Parameters
angDthe new turning rate in degrees.

◆ setLinearVelocity()

void MD_SmartCar2::setLinearVelocity ( int8_t  vel)

Set the linear velocity

Sets the linear velocity without changing any other parameters. Useful for adjusting the speed when already in motion. The vehicle will accelerate/decelerate to the new speed.

The velocity is specified as a percentage of the maximum vehicle velocity [-100..100]. Positive velocity move the vehicle forward, negative moves it in reverse.

/sa getLinearVelocity(), drive(), setAccelProfile()

Parameters
velthe new value for the linear velocity [-100..100].

◆ setVehicleParameters()

void MD_SmartCar2::setVehicleParameters ( uint16_t  ppr,
uint16_t  ppsMax,
uint16_t  dWheel,
uint16_t  lBase 
)

Set the vehicle constants

Sets the number of pulses per encoder revolution, maximum speed reading and important dimensions for the vehicle. This depends on the hardware and could vary between different vehicle configurations.

For encoder ppr, there is only one value for all whole vehicle, so all encoders need to operate the same way.

See also
begin(), Setting up a new SmartCar2
Parameters
pprNumber of encoder pulses per wheel revolution.
ppsMaxMaximum number of encoder pulses per second at top speed (100% velocity).
dWheelWheel diameter in mm.
lBaseBase length (distance between wheel centers) in mm

◆ spin()

void MD_SmartCar2::spin ( int16_t  fraction)

Precisely spin the vehicle.

Controls the movement by spinning the vehicle about its central vertical axis. It works similar to move() to spin the wheels in an directions to effect the turning motion.

The call to spin() specifies the percentage (-100 to 100) of the full circle rotation about the central axis passing through the vehicle base length. Positive angle is a turn to the right, negative to the left.

See also
drive(), move()
Parameters
fractionPercentage fraction of full revolution [-100..100]. Positive spins right; negative pins left.

◆ startSequence() [1/2]

void MD_SmartCar2::startSequence ( actionItem_t actionList)

Start an action sequence stored in RAM.

This method is passed the reference to an action sequence array stored in RAM to the library for background execution. The array must remain in scope (ie, global or static declaration) for the duration of the sequence running.

Details on actions sequences can be found at Action Sequences

See also
isSequenceComplete()
Parameters
actionListpointer to the array of actionItem_t ending with and END record.

◆ startSequence() [2/2]

void MD_SmartCar2::startSequence ( const actionItem_t actionList)

Start an action sequence stored in PROGMEM.

This method is passed the reference to an action sequence array stored in PROGMEM to the library for background execution.

Details on actions sequences can be found at Action Sequences

See also
isSequenceComplete()
Parameters
actionListpointer to the array of actionItem_t ending with and END record.

◆ stop()

void MD_SmartCar2::stop ( bool  insideSequence = false)

Stop the smart car.

This method brings the SmartCar to an immediate stop.

Parameters
insideSequenceset true if this was called from inside a sequence (not for end users)
See also
setSpeed()

◆ stopSequence()

void MD_SmartCar2::stopSequence ( void  )

Stop the currently executing sequence.

This method stops the currently executing sequence in the middle of the execution stream. This vehicle will be left in an indetermined state and the sequence will be reported as completed.

See also
isSequenceComplete()

Member Data Documentation

◆ MAX_MOTOR

const uint8_t MD_SmartCar2::MAX_MOTOR = 2
static

Maximum number of motors

Define the maximum number of motors that this library will control


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