Remove Warning from Servo lib in AsyncServo lib : Single-precision operand implicitly converted to double-precision
Dependencies: CREALIB CreaBotLib X_NUCLEO_6180XA1 mbed
main.cpp@1:e3a7f5c1d266, 2017-08-18 (annotated)
- Committer:
- Gibb
- Date:
- Fri Aug 18 12:36:17 2017 +0000
- Revision:
- 1:e3a7f5c1d266
- Parent:
- 0:e655b0bc47b2
Remove Warning from Servo Lib in AsyncServo lib from Crealib: Single-precision operand implicitly converted to double-precision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gibb | 0:e655b0bc47b2 | 1 | #include <Crealab.h> |
Gibb | 0:e655b0bc47b2 | 2 | #include <CreaBot.h> |
Gibb | 0:e655b0bc47b2 | 3 | #include <XNucleo6180XA1.h> |
Gibb | 0:e655b0bc47b2 | 4 | |
Gibb | 0:e655b0bc47b2 | 5 | Serial pc_uart(PA_2, PA_15,115200); // PC Term |
Gibb | 0:e655b0bc47b2 | 6 | Serial bt_uart(PA_9, PA_10); // BlueTooth |
Gibb | 0:e655b0bc47b2 | 7 | |
Gibb | 0:e655b0bc47b2 | 8 | // --- Define the Four PINs & Time of movement used for Motor drive ----- |
Gibb | 0:e655b0bc47b2 | 9 | Motor motorLeft (D2, D3, D4, D5); // Declare first the 2 motors (to avoid to have an object with 8 pins to create) |
Gibb | 0:e655b0bc47b2 | 10 | Motor motorRight (D6, D7, D8, D9); |
Gibb | 0:e655b0bc47b2 | 11 | Creabot mybot(&motorLeft, &motorRight, 10.0f,13.0f); // insert the motors and indicate wheel diameter and distance between wheels |
Gibb | 0:e655b0bc47b2 | 12 | |
Gibb | 0:e655b0bc47b2 | 13 | // ----------- PIN Definitions 6180 ------------- |
Gibb | 0:e655b0bc47b2 | 14 | #define VL6180X_I2C_SDA D14 |
Gibb | 0:e655b0bc47b2 | 15 | #define VL6180X_I2C_SCL D15 |
Gibb | 0:e655b0bc47b2 | 16 | static XNucleo6180XA1 *board = NULL; |
Gibb | 0:e655b0bc47b2 | 17 | |
Gibb | 0:e655b0bc47b2 | 18 | |
Gibb | 0:e655b0bc47b2 | 19 | int main() { |
Gibb | 0:e655b0bc47b2 | 20 | |
Gibb | 0:e655b0bc47b2 | 21 | |
Gibb | 0:e655b0bc47b2 | 22 | /* Init 6180 X-Nucleo */ |
Gibb | 0:e655b0bc47b2 | 23 | int status; |
Gibb | 0:e655b0bc47b2 | 24 | uint32_t dist; |
Gibb | 0:e655b0bc47b2 | 25 | DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL); |
Gibb | 0:e655b0bc47b2 | 26 | board = XNucleo6180XA1::instance(device_i2c, A5, A4, D13, D4); |
Gibb | 0:e655b0bc47b2 | 27 | status = board->init_board(); |
Gibb | 0:e655b0bc47b2 | 28 | if (status) { |
Gibb | 0:e655b0bc47b2 | 29 | DEBUG("Failed to init board!\n\r"); |
Gibb | 0:e655b0bc47b2 | 30 | } |
Gibb | 0:e655b0bc47b2 | 31 | /* -------- */ |
Gibb | 0:e655b0bc47b2 | 32 | |
Gibb | 0:e655b0bc47b2 | 33 | wait(2); // Some delay |
Gibb | 0:e655b0bc47b2 | 34 | |
Gibb | 0:e655b0bc47b2 | 35 | |
Gibb | 0:e655b0bc47b2 | 36 | mybot.setSpeed(12.5); // 12.5cm/s |
Gibb | 0:e655b0bc47b2 | 37 | mybot.move(FORWARD,10); // Go forward of 10cm |
Gibb | 0:e655b0bc47b2 | 38 | mybot.waitEndMove(); // Wait end of Move |
Gibb | 0:e655b0bc47b2 | 39 | mybot.move(ROTATE,90); // Start rotation of 90° around the center between wheels (two wheels running in same direction at same speed) |
Gibb | 0:e655b0bc47b2 | 40 | mybot.move(BACKWARD,40); // Stop immediately the rotation and go backward of 40cm |
Gibb | 0:e655b0bc47b2 | 41 | mybot.waitEndMove(); // Wait end of Backward |
Gibb | 0:e655b0bc47b2 | 42 | mybot.moveAndWait(LEFT,60); // Move Left of 60° in circle, center being the left wheel (off). Wait end of move |
Gibb | 0:e655b0bc47b2 | 43 | mybot.waitEndMove(); // Not needed, as already waited... |
Gibb | 0:e655b0bc47b2 | 44 | 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. |
Gibb | 0:e655b0bc47b2 | 45 | mybot.moveAndWait(ROTATE,90); |
Gibb | 0:e655b0bc47b2 | 46 | mybot.move(ROTATE,-90); // Opposite direction. |
Gibb | 0:e655b0bc47b2 | 47 | mybot.waitEndMove(60); // with watchdog => if after 60s the move is not ended, continue the execution |
Gibb | 0:e655b0bc47b2 | 48 | mybot.stopMove(); // Stop the movement before end... |
Gibb | 0:e655b0bc47b2 | 49 | |
Gibb | 0:e655b0bc47b2 | 50 | // 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. |
Gibb | 0:e655b0bc47b2 | 51 | mybot.fifo(FORWARD,10); // Already starting... |
Gibb | 0:e655b0bc47b2 | 52 | mybot.fifo(BACKWARD,10); // will wait end of previous command to go |
Gibb | 0:e655b0bc47b2 | 53 | mybot.fifo(ROTATE,120.0); |
Gibb | 0:e655b0bc47b2 | 54 | mybot.fifo(LEFT, 30, 120); |
Gibb | 0:e655b0bc47b2 | 55 | mybot.fifo(RIGHT, 25); |
Gibb | 0:e655b0bc47b2 | 56 | mybot.waitEndMove(100000); // wait until fifo end... can flush anytime with stopMove... |
Gibb | 0:e655b0bc47b2 | 57 | mybot.stopMove(); // before end... Flush the fifo and remove all instructions… |
Gibb | 0:e655b0bc47b2 | 58 | |
Gibb | 0:e655b0bc47b2 | 59 | while(1) { |
Gibb | 0:e655b0bc47b2 | 60 | }; |
Gibb | 0:e655b0bc47b2 | 61 | } |
Gibb | 0:e655b0bc47b2 | 62 |