AX12 gros robot

Fork of command_AX12_gros_robot by CRAC Team

Committer:
mathieulegros
Date:
Wed Mar 15 16:36:50 2017 +0000
Revision:
0:a2a44c043932
command AX12 same time

Who changed what in which revision?

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