librairie pour robot Zumo
zumo.h@11:1082c5b3b418, 2022-01-10 (annotated)
- Committer:
- bouaziz
- Date:
- Mon Jan 10 08:59:37 2022 +0000
- Revision:
- 11:1082c5b3b418
- Parent:
- 10:7935bbc4ebf1
- Child:
- 12:d9c9ef63c5ff
Zumo lib Polytech paris Saclay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bouaziz | 10:7935bbc4ebf1 | 1 | /* mbed zumo Library |
chris | 0:e6020bd04b45 | 2 | * Copyright (c) 2007-2010 cstyles |
chris | 0:e6020bd04b45 | 3 | * |
chris | 0:e6020bd04b45 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
chris | 0:e6020bd04b45 | 5 | * of this software and associated documentation files (the "Software"), to deal |
chris | 0:e6020bd04b45 | 6 | * in the Software without restriction, including without limitation the rights |
chris | 0:e6020bd04b45 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
chris | 0:e6020bd04b45 | 8 | * copies of the Software, and to permit persons to whom the Software is |
chris | 0:e6020bd04b45 | 9 | * furnished to do so, subject to the following conditions: |
chris | 0:e6020bd04b45 | 10 | * |
chris | 0:e6020bd04b45 | 11 | * The above copyright notice and this permission notice shall be included in |
chris | 0:e6020bd04b45 | 12 | * all copies or substantial portions of the Software. |
chris | 0:e6020bd04b45 | 13 | * |
chris | 0:e6020bd04b45 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
chris | 0:e6020bd04b45 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
chris | 0:e6020bd04b45 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
chris | 0:e6020bd04b45 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
chris | 0:e6020bd04b45 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
chris | 0:e6020bd04b45 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
chris | 0:e6020bd04b45 | 20 | * THE SOFTWARE. |
chris | 0:e6020bd04b45 | 21 | */ |
chris | 0:e6020bd04b45 | 22 | |
bouaziz | 10:7935bbc4ebf1 | 23 | #ifndef zumo_H |
bouaziz | 10:7935bbc4ebf1 | 24 | #define zumo_H |
chris | 0:e6020bd04b45 | 25 | |
chris | 0:e6020bd04b45 | 26 | #include "mbed.h" |
chris | 0:e6020bd04b45 | 27 | #include "platform.h" |
chris | 0:e6020bd04b45 | 28 | |
chris | 0:e6020bd04b45 | 29 | |
bouaziz | 11:1082c5b3b418 | 30 | #define SEND_MOTOR_SPEED 0xA4 |
bouaziz | 11:1082c5b3b418 | 31 | #define SEND_MOTOR_STOP 0xA0 |
bouaziz | 11:1082c5b3b418 | 32 | |
bouaziz | 11:1082c5b3b418 | 33 | |
bouaziz | 11:1082c5b3b418 | 34 | |
bouaziz | 9:f65c5aa1775c | 35 | #define SEND_CALIB_SENSOR_VALUES 0x87 |
chris | 0:e6020bd04b45 | 36 | #define SEND_TRIMPOT 0xB0 |
chris | 0:e6020bd04b45 | 37 | #define SEND_BATTERY_MILLIVOLTS 0xB1 |
chris | 0:e6020bd04b45 | 38 | #define DO_PLAY 0xB3 |
chris | 0:e6020bd04b45 | 39 | #define PI_CALIBRATE 0xB4 |
chris | 0:e6020bd04b45 | 40 | #define DO_CLEAR 0xB7 |
chris | 0:e6020bd04b45 | 41 | #define DO_PRINT 0xB8 |
chris | 0:e6020bd04b45 | 42 | #define DO_LCD_GOTO_XY 0xB9 |
chris | 0:e6020bd04b45 | 43 | #define LINE_SENSORS_RESET_CALIBRATION 0xB5 |
chris | 0:e6020bd04b45 | 44 | #define SEND_LINE_POSITION 0xB6 |
chris | 0:e6020bd04b45 | 45 | #define AUTO_CALIBRATE 0xBA |
chris | 0:e6020bd04b45 | 46 | #define SET_PID 0xBB |
chris | 0:e6020bd04b45 | 47 | #define STOP_PID 0xBC |
chris | 0:e6020bd04b45 | 48 | #define M1_FORWARD 0xC1 |
chris | 0:e6020bd04b45 | 49 | #define M1_BACKWARD 0xC2 |
chris | 0:e6020bd04b45 | 50 | #define M2_FORWARD 0xC5 |
chris | 0:e6020bd04b45 | 51 | #define M2_BACKWARD 0xC6 |
chris | 0:e6020bd04b45 | 52 | |
chris | 0:e6020bd04b45 | 53 | |
chris | 0:e6020bd04b45 | 54 | |
bouaziz | 10:7935bbc4ebf1 | 55 | /** zumo control class |
chris | 0:e6020bd04b45 | 56 | * |
chris | 0:e6020bd04b45 | 57 | * Example: |
chris | 0:e6020bd04b45 | 58 | * @code |
bouaziz | 10:7935bbc4ebf1 | 59 | * // Drive the zumo forward, turn left, back, turn right, at half speed for half a second |
chris | 0:e6020bd04b45 | 60 | |
chris | 0:e6020bd04b45 | 61 | #include "mbed.h" |
bouaziz | 10:7935bbc4ebf1 | 62 | #include "zumo.h" |
chris | 0:e6020bd04b45 | 63 | |
bouaziz | 10:7935bbc4ebf1 | 64 | zumo pi; |
chris | 0:e6020bd04b45 | 65 | |
chris | 0:e6020bd04b45 | 66 | int main() { |
chris | 0:e6020bd04b45 | 67 | |
chris | 0:e6020bd04b45 | 68 | wait(0.5); |
chris | 0:e6020bd04b45 | 69 | |
chris | 0:e6020bd04b45 | 70 | pi.forward(0.5); |
chris | 0:e6020bd04b45 | 71 | wait (0.5); |
chris | 0:e6020bd04b45 | 72 | pi.left(0.5); |
chris | 0:e6020bd04b45 | 73 | wait (0.5); |
chris | 0:e6020bd04b45 | 74 | pi.backward(0.5); |
chris | 0:e6020bd04b45 | 75 | wait (0.5); |
chris | 0:e6020bd04b45 | 76 | pi.right(0.5); |
chris | 0:e6020bd04b45 | 77 | wait (0.5); |
chris | 0:e6020bd04b45 | 78 | |
chris | 0:e6020bd04b45 | 79 | pi.stop(); |
chris | 0:e6020bd04b45 | 80 | |
chris | 0:e6020bd04b45 | 81 | } |
chris | 0:e6020bd04b45 | 82 | * @endcode |
chris | 0:e6020bd04b45 | 83 | */ |
bouaziz | 10:7935bbc4ebf1 | 84 | class zumo { |
chris | 0:e6020bd04b45 | 85 | |
chris | 0:e6020bd04b45 | 86 | // Public functions |
chris | 0:e6020bd04b45 | 87 | public: |
chris | 0:e6020bd04b45 | 88 | |
bouaziz | 10:7935bbc4ebf1 | 89 | /** Create the zumo object connected to the default pins |
chris | 0:e6020bd04b45 | 90 | * |
bouaziz | 10:7935bbc4ebf1 | 91 | * @param nrst GPIO pin used for reset. for futre use |
chris | 0:e6020bd04b45 | 92 | * @param tx Serial transmit pin. Default is p9 |
chris | 0:e6020bd04b45 | 93 | * @param rx Serial receive pin. Default is p10 |
chris | 0:e6020bd04b45 | 94 | */ |
bouaziz | 10:7935bbc4ebf1 | 95 | zumo(); |
bouaziz | 10:7935bbc4ebf1 | 96 | //reset(); |
chris | 7:9b128cebb3c2 | 97 | |
bouaziz | 10:7935bbc4ebf1 | 98 | /** Create the zumo object connected to specific pins |
chris | 7:9b128cebb3c2 | 99 | * |
chris | 7:9b128cebb3c2 | 100 | */ |
bouaziz | 10:7935bbc4ebf1 | 101 | zumo(PinName nrst, PinName tx, PinName rx); |
chris | 7:9b128cebb3c2 | 102 | |
chris | 0:e6020bd04b45 | 103 | /** Force a hardware reset of the 3pi |
chris | 0:e6020bd04b45 | 104 | */ |
chris | 0:e6020bd04b45 | 105 | void reset (void); |
chris | 0:e6020bd04b45 | 106 | |
chris | 0:e6020bd04b45 | 107 | /** Stop both motors |
chris | 0:e6020bd04b45 | 108 | * |
chris | 0:e6020bd04b45 | 109 | */ |
chris | 0:e6020bd04b45 | 110 | void stop (void); |
chris | 0:e6020bd04b45 | 111 | |
chris | 0:e6020bd04b45 | 112 | |
chris | 0:e6020bd04b45 | 113 | /** Read the battery voltage on the 3pi |
chris | 0:e6020bd04b45 | 114 | * @returns battery voltage as a float |
chris | 0:e6020bd04b45 | 115 | */ |
chris | 0:e6020bd04b45 | 116 | float battery(void); |
chris | 0:e6020bd04b45 | 117 | |
chris | 0:e6020bd04b45 | 118 | /** Read the position of the detected line |
chris | 0:e6020bd04b45 | 119 | * @returns position as A normalised number -1.0 - 1.0 represents the full range. |
chris | 7:9b128cebb3c2 | 120 | * -1.0 means line is on the left, or the line has been lost |
chris | 7:9b128cebb3c2 | 121 | * 0.0 means the line is in the middle |
chris | 7:9b128cebb3c2 | 122 | * 1.0 means the line is on the right |
chris | 0:e6020bd04b45 | 123 | */ |
chris | 0:e6020bd04b45 | 124 | float line_position (void); |
bouaziz | 9:f65c5aa1775c | 125 | /** lecture capteurs calibres |
bouaziz | 9:f65c5aa1775c | 126 | * @returns tableau val capteurs de gauche à droite |
bouaziz | 9:f65c5aa1775c | 127 | * 0 blanc (reflexion max) |
bouaziz | 9:f65c5aa1775c | 128 | * 1000 noir (pas de reflexion) |
bouaziz | 9:f65c5aa1775c | 129 | */ |
bouaziz | 9:f65c5aa1775c | 130 | void calibrated_sensors(unsigned short ltab[5]); |
bouaziz | 10:7935bbc4ebf1 | 131 | |
bouaziz | 10:7935bbc4ebf1 | 132 | /** fonction speed |
bouaziz | 10:7935bbc4ebf1 | 133 | * @returns pour le future retourne 0x0A pour indiquer bonne prise en compte. |
bouaziz | 10:7935bbc4ebf1 | 134 | * Pour le moment retourne rien. |
bouaziz | 10:7935bbc4ebf1 | 135 | * |
bouaziz | 10:7935bbc4ebf1 | 136 | */ |
bouaziz | 10:7935bbc4ebf1 | 137 | char speed(short spg,short spd); |
chris | 0:e6020bd04b45 | 138 | |
chris | 7:9b128cebb3c2 | 139 | /** Calibrate the sensors. This turns the robot left then right, looking for a line |
chris | 0:e6020bd04b45 | 140 | * |
chris | 0:e6020bd04b45 | 141 | */ |
chris | 0:e6020bd04b45 | 142 | char sensor_auto_calibrate (void); |
chris | 0:e6020bd04b45 | 143 | |
chris | 1:816a80dcc1a3 | 144 | void PID_start(int max_speed, int a, int b, int c, int d); |
chris | 1:816a80dcc1a3 | 145 | |
chris | 1:816a80dcc1a3 | 146 | void PID_stop(); |
chris | 1:816a80dcc1a3 | 147 | |
chris | 5:09fb0636207b | 148 | /** Write to the 8 LEDs |
chris | 5:09fb0636207b | 149 | * |
chris | 5:09fb0636207b | 150 | * @param leds An 8 bit value to put on the LEDs |
chris | 5:09fb0636207b | 151 | */ |
chris | 5:09fb0636207b | 152 | void leds(int val); |
chris | 5:09fb0636207b | 153 | |
bouaziz | 10:7935bbc4ebf1 | 154 | Serial _ser; |
chris | 0:e6020bd04b45 | 155 | private : |
chris | 0:e6020bd04b45 | 156 | |
chris | 0:e6020bd04b45 | 157 | DigitalOut _nrst; |
chris | 4:54c673c71fc0 | 158 | |
chris | 0:e6020bd04b45 | 159 | |
chris | 0:e6020bd04b45 | 160 | }; |
chris | 0:e6020bd04b45 | 161 | |
chris | 0:e6020bd04b45 | 162 | #endif |