Library for driving a motor with one PWM and one DIR signal using PI control.

Fork of Motor2 by Reiko Randoja

Embed: (wiki syntax)

« Back to documentation index

Motor Class Reference

Motor Class Reference

Class for controlling motors trough PCA9555. More...

#include <motor.h>

Public Member Functions

 Motor (PinName PWMpin, PCA9555 *ioExt, unsigned int dirPin, PinName encA, PinName encB)
 Create an instance of the motor connected to specfied pins, and IO-expander.
void setSpeed (int newSpeed)
 Set speed setpoint.
int getSpeed ()
 Get current speed setpoint value.
void pid ()
 Method that calculates appropriate PWM values for keeping motor speed close to setpoint This method shoud be called periodically (60Hz)

Detailed Description

Class for controlling motors trough PCA9555.

Definition at line 8 of file motor.h.


Constructor & Destructor Documentation

Motor ( PinName  PWMpin,
PCA9555 *  ioExt,
unsigned int  dirPin,
PinName  encA,
PinName  encB 
)

Create an instance of the motor connected to specfied pins, and IO-expander.

Parameters:
PWMpinPin for PWM output
*ioExtPointer to IO-expander object
dir1PinDirection pin 1 number (on IO-expander)
dir2PinDirection pin 2 number (on IO-expander)
encAEncoder pin
encBEncoder pin

Definition at line 3 of file motor.cpp.


Member Function Documentation

int getSpeed (  )

Get current speed setpoint value.

Definition at line 42 of file motor.cpp.

void pid (  )

Method that calculates appropriate PWM values for keeping motor speed close to setpoint This method shoud be called periodically (60Hz)

Definition at line 58 of file motor.cpp.

void setSpeed ( int  newSpeed )

Set speed setpoint.

Parameters:
newSpeedNew setpoint

Definition at line 51 of file motor.cpp.