CORE2 v1.0.0
hFramework::hMotor Class Reference

Provides control of on-board motor driver. More...

#include <hMotor.h>

Public Member Functions

 hMotor (hMotor_ID id)
 Initialize specific motor driver. For internal use only - should never be called by user. More...
 
void attachPositionRegulator (hRegulator &regPosition)
 Replace default position regulator (for "rotX" methods). More...
 
bool rotAbs (int32_t angle, uint16_t power=1000, bool block=false, uint32_t timeout=INFINITE)
 Rotate "angle" encoder ticks starting from a motor position at the beginning (when you start using "rotX" functions). More...
 
bool rotRel (int32_t angle, uint16_t power=1000, bool block=false, uint32_t timeout=INFINITE)
 Rotate "angle" encoder ticks starting from a current motor position. More...
 
bool calibrate (int16_t power, uint32_t maxDiff, uint32_t stableTime, bool block=false, uint32_t timeout=INFINITE)
 
void setPower (int16_t power)
 Set a power attached to a motor. More...
 
void setPowerLimit (int16_t limit)
 
void setSlewRate (float time)
 Set slew rate for motor. More...
 
int32_t getEncoderCnt ()
 Get number of encoder ticks. More...
 
void resetEncoderCnt ()
 Set encoder ticks to 0.
 
void stop ()
 Stop the motor.
 
bool waitDone (uint32_t timeout=INFINITE)
 Wait until all tasks are finished by the motor. More...
 
uint8_t getMotorNr (void)
 Get a current motor index. More...
 
bool stopRegulation (bool block=false, uint32_t timeout=INFINITE)
 Stop motor regulation.
 
void setParallelMode ()
 Set parallel mode. Motors are controlled in pairs of two. More...
 
void setSingleMode ()
 Return to single mode. Each motor is controlled independently from each other.
 
void setActiveBraking ()
 
void setPassiveBraking ()
 
void setMotorPolarity (Polarity polarity)
 Set motor polarity. More...
 
void setEncoderPolarity (Polarity polarity)
 Set encoder polarity. More...
 
void setEncoderPu ()
 Set encoder pin A and B as pullups.
 
void setEncoderPd ()
 Set encoder pin A and B as pulldownss.
 
void setEncoderHZ ()
 set encoder pin A and B as floating
 
Polarity getMotorPolarity () const
 Return motor polarity. More...
 
Polarity getEncoderPolarity () const
 Return encoder polarity. More...
 
IServouseAsServo ()
 Configure hMotor as servo and return Servo object. More...
 
void releaseServo ()
 Release servo object and allow to use hMotor with motor again.
 

Static Public Member Functions

static void setPWMFreq (PWM_freq_hMotor_ID id, PWM_freq newFrequency)
 change default PWM frequency for a specific motor driver. More...
 

Friends

class hSystem
 

Detailed Description

Provides control of on-board motor driver.

Constructor & Destructor Documentation

hFramework::hMotor::hMotor ( hMotor_ID  id)

Initialize specific motor driver. For internal use only - should never be called by user.

Parameters
idmotor id

Member Function Documentation

void hFramework::hMotor::attachPositionRegulator ( hRegulator regPosition)

Replace default position regulator (for "rotX" methods).

Parameters
regPositiona reference to a position regulator object.
int32_t hFramework::hMotor::getEncoderCnt ( )

Get number of encoder ticks.

Returns
encoder ticks
Polarity hFramework::hMotor::getEncoderPolarity ( ) const

Return encoder polarity.

Returns
encoder polarity
uint8_t hFramework::hMotor::getMotorNr ( void  )

Get a current motor index.

Returns
1 - hMotor1, 2 - hMotor2, ... , 6 - hMotor6
Polarity hFramework::hMotor::getMotorPolarity ( ) const

Return motor polarity.

Returns
motor polarity
bool hFramework::hMotor::rotAbs ( int32_t  angle,
uint16_t  power = 1000,
bool  block = false,
uint32_t  timeout = INFINITE 
)

Rotate "angle" encoder ticks starting from a motor position at the beginning (when you start using "rotX" functions).

Parameters
anglenumber of encoder ticks to rotate (negative value - left, positive value - right)
powera power that is attached to a motor, the higher the value, the shorter time to reach final position (values from 0 to 1000).
block1 - if you want to block the task until final angle is reached (waiting for maximum time specified by timeout argument)
timeout0 - if you don't want to block, any other value is the maximum time to block the task until final angle is reached.
Returns
1 if order has been successfully stored in motor queue
bool hFramework::hMotor::rotRel ( int32_t  angle,
uint16_t  power = 1000,
bool  block = false,
uint32_t  timeout = INFINITE 
)

Rotate "angle" encoder ticks starting from a current motor position.

Parameters
anglenumber of encoder ticks to rotate (negative value - left, positive value - right)
powera power that is attached to a motor, the higher the value, the shorter time to reach final position (values from 0 to 1000).
block1 - if you want to block the task until final angle is reached (waiting for maximum time specified by timeout argument)
timeout0 - if you don't want to block, any other value is the maximum time to block the task until final angle is reached.
Returns
1 if order has been successfully stored in motor queue
void hFramework::hMotor::setEncoderPolarity ( Polarity  polarity)

Set encoder polarity.

Parameters
polarityencoder polarity
void hFramework::hMotor::setMotorPolarity ( Polarity  polarity)

Set motor polarity.

Parameters
polaritymotor polarity
void hFramework::hMotor::setParallelMode ( )

Set parallel mode. Motors are controlled in pairs of two.

Since call of this function, two motor drivers are used as one in the following manner:

  • motor 1 is used with motor 2
  • motor 3 is used with motor 4
  • motor 5 is used with motor 6
void hFramework::hMotor::setPower ( int16_t  power)

Set a power attached to a motor.

Parameters
powera power that is attached to a motor, the higher the value, the more power is attached to a motor (values from -1000 to 1000). The positive and negative values correspond to normal or reversed polarity of the motor. In other words, this value is proportional to the the average voltage between the A and B outputs of H-bridge driver (can be positive or negative).
Returns
1 if order has been successfully stored in motor queue
static void hFramework::hMotor::setPWMFreq ( PWM_freq_hMotor_ID  id,
PWM_freq  newFrequency 
)
static

change default PWM frequency for a specific motor driver.

Parameters
idmotor id
newFrequencynew PWM frequency value
void hFramework::hMotor::setSlewRate ( float  time)

Set slew rate for motor.

Parameters
time(min 0.01) Time constant of rate regulation
IServo& hFramework::hMotor::useAsServo ( )

Configure hMotor as servo and return Servo object.

Returns
servo object
bool hFramework::hMotor::waitDone ( uint32_t  timeout = INFINITE)

Wait until all tasks are finished by the motor.

Parameters
timeouttime to wait for a motor to done all operations.
Returns
1 if motor has finished all its operations from its queue before timeout.

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