Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ros_lib_melodic
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.
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
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:
-
EncoderChanA Encoder channel A pin, set up using internal pullup EncoderChanB Encoder channel B pin, set up using internal pullup CPR Encoder counts per revolution side Left side or right side motor, defines whether counter-clockwise rotation is forwards (left) or backwards (right) (when looking at the robot from outside) period Sampling period for control algorithm and speed calculation from encoder readings Motor Pointer to the motor object to be controlled MaxSpeed Maximum speed of the motor, no set points above this value will be accepted kp Proportional control gain ti Integral control time diameter Wheel 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] |
| 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] |
| 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:
-
k Controller 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:
-
speed Speed 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
Generated on Mon Sep 19 2022 06:28:58 by
1.7.2