Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
R66Y
Date:
Sat May 20 15:23:58 2017 +0000
Revision:
3:1bb26049bdd1
Parent:
2:9d280856a536
Programme de contr?le des AX12 avec rajout de l'MX12;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 1:f3f702086a30 1 /* mbed AX-12+ Servo Library
ClementBreteau 1:f3f702086a30 2 *
ClementBreteau 1:f3f702086a30 3 * Copyright (c) 2010, cstyles (http://mbed.org)
ClementBreteau 1:f3f702086a30 4 *
ClementBreteau 1:f3f702086a30 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
ClementBreteau 1:f3f702086a30 6 * of this software and associated documentation files (the "Software"), to deal
ClementBreteau 1:f3f702086a30 7 * in the Software without restriction, including without limitation the rights
ClementBreteau 1:f3f702086a30 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ClementBreteau 1:f3f702086a30 9 * copies of the Software, and to permit persons to whom the Software is
ClementBreteau 1:f3f702086a30 10 * furnished to do so, subject to the following conditions:
ClementBreteau 1:f3f702086a30 11 *
ClementBreteau 1:f3f702086a30 12 * The above copyright notice and this permission notice shall be included in
ClementBreteau 1:f3f702086a30 13 * all copies or substantial portions of the Software.
ClementBreteau 1:f3f702086a30 14 *
ClementBreteau 1:f3f702086a30 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ClementBreteau 1:f3f702086a30 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ClementBreteau 1:f3f702086a30 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ClementBreteau 1:f3f702086a30 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ClementBreteau 1:f3f702086a30 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ClementBreteau 1:f3f702086a30 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ClementBreteau 1:f3f702086a30 21 * THE SOFTWARE.
ClementBreteau 1:f3f702086a30 22 */
ClementBreteau 1:f3f702086a30 23
ClementBreteau 1:f3f702086a30 24 #ifndef MBED_AX12_H
ClementBreteau 1:f3f702086a30 25 #define MBED_AX12_H
ClementBreteau 1:f3f702086a30 26 #include "SerialHalfDuplex.h"
ClementBreteau 1:f3f702086a30 27 #include "mbed.h"
ClementBreteau 1:f3f702086a30 28
ClementBreteau 1:f3f702086a30 29 //#define AX12_WRITE_DEBUG 0
matthieuvignon 2:9d280856a536 30 //#define AX12_READ_DEBUG
ClementBreteau 1:f3f702086a30 31 //#define AX12_TRIGGER_DEBUG 0
matthieuvignon 2:9d280856a536 32 //#define AX12_DEBUG 0
ClementBreteau 1:f3f702086a30 33
ClementBreteau 1:f3f702086a30 34 /****** à utiliser pour le debug !! ******/
ClementBreteau 1:f3f702086a30 35
ClementBreteau 1:f3f702086a30 36 //#define AX12_DEBUG_WRITE 0
ClementBreteau 1:f3f702086a30 37 //#define AX12_DEBUG_READ 0
ClementBreteau 1:f3f702086a30 38
ClementBreteau 1:f3f702086a30 39 /******************************************/
ClementBreteau 1:f3f702086a30 40
ClementBreteau 1:f3f702086a30 41
ClementBreteau 1:f3f702086a30 42 #define AX12_REG_ID 0x03
ClementBreteau 1:f3f702086a30 43 #define AX12_REG_BAUD 0x04
ClementBreteau 1:f3f702086a30 44 #define AX12_REG_DELAY_TIME 0x05
ClementBreteau 1:f3f702086a30 45 #define AX12_REG_CW_LIMIT 0x06
ClementBreteau 1:f3f702086a30 46 #define AX12_REG_CCW_LIMIT 0x08
ClementBreteau 1:f3f702086a30 47 #define AX12_REG_TEMP_MAX 0x0B
ClementBreteau 1:f3f702086a30 48 #define AX12_REG_LOWEST_VOLTAGE 0x0C
ClementBreteau 1:f3f702086a30 49 #define AX12_REG_HIGHEST_VOLTAGE 0x0D
ClementBreteau 1:f3f702086a30 50 #define AX12_REG_MAX_TORQUE 0x0E
ClementBreteau 1:f3f702086a30 51 #define AX12_REG_SATUS_RETURN 0x10
ClementBreteau 1:f3f702086a30 52 #define AX12_REG_ALARM_LED 0x11
ClementBreteau 1:f3f702086a30 53 #define AX12_REG_ALARM_SHUTDOWN 0x12
ClementBreteau 1:f3f702086a30 54 #define AX12_REG_DOWN_CALIBRATION 0x14
ClementBreteau 1:f3f702086a30 55 #define AX12_REG_UP_CALIBRATION 0x16
ClementBreteau 1:f3f702086a30 56 #define AX12_REG_TORQUE_ENABLE 0x18
ClementBreteau 1:f3f702086a30 57 #define AX12_REG_LED 0x19
ClementBreteau 1:f3f702086a30 58 #define AX12_REG_CW_MARGIN 0x1A
ClementBreteau 1:f3f702086a30 59 #define AX12_REG_CCW_MARGIN 0x1B
ClementBreteau 1:f3f702086a30 60 #define AX12_REG_CW_SLOPE 0x1C
ClementBreteau 1:f3f702086a30 61 #define AX12_REG_CCW_SLOPE 0x1D
ClementBreteau 1:f3f702086a30 62 #define AX12_REG_GOAL_POSITION 0x1E
ClementBreteau 1:f3f702086a30 63 #define AX12_REG_MOVING_SPEED 0x20
ClementBreteau 1:f3f702086a30 64 #define AX12_REG_TORQUE_LIMIT 0x22
ClementBreteau 1:f3f702086a30 65 #define AX12_REG_POSITION 0x24
ClementBreteau 1:f3f702086a30 66 #define AX12_REG_PRESENT_SPEED 0x26
ClementBreteau 1:f3f702086a30 67 #define AX12_REG_PRESENT_LOAD 0x28
ClementBreteau 1:f3f702086a30 68 #define AX12_REG_VOLTS 0x2A
ClementBreteau 1:f3f702086a30 69 #define AX12_REG_TEMP 0x2B
ClementBreteau 1:f3f702086a30 70 #define AX12_REG_INSTRUCTION 0x2C
ClementBreteau 1:f3f702086a30 71 #define AX12_REG_MOVING 0x2E
ClementBreteau 1:f3f702086a30 72 #define AX12_REG_LOCK 0x2F
ClementBreteau 1:f3f702086a30 73 #define AX12_REG_PUNCH 0x30
ClementBreteau 1:f3f702086a30 74
ClementBreteau 1:f3f702086a30 75
ClementBreteau 1:f3f702086a30 76 #define AX12_MODE_POSITION 0
ClementBreteau 1:f3f702086a30 77 #define AX12_MODE_ROTATION 1
ClementBreteau 1:f3f702086a30 78
ClementBreteau 1:f3f702086a30 79 #define AX12_CW 1
ClementBreteau 1:f3f702086a30 80 #define AX12_CCW 0
ClementBreteau 1:f3f702086a30 81
ClementBreteau 1:f3f702086a30 82 //--- Instruction ---
ClementBreteau 1:f3f702086a30 83 #define INST_PING 0x01
ClementBreteau 1:f3f702086a30 84 #define INST_READ 0x02
ClementBreteau 1:f3f702086a30 85 #define INST_WRITE 0x03
ClementBreteau 1:f3f702086a30 86 #define INST_REG_WRITE 0x04
ClementBreteau 1:f3f702086a30 87 #define INST_ACTION 0x05
ClementBreteau 1:f3f702086a30 88 #define INST_RESET 0x06
ClementBreteau 1:f3f702086a30 89 #define INST_DIGITAL_RESET 0x07
ClementBreteau 1:f3f702086a30 90 #define INST_SYSTEM_READ 0x0C
ClementBreteau 1:f3f702086a30 91 #define INST_SYSTEM_WRITE 0x0D
ClementBreteau 1:f3f702086a30 92 #define INST_SYNC_WRITE 0x83
ClementBreteau 1:f3f702086a30 93 #define INST_SYNC_REG_WRITE 0x84
ClementBreteau 1:f3f702086a30 94
ClementBreteau 1:f3f702086a30 95 #define DEFAULT_RETURN_PACKET_SIZE 6
ClementBreteau 1:f3f702086a30 96
ClementBreteau 1:f3f702086a30 97 #define BROADCASTING_ID 0xfe
ClementBreteau 1:f3f702086a30 98
ClementBreteau 1:f3f702086a30 99 /** Servo control class, based on a PwmOut
ClementBreteau 1:f3f702086a30 100 *
ClementBreteau 1:f3f702086a30 101 * Example:
ClementBreteau 1:f3f702086a30 102 * @code
ClementBreteau 1:f3f702086a30 103 * #include "mbed.h"
ClementBreteau 1:f3f702086a30 104 * #include "AX12.h"
ClementBreteau 1:f3f702086a30 105 *
ClementBreteau 1:f3f702086a30 106 * int main() {
ClementBreteau 1:f3f702086a30 107 *
ClementBreteau 1:f3f702086a30 108 * AX12 myax12 (p9, p10, 1);
ClementBreteau 1:f3f702086a30 109 *
ClementBreteau 1:f3f702086a30 110 * while (1) {
ClementBreteau 1:f3f702086a30 111 * myax12.SetGoal(0); // go to 0 degrees
ClementBreteau 1:f3f702086a30 112 * wait (2.0);
ClementBreteau 1:f3f702086a30 113 * myax12.SetGoal(300); // go to 300 degrees
ClementBreteau 1:f3f702086a30 114 * wait (2.0);
ClementBreteau 1:f3f702086a30 115 * }
ClementBreteau 1:f3f702086a30 116 * }
ClementBreteau 1:f3f702086a30 117 * @endcode
ClementBreteau 1:f3f702086a30 118 */
ClementBreteau 1:f3f702086a30 119 class AX12
ClementBreteau 1:f3f702086a30 120 {
ClementBreteau 1:f3f702086a30 121
ClementBreteau 1:f3f702086a30 122 public:
ClementBreteau 1:f3f702086a30 123
ClementBreteau 1:f3f702086a30 124 /** Create an AX12 servo object connected to the specified serial port, with the specified ID
ClementBreteau 1:f3f702086a30 125 *
ClementBreteau 1:f3f702086a30 126 * @param pin tx pin
ClementBreteau 1:f3f702086a30 127 * @param pin rx pin
ClementBreteau 1:f3f702086a30 128 * @param int ID, the Bus ID of the servo 1-255
ClementBreteau 1:f3f702086a30 129 */
ClementBreteau 1:f3f702086a30 130 AX12(PinName tx, PinName rx, int ID, int baud=1000000);
ClementBreteau 1:f3f702086a30 131
ClementBreteau 1:f3f702086a30 132 /** Nouvelle fonction de commande de position du servomoteur avec sécurité d'arriver à la bonne position
ClementBreteau 1:f3f702086a30 133 Si une erreur se produit et que le servo ne recoit vraiment rien cette fonction dispose d'une sortie en timeout error;
ClementBreteau 1:f3f702086a30 134 */
ClementBreteau 1:f3f702086a30 135 int Set_Secure_Goal(int degres);
ClementBreteau 1:f3f702086a30 136
ClementBreteau 1:f3f702086a30 137 /** Retourne le temps d'attente avant l'envoi de la trame de retour par l'actionneur ( en micro seconde )
ClementBreteau 1:f3f702086a30 138 */
ClementBreteau 1:f3f702086a30 139 int Get_Return_Delay_Time(void);
ClementBreteau 1:f3f702086a30 140
ClementBreteau 1:f3f702086a30 141
ClementBreteau 1:f3f702086a30 142 /** Retourne la vitesse de communication de l'actionneur ( en Bits/seconde )
ClementBreteau 1:f3f702086a30 143 */
ClementBreteau 1:f3f702086a30 144 int Get_Baud_Rate(void);
ClementBreteau 1:f3f702086a30 145
ClementBreteau 1:f3f702086a30 146
ClementBreteau 1:f3f702086a30 147 /** Reglage du courant minimum necessaire au bon fonctionnement de l'actionneur
ClementBreteau 1:f3f702086a30 148 // minimum >> Ox000 >> decimal 0
ClementBreteau 1:f3f702086a30 149 // maximum >> 0x3FF >> decimal 1023
ClementBreteau 1:f3f702086a30 150 // deflaut >> 0x20 >> decimal 32
ClementBreteau 1:f3f702086a30 151 */
ClementBreteau 1:f3f702086a30 152 int Set_Punch(int punch);
ClementBreteau 1:f3f702086a30 153
ClementBreteau 1:f3f702086a30 154
ClementBreteau 1:f3f702086a30 155 /** Retourne le courant minimum au fonctionnement de l'actionneur
ClementBreteau 1:f3f702086a30 156 */
ClementBreteau 1:f3f702086a30 157 int Get_Punch (void);
ClementBreteau 1:f3f702086a30 158
ClementBreteau 1:f3f702086a30 159
ClementBreteau 1:f3f702086a30 160 /** Retourne l'ampleur de la charge sur l'actionneur
ClementBreteau 1:f3f702086a30 161 */
ClementBreteau 1:f3f702086a30 162 int Get_Load_Value (void);
ClementBreteau 1:f3f702086a30 163
ClementBreteau 1:f3f702086a30 164 void read_all_info(unsigned char, unsigned char);
ClementBreteau 1:f3f702086a30 165
ClementBreteau 1:f3f702086a30 166 /** Reset
ClementBreteau 1:f3f702086a30 167 */
ClementBreteau 1:f3f702086a30 168 int Reset(int);
ClementBreteau 1:f3f702086a30 169
ClementBreteau 1:f3f702086a30 170 /** Retourne la direction de la charge sur l'actionneur
ClementBreteau 1:f3f702086a30 171 */
ClementBreteau 1:f3f702086a30 172 int Get_Load_Direction (void);
ClementBreteau 1:f3f702086a30 173
ClementBreteau 1:f3f702086a30 174
ClementBreteau 1:f3f702086a30 175 /** Retourne la vitesse angulaire actuelle de l'actionneur
ClementBreteau 1:f3f702086a30 176 */
ClementBreteau 1:f3f702086a30 177 int Get_Present_Speed (void);
ClementBreteau 1:f3f702086a30 178
ClementBreteau 1:f3f702086a30 179
ClementBreteau 1:f3f702086a30 180 /** Retourne la valeur en degres du registre CCW angle limit qui est l'angle limite maximum de l'actionneur
ClementBreteau 1:f3f702086a30 181 */
ClementBreteau 1:f3f702086a30 182 int Get_CCW_Angle_Limit (void);
ClementBreteau 1:f3f702086a30 183
ClementBreteau 1:f3f702086a30 184
ClementBreteau 1:f3f702086a30 185 /** Retourne la valeur en degres du registre CW angle limit qui est l'angle limite minimum de l'actionneur
ClementBreteau 1:f3f702086a30 186 */
ClementBreteau 1:f3f702086a30 187 int Get_CW_Angle_Limit (void);
ClementBreteau 1:f3f702086a30 188
ClementBreteau 1:f3f702086a30 189
ClementBreteau 1:f3f702086a30 190 /** Retourne la valeur du registre Torque Enable
ClementBreteau 1:f3f702086a30 191 */
ClementBreteau 1:f3f702086a30 192 int Get_Torque_Enable(void);
ClementBreteau 1:f3f702086a30 193
ClementBreteau 1:f3f702086a30 194
ClementBreteau 1:f3f702086a30 195 /**
ClementBreteau 1:f3f702086a30 196 1 >>>
ClementBreteau 1:f3f702086a30 197 0 >>>
ClementBreteau 1:f3f702086a30 198 */
ClementBreteau 1:f3f702086a30 199 int Set_Torque_Enable(int etat);
ClementBreteau 1:f3f702086a30 200
ClementBreteau 1:f3f702086a30 201
ClementBreteau 1:f3f702086a30 202 /** Retourne les données de compensation des différences entre les potentiomètres
ClementBreteau 1:f3f702086a30 203 utilisés dans l'AX12 (Up) ????????
ClementBreteau 1:f3f702086a30 204 */
ClementBreteau 1:f3f702086a30 205 int Get_Up_Calibration (void);
ClementBreteau 1:f3f702086a30 206
ClementBreteau 1:f3f702086a30 207
ClementBreteau 1:f3f702086a30 208 /** Retourne les données de compensation des différences entre les potentiomètres
ClementBreteau 1:f3f702086a30 209 utilisés dans l'AX12 (Dowm) ????????
ClementBreteau 1:f3f702086a30 210 */
ClementBreteau 1:f3f702086a30 211 int Get_Down_Calibration(void);
ClementBreteau 1:f3f702086a30 212
ClementBreteau 1:f3f702086a30 213
ClementBreteau 1:f3f702086a30 214 /** Retourne l'ID de l'AX_12 avec lequel on dialogue
ClementBreteau 1:f3f702086a30 215 utile seulement dans le cas d'un broadcast ID
ClementBreteau 1:f3f702086a30 216 */
ClementBreteau 1:f3f702086a30 217 int Get_ID(void);
ClementBreteau 1:f3f702086a30 218
ClementBreteau 1:f3f702086a30 219
ClementBreteau 1:f3f702086a30 220 /** Reglage du couple maximum de l'actionneur
ClementBreteau 1:f3f702086a30 221 // minimum >> Ox000 >> decimal 0
ClementBreteau 1:f3f702086a30 222 // maximum >> 0x3FF >> decimal 1023
ClementBreteau 1:f3f702086a30 223 // deflaut >> >> decimal
ClementBreteau 1:f3f702086a30 224 */
ClementBreteau 1:f3f702086a30 225 int Set_Max_Torque(int torque);
ClementBreteau 1:f3f702086a30 226
ClementBreteau 1:f3f702086a30 227
ClementBreteau 1:f3f702086a30 228 /** Reglage de la desactivation des actionneurs si une erreur le concernant se produit
ClementBreteau 1:f3f702086a30 229 Bit Function
ClementBreteau 1:f3f702086a30 230 Bit 7 0
ClementBreteau 1:f3f702086a30 231 Bit 6 If set to 1, torque off when an Instruction Error occurs
ClementBreteau 1:f3f702086a30 232 Bit 5 If set to 1, torque off when an Overload Error occurs
ClementBreteau 1:f3f702086a30 233 Bit 4 If set to 1, torque off when a Checksum Error occurs
ClementBreteau 1:f3f702086a30 234 Bit 3 If set to 1, torque off when a Range Error occurs
ClementBreteau 1:f3f702086a30 235 Bit 2 If set to 1, torque off when an Overheating Error occurs
ClementBreteau 1:f3f702086a30 236 Bit 1 If set to 1, torque off when an Angle Limit Error occurs
ClementBreteau 1:f3f702086a30 237 Bit 0 If set to 1, torque off when an Input Voltage Error occurs
ClementBreteau 1:f3f702086a30 238 */
ClementBreteau 1:f3f702086a30 239 int Set_Alarm_Shutdown(int valeur);
ClementBreteau 1:f3f702086a30 240
ClementBreteau 1:f3f702086a30 241
ClementBreteau 1:f3f702086a30 242 /** Reglage de l'activation de l'alarme
ClementBreteau 1:f3f702086a30 243 Bit Function
ClementBreteau 1:f3f702086a30 244 Bit 7 0
ClementBreteau 1:f3f702086a30 245 Bit 6 If set to 1, the LED blinks when an Instruction Error occurs
ClementBreteau 1:f3f702086a30 246 Bit 5 If set to 1, the LED blinks when an Overload Error occurs
ClementBreteau 1:f3f702086a30 247 Bit 4 If set to 1, the LED blinks when a Checksum Error occurs
ClementBreteau 1:f3f702086a30 248 Bit 3 If set to 1, the LED blinks when a Range Error occurs
ClementBreteau 1:f3f702086a30 249 Bit 2 If set to 1, the LED blinks when an Overheating Error occurs
ClementBreteau 1:f3f702086a30 250 Bit 1 If set to 1, the LED blinks when an Angle Limit Error occurs
ClementBreteau 1:f3f702086a30 251 Bit 0 If set to 1, the LED blinks when an Input Voltage Error occurs
ClementBreteau 1:f3f702086a30 252 */
ClementBreteau 1:f3f702086a30 253 int Set_Alarm_LED(int valeur);
ClementBreteau 1:f3f702086a30 254
ClementBreteau 1:f3f702086a30 255
ClementBreteau 1:f3f702086a30 256 /** Reglage de la réponse à une instruction
ClementBreteau 1:f3f702086a30 257 * @param mode
ClementBreteau 1:f3f702086a30 258 * 0 >> ne repond a aucune instructions
ClementBreteau 1:f3f702086a30 259 * 1 >> repond seulement aux instructions READ_DATA
ClementBreteau 1:f3f702086a30 260 * 2 >> repond à toutes les instructions
ClementBreteau 1:f3f702086a30 261 */
ClementBreteau 1:f3f702086a30 262 int Set_Status_Return_Level(int etat);
ClementBreteau 1:f3f702086a30 263
ClementBreteau 1:f3f702086a30 264
ClementBreteau 1:f3f702086a30 265 /** Reglage de la tension minimale
ClementBreteau 1:f3f702086a30 266 * @param mode
ClementBreteau 1:f3f702086a30 267 * minimum >> 0x32 >> decimal 50
ClementBreteau 1:f3f702086a30 268 * maximum >> 0xFA >> decimal 250
ClementBreteau 1:f3f702086a30 269 * deflaut >> 0x3C >> decimal 60
ClementBreteau 1:f3f702086a30 270 */
ClementBreteau 1:f3f702086a30 271 int Set_Lowest_Voltage(int val_lowest_voltage);
ClementBreteau 1:f3f702086a30 272
ClementBreteau 1:f3f702086a30 273
ClementBreteau 1:f3f702086a30 274 /** Reglage de la tension maximale
ClementBreteau 1:f3f702086a30 275 * @param mode
ClementBreteau 1:f3f702086a30 276 * minimum >> Ox32 >> decimal 50
ClementBreteau 1:f3f702086a30 277 * maximum >> 0xFA >> decimal 250
ClementBreteau 1:f3f702086a30 278 * deflaut >> 0xBE >> decimal 190
ClementBreteau 1:f3f702086a30 279 */
ClementBreteau 1:f3f702086a30 280 int Set_Highest_Voltage(int val_highest_voltage);
ClementBreteau 1:f3f702086a30 281
ClementBreteau 1:f3f702086a30 282
ClementBreteau 1:f3f702086a30 283 // Reglage du return time delay EN MICRO SECONDE 2uSec * val_delay_time
ClementBreteau 1:f3f702086a30 284 // minimum >> 0 us
ClementBreteau 1:f3f702086a30 285 // maximum >> 508 us
ClementBreteau 1:f3f702086a30 286 // deflaut >> 125 us
ClementBreteau 1:f3f702086a30 287 int Set_Delay_Time (int val_delay_time );
ClementBreteau 1:f3f702086a30 288
ClementBreteau 1:f3f702086a30 289
ClementBreteau 1:f3f702086a30 290 /** Set Highest Limit Temperature
ClementBreteau 1:f3f702086a30 291 * @param mode
ClementBreteau 1:f3f702086a30 292 * minimum >> Ox00 >> decimal 0
ClementBreteau 1:f3f702086a30 293 * maximum >> 0x96 >> decimal 150
ClementBreteau 1:f3f702086a30 294 */
ClementBreteau 1:f3f702086a30 295 int Set_Temperature_Max (int val_temperature );
ClementBreteau 1:f3f702086a30 296
ClementBreteau 1:f3f702086a30 297
ClementBreteau 1:f3f702086a30 298
ClementBreteau 1:f3f702086a30 299 /** Set the state of LED
ClementBreteau 1:f3f702086a30 300 * @param mode
ClementBreteau 1:f3f702086a30 301 * 0 = off, default
ClementBreteau 1:f3f702086a30 302 * 1 = on
ClementBreteau 1:f3f702086a30 303 */
ClementBreteau 1:f3f702086a30 304 int Set_Etat_LED(int etat);
ClementBreteau 1:f3f702086a30 305
ClementBreteau 1:f3f702086a30 306
ClementBreteau 1:f3f702086a30 307
ClementBreteau 1:f3f702086a30 308 /** Set the mode of the servo
ClementBreteau 1:f3f702086a30 309 * @param mode
ClementBreteau 1:f3f702086a30 310 * 0 = Positional, default
ClementBreteau 1:f3f702086a30 311 * 1 = Continuous rotation
ClementBreteau 1:f3f702086a30 312 */
ClementBreteau 1:f3f702086a30 313 int Set_Mode(int mode);
ClementBreteau 1:f3f702086a30 314
ClementBreteau 1:f3f702086a30 315 /** Set baud rate of all attached servos
ClementBreteau 1:f3f702086a30 316 * @param mode
ClementBreteau 1:f3f702086a30 317 * 0x01 = 1,000,000 bps
ClementBreteau 1:f3f702086a30 318 * 0x03 = 500,000 bps
ClementBreteau 1:f3f702086a30 319 * 0x04 = 400,000 bps
ClementBreteau 1:f3f702086a30 320 * 0x07 = 250,000 bps
ClementBreteau 1:f3f702086a30 321 * 0x09 = 200,000 bps
ClementBreteau 1:f3f702086a30 322 * 0x10 = 115,200 bps
ClementBreteau 1:f3f702086a30 323 * 0x22 = 57,600 bps
ClementBreteau 1:f3f702086a30 324 * 0x67 = 19,200 bps
ClementBreteau 1:f3f702086a30 325 * 0xCF = 9,600 bp
ClementBreteau 1:f3f702086a30 326 */
ClementBreteau 1:f3f702086a30 327 int Set_Baud(int baud);
ClementBreteau 1:f3f702086a30 328
ClementBreteau 1:f3f702086a30 329
ClementBreteau 1:f3f702086a30 330 /** Set goal angle in integer degrees, in positional mode
ClementBreteau 1:f3f702086a30 331 *
ClementBreteau 1:f3f702086a30 332 * @param degrees 0-300
ClementBreteau 1:f3f702086a30 333 * @param flags, defaults to 0
ClementBreteau 1:f3f702086a30 334 * flags[0] = blocking, return when goal position reached
ClementBreteau 1:f3f702086a30 335 * flags[1] = register, activate with a broadcast trigger
ClementBreteau 1:f3f702086a30 336 *
ClementBreteau 1:f3f702086a30 337 */
ClementBreteau 1:f3f702086a30 338 int Set_Goal(int degrees, int flags = 0);
ClementBreteau 1:f3f702086a30 339
ClementBreteau 1:f3f702086a30 340 int Set_Goal_speed(int degrees, int flags = 0);
ClementBreteau 1:f3f702086a30 341
ClementBreteau 1:f3f702086a30 342 /** Set the speed of the servo in continuous rotation mode
ClementBreteau 1:f3f702086a30 343 *
ClementBreteau 1:f3f702086a30 344 * @param speed, -1.0 to 1.0
ClementBreteau 1:f3f702086a30 345 * -1.0 = full speed counter clock wise
ClementBreteau 1:f3f702086a30 346 * 1.0 = full speed clock wise
ClementBreteau 1:f3f702086a30 347 */
ClementBreteau 1:f3f702086a30 348 int Set_CR_Speed(float speed);
ClementBreteau 1:f3f702086a30 349
ClementBreteau 1:f3f702086a30 350
ClementBreteau 1:f3f702086a30 351 /** Permet de définir l'angle limite minimum de l'actionneur ( prend une valeur d'entrée en degres )
ClementBreteau 1:f3f702086a30 352 // minimum >> 0°
ClementBreteau 1:f3f702086a30 353 // maximum >> 300°
ClementBreteau 1:f3f702086a30 354 // deflaut >> 0°
ClementBreteau 1:f3f702086a30 355 */
ClementBreteau 1:f3f702086a30 356 int Set_CW_Angle_Limit(int degrees);
ClementBreteau 1:f3f702086a30 357
ClementBreteau 1:f3f702086a30 358 /** Permet de définir l'angle limite maximum de l'actionneur ( prend une valeur d'entrée en degres )
ClementBreteau 1:f3f702086a30 359 // minimum >> 0°
ClementBreteau 1:f3f702086a30 360 // maximum >> 300°
ClementBreteau 1:f3f702086a30 361 // deflaut >> 300°
ClementBreteau 1:f3f702086a30 362 */
ClementBreteau 1:f3f702086a30 363 int Set_CCW_Angle_Limit(int degrees);
ClementBreteau 1:f3f702086a30 364
ClementBreteau 1:f3f702086a30 365 // Change the ID
ClementBreteau 1:f3f702086a30 366
ClementBreteau 1:f3f702086a30 367 /** Change the ID of a servo
ClementBreteau 1:f3f702086a30 368 *
ClementBreteau 1:f3f702086a30 369 * @param CurentID 1-255
ClementBreteau 1:f3f702086a30 370 * @param NewID 1-255
ClementBreteau 1:f3f702086a30 371 *
ClementBreteau 1:f3f702086a30 372 * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID.
ClementBreteau 1:f3f702086a30 373 * In this situation, only one servo should be connected to the bus
ClementBreteau 1:f3f702086a30 374 */
ClementBreteau 1:f3f702086a30 375 int Set_ID(int CurrentID, int NewID);
ClementBreteau 1:f3f702086a30 376
ClementBreteau 1:f3f702086a30 377
ClementBreteau 1:f3f702086a30 378 /** Poll to see if the servo is moving
ClementBreteau 1:f3f702086a30 379 *
ClementBreteau 1:f3f702086a30 380 * @returns true is the servo is moving
ClementBreteau 1:f3f702086a30 381 */
ClementBreteau 1:f3f702086a30 382 int isMoving(void);
ClementBreteau 1:f3f702086a30 383
ClementBreteau 1:f3f702086a30 384 /** Send the broadcast "trigger" command, to activate any outstanding registered commands
ClementBreteau 1:f3f702086a30 385 */
ClementBreteau 1:f3f702086a30 386 void trigger(void);
ClementBreteau 1:f3f702086a30 387
ClementBreteau 1:f3f702086a30 388 /** Send the "reset" command, to activate any outstanding registered commands
ClementBreteau 1:f3f702086a30 389 */
ClementBreteau 1:f3f702086a30 390 void reset();
ClementBreteau 1:f3f702086a30 391
ClementBreteau 1:f3f702086a30 392 /** Read the current angle of the servo
ClementBreteau 1:f3f702086a30 393 *
ClementBreteau 1:f3f702086a30 394 * @returns float in the range 0.0-300.0
ClementBreteau 1:f3f702086a30 395 */
ClementBreteau 1:f3f702086a30 396 float Get_Position();
ClementBreteau 1:f3f702086a30 397
ClementBreteau 1:f3f702086a30 398 /** Read the temperature of the servo
ClementBreteau 1:f3f702086a30 399 *
ClementBreteau 1:f3f702086a30 400 * @returns float temperature
ClementBreteau 1:f3f702086a30 401 */
ClementBreteau 1:f3f702086a30 402 float Get_Temp(void);
ClementBreteau 1:f3f702086a30 403
ClementBreteau 1:f3f702086a30 404 /** Read the supply voltage of the servo
ClementBreteau 1:f3f702086a30 405 *
ClementBreteau 1:f3f702086a30 406 * @returns float voltage
ClementBreteau 1:f3f702086a30 407 */
ClementBreteau 1:f3f702086a30 408 float Get_Volts(void);
ClementBreteau 1:f3f702086a30 409
ClementBreteau 1:f3f702086a30 410 // Lecture du couple maximum ( retourne la valeur du registre Max Torque de l'AX12 )
ClementBreteau 1:f3f702086a30 411 int Get_Max_Torque (void);
ClementBreteau 1:f3f702086a30 412
ClementBreteau 1:f3f702086a30 413
ClementBreteau 1:f3f702086a30 414 int read(int ID, int start, int length, char* data);
ClementBreteau 1:f3f702086a30 415 int write(int ID, int start, int length, char* data, int flag=0);
ClementBreteau 1:f3f702086a30 416 void multiple_goal_and_speed(int number_ax12,char* tab);
ClementBreteau 1:f3f702086a30 417 float read_and_test(float angle,char* Tab);
ClementBreteau 1:f3f702086a30 418
ClementBreteau 1:f3f702086a30 419 private :
ClementBreteau 1:f3f702086a30 420
ClementBreteau 1:f3f702086a30 421 SerialHalfDuplex _ax12;
ClementBreteau 1:f3f702086a30 422 int _ID;
ClementBreteau 1:f3f702086a30 423 int _baud;
ClementBreteau 1:f3f702086a30 424
ClementBreteau 1:f3f702086a30 425
ClementBreteau 1:f3f702086a30 426 };
ClementBreteau 1:f3f702086a30 427
ClementBreteau 1:f3f702086a30 428 #endif