Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otBotEngine Class Reference
[BotEngine - Library for the control of two DC motors. Base for making small robots.BotEngine - Library for the control of two DC motors. Base for making small robots.]

Library for the control of two DC motors.

#include <otBotEngine.h>


Public Types

enum  MotionAction {
  MA_NOP, MA_FORWARD, MA_BACKWARD, MA_TURNLEFT,
  MA_TURNRIGHT, MA_COMPASS_LEFT_CW, MA_COMPASS_LEFT_CCW, MA_COMPASS_RIGHT_CW,
  MA_COMPASS_RIGHT_CCW, MA_BRAKE, MA_HARD_STOP, MA_RUN
}
 < Motors activities More...
enum  MotorControls {
  MC_FORWARD, MC_BACKWARD, MC_TURNLEFT, MC_TURNRIGHT,
  MC_COMPASS_LEFT_CW, MC_COMPASS_LEFT_CCW, MC_COMPASS_RIGHT_CW, MC_COMPASS_RIGHT_CCW,
  MC_MASK_LEFT, MC_MASK_RIGHT, MC_COM_INVERT
}

Public Member Functions

 otBotEngine ()
void init (U8 timerId, otPWM *pwmClass, U8 leftPwmPin=0, U8 rightPwmPin=0, U8 leftEncoderIndex=0, U8 rightEncoderIndex=1, portOutputCallBack op=0)
void setMotorControls (U8 index, U8 val)
void process (bool force=false)
void action (U8 com, U32 trip=0)
U8 action ()
void setSpeed (U16 lspeed, U16 rspeed=0xFFFF)
U16 speed (bool left=true)
void setMinimumPwm (U16 pwmValue)
void setMaximumEncoderError (U16 val)
S32 route (bool left=true)
bool ready ()
S16 encoder (bool left)
void setBrakeTime (U32 dly)
void setSlope (U16 val)
void waitEnded (U32 timeout=1200)


Member Enumeration Documentation

enum otBotEngine::MotionAction
 

Enumeration values:
MA_NOP  Do nothing.
MA_FORWARD  It moves forward, all motors are on.
MA_BACKWARD  It moves back, all motors are on.
MA_TURNLEFT  Rotate on itself to the left, all motors are on.
MA_TURNRIGHT  Rotate on itself to the right, all motors are on.
MA_COMPASS_LEFT_CW  Left motor on CW rotation, Right motor is off.
MA_COMPASS_LEFT_CCW  Left motor on CCW rotation, Right motor is off.
MA_COMPASS_RIGHT_CW  Right motor on CW rotation, Left motor is off.
MA_COMPASS_RIGHT_CCW  Right motor on CCW rotation, Left motor is off.
MA_BRAKE  Stop the movement by slowing down.
MA_HARD_STOP  Immediate stop, very violent!
MA_RUN  Internal status, don't use!

enum otBotEngine::MotorControls
 

Enumeration values:
MC_FORWARD 
MC_BACKWARD 
MC_TURNLEFT 
MC_TURNRIGHT 
MC_COMPASS_LEFT_CW 
MC_COMPASS_LEFT_CCW 
MC_COMPASS_RIGHT_CW 
MC_COMPASS_RIGHT_CCW 
MC_MASK_LEFT 
MC_MASK_RIGHT 
MC_COM_INVERT 


Constructor & Destructor Documentation

otBotEngine.otBotEngine  ) 
 

Create the class


Member Function Documentation

U8 otBotEngine.action  ) 
 

Check latest command in action

Returns:
Latest command

void otBotEngine.action U8  com,
U32  trip = 0
 

Run a command, see MotionAction

Parameters:
com Command to be executed, see MotionAction
trip Maximum number of encoder counts to be executed, 0 is forever.

S16 otBotEngine.encoder bool  left  ) 
 

Read current encoder count

Parameters:
left If true return the left encoder counts else the right
Returns:
Encoder count

void otBotEngine.init U8  timerId,
otPWM pwmClass,
U8  leftPwmPin = 0,
U8  rightPwmPin = 0,
U8  leftEncoderIndex = 0,
U8  rightEncoderIndex = 1,
portOutputCallBack  op = 0
 

Init BotEngine

Parameters:
timerId Timer identifier used for time measure, see TimerId
pwmClass Class otPWM pointer
leftPwmPin Used PWM output 0 to 15
rightPwmPin Used PWM output 0 to 15
leftEncoderIndex Used encoder channel for left wheel, 0 to 3
rightEncoderIndex Used encoder channel for right wheel, 0 to 3
op Function pointer used for port access to motor controls

void otBotEngine.process bool  force = false  ) 
 

Procedure that must be called continuously, to be inserted in the main loop. It does not have an important time consumption.

bool otBotEngine.ready  ) 
 

Checks whether the command has been executed.

Returns:
True if the command has been executed.

S32 otBotEngine.route bool  left = true  ) 
 

Read current total trip.

Returns:
Trip, positve if forward, negative backward

void otBotEngine.setBrakeTime U32  dly  ) 
 

Set activation time for the brake function

Parameters:
dly Activation time as ms

void otBotEngine.setMaximumEncoderError U16  val  ) 
 

Sets the maximum difference of encoder counts for the implementation of the electronic differential

Parameters:
val Values from 0 to n. A high value equals less feed accuracy. Too low a value introduces a lot of noise into the movement.

void otBotEngine.setMinimumPwm U16  pwmValue  ) 
 

Set the minimum PWM value to be used

Parameters:
pwmValue Minimu PWM value used (0-4095).

void otBotEngine.setMotorControls U8  index,
U8  val
 

Specify control codes used for the motor controls. See MotorControls enum.

void otBotEngine.setSlope U16  val  ) 
 

Set slope step used for acceleration and deceleration

Parameters:
val Slope value, absolute accepted range is 1 to 4095, default is 200

void otBotEngine.setSpeed U16  lspeed,
U16  rspeed = 0xFFFF
 

Set Cruising speed desired (as encoder counts x second)

Parameters:
lspeed Cruising speed desired on left side
rspeed Cruising speed desired on right side. If set 0xFFFF speed of left is used.

U16 otBotEngine.speed bool  left = true  ) 
 

void otBotEngine.waitEnded U32  timeout = 1200  ) 
 

Very dangerous procedure waiting for the completion of the running operation. If the operation does not foresee an immediate end, it exits only for timeout.

Parameters:
timeout Timeout value, every count is approx 50ms


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0