mouvement AX12 petit robot version 2
Fork of command_AX12_petit_robot by
AX12.h
00001 /* mbed AX-12+ Servo Library 00002 * 00003 * Copyright (c) 2010, cstyles (http://mbed.org) 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #ifndef MBED_AX12_H 00025 #define MBED_AX12_H 00026 #include "SerialHalfDuplex.h" 00027 #include "mbed.h" 00028 00029 //#define AX12_WRITE_DEBUG 0 00030 #define AX12_READ_DEBUG 00031 //#define AX12_TRIGGER_DEBUG 0 00032 #define AX12_DEBUG 0 00033 00034 /****** à utiliser pour le debug !! ******/ 00035 00036 //#define AX12_DEBUG_WRITE 0 00037 //#define AX12_DEBUG_READ 0 00038 00039 /******************************************/ 00040 00041 00042 #define AX12_REG_ID 0x03 00043 #define AX12_REG_BAUD 0x04 00044 #define AX12_REG_DELAY_TIME 0x05 00045 #define AX12_REG_CW_LIMIT 0x06 00046 #define AX12_REG_CCW_LIMIT 0x08 00047 #define AX12_REG_TEMP_MAX 0x0B 00048 #define AX12_REG_LOWEST_VOLTAGE 0x0C 00049 #define AX12_REG_HIGHEST_VOLTAGE 0x0D 00050 #define AX12_REG_MAX_TORQUE 0x0E 00051 #define AX12_REG_SATUS_RETURN 0x10 00052 #define AX12_REG_ALARM_LED 0x11 00053 #define AX12_REG_ALARM_SHUTDOWN 0x12 00054 #define AX12_REG_DOWN_CALIBRATION 0x14 00055 #define AX12_REG_UP_CALIBRATION 0x16 00056 #define AX12_REG_TORQUE_ENABLE 0x18 00057 #define AX12_REG_LED 0x19 00058 #define AX12_REG_CW_MARGIN 0x1A 00059 #define AX12_REG_CCW_MARGIN 0x1B 00060 #define AX12_REG_CW_SLOPE 0x1C 00061 #define AX12_REG_CCW_SLOPE 0x1D 00062 #define AX12_REG_GOAL_POSITION 0x1E 00063 #define AX12_REG_MOVING_SPEED 0x20 00064 #define AX12_REG_TORQUE_LIMIT 0x22 00065 #define AX12_REG_POSITION 0x24 00066 #define AX12_REG_PRESENT_SPEED 0x26 00067 #define AX12_REG_PRESENT_LOAD 0x28 00068 #define AX12_REG_VOLTS 0x2A 00069 #define AX12_REG_TEMP 0x2B 00070 #define AX12_REG_INSTRUCTION 0x2C 00071 #define AX12_REG_MOVING 0x2E 00072 #define AX12_REG_LOCK 0x2F 00073 #define AX12_REG_PUNCH 0x30 00074 00075 00076 #define AX12_MODE_POSITION 0 00077 #define AX12_MODE_ROTATION 1 00078 00079 #define AX12_CW 1 00080 #define AX12_CCW 0 00081 00082 //--- Instruction --- 00083 #define INST_PING 0x01 00084 #define INST_READ 0x02 00085 #define INST_WRITE 0x03 00086 #define INST_REG_WRITE 0x04 00087 #define INST_ACTION 0x05 00088 #define INST_RESET 0x06 00089 #define INST_DIGITAL_RESET 0x07 00090 #define INST_SYSTEM_READ 0x0C 00091 #define INST_SYSTEM_WRITE 0x0D 00092 #define INST_SYNC_WRITE 0x83 00093 #define INST_SYNC_REG_WRITE 0x84 00094 00095 #define DEFAULT_RETURN_PACKET_SIZE 6 00096 00097 #define BROADCASTING_ID 0xfe 00098 00099 /** Servo control class, based on a PwmOut 00100 * 00101 * Example: 00102 * @code 00103 * #include "mbed.h" 00104 * #include "AX12.h" 00105 * 00106 * int main() { 00107 * 00108 * AX12 myax12 (p9, p10, 1); 00109 * 00110 * while (1) { 00111 * myax12.SetGoal(0); // go to 0 degrees 00112 * wait (2.0); 00113 * myax12.SetGoal(300); // go to 300 degrees 00114 * wait (2.0); 00115 * } 00116 * } 00117 * @endcode 00118 */ 00119 class AX12 00120 { 00121 00122 public: 00123 00124 /** Create an AX12 servo object connected to the specified serial port, with the specified ID 00125 * 00126 * @param pin tx pin 00127 * @param pin rx pin 00128 * @param int ID, the Bus ID of the servo 1-255 00129 */ 00130 AX12(PinName tx, PinName rx, int ID, int baud=1000000); 00131 00132 /** Nouvelle fonction de commande de position du servomoteur avec sécurité d'arriver à la bonne position 00133 Si une erreur se produit et que le servo ne recoit vraiment rien cette fonction dispose d'une sortie en timeout error; 00134 */ 00135 int Set_Secure_Goal(int degres); 00136 00137 /** Retourne le temps d'attente avant l'envoi de la trame de retour par l'actionneur ( en micro seconde ) 00138 */ 00139 int Get_Return_Delay_Time(void); 00140 00141 00142 /** Retourne la vitesse de communication de l'actionneur ( en Bits/seconde ) 00143 */ 00144 int Get_Baud_Rate(void); 00145 00146 00147 /** Reglage du courant minimum necessaire au bon fonctionnement de l'actionneur 00148 // minimum >> Ox000 >> decimal 0 00149 // maximum >> 0x3FF >> decimal 1023 00150 // deflaut >> 0x20 >> decimal 32 00151 */ 00152 int Set_Punch(int punch); 00153 00154 00155 /** Retourne le courant minimum au fonctionnement de l'actionneur 00156 */ 00157 int Get_Punch (void); 00158 00159 00160 /** Retourne l'ampleur de la charge sur l'actionneur 00161 */ 00162 int Get_Load_Value (void); 00163 00164 void read_all_info(unsigned char, unsigned char); 00165 00166 /** Reset 00167 */ 00168 int Reset(int); 00169 00170 /** Retourne la direction de la charge sur l'actionneur 00171 */ 00172 int Get_Load_Direction (void); 00173 00174 00175 /** Retourne la vitesse angulaire actuelle de l'actionneur 00176 */ 00177 int Get_Present_Speed (void); 00178 00179 00180 /** Retourne la valeur en degres du registre CCW angle limit qui est l'angle limite maximum de l'actionneur 00181 */ 00182 int Get_CCW_Angle_Limit (void); 00183 00184 00185 /** Retourne la valeur en degres du registre CW angle limit qui est l'angle limite minimum de l'actionneur 00186 */ 00187 int Get_CW_Angle_Limit (void); 00188 00189 00190 /** Retourne la valeur du registre Torque Enable 00191 */ 00192 int Get_Torque_Enable(void); 00193 00194 00195 /** 00196 1 >>> 00197 0 >>> 00198 */ 00199 int Set_Torque_Enable(int etat); 00200 00201 00202 /** Retourne les données de compensation des différences entre les potentiomètres 00203 utilisés dans l'AX12 (Up) ???????? 00204 */ 00205 int Get_Up_Calibration (void); 00206 00207 00208 /** Retourne les données de compensation des différences entre les potentiomètres 00209 utilisés dans l'AX12 (Dowm) ???????? 00210 */ 00211 int Get_Down_Calibration(void); 00212 00213 00214 /** Retourne l'ID de l'AX_12 avec lequel on dialogue 00215 utile seulement dans le cas d'un broadcast ID 00216 */ 00217 int Get_ID(void); 00218 00219 00220 /** Reglage du couple maximum de l'actionneur 00221 // minimum >> Ox000 >> decimal 0 00222 // maximum >> 0x3FF >> decimal 1023 00223 // deflaut >> >> decimal 00224 */ 00225 int Set_Max_Torque(int torque); 00226 00227 00228 /** Reglage de la desactivation des actionneurs si une erreur le concernant se produit 00229 Bit Function 00230 Bit 7 0 00231 Bit 6 If set to 1, torque off when an Instruction Error occurs 00232 Bit 5 If set to 1, torque off when an Overload Error occurs 00233 Bit 4 If set to 1, torque off when a Checksum Error occurs 00234 Bit 3 If set to 1, torque off when a Range Error occurs 00235 Bit 2 If set to 1, torque off when an Overheating Error occurs 00236 Bit 1 If set to 1, torque off when an Angle Limit Error occurs 00237 Bit 0 If set to 1, torque off when an Input Voltage Error occurs 00238 */ 00239 int Set_Alarm_Shutdown(int valeur); 00240 00241 00242 /** Reglage de l'activation de l'alarme 00243 Bit Function 00244 Bit 7 0 00245 Bit 6 If set to 1, the LED blinks when an Instruction Error occurs 00246 Bit 5 If set to 1, the LED blinks when an Overload Error occurs 00247 Bit 4 If set to 1, the LED blinks when a Checksum Error occurs 00248 Bit 3 If set to 1, the LED blinks when a Range Error occurs 00249 Bit 2 If set to 1, the LED blinks when an Overheating Error occurs 00250 Bit 1 If set to 1, the LED blinks when an Angle Limit Error occurs 00251 Bit 0 If set to 1, the LED blinks when an Input Voltage Error occurs 00252 */ 00253 int Set_Alarm_LED(int valeur); 00254 00255 00256 /** Reglage de la réponse à une instruction 00257 * @param mode 00258 * 0 >> ne repond a aucune instructions 00259 * 1 >> repond seulement aux instructions READ_DATA 00260 * 2 >> repond à toutes les instructions 00261 */ 00262 int Set_Status_Return_Level(int etat); 00263 00264 00265 /** Reglage de la tension minimale 00266 * @param mode 00267 * minimum >> 0x32 >> decimal 50 00268 * maximum >> 0xFA >> decimal 250 00269 * deflaut >> 0x3C >> decimal 60 00270 */ 00271 int Set_Lowest_Voltage(int val_lowest_voltage); 00272 00273 00274 /** Reglage de la tension maximale 00275 * @param mode 00276 * minimum >> Ox32 >> decimal 50 00277 * maximum >> 0xFA >> decimal 250 00278 * deflaut >> 0xBE >> decimal 190 00279 */ 00280 int Set_Highest_Voltage(int val_highest_voltage); 00281 00282 00283 // Reglage du return time delay EN MICRO SECONDE 2uSec * val_delay_time 00284 // minimum >> 0 us 00285 // maximum >> 508 us 00286 // deflaut >> 125 us 00287 int Set_Delay_Time (int val_delay_time ); 00288 00289 00290 /** Set Highest Limit Temperature 00291 * @param mode 00292 * minimum >> Ox00 >> decimal 0 00293 * maximum >> 0x96 >> decimal 150 00294 */ 00295 int Set_Temperature_Max (int val_temperature ); 00296 00297 00298 00299 /** Set the state of LED 00300 * @param mode 00301 * 0 = off, default 00302 * 1 = on 00303 */ 00304 int Set_Etat_LED(int etat); 00305 00306 00307 00308 /** Set the mode of the servo 00309 * @param mode 00310 * 0 = Positional, default 00311 * 1 = Continuous rotation 00312 */ 00313 int Set_Mode(int mode); 00314 00315 /** Set baud rate of all attached servos 00316 * @param mode 00317 * 0x01 = 1,000,000 bps 00318 * 0x03 = 500,000 bps 00319 * 0x04 = 400,000 bps 00320 * 0x07 = 250,000 bps 00321 * 0x09 = 200,000 bps 00322 * 0x10 = 115,200 bps 00323 * 0x22 = 57,600 bps 00324 * 0x67 = 19,200 bps 00325 * 0xCF = 9,600 bp 00326 */ 00327 int Set_Baud(int baud); 00328 00329 00330 /** Set goal angle in integer degrees, in positional mode 00331 * 00332 * @param degrees 0-300 00333 * @param flags, defaults to 0 00334 * flags[0] = blocking, return when goal position reached 00335 * flags[1] = register, activate with a broadcast trigger 00336 * 00337 */ 00338 int Set_Goal(int degrees, int flags = 0); 00339 00340 int Set_Goal_speed(int degrees, int flags = 0); 00341 00342 /** Set the speed of the servo in continuous rotation mode 00343 * 00344 * @param speed, -1.0 to 1.0 00345 * -1.0 = full speed counter clock wise 00346 * 1.0 = full speed clock wise 00347 */ 00348 int Set_CR_Speed(float speed); 00349 00350 00351 /** Permet de définir l'angle limite minimum de l'actionneur ( prend une valeur d'entrée en degres ) 00352 // minimum >> 0° 00353 // maximum >> 300° 00354 // deflaut >> 0° 00355 */ 00356 int Set_CW_Angle_Limit(int degrees); 00357 00358 /** Permet de définir l'angle limite maximum de l'actionneur ( prend une valeur d'entrée en degres ) 00359 // minimum >> 0° 00360 // maximum >> 300° 00361 // deflaut >> 300° 00362 */ 00363 int Set_CCW_Angle_Limit(int degrees); 00364 00365 // Change the ID 00366 00367 /** Change the ID of a servo 00368 * 00369 * @param CurentID 1-255 00370 * @param NewID 1-255 00371 * 00372 * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID. 00373 * In this situation, only one servo should be connected to the bus 00374 */ 00375 int Set_ID(int CurrentID, int NewID); 00376 00377 00378 /** Poll to see if the servo is moving 00379 * 00380 * @returns true is the servo is moving 00381 */ 00382 int isMoving(void); 00383 00384 /** Send the broadcast "trigger" command, to activate any outstanding registered commands 00385 */ 00386 void trigger(void); 00387 00388 /** Send the "reset" command, to activate any outstanding registered commands 00389 */ 00390 void reset(); 00391 00392 /** Read the current angle of the servo 00393 * 00394 * @returns float in the range 0.0-300.0 00395 */ 00396 float Get_Position(); 00397 00398 /** Read the temperature of the servo 00399 * 00400 * @returns float temperature 00401 */ 00402 float Get_Temp(void); 00403 00404 /** Read the supply voltage of the servo 00405 * 00406 * @returns float voltage 00407 */ 00408 float Get_Volts(void); 00409 00410 // Lecture du couple maximum ( retourne la valeur du registre Max Torque de l'AX12 ) 00411 int Get_Max_Torque (void); 00412 00413 00414 int read(int ID, int start, int length, char* data); 00415 int write(int ID, int start, int length, char* data, int flag=0); 00416 void multiple_goal_and_speed(int number_ax12,char* tab); 00417 float read_and_test(float angle,char* Tab); 00418 00419 private : 00420 00421 SerialHalfDuplex _ax12; 00422 int _ID; 00423 int _baud; 00424 00425 00426 }; 00427 00428 #endif
Generated on Tue Jul 12 2022 20:39:16 by 1.7.2