Data Structures | |
class | Tle94112Motor |
represents a motor connected to a TLE94112 More... | |
Macros | |
#define | TLE94112_MAX_SPEED 255 |
The maximum absolute speed value which can be set. More... | |
#define | TLE94112MOTOR_MAX_CONNECTORS 4 |
maximum number of Tle94112 outputs per motor connector More... | |
class Tle94112Motor |
represents a motor connected to a TLE94112
This class provides a simple API for connecting and controlling motors. Each motor is assigned to a Tle94112 which acts as output driver. Calls to Tle94112Motor instances are mapped to calls to Tle94112. Therefore, this class does not bring new features, it does only provide further abstraction.
Public Types | |
enum | ePolarity { LOWSIDE = 0 , HIGHSIDE } |
Enum to select polarity of a motor connector. More... | |
Public Member Functions | |
Tle94112Motor (Tle94112 &driver) | |
Construct a new Tle94112Motor object. More... | |
~Tle94112Motor () | |
Destroy the Tle94112Motor object. More... | |
void | begin (void) |
finishes configuration and enables motor controls More... | |
void | end (void) |
disables motor controls and switches back to configuration mode More... | |
void | initConnector (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel, Tle94112::HalfBridge out1, Tle94112::HalfBridge out2, Tle94112::HalfBridge out3, Tle94112::HalfBridge out4) |
configures most important settings for one motor connector More... | |
void | initConnector (Tle94112Motor::ePolarity, Tle94112::PWMChannel channel, Tle94112::PWMFreq freq, Tle94112::HalfBridge out1, Tle94112::HalfBridge out2, Tle94112::HalfBridge out3, Tle94112::HalfBridge out4) |
configures most important settings for one motor connector More... | |
void | connect (Tle94112Motor::ePolarity pol, Tle94112::HalfBridge connector) |
connects a single halfbridge output to a motor connector More... | |
void | disconnect (Tle94112::HalfBridge connector) |
disconnects a single halfbridge output from a motor connector More... | |
void | setPwm (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel) |
Sets the PWM channel to be used for a motor connector. More... | |
void | setPwm (Tle94112Motor::ePolarity pol, Tle94112::PWMChannel channel, Tle94112::PWMFreq freq) |
Sets the PWM channel and frequency for a motor connector. More... | |
void | setPwmFreq (Tle94112Motor::ePolarity pol, Tle94112::PWMFreq freq) |
Sets the PWM frequency for driving a motor connector. More... | |
void | setActiveFreeWheeling (Tle94112Motor::ePolarity pol, uint8_t active_fw) |
Enables or disables active freewheeling. More... | |
void | stop (uint8_t force=255) |
actively breaks the motor to stop it More... | |
void | coast () |
releases the motor without driving or active breaking More... | |
void | start (int16_t speed) |
starts the motor with a certain speed in a certain direction More... | |
void | setSpeed (int16_t speed) |
equivalent to start() More... | |
int16_t | getSpeed (void) |
Returns the motor's current speed setting. More... | |
void | rampSpeed (int16_t speed, uint16_t slope) |
function to gradually change the motors speed More... | |
Protected Types | |
enum | eMode { COAST , FORWARD , BACKWARD , STOP } |
enum for motor operation modes More... | |
typedef struct Tle94112Motor::Connector_t * | Connector_p |
Protected Member Functions | |
uint32_t | _measureSetSpeedDuration (int16_t speed, int16_t start_speed) |
private function needed by rampSpeed More... | |
void | _performSpeedStepping (int16_t start_speed, int16_t ramp_delta_speed, int16_t num_steps, uint16_t steptime) |
private function needed by rampSpeed More... | |
Protected Attributes | |
Connector_t | mConnectors [2] |
array of motor connectors More... | |
Tle94112 * | mDriver |
Tle94112 instance acting as output driver. More... | |
eMode | mMode |
current operation mode More... | |
uint8_t | mEnabled |
flag indicating if motor controls are enabled More... | |
uint8_t | mSpeed |
value of the current motor speed More... | |
|
protected |
|
protected |
Tle94112Motor::Tle94112Motor | ( | Tle94112 & | driver | ) |
Construct a new Tle94112Motor object.
After constructing, the motor must be configured. You can use functions initConnector(), connect(), disconnect(), setPwm(), setPwmFreq() and setActiveFreeWheeling() for configuration. Call begin() to finish configuration and enable motor controls.
driver | Tle94112 instance acting as a driver |
Tle94112Motor::~Tle94112Motor | ( | ) |
void Tle94112Motor::begin | ( | void | ) |
finishes configuration and enables motor controls
For controlling the motor, you can use the functions start(), stop(), coast(), setSpeed(), getSpeed() and rampSpeed() Call end() to get back to configuration mode. After calling end() and changing configuration, you can get back to controlling mode by calling begin()
void Tle94112Motor::end | ( | void | ) |
disables motor controls and switches back to configuration mode
If necessary, you can call end() and change the configuration settings at any point of time. This might be useful when sharing PWM channels between several motors. Configuration changes to motors are not allowed while controls are active! Call begin() again when the configuration changes are done to enable motor controls again.
void Tle94112Motor::initConnector | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::PWMChannel | channel, | ||
Tle94112::HalfBridge | out1, | ||
Tle94112::HalfBridge | out2, | ||
Tle94112::HalfBridge | out3, | ||
Tle94112::HalfBridge | out4 | ||
) |
configures most important settings for one motor connector
Call this function twice to setup motor configuration for both the
pol | Polarity of the motor connector to be configured |
channel | PWM channel assigned to this connector |
out1 | halfbridge output 1 of 4 assigned to this connector |
out2 | halfbridge output 2 of 4 assigned to this connector |
out3 | halfbridge output 3 of 4 assigned to this connector |
out4 | halfbridge output 4 of 4 assigned to this connector |
void Tle94112Motor::initConnector | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::PWMChannel | channel, | ||
Tle94112::PWMFreq | freq, | ||
Tle94112::HalfBridge | out1, | ||
Tle94112::HalfBridge | out2, | ||
Tle94112::HalfBridge | out3, | ||
Tle94112::HalfBridge | out4 | ||
) |
configures most important settings for one motor connector
Call this function twice to setup motor configuration for both the
pol | Polarity of the motor connector to be configured |
channel | PWM channel assigned to this connector |
freq | optional PWM frequency setting |
out1 | halfbridge output 1 of 4 assigned to this connector |
out2 | halfbridge output 2 of 4 assigned to this connector |
out3 | halfbridge output 3 of 4 assigned to this connector |
out4 | halfbridge output 4 of 4 assigned to this connector |
void Tle94112Motor::connect | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::HalfBridge | connector | ||
) |
connects a single halfbridge output to a motor connector
pol | Polarity of the motor connector to be configured |
connector | halfbridge output to be assigned to this motor |
void Tle94112Motor::disconnect | ( | Tle94112::HalfBridge | connector | ) |
disconnects a single halfbridge output from a motor connector
connector | halfbridge output to be removed from this motor |
void Tle94112Motor::setPwm | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::PWMChannel | channel | ||
) |
Sets the PWM channel to be used for a motor connector.
pol | Polarity of the motor connector to be configured |
channel | PWM channel to be used |
void Tle94112Motor::setPwm | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::PWMChannel | channel, | ||
Tle94112::PWMFreq | freq | ||
) |
Sets the PWM channel and frequency for a motor connector.
pol | Polarity of the motor connector to be configured |
channel | PWM channel to be used |
freq | PWM frequency selection |
void Tle94112Motor::setPwmFreq | ( | Tle94112Motor::ePolarity | pol, |
Tle94112::PWMFreq | freq | ||
) |
Sets the PWM frequency for driving a motor connector.
pol | Polarity of the motor connector to be configured |
freq | PWM frequency selection |
void Tle94112Motor::setActiveFreeWheeling | ( | Tle94112Motor::ePolarity | pol, |
uint8_t | active_fw | ||
) |
Enables or disables active freewheeling.
Default is false i.e. passive freewheeling. Depending on your application circuit, active freewheeling may lead to electrical problems. Do not change this setting unless you know what you are doing.
pol | Polarity of the motor connector to be configured |
active_fw | true/false to enable/disable active freewheeling |
void Tle94112Motor::stop | ( | uint8_t | force = 255 | ) |
actively breaks the motor to stop it
force | higher force lets the motor stop quicker, maximum is 255 |
void Tle94112Motor::coast | ( | ) |
releases the motor without driving or active breaking
void Tle94112Motor::start | ( | int16_t | speed | ) |
starts the motor with a certain speed in a certain direction
The behaviour of this function depends on the way the motor is connected to the Tle94112. Motors which have just one connector assigned to the Tle94112 cannot run in reverse direction and break instead if a negative speed value is passed. Motors without PWM assigned cannot run at a certain speed. They can just coast, run and break. Speed values greater or smaller than 0 are treated like -255 or 255, respectively.
speed | an integer in a range from -255 to 255 to set motor speed and direction |
void Tle94112Motor::setSpeed | ( | int16_t | speed | ) |
equivalent to start()
This function is fully equivalent to start(), but it is intended to be used if the motor is already running. (Distinguishing between these two functions helps improving the readability of your code) The behaviour of this function depends on the way the motor is connected to the Tle94112. Motors which have just one connector assigned to the Tle94112 cannot run in reverse direction and break instead if a negative speed value is passed. Motors without PWM assigned cannot run at a certain speed. They can just coast, run and break. Speed values greater or smaller than 0 are treated like -255 or 255, respectively.
speed | an integer in a range from -255 to 255 to set motor speed and direction |
int16_t Tle94112Motor::getSpeed | ( | void | ) |
Returns the motor's current speed setting.
void Tle94112Motor::rampSpeed | ( | int16_t | speed, |
uint16_t | slope | ||
) |
function to gradually change the motors speed
speed | target speed |
slope | time for a full ramp from speed=0 to speed=255 |
|
protected |
private function needed by rampSpeed
speed | integer in a range from -255 to 255 to set motor speed and direction. Here the target speed. |
start_speed | integer a range from -255 to 255 to set motor speed and direction. Here the source speed |
|
protected |
private function needed by rampSpeed
start_speed | integer a range from -255 to 255 to set motor speed and direction. Here the source speed |
ramp_delta_speed | slope value how fast the speed change should raise or fall |
num_steps | number of steps to raise or fall the speed |
steptime | time to be needed for each step |
none blocking delay
|
protected |
array of motor connectors
|
protected |
current operation mode
|
protected |
flag indicating if motor controls are enabled
|
protected |
value of the current motor speed
#define TLE94112_MAX_SPEED 255 |
The maximum absolute speed value which can be set.
#define TLE94112MOTOR_MAX_CONNECTORS 4 |
maximum number of Tle94112 outputs per motor connector
When this is changed, also the function signature and implementation of Tle94112Motor::initConnector has to be changed.