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