librairie pour robot Zumo
Embed:
(wiki syntax)
Show/hide line numbers
zumo.h
00001 /* mbed zumo Library 00002 * Copyright (c) 2007-2010 cstyles 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #ifndef zumo_H 00024 #define zumo_H 00025 00026 #include "mbed.h" 00027 #include "platform.h" 00028 00029 // commandes pour le ZUMO 00030 #define SEND_MOTOR_SPEED 0xA4 00031 #define SEND_MOTOR_STOP 0xA0 00032 #define SEND_ROTATE_GYRO 0x94 00033 #define SEND_AVANCE 0x84 00034 #define SEND_CALIBRE_LIGNE 0x60 00035 #define READ_SENSOR 0x71 00036 00037 00038 00039 // sous commande de la commande READ_SENSOR 00040 #define DATA_SENSOR_GYRO 0x12 00041 #define DATA_SENSOR_MEANDIST 0x24 00042 #define DATA_SENSOR_LRDIST 0x38 00043 #define DATA_SENSOR_LIGNE 0x42 00044 #define DATA_SENSOR_LIGNE_5BIT 0x51 00045 #define DATA_SENSOR_OBSTACLE 0x62 00046 00047 00048 00049 #define SEND_CALIB_SENSOR_VALUES 0x87 00050 #define SEND_TRIMPOT 0xB0 00051 #define SEND_BATTERY_MILLIVOLTS 0xB1 00052 #define DO_PLAY 0xB3 00053 #define PI_CALIBRATE 0xB4 00054 #define DO_CLEAR 0xB7 00055 #define DO_PRINT 0xB8 00056 #define DO_LCD_GOTO_XY 0xB9 00057 #define LINE_SENSORS_RESET_CALIBRATION 0xB5 00058 #define SEND_LINE_POSITION 0xB6 00059 #define AUTO_CALIBRATE 0xBA 00060 #define SET_PID 0xBB 00061 #define STOP_PID 0xBC 00062 #define M1_FORWARD 0xC1 00063 #define M1_BACKWARD 0xC2 00064 #define M2_FORWARD 0xC5 00065 #define M2_BACKWARD 0xC6 00066 00067 00068 00069 /** zumo control class 00070 * 00071 * Example: 00072 * @code 00073 * // Drive the zumo forward, turn left, back, turn right, at half speed for half a second 00074 00075 #include "mbed.h" 00076 #include "zumo.h" 00077 00078 zumo pi; 00079 00080 int main() { 00081 00082 wait(0.5); 00083 00084 pi.forward(0.5); 00085 wait (0.5); 00086 pi.left(0.5); 00087 wait (0.5); 00088 pi.backward(0.5); 00089 wait (0.5); 00090 pi.right(0.5); 00091 wait (0.5); 00092 00093 pi.stop(); 00094 00095 } 00096 * @endcode 00097 */ 00098 class zumo { 00099 00100 // Public functions 00101 public: 00102 00103 /** Create the zumo object connected to the default pins 00104 * 00105 * @param nrst GPIO pin used for reset. for futre use 00106 * @param tx Serial transmit pin. Default is p9 00107 * @param rx Serial receive pin. Default is p10 00108 */ 00109 zumo(); 00110 //reset(); 00111 00112 /** Create the zumo object connected to specific pins 00113 * 00114 */ 00115 zumo(PinName nrst, PinName tx, PinName rx); 00116 00117 /** Force a hardware reset of the 3pi 00118 */ 00119 void reset (void); 00120 00121 /** Stop both motors 00122 * 00123 */ 00124 void stop (void); 00125 00126 00127 /** Read the battery voltage on the 3pi 00128 * @returns battery voltage as a float 00129 */ 00130 float battery(void); 00131 00132 /** Read the position of the detected line 00133 * @returns position as A normalised number -1.0 - 1.0 represents the full range. 00134 * -1.0 means line is on the left, or the line has been lost 00135 * 0.0 means the line is in the middle 00136 * 1.0 means the line is on the right 00137 */ 00138 float line_position (void); 00139 /** lecture capteurs calibres 00140 * @returns tableau val capteurs de gauche à droite 00141 * 0 blanc (reflexion max) 00142 * 1000 noir (pas de reflexion) 00143 */ 00144 void calibrated_sensors(unsigned short ltab[5]); 00145 00146 /** fonction speed 00147 * @returns pour le future retourne 0x0A pour indiquer bonne prise en compte. 00148 * Pour le moment retourne rien. 00149 * 00150 */ 00151 char speed(short spg,short spd); 00152 00153 // speed vitesse absolue 00154 // rot exprim au 1/100eme de deg 45.01 sera 4501 00155 char rotate_speed_gyro_wait (short spd,short rot); 00156 00157 // avance tout droit de dist mm 00158 // avec speed positif (car calcul sens par dist) 00159 // angle envoyé au centime de deg rot et sens trigo 00160 char avance_wait(short spd, short dist); 00161 00162 /** Calibrate the sensors. 00163 */ 00164 char Calibrate_line_sensor_wait (); 00165 00166 char read_data_wait (char whatdata,char*tab); 00167 00168 00169 void PID_start(int max_speed, int a, int b, int c, int d); 00170 00171 void PID_stop(); 00172 00173 /** Write to the 8 LEDs 00174 * 00175 * @param leds An 8 bit value to put on the LEDs 00176 */ 00177 void leds(int val); 00178 00179 Serial _ser; 00180 private : 00181 00182 DigitalOut _nrst; 00183 00184 00185 }; 00186 00187 #endif
Generated on Fri Jul 29 2022 16:23:38 by
1.7.2