Simon Krogedal / Karbot_wheel_control

Dependencies:   mbed ros_lib_melodic

Embed: (wiki syntax)

« Back to documentation index

MotorControl Class Reference

Motor Controller Class. More...

#include <MotorControl.h>

Inherits encoder.

Public Types

enum  Side
 

Direction enumerator.

More...

Public Member Functions

 MotorControl (PinName EncoderChanA, PinName EncoderChanB, int CPR, encoder::Side side, double period, motor *Motor, double MaxSpeed, double kp, double ti, double diameter)
 Creates an instance.
void setSpeed (double speed)
 Set the speed set point of the controller This can be done while driving or while stopped, though the update will only be reflected while driving.
void drive (void)
 Start driving Attaches a ticker object to the control algorithm, running it at the frequency specified in the constructor.
void stop (void)
 Stops the control algorithm Stops the motors and detaches the ticker callback.
void driveManual (void)
 Drives the motor in open loop No ticket object is attaced, the motors are just activated.
void samplecall (void)
 Sample the encoders to read speed value This function does not return anything, the speed must then be obtained through getSpeed()
void setK (double k)
 Set proportional gain This function is useful for Ziegler-Nichols tuning.
double getOutput (void)
 Returns the current duty cycle, useful for debugging.
bool checkFlag (void)
 Checks whether the output saturation flag is set.
double getSpeed (void)
 Get wheel speed.
double getDistance (void)
 Get distance travelled.
double tempDist (void)
 Get distance travelled.
void distRst (void)
 Reset distance measurement.
void tempRst (void)
 Reset distance measurement.
void start (void)
 Start encoder reading.
void reset (void)
 Stop encoder reading.
int getCurrentState (void)
 Read the state of the encoder.
int getPulses (void)
 Read the number of pulses recorded by the encoder.

Protected Member Functions

void sample_func (void)
 sampling period and wheel constant
double getClicks (void)
 Get wheel speed.

Protected Attributes

double period
 ticker object to sample speed

Detailed Description

Motor Controller Class.

This class controls the speed of an individual motor, helping the system keep symmetric with asymmetric components. It is based on the encoder class and contains a pointer to a motor object. With two of these the motion controller can drive the robot to the desired points.

Author:
Simon Krogedal

Written by Simon Krogedal

Team 9 4th Year project

for NUCLEO-F401RE

Version:
0.1

Definition at line 46 of file MotorControl.h.


Member Enumeration Documentation

enum Side [inherited]

Direction enumerator.

Definition at line 45 of file encoder.h.


Constructor & Destructor Documentation

MotorControl ( PinName  EncoderChanA,
PinName  EncoderChanB,
int  CPR,
encoder::Side  side,
double  period,
motor *  Motor,
double  MaxSpeed,
double  kp,
double  ti,
double  diameter 
)

Creates an instance.

Parameters:
EncoderChanAEncoder channel A pin, set up using internal pullup
EncoderChanBEncoder channel B pin, set up using internal pullup
CPREncoder counts per revolution
sideLeft side or right side motor, defines whether counter-clockwise rotation is forwards (left) or backwards (right) (when looking at the robot from outside)
periodSampling period for control algorithm and speed calculation from encoder readings
MotorPointer to the motor object to be controlled
MaxSpeedMaximum speed of the motor, no set points above this value will be accepted
kpProportional control gain
tiIntegral control time
diameterWheel diameter in meters

Definition at line 36 of file MotorControl.cpp.


Member Function Documentation

bool checkFlag ( void   )

Checks whether the output saturation flag is set.

Returns:
True: Output is saturated
False: Output is not saturated

Definition at line 74 of file MotorControl.cpp.

void distRst ( void   ) [inherited]

Reset distance measurement.

Definition at line 183 of file encoder.cpp.

void drive ( void   )

Start driving Attaches a ticker object to the control algorithm, running it at the frequency specified in the constructor.

Definition at line 49 of file MotorControl.cpp.

void driveManual ( void   )

Drives the motor in open loop No ticket object is attaced, the motors are just activated.

Note that this also means new speed set points will not be passed to the motor unless this function is called again!

Definition at line 62 of file MotorControl.cpp.

double getClicks ( void   ) [protected, inherited]

Get wheel speed.

Returns:
Wheel speed in clicks/second

Definition at line 149 of file encoder.cpp.

int getCurrentState ( void   ) [inherited]

Read the state of the encoder.

Returns:
The current state of the encoder as a 2-bit number, where: bit 1 = The reading from channel B bit 2 = The reading from channel A

Definition at line 59 of file encoder.cpp.

double getDistance ( void   ) [inherited]

Get distance travelled.

Returns:
Distance travelled in meters

Definition at line 165 of file encoder.cpp.

double getOutput ( void   )

Returns the current duty cycle, useful for debugging.

Returns:
Current duty cycle

Definition at line 73 of file MotorControl.cpp.

int getPulses ( void   ) [inherited]

Read the number of pulses recorded by the encoder.

Returns:
Number of pulses which have occured.

Definition at line 65 of file encoder.cpp.

double getSpeed ( void   ) [inherited]

Get wheel speed.

Returns:
Wheel speed in meters/second

Definition at line 157 of file encoder.cpp.

void reset ( void   ) [inherited]

Stop encoder reading.

Definition at line 55 of file encoder.cpp.

void sample_func ( void   ) [protected, inherited]

sampling period and wheel constant

Sample function called by ticker object

Definition at line 141 of file encoder.cpp.

void samplecall ( void   )

Sample the encoders to read speed value This function does not return anything, the speed must then be obtained through getSpeed()

Definition at line 67 of file MotorControl.cpp.

void setK ( double  k )

Set proportional gain This function is useful for Ziegler-Nichols tuning.

Parameters:
kController proportional gain

Definition at line 69 of file MotorControl.cpp.

void setSpeed ( double  speed )

Set the speed set point of the controller This can be done while driving or while stopped, though the update will only be reflected while driving.

Parameters:
speedSpeed set point in m/s

Definition at line 43 of file MotorControl.cpp.

void start ( void   ) [inherited]

Start encoder reading.

Definition at line 197 of file encoder.cpp.

void stop ( void   )

Stops the control algorithm Stops the motors and detaches the ticker callback.

Definition at line 56 of file MotorControl.cpp.

double tempDist ( void   ) [inherited]

Get distance travelled.

Returns:
Distance travelled in meters since last reset

Definition at line 174 of file encoder.cpp.

void tempRst ( void   ) [inherited]

Reset distance measurement.

Definition at line 195 of file encoder.cpp.


Field Documentation

double period [protected, inherited]

ticker object to sample speed

Definition at line 134 of file encoder.h.