librairie pour robot Zumo

Committer:
bouaziz
Date:
Wed Dec 08 16:33:24 2021 +0000
Revision:
10:7935bbc4ebf1
Parent:
m3pi.h@9:f65c5aa1775c
Child:
11:1082c5b3b418
projet APP5 Polytech paris saclay

Who changed what in which revision?

UserRevisionLine numberNew 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
chris 0:e6020bd04b45 30 #define SEND_SIGNATURE 0x81
chris 0:e6020bd04b45 31 #define SEND_RAW_SENSOR_VALUES 0x86
bouaziz 9:f65c5aa1775c 32 #define SEND_CALIB_SENSOR_VALUES 0x87
chris 0:e6020bd04b45 33 #define SEND_TRIMPOT 0xB0
chris 0:e6020bd04b45 34 #define SEND_BATTERY_MILLIVOLTS 0xB1
chris 0:e6020bd04b45 35 #define DO_PLAY 0xB3
chris 0:e6020bd04b45 36 #define PI_CALIBRATE 0xB4
chris 0:e6020bd04b45 37 #define DO_CLEAR 0xB7
chris 0:e6020bd04b45 38 #define DO_PRINT 0xB8
chris 0:e6020bd04b45 39 #define DO_LCD_GOTO_XY 0xB9
chris 0:e6020bd04b45 40 #define LINE_SENSORS_RESET_CALIBRATION 0xB5
chris 0:e6020bd04b45 41 #define SEND_LINE_POSITION 0xB6
chris 0:e6020bd04b45 42 #define AUTO_CALIBRATE 0xBA
chris 0:e6020bd04b45 43 #define SET_PID 0xBB
chris 0:e6020bd04b45 44 #define STOP_PID 0xBC
chris 0:e6020bd04b45 45 #define M1_FORWARD 0xC1
chris 0:e6020bd04b45 46 #define M1_BACKWARD 0xC2
chris 0:e6020bd04b45 47 #define M2_FORWARD 0xC5
chris 0:e6020bd04b45 48 #define M2_BACKWARD 0xC6
chris 0:e6020bd04b45 49
chris 0:e6020bd04b45 50
chris 0:e6020bd04b45 51
bouaziz 10:7935bbc4ebf1 52 /** zumo control class
chris 0:e6020bd04b45 53 *
chris 0:e6020bd04b45 54 * Example:
chris 0:e6020bd04b45 55 * @code
bouaziz 10:7935bbc4ebf1 56 * // Drive the zumo forward, turn left, back, turn right, at half speed for half a second
chris 0:e6020bd04b45 57
chris 0:e6020bd04b45 58 #include "mbed.h"
bouaziz 10:7935bbc4ebf1 59 #include "zumo.h"
chris 0:e6020bd04b45 60
bouaziz 10:7935bbc4ebf1 61 zumo pi;
chris 0:e6020bd04b45 62
chris 0:e6020bd04b45 63 int main() {
chris 0:e6020bd04b45 64
chris 0:e6020bd04b45 65 wait(0.5);
chris 0:e6020bd04b45 66
chris 0:e6020bd04b45 67 pi.forward(0.5);
chris 0:e6020bd04b45 68 wait (0.5);
chris 0:e6020bd04b45 69 pi.left(0.5);
chris 0:e6020bd04b45 70 wait (0.5);
chris 0:e6020bd04b45 71 pi.backward(0.5);
chris 0:e6020bd04b45 72 wait (0.5);
chris 0:e6020bd04b45 73 pi.right(0.5);
chris 0:e6020bd04b45 74 wait (0.5);
chris 0:e6020bd04b45 75
chris 0:e6020bd04b45 76 pi.stop();
chris 0:e6020bd04b45 77
chris 0:e6020bd04b45 78 }
chris 0:e6020bd04b45 79 * @endcode
chris 0:e6020bd04b45 80 */
bouaziz 10:7935bbc4ebf1 81 class zumo {
chris 0:e6020bd04b45 82
chris 0:e6020bd04b45 83 // Public functions
chris 0:e6020bd04b45 84 public:
chris 0:e6020bd04b45 85
bouaziz 10:7935bbc4ebf1 86 /** Create the zumo object connected to the default pins
chris 0:e6020bd04b45 87 *
bouaziz 10:7935bbc4ebf1 88 * @param nrst GPIO pin used for reset. for futre use
chris 0:e6020bd04b45 89 * @param tx Serial transmit pin. Default is p9
chris 0:e6020bd04b45 90 * @param rx Serial receive pin. Default is p10
chris 0:e6020bd04b45 91 */
bouaziz 10:7935bbc4ebf1 92 zumo();
bouaziz 10:7935bbc4ebf1 93 //reset();
chris 7:9b128cebb3c2 94
bouaziz 10:7935bbc4ebf1 95 /** Create the zumo object connected to specific pins
chris 7:9b128cebb3c2 96 *
chris 7:9b128cebb3c2 97 */
bouaziz 10:7935bbc4ebf1 98 zumo(PinName nrst, PinName tx, PinName rx);
chris 7:9b128cebb3c2 99
chris 0:e6020bd04b45 100 /** Force a hardware reset of the 3pi
chris 0:e6020bd04b45 101 */
chris 0:e6020bd04b45 102 void reset (void);
chris 0:e6020bd04b45 103
chris 0:e6020bd04b45 104 /** Stop both motors
chris 0:e6020bd04b45 105 *
chris 0:e6020bd04b45 106 */
chris 0:e6020bd04b45 107 void stop (void);
chris 0:e6020bd04b45 108
chris 0:e6020bd04b45 109
chris 0:e6020bd04b45 110 /** Read the battery voltage on the 3pi
chris 0:e6020bd04b45 111 * @returns battery voltage as a float
chris 0:e6020bd04b45 112 */
chris 0:e6020bd04b45 113 float battery(void);
chris 0:e6020bd04b45 114
chris 0:e6020bd04b45 115 /** Read the position of the detected line
chris 0:e6020bd04b45 116 * @returns position as A normalised number -1.0 - 1.0 represents the full range.
chris 7:9b128cebb3c2 117 * -1.0 means line is on the left, or the line has been lost
chris 7:9b128cebb3c2 118 * 0.0 means the line is in the middle
chris 7:9b128cebb3c2 119 * 1.0 means the line is on the right
chris 0:e6020bd04b45 120 */
chris 0:e6020bd04b45 121 float line_position (void);
bouaziz 9:f65c5aa1775c 122 /** lecture capteurs calibres
bouaziz 9:f65c5aa1775c 123 * @returns tableau val capteurs de gauche à droite
bouaziz 9:f65c5aa1775c 124 * 0 blanc (reflexion max)
bouaziz 9:f65c5aa1775c 125 * 1000 noir (pas de reflexion)
bouaziz 9:f65c5aa1775c 126 */
bouaziz 9:f65c5aa1775c 127 void calibrated_sensors(unsigned short ltab[5]);
bouaziz 10:7935bbc4ebf1 128
bouaziz 10:7935bbc4ebf1 129 /** fonction speed
bouaziz 10:7935bbc4ebf1 130 * @returns pour le future retourne 0x0A pour indiquer bonne prise en compte.
bouaziz 10:7935bbc4ebf1 131 * Pour le moment retourne rien.
bouaziz 10:7935bbc4ebf1 132 *
bouaziz 10:7935bbc4ebf1 133 */
bouaziz 10:7935bbc4ebf1 134 char speed(short spg,short spd);
chris 0:e6020bd04b45 135
chris 7:9b128cebb3c2 136 /** Calibrate the sensors. This turns the robot left then right, looking for a line
chris 0:e6020bd04b45 137 *
chris 0:e6020bd04b45 138 */
chris 0:e6020bd04b45 139 char sensor_auto_calibrate (void);
chris 0:e6020bd04b45 140
chris 1:816a80dcc1a3 141 void PID_start(int max_speed, int a, int b, int c, int d);
chris 1:816a80dcc1a3 142
chris 1:816a80dcc1a3 143 void PID_stop();
chris 1:816a80dcc1a3 144
chris 5:09fb0636207b 145 /** Write to the 8 LEDs
chris 5:09fb0636207b 146 *
chris 5:09fb0636207b 147 * @param leds An 8 bit value to put on the LEDs
chris 5:09fb0636207b 148 */
chris 5:09fb0636207b 149 void leds(int val);
chris 5:09fb0636207b 150
bouaziz 10:7935bbc4ebf1 151 Serial _ser;
chris 0:e6020bd04b45 152 private :
chris 0:e6020bd04b45 153
chris 0:e6020bd04b45 154 DigitalOut _nrst;
chris 4:54c673c71fc0 155
chris 0:e6020bd04b45 156
chris 0:e6020bd04b45 157 };
chris 0:e6020bd04b45 158
chris 0:e6020bd04b45 159 #endif