eLab Team / Mbed 2 deprecated myRobot

Dependencies:   mbed WS2812

Embed: (wiki syntax)

« Back to documentation index

Creabot Class Reference

Creabot Class Reference

Asynchronous Control of 2 motors part of a robot. More...

#include <CreaBot.h>

Public Member Functions

 Creabot (Motor *left, Motor *right, float diameter_wheel_cm, float distance_wheel_cm)
 Create a Creabot object to synchronize 2 motors.

Detailed Description

Asynchronous Control of 2 motors part of a robot.

Example:

 // --- Define the Four PINs & Time of movement used for Motor drive -----
 Motor motorLeft(PA_12, PB_0, PB_1, PB_6); // Declare first the 2 motors (to avoid to have an object with 8 pins to create)
 Motor motorRight(PA_5,PA_4,PA_3,PA_1);
 Creabot mybot(&motorLeft, &motorRight, 10.0f,13.0f); // insert the motors and indicate wheel diameter and distance between wheels
 
 int main() {
 
     mybot.setSpeed(12.5); // 12.5cm/s
     mybot.move(FORWARD,10); // Go forward of 10cm
     mybot.waitEndMove(); // Wait end of Move
     mybot.move(ROTATE,90); // Start rotation of 90° around the center between wheels (two wheels running in same direction at same speed)
     mybot.move(BACKWARD,40); // Stop immediately the rotation and go backward of 40cm
     mybot.waitEndMove(); // Wait end of Backward
     mybot.moveAndWait(LEFT,60); // Move Left of 60° in circle, center being the left wheel (off). Wait end of move
     mybot.waitEndMove();  // Not needed, as already waited... 
     mybot.moveAndWait(RIGHT,45, 33); // Move Right of 45°, center being at 33cm of the right wheel. Right wheel moving slower and on a shorter distance than left one. 
     mybot.moveAndWait(ROTATE,90);
     mybot.move(ROTATE,-90); // Opposite direction.
     mybot.waitEndMove(60); // with watchdog => if after 60s the move is not ended, continue the execution
     mybot.stopMove(); // Stop the movement before end...
     
     // Same with a fifo of command, opposite to the move, receiving a new command will not stop the current execution, but the bot will store it.
     mybot.fifo(FORWARD,10); // Already starting...
     mybot.fifo(BACKWARD,10); // will wait end of previous command to go
     mybot.fifo(ROTATE,120.0);
     mybot.fifo(LEFT, 30, 120);
     mybot.fifo(RIGHT, 25);
     mybot.waitEndMove(100000); // wait until fifo end... can flush anytime with stopMove...
     mybot.stopMove(); // before end... Flush the fifo and remove all instructions…
 
     while(1) {
     };
 }

Definition at line 77 of file CreaBot.h.


Constructor & Destructor Documentation

Creabot ( Motor *  left,
Motor *  right,
float  diameter_wheel_cm,
float  distance_wheel_cm 
)

Create a Creabot object to synchronize 2 motors.

Parameters:
leftMotor object declared before corresponding to left motor of the Creabot
rightMotor object declared before corresponding to right motor of the Creabot
diameter_wheel_cmdiameter in cm of the wheels (both supposed to be at same diameter)
distance_wheel_cmdistance in cm between center of left wheel and center of right wheel

Definition at line 3 of file CreaBot.cpp.