My Version of CreaBotLib

Fork of CreaBotLib by CreaLab

Committer:
sepp_nepp
Date:
Tue Jan 01 13:05:08 2019 +0000
Revision:
7:3a793ddc3490
Parent:
6:4d8938b686a6
Child:
8:3b5b0a82b429
uncommented doxy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sepp_nepp 7:3a793ddc3490 1 /*
sepp_nepp 7:3a793ddc3490 2 * at: file CreaBot.h
sepp_nepp 7:3a793ddc3490 3 * bs_brief File contains Creabot Library.
sepp_nepp 6:4d8938b686a6 4
sepp_nepp 6:4d8938b686a6 5 * CreaBot.h contains the class Motor, and related enums and structs.
sepp_nepp 6:4d8938b686a6 6 * Includes "mbed.h" and "motor.h"
sepp_nepp 6:4d8938b686a6 7
sepp_nepp 6:4d8938b686a6 8 * Refactorings:
sepp_nepp 6:4d8938b686a6 9 * All variables with suffixes "_cm_sec" = speeds in centimeters per second
sepp_nepp 6:4d8938b686a6 10 * MotCommand -> BotCommand
sepp_nepp 6:4d8938b686a6 11 * cmdbot_t -> BotCmdVerb
sepp_nepp 6:4d8938b686a6 12 * cm -> dist_cm
sepp_nepp 6:4d8938b686a6 13
sepp_nepp 7:3a793ddc3490 14 * at_author Tarek Lule, Francois Druilhe, et al.
sepp_nepp 7:3a793ddc3490 15 * at_date 21. Nov. 2018.
sepp_nepp 7:3a793ddc3490 16 * at_see https://os.mbed.com/users/sepp_nepp/code/CreaBotLib/ */
sepp_nepp 6:4d8938b686a6 17
sepp_nepp 6:4d8938b686a6 18 // -------------------- Motor ---------------------------
sepp_nepp 6:4d8938b686a6 19
garphil 0:a7fb03c9ea9d 20 #ifndef CREABOT_H
garphil 0:a7fb03c9ea9d 21 #define CREABOT_H
garphil 0:a7fb03c9ea9d 22
garphil 0:a7fb03c9ea9d 23 #include "mbed.h"
garphil 0:a7fb03c9ea9d 24 #include "motor.h"
garphil 0:a7fb03c9ea9d 25
sepp_nepp 7:3a793ddc3490 26 #define MAX_SPEED_CM_SEC 30.0f /*star< Clamp maximum advancement speed = 30cm/sec, was MAX_SPEED */
sepp_nepp 7:3a793ddc3490 27 #define MIN_SPEED_CM_SEC 0.001f /*star< Clamp minimum advancement speed = 10um/sec */
sepp_nepp 7:3a793ddc3490 28 #define DEFAULT_SPEED_CM_SEC 2.0f /*star< Default advancement speed = 2.0cm/sec, was DEFAULT_SPEED */
garphil 0:a7fb03c9ea9d 29 #define PI 3.141592f
sepp_nepp 7:3a793ddc3490 30 #define DEPTH_FIFO 256 /*star< Initialize the depth of the command FIFO to 256 */
garphil 0:a7fb03c9ea9d 31
sepp_nepp 7:3a793ddc3490 32 /*star \enum BotCmdVerb
sepp_nepp 7:3a793ddc3490 33 * bs_brief Robot Commands Verbs, gives the movement direction
sepp_nepp 6:4d8938b686a6 34 * */
sepp_nepp 6:4d8938b686a6 35 typedef enum {
sepp_nepp 7:3a793ddc3490 36 IDLE = 0, /*star< Command to do nothing */
sepp_nepp 7:3a793ddc3490 37 FORWARD, /*star< Advance the robot straight forward */
sepp_nepp 7:3a793ddc3490 38 BACKWARD, /*star< Advance the robot straight backwards. */
sepp_nepp 7:3a793ddc3490 39 ROTATE, /*star< Rotate around its own axis */
sepp_nepp 7:3a793ddc3490 40 LEFT, /*star< Advance in a left curve */
sepp_nepp 7:3a793ddc3490 41 RIGHT, /*star< Advance in a right curve */
sepp_nepp 7:3a793ddc3490 42 REVLEFT, /*star< Reverse in a left curve */
sepp_nepp 7:3a793ddc3490 43 REVRIGHT /*star< Reverse in a right curve */
sepp_nepp 6:4d8938b686a6 44 } BotCmdVerb;
sepp_nepp 6:4d8938b686a6 45
sepp_nepp 5:efe80c5db389 46
sepp_nepp 7:3a793ddc3490 47 /*star \enum TMotorsState
sepp_nepp 7:3a793ddc3490 48 * bs_brief Possible states of the two motors of the Bot
sepp_nepp 6:4d8938b686a6 49 * */
sepp_nepp 6:4d8938b686a6 50 typedef enum {
sepp_nepp 7:3a793ddc3490 51 LRMOTS_STOP = 0,/*star< All Motors have stopped */
sepp_nepp 7:3a793ddc3490 52 LMOT_RUNS, /*star< Left Motor runs */
sepp_nepp 7:3a793ddc3490 53 RMOT_RUNS, /*star< Right Motor runs */
sepp_nepp 7:3a793ddc3490 54 LRMOTS_RUN /*star< Both Motors run */
sepp_nepp 7:3a793ddc3490 55 } TMotorsState;
sepp_nepp 6:4d8938b686a6 56
sepp_nepp 7:3a793ddc3490 57 /*star \struct BotCommand
sepp_nepp 7:3a793ddc3490 58 * bs_brief Structure of a Motor Command.
sepp_nepp 6:4d8938b686a6 59 * The command structure is put into command FIFO, and treated by the FIFO-Handler */
sepp_nepp 6:4d8938b686a6 60 typedef struct {
sepp_nepp 7:3a793ddc3490 61 BotCmdVerb command; /*star< General Command to give movement direction.*/
sepp_nepp 7:3a793ddc3490 62 float dist_cm; /*star< Distance in dist_cm for translational movements .*/
sepp_nepp 7:3a793ddc3490 63 float angle_deg; /*star< Angle in degree for rotational movement .*/
sepp_nepp 7:3a793ddc3490 64 void set(BotCmdVerb Acommand, float Aangle_deg, float Adist_cm); /*star< Helper; set structure fields to values */
sepp_nepp 7:3a793ddc3490 65 void set(BotCmdVerb Acommand, float Aparam); /*star< Helper; set structure fields to values */
sepp_nepp 6:4d8938b686a6 66 } BotCommand;
sepp_nepp 6:4d8938b686a6 67
sepp_nepp 7:3a793ddc3490 68 /*star \struct geometries
sepp_nepp 7:3a793ddc3490 69 * bs_brief Some geometric encapsulation
sepp_nepp 7:3a793ddc3490 70 * Holds some geometric values */
sepp_nepp 7:3a793ddc3490 71 typedef struct {
sepp_nepp 7:3a793ddc3490 72 float diam_cm;
sepp_nepp 7:3a793ddc3490 73 float perim_cm;
sepp_nepp 7:3a793ddc3490 74 float degree_per_cm;
sepp_nepp 7:3a793ddc3490 75 void setDiam( float Adiam_cm); /*star< Helper; set diameter and perim to values */
sepp_nepp 7:3a793ddc3490 76 } circle_geos;
sepp_nepp 7:3a793ddc3490 77
sepp_nepp 7:3a793ddc3490 78 /*star \class CommandFIFO
sepp_nepp 7:3a793ddc3490 79 * bs_brief 256 elements deep Command FIFO, to puts BotCommand in a queue.
sepp_nepp 6:4d8938b686a6 80 *
sepp_nepp 6:4d8938b686a6 81 * Internally stores all BotCommand in a static 256 array used as a circular ring buffer.
sepp_nepp 6:4d8938b686a6 82 * Adds incoming commands at the head of the ring buffer at position writeIdx,
sepp_nepp 6:4d8938b686a6 83 * Gets oldest commands from the tail of the ring buffer at position readIdx,
sepp_nepp 7:3a793ddc3490 84 * Keeps track of the occupied size in Count.
sepp_nepp 6:4d8938b686a6 85 * BotCommands are passed back as pointers.
sepp_nepp 5:efe80c5db389 86 */
sepp_nepp 5:efe80c5db389 87 class CommandFIFO {
sepp_nepp 5:efe80c5db389 88 public:
sepp_nepp 7:3a793ddc3490 89 /*star Class Creator: initializes an empties FIFO
sepp_nepp 6:4d8938b686a6 90 *
sepp_nepp 6:4d8938b686a6 91 * Ring buffer is allocated statically. Read and Write Index are set to 0. */
sepp_nepp 6:4d8938b686a6 92 CommandFIFO();
sepp_nepp 6:4d8938b686a6 93
sepp_nepp 7:3a793ddc3490 94 /*star Empty the FIFO.
sepp_nepp 6:4d8938b686a6 95 *
sepp_nepp 6:4d8938b686a6 96 * Since ring buffer is static, it suffice to set all pointers to 0, commands are left in memory. */
sepp_nepp 7:3a793ddc3490 97 void empty() {readIdx=writeIdx=Count=0;};
sepp_nepp 6:4d8938b686a6 98
sepp_nepp 7:3a793ddc3490 99 /*star Reserve a new element at the head of the FIFO
sepp_nepp 6:4d8938b686a6 100 *
sepp_nepp 6:4d8938b686a6 101 *If FIFO is full, it passes back NULL
sepp_nepp 6:4d8938b686a6 102 *Otherwise Advances the write index once and returns a pointer the next free command struct.
sepp_nepp 6:4d8938b686a6 103 *The caller then has to fills the command structure at that position.
sepp_nepp 6:4d8938b686a6 104 *Do not free memory associated to the pointer.
sepp_nepp 6:4d8938b686a6 105 *
sepp_nepp 7:3a793ddc3490 106 *at_return <BotCommand*> Pointer to the reserved BotCommand to write to.
sepp_nepp 6:4d8938b686a6 107 */
sepp_nepp 6:4d8938b686a6 108 BotCommand *put();
sepp_nepp 6:4d8938b686a6 109
sepp_nepp 6:4d8938b686a6 110 void put(BotCmdVerb Acommand, float Adist_cm, float Aangle_deg);
sepp_nepp 6:4d8938b686a6 111
sepp_nepp 7:3a793ddc3490 112 /*star Get and remove the oldest element at the tail of the FIFO
sepp_nepp 6:4d8938b686a6 113 *
sepp_nepp 6:4d8938b686a6 114 *If FIFO is empty, it passes back NULL
sepp_nepp 6:4d8938b686a6 115 *Otherwise advances the read index once and returns a pointer the oldest stored command in the FIFO.
sepp_nepp 6:4d8938b686a6 116 *Do not free memory associated with the pointer.
sepp_nepp 6:4d8938b686a6 117 *
sepp_nepp 7:3a793ddc3490 118 *at_return <BotCommand*> Pointer to the oldest BotCommand.
sepp_nepp 6:4d8938b686a6 119 */
sepp_nepp 6:4d8938b686a6 120 BotCommand *get();
sepp_nepp 6:4d8938b686a6 121
sepp_nepp 7:3a793ddc3490 122 /*star Access FIFO used Count.
sepp_nepp 6:4d8938b686a6 123 *
sepp_nepp 7:3a793ddc3490 124 *at_return <int> the number of commands in the FIFO */
sepp_nepp 7:3a793ddc3490 125 int getCount() {return Count;}
sepp_nepp 6:4d8938b686a6 126
sepp_nepp 7:3a793ddc3490 127 /*star Check if FIFO is full.
sepp_nepp 6:4d8938b686a6 128 *
sepp_nepp 6:4d8938b686a6 129 * Space is limited to DEPTH_FIFO=256 BotCommand elements.
sepp_nepp 6:4d8938b686a6 130 * Should be checked before trying to put new elements
sepp_nepp 6:4d8938b686a6 131 *
sepp_nepp 7:3a793ddc3490 132 * at_return <bool> True if FIFO is full*/
sepp_nepp 7:3a793ddc3490 133 bool isFull() {return Count>=DEPTH_FIFO;}
sepp_nepp 6:4d8938b686a6 134
sepp_nepp 7:3a793ddc3490 135 /*star Check if FIFO is empty.
sepp_nepp 6:4d8938b686a6 136 *
sepp_nepp 6:4d8938b686a6 137 * Should be checked before trying to get new elements
sepp_nepp 6:4d8938b686a6 138 *
sepp_nepp 7:3a793ddc3490 139 * at_return <bool> True if FIFO is empty*/
sepp_nepp 7:3a793ddc3490 140 bool isEmpty() {return Count<=0;}
sepp_nepp 6:4d8938b686a6 141
sepp_nepp 5:efe80c5db389 142 private:
sepp_nepp 7:3a793ddc3490 143 int readIdx; /*star< Index in FIFO array where to get the oldest element from. */
sepp_nepp 7:3a793ddc3490 144 int writeIdx; /*star< Index in FIFO array where to put the next new element to. */
sepp_nepp 7:3a793ddc3490 145 int Count; /*star< Counts the number of elements in array used. */
sepp_nepp 7:3a793ddc3490 146 BotCommand cmd[DEPTH_FIFO]; /*star< Actual static FIFO array where all elements reside. */
sepp_nepp 7:3a793ddc3490 147 BotCommand cmd_idle; /*star< A Constant Idle command */
garphil 0:a7fb03c9ea9d 148 };
garphil 0:a7fb03c9ea9d 149
sepp_nepp 7:3a793ddc3490 150 /*star \class Creabot
garphil 0:a7fb03c9ea9d 151
sepp_nepp 7:3a793ddc3490 152 * bs_brief Synchronous Control of 2 motors as part of a two wheel robot
garphil 0:a7fb03c9ea9d 153 *
garphil 0:a7fb03c9ea9d 154 * Example:
sepp_nepp 7:3a793ddc3490 155 * at_code
garphil 0:a7fb03c9ea9d 156 * // --- Define the Four PINs & Time of movement used for Motor drive -----
garphil 0:a7fb03c9ea9d 157 * 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)
garphil 0:a7fb03c9ea9d 158 * Motor motorRight(PA_5,PA_4,PA_3,PA_1);
garphil 0:a7fb03c9ea9d 159 * Creabot mybot(&motorLeft, &motorRight, 10.0f,13.0f); // insert the motors and indicate wheel diameter and distance between wheels
garphil 0:a7fb03c9ea9d 160 *
garphil 0:a7fb03c9ea9d 161 * int main() {
garphil 0:a7fb03c9ea9d 162 *
garphil 0:a7fb03c9ea9d 163 * mybot.setSpeed(12.5); // 12.5cm/s
garphil 0:a7fb03c9ea9d 164 * mybot.move(FORWARD,10); // Go forward of 10cm
garphil 0:a7fb03c9ea9d 165 * mybot.waitEndMove(); // Wait end of Move
garphil 0:a7fb03c9ea9d 166 * mybot.move(ROTATE,90); // Start rotation of 90° around the center between wheels (two wheels running in same direction at same speed)
garphil 0:a7fb03c9ea9d 167 * mybot.move(BACKWARD,40); // Stop immediately the rotation and go backward of 40cm
garphil 0:a7fb03c9ea9d 168 * mybot.waitEndMove(); // Wait end of Backward
garphil 0:a7fb03c9ea9d 169 * mybot.moveAndWait(LEFT,60); // Move Left of 60° in circle, center being the left wheel (off). Wait end of move
garphil 0:a7fb03c9ea9d 170 * mybot.waitEndMove(); // Not needed, as already waited...
garphil 0:a7fb03c9ea9d 171 * 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.
garphil 0:a7fb03c9ea9d 172 * mybot.moveAndWait(ROTATE,90);
garphil 0:a7fb03c9ea9d 173 * mybot.move(ROTATE,-90); // Opposite direction.
garphil 0:a7fb03c9ea9d 174 * mybot.waitEndMove(60); // with watchdog => if after 60s the move is not ended, continue the execution
garphil 0:a7fb03c9ea9d 175 * mybot.stopMove(); // Stop the movement before end...
garphil 0:a7fb03c9ea9d 176 *
garphil 0:a7fb03c9ea9d 177 * // 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.
garphil 0:a7fb03c9ea9d 178 * mybot.fifo(FORWARD,10); // Already starting...
garphil 0:a7fb03c9ea9d 179 * mybot.fifo(BACKWARD,10); // will wait end of previous command to go
garphil 0:a7fb03c9ea9d 180 * mybot.fifo(ROTATE,120.0);
garphil 0:a7fb03c9ea9d 181 * mybot.fifo(LEFT, 30, 120);
garphil 0:a7fb03c9ea9d 182 * mybot.fifo(RIGHT, 25);
garphil 0:a7fb03c9ea9d 183 * mybot.waitEndMove(100000); // wait until fifo end... can flush anytime with stopMove...
garphil 0:a7fb03c9ea9d 184 * mybot.stopMove(); // before end... Flush the fifo and remove all instructions…
garphil 0:a7fb03c9ea9d 185 *
garphil 0:a7fb03c9ea9d 186 * while(1) {
garphil 0:a7fb03c9ea9d 187 * };
garphil 0:a7fb03c9ea9d 188 * }
sepp_nepp 7:3a793ddc3490 189 * at_endcode
garphil 0:a7fb03c9ea9d 190 */
sepp_nepp 5:efe80c5db389 191
garphil 0:a7fb03c9ea9d 192 class Creabot {
garphil 0:a7fb03c9ea9d 193 public:
sepp_nepp 7:3a793ddc3490 194 /*star Create a Creabot object with 2 motors
garphil 0:a7fb03c9ea9d 195 *
sepp_nepp 7:3a793ddc3490 196 * at_param left Motor object declared before corresponding to left motor of the Creabot
sepp_nepp 7:3a793ddc3490 197 * at_param right Motor object declared before corresponding to right motor of the Creabot
sepp_nepp 7:3a793ddc3490 198 * at_param wheel_diam_cm diameter in cm of the wheels (both muste be the same diameter)
sepp_nepp 7:3a793ddc3490 199 * at_param bot_diam_cm distance cm between center of left wheel and center of right wheel
garphil 0:a7fb03c9ea9d 200 */
sepp_nepp 7:3a793ddc3490 201 Creabot(Motor *left, Motor *right, float wheel_diam_cm, float bot_diam_cm);
sepp_nepp 7:3a793ddc3490 202 /*star Property access to Motor state */
sepp_nepp 7:3a793ddc3490 203 TMotorsState getState() {return MotState; };
sepp_nepp 7:3a793ddc3490 204
sepp_nepp 7:3a793ddc3490 205 public:
sepp_nepp 7:3a793ddc3490 206 void qMove(BotCmdVerb moveType, float angle_or_cm);
sepp_nepp 7:3a793ddc3490 207 void qMove(BotCmdVerb moveType, float angle_deg, float dist_cm);
sepp_nepp 6:4d8938b686a6 208
sepp_nepp 6:4d8938b686a6 209 void setCallBack(void (*Acallback)(int status));
sepp_nepp 6:4d8938b686a6 210 void moveAndWait(BotCmdVerb moveType, float angle_or_cm);
sepp_nepp 6:4d8938b686a6 211 void moveAndWait(BotCmdVerb moveType, float angle_deg, float dist_cm);
garphil 0:a7fb03c9ea9d 212 void flushFifo();
garphil 4:531b1120d3ec 213 void spirale(float b, float turns);
garphil 0:a7fb03c9ea9d 214 int moveInFifo();
garphil 0:a7fb03c9ea9d 215 void executeFifo();
sepp_nepp 5:efe80c5db389 216 void stopMove();
garphil 0:a7fb03c9ea9d 217
garphil 0:a7fb03c9ea9d 218 private:
sepp_nepp 6:4d8938b686a6 219 uint32_t computeSpeed(Motor *motor, float speed_cm_sec);
garphil 0:a7fb03c9ea9d 220
sepp_nepp 7:3a793ddc3490 221 private:
sepp_nepp 7:3a793ddc3490 222 CommandFIFO fifoBot;
sepp_nepp 7:3a793ddc3490 223 Ticker botTicker;
sepp_nepp 7:3a793ddc3490 224 bool executingFifo;
sepp_nepp 7:3a793ddc3490 225
sepp_nepp 7:3a793ddc3490 226 public:
sepp_nepp 7:3a793ddc3490 227 void move(BotCmdVerb moveType, float angle_or_cm);
sepp_nepp 7:3a793ddc3490 228 void move(BotCmdVerb moveType, float angle_deg, float dist_cm);
sepp_nepp 6:4d8938b686a6 229 void executeCommand(BotCommand *cmd);
garphil 0:a7fb03c9ea9d 230
sepp_nepp 7:3a793ddc3490 231 public:
sepp_nepp 7:3a793ddc3490 232 /* Mid level access functions: set bot-speed parameter for next motor command*/
sepp_nepp 7:3a793ddc3490 233 void setBotSpeed(float Abot_speed_cm_sec);
sepp_nepp 5:efe80c5db389 234
sepp_nepp 7:3a793ddc3490 235 /* Mid level control function: move bot forward for a given distance */
sepp_nepp 7:3a793ddc3490 236 void moveForward(float dist_cm);
sepp_nepp 7:3a793ddc3490 237 /* Mid level control function: move bot backwards for a given distance */
sepp_nepp 7:3a793ddc3490 238 void moveBackward(float dist_cm);
sepp_nepp 7:3a793ddc3490 239 /* Mid level control function: turn bot forward right,
sepp_nepp 7:3a793ddc3490 240 around a radius twice the bot size */
sepp_nepp 7:3a793ddc3490 241 void moveRight(float angle_deg);
sepp_nepp 7:3a793ddc3490 242 /* Mid level control function: turn bot forward right,
sepp_nepp 7:3a793ddc3490 243 around a radius that is center_cm away from the right wheel*/
sepp_nepp 7:3a793ddc3490 244 void moveRight(float angle_deg, float center_cm);
sepp_nepp 7:3a793ddc3490 245 /* Mid level control function: turn bot forward left,
sepp_nepp 7:3a793ddc3490 246 around a radius twice the bot size */
sepp_nepp 7:3a793ddc3490 247 void moveLeft(float angle_deg);
sepp_nepp 7:3a793ddc3490 248 /* Mid level control function: turn bot forward left,
sepp_nepp 7:3a793ddc3490 249 around a radius that is center_cm away from the left wheel*/
sepp_nepp 7:3a793ddc3490 250 void moveLeft(float angle_deg, float center_cm);
sepp_nepp 7:3a793ddc3490 251 /* Mid level control function: turn bot on its place for a given angle.
sepp_nepp 7:3a793ddc3490 252 positive angles turn right, negative angles turn left*/
sepp_nepp 7:3a793ddc3490 253 void rotate(float angle_deg);
sepp_nepp 7:3a793ddc3490 254
sepp_nepp 7:3a793ddc3490 255 /* Low Level: spends all time with waits,
sepp_nepp 7:3a793ddc3490 256 returns only once MotorState = LRMOTS_STOP,
sepp_nepp 7:3a793ddc3490 257 not recommended due its exclusive blocking behavior */
sepp_nepp 7:3a793ddc3490 258 void waitEndMotors();
sepp_nepp 7:3a793ddc3490 259 /* Low Level: spends all time with waits,
sepp_nepp 7:3a793ddc3490 260 returns only once MotorState = LRMOTS_STOP,
sepp_nepp 7:3a793ddc3490 261 but waits no more than max_wait_ms milli seconds,
sepp_nepp 7:3a793ddc3490 262 not recommended due its exclusive blocking behavior */
sepp_nepp 7:3a793ddc3490 263 void waitEndMotors(uint32_t max_wait_ms); // watchdog
sepp_nepp 7:3a793ddc3490 264
sepp_nepp 6:4d8938b686a6 265 private:
sepp_nepp 7:3a793ddc3490 266 /* geometric properties of each wheel and the bot */
sepp_nepp 7:3a793ddc3490 267 circle_geos wheel,bot;
sepp_nepp 7:3a793ddc3490 268 float ratio_wheel_bot;
sepp_nepp 7:3a793ddc3490 269 float bot_speed_cm_sec; // the requested bot speed
sepp_nepp 7:3a793ddc3490 270
sepp_nepp 7:3a793ddc3490 271 /* Low level access functions: sets both motor speeds immediately */
sepp_nepp 7:3a793ddc3490 272 void setMotorsSpeed(float mot_speed_cm_sec)
sepp_nepp 7:3a793ddc3490 273 /* Low level motor command wrappers, speed, move and stop, state management */
sepp_nepp 7:3a793ddc3490 274 void setMotorSpeed(Motor *motor, float speed_cm_sec);
sepp_nepp 7:3a793ddc3490 275 /*star Commands the Left Motor to Move for a given angle in a given direction
sepp_nepp 7:3a793ddc3490 276 * updates the Motor state MotState */
sepp_nepp 7:3a793ddc3490 277 void moveMotorLeft(motorDir dir, float angle_deg);
sepp_nepp 7:3a793ddc3490 278 /*star Commands the Right Motor to Move for a given angle in a given direction
sepp_nepp 7:3a793ddc3490 279 * updates the Motor state MotState */
sepp_nepp 7:3a793ddc3490 280 void moveMotorRight(motorDir dir, float angle_deg);
sepp_nepp 7:3a793ddc3490 281
sepp_nepp 7:3a793ddc3490 282 /*star Callback when left Motor stops.
sepp_nepp 7:3a793ddc3490 283 * updates the Motor state MotState */
sepp_nepp 6:4d8938b686a6 284 void cbLeftMotStopped();
sepp_nepp 7:3a793ddc3490 285 /*star Callback when right Motor stops.
sepp_nepp 7:3a793ddc3490 286 * updates the Motor state MotState */
sepp_nepp 6:4d8938b686a6 287 void cbRightMotStopped();
sepp_nepp 7:3a793ddc3490 288 /*star Callback when all Motors have stopped.
sepp_nepp 7:3a793ddc3490 289 * updates the Motor state MotState, switch off all Phases */
sepp_nepp 6:4d8938b686a6 290 void AllMotorsStopped();
sepp_nepp 7:3a793ddc3490 291
sepp_nepp 7:3a793ddc3490 292 /*star Callback function pointer: if set it is called when All Motors Stopped()*/
sepp_nepp 7:3a793ddc3490 293 void (*extCallBack)(int status);
sepp_nepp 7:3a793ddc3490 294
sepp_nepp 7:3a793ddc3490 295 /*star Motor status register, remember which of the motors still run */
sepp_nepp 7:3a793ddc3490 296 TMotorsState MotState;
sepp_nepp 7:3a793ddc3490 297
sepp_nepp 7:3a793ddc3490 298 // The two motors, as pointers to their classes
garphil 0:a7fb03c9ea9d 299 Motor *motor_left;
garphil 0:a7fb03c9ea9d 300 Motor *motor_right;
sepp_nepp 5:efe80c5db389 301
sepp_nepp 5:efe80c5db389 302 private:
sepp_nepp 5:efe80c5db389 303 /* members that were not used in last release
sepp_nepp 5:efe80c5db389 304 * float macro_move_parameter;
sepp_nepp 6:4d8938b686a6 305 * BotCommand macro_move;
sepp_nepp 6:4d8938b686a6 306 * void setSpeedLeft(float speed_cm_sec);
sepp_nepp 6:4d8938b686a6 307 * void setSpeedRight(float speed_cm_sec); */
garphil 0:a7fb03c9ea9d 308 };
garphil 0:a7fb03c9ea9d 309
garphil 0:a7fb03c9ea9d 310 #endif