Provides an interface to an AX-12A servo. Requires the Dynamixel bus protocol library/

Fork of AX-12A by Jonathan Pickett

Committer:
henryrawas
Date:
Wed Dec 23 18:32:37 2015 +0000
Revision:
3:7b970151bf19
Parent:
1:d7642b2e155d
Child:
5:bae6dc62dfb4
make it derive from RobotNode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jepickett 0:1a48094c99d1 1 /* Copyright (c) 2012 Martin Smith, MIT License
jepickett 0:1a48094c99d1 2 *
jepickett 0:1a48094c99d1 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
jepickett 0:1a48094c99d1 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
jepickett 0:1a48094c99d1 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
jepickett 0:1a48094c99d1 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
jepickett 0:1a48094c99d1 7 * furnished to do so, subject to the following conditions:
jepickett 0:1a48094c99d1 8 *
jepickett 0:1a48094c99d1 9 * The above copyright notice and this permission notice shall be included in all copies or
jepickett 0:1a48094c99d1 10 * substantial portions of the Software.
jepickett 0:1a48094c99d1 11 *
jepickett 0:1a48094c99d1 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
jepickett 0:1a48094c99d1 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
jepickett 0:1a48094c99d1 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
jepickett 0:1a48094c99d1 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jepickett 0:1a48094c99d1 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jepickett 0:1a48094c99d1 17 */
jepickett 0:1a48094c99d1 18
jepickett 0:1a48094c99d1 19 #ifndef MBED_AX12_H
jepickett 0:1a48094c99d1 20 #define MBED_AX12_H
jepickett 0:1a48094c99d1 21
jepickett 0:1a48094c99d1 22 #include "mbed.h"
jepickett 0:1a48094c99d1 23 #include "DynamixelBus.h"
henryrawas 3:7b970151bf19 24 #include "RobotNode.h"
jepickett 0:1a48094c99d1 25
jepickett 0:1a48094c99d1 26 enum ControlTable
jepickett 0:1a48094c99d1 27 {
jepickett 1:d7642b2e155d 28 ctModelNumberLow = 0, // RD
jepickett 1:d7642b2e155d 29 ctModelNumberHigh = 1, // RD
jepickett 1:d7642b2e155d 30 ctFirmwareVersion = 2, // RD
jepickett 1:d7642b2e155d 31 ctID = 3, // RD/WR
jepickett 1:d7642b2e155d 32 ctBaudRate = 4, // RD/WR
jepickett 1:d7642b2e155d 33 ctReturnDelayTime = 5, // RD/WR
jepickett 1:d7642b2e155d 34 ctCWAngleLimitL = 6, // RD/WR
jepickett 1:d7642b2e155d 35 ctCWAngleLimitH = 7, // RD/WR
jepickett 1:d7642b2e155d 36 ctCCWAngleLimitL = 8, // RD/WR
jepickett 1:d7642b2e155d 37 ctCCWAngleLimitH = 9, // RD/WR
jepickett 1:d7642b2e155d 38 ctReserved1 = 10,
jepickett 1:d7642b2e155d 39 ctTemperatureLimit = 11, // RD/WR
jepickett 1:d7642b2e155d 40 ctVoltageLow = 12, // RD/WR
jepickett 1:d7642b2e155d 41 ctVoltageHigh = 13, // RD/WR
jepickett 1:d7642b2e155d 42 ctMaxTorqueL = 14, // RD/WR
jepickett 1:d7642b2e155d 43 ctMaxTorqueH = 15, // RD/WR
jepickett 1:d7642b2e155d 44 ctStatusReturnLevel = 16, // RD/WR
jepickett 1:d7642b2e155d 45 ctAlarmLED = 17, // RD/WR
jepickett 1:d7642b2e155d 46 ctAlarmShutdown = 18, // RD/WR
jepickett 1:d7642b2e155d 47 ctReserved2 = 19,
jepickett 1:d7642b2e155d 48 ctDownCalibrationL = 20, // RR
jepickett 1:d7642b2e155d 49 ctDownCalibrationH = 21, // RD
jepickett 1:d7642b2e155d 50 ctUpCalibrationL = 22, // RD
jepickett 1:d7642b2e155d 51 ctUpCalibrationH = 23, // RD
jepickett 1:d7642b2e155d 52 ctTorqueEnable = 24, // RD/WR
jepickett 1:d7642b2e155d 53 ctLED = 25, // RD/WR
jepickett 1:d7642b2e155d 54 ctCWComplianceMargin = 26, // RD/WR
jepickett 1:d7642b2e155d 55 ctCCWComplianceMargin = 27, // RD/WR
jepickett 1:d7642b2e155d 56 ctCWComplianceSlope = 28, // RD/WR
jepickett 1:d7642b2e155d 57 ctCCWComplianceSlope = 29, // RD/WR
jepickett 1:d7642b2e155d 58 ctGoalPositionL = 30, // RD/WR
jepickett 1:d7642b2e155d 59 ctGoalPositionH = 31, // RD/WR
jepickett 1:d7642b2e155d 60 ctMovingSpeedL = 32, // RD/WR
jepickett 1:d7642b2e155d 61 ctMovingSpeedH = 33, // RD/WR
jepickett 1:d7642b2e155d 62 ctTorqueLimitL = 34, // RD/WR
jepickett 1:d7642b2e155d 63 ctTorqueLimitH = 35, // RD/WR
jepickett 1:d7642b2e155d 64 ctPresentPositionL = 36, // RD
jepickett 1:d7642b2e155d 65 ctPresentPositionH = 37, // RD
jepickett 1:d7642b2e155d 66 ctPresentSpeedL = 38, // RD
jepickett 1:d7642b2e155d 67 ctPresentSpeedH = 39, // RD
jepickett 1:d7642b2e155d 68 ctPresentLoadL = 40, // RD
jepickett 1:d7642b2e155d 69 ctPresentLoadH = 41, // RD
jepickett 1:d7642b2e155d 70 ctPresentVoltage = 42, // RD
jepickett 1:d7642b2e155d 71 ctPresentTemperature = 43, // RD
jepickett 1:d7642b2e155d 72 ctRegisteredInst = 44, // RD/WR
jepickett 1:d7642b2e155d 73 ctReserved3 = 45,
jepickett 1:d7642b2e155d 74 ctMoving = 46, // RD
jepickett 1:d7642b2e155d 75 ctLock = 47, // RD/WR
jepickett 1:d7642b2e155d 76 ctPunchL = 48, // RD/WR
jepickett 1:d7642b2e155d 77 ctPunchH = 49 // RD/WR
jepickett 0:1a48094c99d1 78 };
jepickett 0:1a48094c99d1 79
henryrawas 3:7b970151bf19 80 class AX12 : public RobotNode
jepickett 0:1a48094c99d1 81 {
jepickett 0:1a48094c99d1 82
jepickett 0:1a48094c99d1 83 public:
jepickett 0:1a48094c99d1 84 AX12(DynamixelBus* pbus, ServoId = 1);
jepickett 0:1a48094c99d1 85
jepickett 0:1a48094c99d1 86 // returns the status of the servo (connected/not connected + errors)
jepickett 0:1a48094c99d1 87 StatusCode Ping();
jepickett 0:1a48094c99d1 88
henryrawas 3:7b970151bf19 89 // Sets the goal position of the servo in degrees
jepickett 0:1a48094c99d1 90 StatusCode SetGoal(float degrees);
jepickett 0:1a48094c99d1 91
jepickett 0:1a48094c99d1 92 // determines if the servo is moving
jepickett 0:1a48094c99d1 93 bool IsMoving(void);
jepickett 0:1a48094c99d1 94
jepickett 0:1a48094c99d1 95 // gets the position of the servo in degrees
jepickett 0:1a48094c99d1 96 float GetPosition();
jepickett 0:1a48094c99d1 97
jepickett 0:1a48094c99d1 98 // gets the internal temperature of the servo
jepickett 1:d7642b2e155d 99 int GetTemperature(void);
jepickett 0:1a48094c99d1 100
jepickett 0:1a48094c99d1 101 // gets the servo power supply voltage
jepickett 0:1a48094c99d1 102 float GetSupplyVoltage(void);
jepickett 1:d7642b2e155d 103
jepickett 1:d7642b2e155d 104 // enables/disables holding torque
jepickett 1:d7642b2e155d 105 StatusCode TorqueEnable( bool );
jepickett 0:1a48094c99d1 106
henryrawas 3:7b970151bf19 107 // check if measure available
henryrawas 3:7b970151bf19 108 virtual bool HasMeasure(int measureId);
henryrawas 3:7b970151bf19 109
henryrawas 3:7b970151bf19 110 // get normalized measure value
henryrawas 3:7b970151bf19 111 virtual float GetMeasure(int measureId);
henryrawas 3:7b970151bf19 112
henryrawas 3:7b970151bf19 113 // get normalized measure value
henryrawas 3:7b970151bf19 114 virtual float GetLastMeasure(int measureId);
henryrawas 3:7b970151bf19 115
henryrawas 3:7b970151bf19 116 // do action
henryrawas 3:7b970151bf19 117 virtual bool DoAction(int actionId, float actionValue);
henryrawas 3:7b970151bf19 118
henryrawas 3:7b970151bf19 119 // check if has action
henryrawas 3:7b970151bf19 120 virtual bool HasAction(int actionId);
henryrawas 3:7b970151bf19 121
henryrawas 3:7b970151bf19 122 // get last error
henryrawas 3:7b970151bf19 123 virtual unsigned char GetLastError();
henryrawas 3:7b970151bf19 124
henryrawas 3:7b970151bf19 125 // get node type
henryrawas 3:7b970151bf19 126 virtual NodePartType GetNodeType();
henryrawas 3:7b970151bf19 127
jepickett 0:1a48094c99d1 128 private :
jepickett 0:1a48094c99d1 129 ServoId _ID;
jepickett 0:1a48094c99d1 130 DynamixelBus* _pbus;
henryrawas 3:7b970151bf19 131
henryrawas 3:7b970151bf19 132 // last read temperature
henryrawas 3:7b970151bf19 133 int _LastTemperature;
henryrawas 3:7b970151bf19 134
henryrawas 3:7b970151bf19 135 // last read position
henryrawas 3:7b970151bf19 136 float _LastPosition;
henryrawas 3:7b970151bf19 137
henryrawas 3:7b970151bf19 138 // last read voltage
henryrawas 3:7b970151bf19 139 float _LastVoltage;
henryrawas 3:7b970151bf19 140
henryrawas 3:7b970151bf19 141 unsigned char _LastError;
henryrawas 3:7b970151bf19 142
jepickett 0:1a48094c99d1 143 };
jepickett 0:1a48094c99d1 144 #endif