QuadroCopter  0.1.4
quadro::pwm::motors Class Reference

#include <motors.h>

Inheritance diagram for quadro::pwm::motors:
quadro::pwm::pwmDevice quadro::IDevice quadro::pwm::pwmOverlay quadro::pwm::dji_2212

Public Member Functions

 motors ()
 
 motors (pinBlocks _block, PWMPins _pin)
 
void setTargetSpeed (long _targetSpeed)
 
void reversePolarity ()
 
void start ()
 
void stop ()
 
- Public Member Functions inherited from quadro::pwm::pwmDevice
 pwmDevice ()
 
 pwmDevice (pinBlocks _block, PWMPins _pin) throw ( pwmSetupException& )
 
long get (valType _vt)
 
void set (valType _vt, long _val)
 
void setPinNum (PWMPins _pin)
 
void setBlockNum (pinBlocks _block)
 
- Public Member Functions inherited from quadro::IDevice
virtual ~IDevice ()
 

Public Attributes

long currentDuty
 Storage for the current Duty value. More...
 
long currentPeriod
 Storage for the current Period value. More...
 
int currentRun
 Storage for the current Run value. More...
 
int currentPolarity
 Storage for the current Polarity value. More...
 
- Public Attributes inherited from quadro::pwm::pwmDevice
pinBlocks blockNum
 stores the PWM device block num More...
 
PWMPins pinNum
 stores the PWM device pin num More...
 
string powerControlStr
 stores the current power setting string More...
 

Protected Member Functions

long getMaxSpeed ()
 
long getMinSpeed ()
 
int getSpeedStep ()
 
void setMaxSpeed (long _maxSpeed)
 
void setMinSpeed (long _minSpeed)
 
void setSpeedStep (int _speedStep)
 

Additional Inherited Members

- Public Types inherited from quadro::pwm::pwmDevice
enum  valType {
  Run, Duty, Period, Polarity,
  Power_Control, Power_RunTime_Active, Power_RunTime_Suspended
}
 

Detailed Description

Base class for adding functionality to the program for pwm motors

Constructor & Destructor Documentation

quadro::pwm::motors::motors ( )
inline

default constructor

37 { };
motors::motors ( pinBlocks  _block,
PWMPins  _pin 
)

Constructor for initialising the motor with it's associated pinBlock and PWMPin

Parameters
pinBlocks_block
PWMPins_pin
26  :pwmDevice( _block, _pin )
27 {
28  targetSpeed = getMinSpeed();
29 };
pwmDevice()
Definition: pwmDevice.h:46
long getMinSpeed()
Definition: motors.cpp:111

Member Function Documentation

long motors::getMaxSpeed ( )
protected

Every motor has it's own max PWM value, you can retrieve it here after it has been set using setMaxSpeed()

See also
setMaxSpeed()
Returns
long maxSpeed
107 {
108  return maxSpeed;
109 }
long motors::getMinSpeed ( )
protected

Every motor has it's own min PWM value, you can retrieve it here after it has been set using setMinSpeed()

See also
setMinSpeed()
Returns
long minSpeed
112 {
113  return minSpeed;
114 }
int motors::getSpeedStep ( )
protected

After testing you may find you need to change how fast the motors speed up and slow down, one way of accomplishing this is to set the speed step to a larger number, you can get the current speed step here.

Returns
int
117 {
118  return speedStep;
119 }
void motors::reversePolarity ( )

Reverse the motors polarity using this method

57 {
58  currentPolarity = ( currentPolarity == polarity::Positive ) ? polarity::Negative
59  : polarity::Positive;
61 }
Polarity Value Type.
Definition: pwmDevice.h:64
void set(valType _vt, long _val)
Definition: pwmDevice.cpp:111
int currentPolarity
Storage for the current Polarity value.
Definition: motors.h:76
void motors::setMaxSpeed ( long  _maxSpeed)
protected

Set your motors max speed here, it will probably be the lowest of the numbers as lower means faster.

Parameters
_maxSpeed
127 {
128  maxSpeed = _maxSpeed;
129 }
void motors::setMinSpeed ( long  _minSpeed)
protected

Set your motors min speed here, it will probably be the highest of the numbers as higher means slower.

Parameters
_minSpeed
122 {
123  minSpeed = _minSpeed;
124 }
void motors::setSpeedStep ( int  _speedStep)
protected

Set the speed step increment here, this is how fast your motor will speed up - some testing may be required to find the ideal setting.

Parameters
_speedStep
132 {
133  speedStep = _speedStep;
134 }
void motors::setTargetSpeed ( long  _targetSpeed)

Set the speed that you want the motor to achieve.

Parameters
_targetSpeed
32 {
33  if( _targetSpeed < getMaxSpeed() ) {
34  targetSpeed = getMaxSpeed();
35  }
36  else if( _targetSpeed > getMinSpeed() ) {
37  targetSpeed = getMinSpeed();
38  }
39  else {
40  targetSpeed = _targetSpeed;
41  }
42 }
long getMinSpeed()
Definition: motors.cpp:111
long getMaxSpeed()
Definition: motors.cpp:106
void motors::start ( )

If the motor thread isn't running, this method will start the thread running which continuously attempts to maintain the current motor speed as closely as possible to the target speed that has been set.

Exceptions
pwmSetupException
82 {
83  if ( Status == status::Off ) {
84  threadRet = pthread_create( &threadHandle, NULL, motors::maintainTargetSpeed, this );
85 
86  if ( threadRet == 0 )
87  setStatus( status::On );
88  else {
89  setStatus( status::Error );
90  if ( threadRet == EAGAIN )
91  throw pwmSetupException( "Unable to create thread : Resource Limit Reached." );
92  else
93  throw pwmSetupException( "Unable to create thread : Unknown Error Occurred." );
94  }
95  }
96 }
Off
Status Off (thread is disabled)
Definition: LVMaxSonarEZ.h:91
Error
Status Error (thread is disabled)
Definition: LVMaxSonarEZ.h:92
Definition: pwmSetupException.h:17
On
Status On (thread is active)
Definition: LVMaxSonarEZ.h:90
void motors::stop ( )

Run this method if you want to stop your motor from maintaining it's targets. Please note, this will make the motor stop completely - if in mid air...well...catastrophe!

99 {
100  if ( Status != status::Off ) {
101  setStatus( status::Off );
102  pthread_exit( &threadHandle );
103  }
104 }
Off
Status Off (thread is disabled)
Definition: LVMaxSonarEZ.h:91

Member Data Documentation

long quadro::pwm::motors::currentDuty

Storage for the current Duty value.

long quadro::pwm::motors::currentPeriod

Storage for the current Period value.

int quadro::pwm::motors::currentPolarity

Storage for the current Polarity value.

int quadro::pwm::motors::currentRun

Storage for the current Run value.


The documentation for this class was generated from the following files:
  • /Users/michaelbrookes/ClionProjects/Quadro/lib/pwm/motors/motors.h
  • /Users/michaelbrookes/ClionProjects/Quadro/lib/pwm/motors/motors.cpp