My Version of CreaBotLib

Fork of CreaBotLib by CreaLab

Committer:
sepp_nepp
Date:
Tue Jan 01 21:31:14 2019 +0000
Revision:
8:3b5b0a82b429
Parent:
7:3a793ddc3490
Child:
9:efe9f76d6f76
Minor change to test doxygen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sepp_nepp 7:3a793ddc3490 1 /*
sepp_nepp 8:3b5b0a82b429 2 * \file CreaBot.h
sepp_nepp 8:3b5b0a82b429 3 * \brief File contains Creabot Library.
sepp_nepp 6:4d8938b686a6 4
sepp_nepp 8:3b5b0a82b429 5 * CreaBot.h contains the Motor class, 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 8:3b5b0a82b429 14 * @author Tarek Lule, Francois Druilhe, et al.
sepp_nepp 8:3b5b0a82b429 15 * @date 21. Nov. 2018.
sepp_nepp 8:3b5b0a82b429 16 * @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 8:3b5b0a82b429 26 #define MAX_SPEED_CM_SEC 30.0f /**< Clamp maximum advancement speed = 30cm/sec, was MAX_SPEED */
sepp_nepp 8:3b5b0a82b429 27 #define MIN_SPEED_CM_SEC 0.001f /**< Clamp minimum advancement speed = 10um/sec */
sepp_nepp 8:3b5b0a82b429 28 #define DEFAULT_SPEED_CM_SEC 2.0f /**< Default advancement speed = 2.0cm/sec, was DEFAULT_SPEED */
garphil 0:a7fb03c9ea9d 29 #define PI 3.141592f
sepp_nepp 8:3b5b0a82b429 30 #define DEPTH_FIFO 256 /**< Initialize the depth of the command FIFO to 256 */
garphil 0:a7fb03c9ea9d 31
sepp_nepp 8:3b5b0a82b429 32 /** \enum BotCmdVerb
sepp_nepp 8:3b5b0a82b429 33 * \brief Robot Commands Verbs, gives the movement direction
sepp_nepp 6:4d8938b686a6 34 * */
sepp_nepp 6:4d8938b686a6 35 typedef enum {
sepp_nepp 8:3b5b0a82b429 36 IDLE = 0, /**< Command to do nothing */
sepp_nepp 8:3b5b0a82b429 37 FORWARD, /**< Advance the robot straight forward */
sepp_nepp 8:3b5b0a82b429 38 BACKWARD, /**< Advance the robot straight backwards. */
sepp_nepp 8:3b5b0a82b429 39 ROTATE, /**< Rotate around its own axis */
sepp_nepp 8:3b5b0a82b429 40 LEFT, /**< Advance in a left curve */
sepp_nepp 8:3b5b0a82b429 41 RIGHT, /**< Advance in a right curve */
sepp_nepp 8:3b5b0a82b429 42 REVLEFT, /**< Reverse in a left curve */
sepp_nepp 8:3b5b0a82b429 43 REVRIGHT /**< Reverse in a right curve */
sepp_nepp 6:4d8938b686a6 44 } BotCmdVerb;
sepp_nepp 6:4d8938b686a6 45
sepp_nepp 5:efe80c5db389 46
sepp_nepp 8:3b5b0a82b429 47 /** \enum TMotorsState
sepp_nepp 8:3b5b0a82b429 48 * \brief Possible states of the two motors of the Bot
sepp_nepp 6:4d8938b686a6 49 * */
sepp_nepp 6:4d8938b686a6 50 typedef enum {
sepp_nepp 8:3b5b0a82b429 51 LRMOTS_STOP = 0,/**< All Motors have stopped */
sepp_nepp 8:3b5b0a82b429 52 LMOT_RUNS, /**< Left Motor runs */
sepp_nepp 8:3b5b0a82b429 53 RMOT_RUNS, /**< Right Motor runs */
sepp_nepp 8:3b5b0a82b429 54 LRMOTS_RUN /**< Both Motors run */
sepp_nepp 7:3a793ddc3490 55 } TMotorsState;
sepp_nepp 6:4d8938b686a6 56
sepp_nepp 8:3b5b0a82b429 57 /** \struct BotCommand
sepp_nepp 8:3b5b0a82b429 58 * \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 8:3b5b0a82b429 61 BotCmdVerb command; /**< General Command to give movement direction.*/
sepp_nepp 8:3b5b0a82b429 62 float dist_cm; /**< Distance in dist_cm for translational movements .*/
sepp_nepp 8:3b5b0a82b429 63 float angle_deg; /**< Angle in degree for rotational movement .*/
sepp_nepp 8:3b5b0a82b429 64 void set(BotCmdVerb Acommand, float Aangle_deg, float Adist_cm); /**< Helper; set structure fields to values */
sepp_nepp 8:3b5b0a82b429 65 void set(BotCmdVerb Acommand, float Aparam); /**< Helper; set structure fields to values */
sepp_nepp 6:4d8938b686a6 66 } BotCommand;
sepp_nepp 6:4d8938b686a6 67
sepp_nepp 8:3b5b0a82b429 68 /** \struct geometries
sepp_nepp 8:3b5b0a82b429 69 * \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 8:3b5b0a82b429 75 void setDiam( float Adiam_cm); /**< Helper; set diameter and perim to values */
sepp_nepp 7:3a793ddc3490 76 } circle_geos;
sepp_nepp 7:3a793ddc3490 77
sepp_nepp 8:3b5b0a82b429 78 /** \class CommandFIFO
sepp_nepp 8:3b5b0a82b429 79 * \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 8:3b5b0a82b429 89 /** 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 8:3b5b0a82b429 94 /** 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 8:3b5b0a82b429 99 /** 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 8:3b5b0a82b429 106 *@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 8:3b5b0a82b429 112 /** 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 8:3b5b0a82b429 118 *@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 8:3b5b0a82b429 122 /** Access FIFO used Count.
sepp_nepp 6:4d8938b686a6 123 *
sepp_nepp 8:3b5b0a82b429 124 *@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 8:3b5b0a82b429 127 /** 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 8:3b5b0a82b429 132 * @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 8:3b5b0a82b429 135 /** 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 8:3b5b0a82b429 139 * @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 8:3b5b0a82b429 143 int readIdx; /**< Index in FIFO array where to get the oldest element from. */
sepp_nepp 8:3b5b0a82b429 144 int writeIdx; /**< Index in FIFO array where to put the next new element to. */
sepp_nepp 8:3b5b0a82b429 145 int Count; /**< Counts the number of elements in array used. */
sepp_nepp 8:3b5b0a82b429 146 BotCommand cmd[DEPTH_FIFO]; /**< Actual static FIFO array where all elements reside. */
sepp_nepp 8:3b5b0a82b429 147 BotCommand cmd_idle; /**< A Constant Idle command */
garphil 0:a7fb03c9ea9d 148 };
garphil 0:a7fb03c9ea9d 149
sepp_nepp 8:3b5b0a82b429 150 /** \class Creabot
garphil 0:a7fb03c9ea9d 151
sepp_nepp 8:3b5b0a82b429 152 * \brief Synchronous Control of 2 motors as part of a two wheel robot
garphil 0:a7fb03c9ea9d 153 *
garphil 0:a7fb03c9ea9d 154 * Example:
sepp_nepp 8:3b5b0a82b429 155 * @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 8:3b5b0a82b429 189 * @endcode
garphil 0:a7fb03c9ea9d 190 */
sepp_nepp 5:efe80c5db389 191
garphil 0:a7fb03c9ea9d 192 class Creabot {
garphil 0:a7fb03c9ea9d 193 public:
sepp_nepp 8:3b5b0a82b429 194 /** Create a Creabot object with 2 motors
garphil 0:a7fb03c9ea9d 195 *
sepp_nepp 8:3b5b0a82b429 196 * @param left Motor object declared before corresponding to left motor of the Creabot
sepp_nepp 8:3b5b0a82b429 197 * @param right Motor object declared before corresponding to right motor of the Creabot
sepp_nepp 8:3b5b0a82b429 198 * @param wheel_diam_cm diameter in cm of the wheels (both muste be the same diameter)
sepp_nepp 8:3b5b0a82b429 199 * @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 8:3b5b0a82b429 202 /** 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 8:3b5b0a82b429 227 /** Mid level, immediate: set bot-speed parameter all future motor commands*/
sepp_nepp 8:3b5b0a82b429 228 void setBotSpeed(float Abot_speed_cm_sec);
sepp_nepp 8:3b5b0a82b429 229
sepp_nepp 8:3b5b0a82b429 230 /** Mid level, immediate: move bot according to command and parameter
sepp_nepp 8:3b5b0a82b429 231 * Use for commands that need only one parameter: FORWARD, BACKWARD, ROTATE
sepp_nepp 8:3b5b0a82b429 232 * Can also be called with IDLE, but then has no effect.
sepp_nepp 8:3b5b0a82b429 233 * Preset the speed using setBotSpeed().
sepp_nepp 8:3b5b0a82b429 234 * Warning: Collides with queued commands.
sepp_nepp 8:3b5b0a82b429 235 * @param[in] <Acommand> Requested movement, of type BotCmdVerb
sepp_nepp 8:3b5b0a82b429 236 * @param[in] <Aparam> Requested amount, defines angle for ROTATE, or distance for FORWARD, BACKWARD
sepp_nepp 8:3b5b0a82b429 237 */
sepp_nepp 8:3b5b0a82b429 238 void moveBot(BotCmdVerb Acommand, float Aparam);
sepp_nepp 8:3b5b0a82b429 239 void moveBot(BotCmdVerb Acommand, float Aangle_deg, float Adist_cm);
sepp_nepp 6:4d8938b686a6 240 void executeCommand(BotCommand *cmd);
sepp_nepp 8:3b5b0a82b429 241 LEFT, /**< Advance in a left curve */
sepp_nepp 8:3b5b0a82b429 242 RIGHT, /**< Advance in a right curve */
sepp_nepp 8:3b5b0a82b429 243 REVLEFT, /**< Reverse in a left curve */
sepp_nepp 8:3b5b0a82b429 244 REVRIGHT /**< Reverse in a right curve */
garphil 0:a7fb03c9ea9d 245
sepp_nepp 7:3a793ddc3490 246 public:
sepp_nepp 5:efe80c5db389 247
sepp_nepp 8:3b5b0a82b429 248 /** Mid level, immediate: move bot forward for a given distance,
sepp_nepp 8:3b5b0a82b429 249 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 250 void moveForward(float dist_cm);
sepp_nepp 8:3b5b0a82b429 251
sepp_nepp 8:3b5b0a82b429 252 /** Mid level, immediate: move bot backwards for a given distance,
sepp_nepp 8:3b5b0a82b429 253 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 254 void moveBackward(float dist_cm);
sepp_nepp 8:3b5b0a82b429 255
sepp_nepp 8:3b5b0a82b429 256 /* Mid level, immediate: turn bot forward right,
sepp_nepp 8:3b5b0a82b429 257 * around a radius twice the bot size ,
sepp_nepp 8:3b5b0a82b429 258 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 259 void moveRight(float angle_deg);
sepp_nepp 8:3b5b0a82b429 260
sepp_nepp 8:3b5b0a82b429 261 /** Mid level, immediate: turn bot forward right,
sepp_nepp 8:3b5b0a82b429 262 * around a radius that is center_cm away from the right wheel,
sepp_nepp 8:3b5b0a82b429 263 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 264 void moveRight(float angle_deg, float center_cm);
sepp_nepp 8:3b5b0a82b429 265
sepp_nepp 8:3b5b0a82b429 266 /** Mid level, immediate: turn bot forward left,
sepp_nepp 8:3b5b0a82b429 267 * around a radius twice the bot size,
sepp_nepp 8:3b5b0a82b429 268 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 269 void moveLeft(float angle_deg);
sepp_nepp 8:3b5b0a82b429 270
sepp_nepp 8:3b5b0a82b429 271 /** Mid level, immediate: turn bot forward left,
sepp_nepp 8:3b5b0a82b429 272 around a radius that is center_cm away from the left wheel,
sepp_nepp 8:3b5b0a82b429 273 Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 274 void moveLeft(float angle_deg, float center_cm);
sepp_nepp 8:3b5b0a82b429 275
sepp_nepp 8:3b5b0a82b429 276 /** Mid level, immediate: turn bot on its place for a given angle.
sepp_nepp 8:3b5b0a82b429 277 * positive angles turn right, negative angles turn left,
sepp_nepp 8:3b5b0a82b429 278 * Set speed with setBotSpeed, collides with queued commands. */
sepp_nepp 7:3a793ddc3490 279 void rotate(float angle_deg);
sepp_nepp 7:3a793ddc3490 280
sepp_nepp 8:3b5b0a82b429 281 /** Low Level: spends all time with waits,
sepp_nepp 8:3b5b0a82b429 282 * returns only once MotorState = LRMOTS_STOP,
sepp_nepp 8:3b5b0a82b429 283 * not recommended due its exclusive blocking behavior */
sepp_nepp 7:3a793ddc3490 284 void waitEndMotors();
sepp_nepp 8:3b5b0a82b429 285
sepp_nepp 8:3b5b0a82b429 286 /** Low Level: spends all time with waits,
sepp_nepp 8:3b5b0a82b429 287 * returns only once MotorState = LRMOTS_STOP,
sepp_nepp 8:3b5b0a82b429 288 * but waits no more than max_wait_ms milli seconds.
sepp_nepp 8:3b5b0a82b429 289 * Not recommended due its exclusive blocking behavior */
sepp_nepp 7:3a793ddc3490 290 void waitEndMotors(uint32_t max_wait_ms); // watchdog
sepp_nepp 7:3a793ddc3490 291
sepp_nepp 6:4d8938b686a6 292 private:
sepp_nepp 7:3a793ddc3490 293
sepp_nepp 8:3b5b0a82b429 294 /** Low level, immediate: sets both motor speeds */
sepp_nepp 8:3b5b0a82b429 295 void setMotorsSpeed(float mot_speed_cm_sec);
sepp_nepp 8:3b5b0a82b429 296
sepp_nepp 8:3b5b0a82b429 297 /** Low level, immediate: command wrappers, speed, move and stop, state management */
sepp_nepp 7:3a793ddc3490 298 void setMotorSpeed(Motor *motor, float speed_cm_sec);
sepp_nepp 8:3b5b0a82b429 299
sepp_nepp 8:3b5b0a82b429 300 /** Low level, immediate: Left Motor Move for a given angle in a given direction
sepp_nepp 7:3a793ddc3490 301 * updates the Motor state MotState */
sepp_nepp 7:3a793ddc3490 302 void moveMotorLeft(motorDir dir, float angle_deg);
sepp_nepp 8:3b5b0a82b429 303
sepp_nepp 8:3b5b0a82b429 304 /** Low level, immediate: Right Motor Move for a given angle in a given direction
sepp_nepp 7:3a793ddc3490 305 * updates the Motor state MotState */
sepp_nepp 7:3a793ddc3490 306 void moveMotorRight(motorDir dir, float angle_deg);
sepp_nepp 7:3a793ddc3490 307
sepp_nepp 8:3b5b0a82b429 308 /** Callback when left Motor stops;
sepp_nepp 7:3a793ddc3490 309 * updates the Motor state MotState */
sepp_nepp 6:4d8938b686a6 310 void cbLeftMotStopped();
sepp_nepp 8:3b5b0a82b429 311
sepp_nepp 8:3b5b0a82b429 312 /** Callback when right Motor stops.
sepp_nepp 7:3a793ddc3490 313 * updates the Motor state MotState */
sepp_nepp 6:4d8938b686a6 314 void cbRightMotStopped();
sepp_nepp 8:3b5b0a82b429 315
sepp_nepp 8:3b5b0a82b429 316 /** Callback when all Motors have stopped.
sepp_nepp 7:3a793ddc3490 317 * updates the Motor state MotState, switch off all Phases */
sepp_nepp 6:4d8938b686a6 318 void AllMotorsStopped();
sepp_nepp 7:3a793ddc3490 319
sepp_nepp 8:3b5b0a82b429 320 /** Callback function pointer:
sepp_nepp 8:3b5b0a82b429 321 * If set non-NULL it is called when All Motors Stopped()*/
sepp_nepp 7:3a793ddc3490 322 void (*extCallBack)(int status);
sepp_nepp 7:3a793ddc3490 323
sepp_nepp 8:3b5b0a82b429 324 /** Motor status register:
sepp_nepp 8:3b5b0a82b429 325 * Remembers which of the motors still run */
sepp_nepp 7:3a793ddc3490 326 TMotorsState MotState;
sepp_nepp 7:3a793ddc3490 327
sepp_nepp 8:3b5b0a82b429 328 /** geometric properties of each wheel and the bot */
sepp_nepp 8:3b5b0a82b429 329 circle_geos wheel,bot;
sepp_nepp 8:3b5b0a82b429 330 /** Ratio of wheel diameter and bot diameter */
sepp_nepp 8:3b5b0a82b429 331 float ratio_wheel_bot;
sepp_nepp 8:3b5b0a82b429 332 /** last requested bot speed */
sepp_nepp 8:3b5b0a82b429 333 float bot_speed_cm_sec;
sepp_nepp 8:3b5b0a82b429 334
sepp_nepp 8:3b5b0a82b429 335 /** The two motors, as pointers to their classes */
garphil 0:a7fb03c9ea9d 336 Motor *motor_left;
garphil 0:a7fb03c9ea9d 337 Motor *motor_right;
sepp_nepp 5:efe80c5db389 338
sepp_nepp 8:3b5b0a82b429 339 /* members that were already stale in last public release
sepp_nepp 5:efe80c5db389 340 * float macro_move_parameter;
sepp_nepp 6:4d8938b686a6 341 * BotCommand macro_move;
sepp_nepp 6:4d8938b686a6 342 * void setSpeedLeft(float speed_cm_sec);
sepp_nepp 6:4d8938b686a6 343 * void setSpeedRight(float speed_cm_sec); */
garphil 0:a7fb03c9ea9d 344 };
garphil 0:a7fb03c9ea9d 345
garphil 0:a7fb03c9ea9d 346 #endif