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 AX-12A by
AX12.h
00001 /* Copyright (C) 2016 Telesensorics Inc, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef MBED_AX12_H 00020 #define MBED_AX12_H 00021 00022 #include "mbed.h" 00023 #include "DynamixelBus.h" 00024 00025 00026 enum ControlTable 00027 { 00028 ctModelNumberLow = 0, // RD 00029 ctModelNumberHigh = 1, // RD 00030 ctFirmwareVersion = 2, // RD 00031 ctID = 3, // RD/WR 00032 ctBaudRate = 4, // RD/WR 00033 ctReturnDelayTime = 5, // RD/WR 00034 ctCWAngleLimitL = 6, // RD/WR 00035 ctCWAngleLimitH = 7, // RD/WR 00036 ctCCWAngleLimitL = 8, // RD/WR 00037 ctCCWAngleLimitH = 9, // RD/WR 00038 ctReserved1 = 10, 00039 ctTemperatureLimit = 11, // RD/WR 00040 ctVoltageLow = 12, // RD/WR 00041 ctVoltageHigh = 13, // RD/WR 00042 ctMaxTorqueL = 14, // RD/WR 00043 ctMaxTorqueH = 15, // RD/WR 00044 ctStatusReturnLevel = 16, // RD/WR 00045 ctAlarmLED = 17, // RD/WR 00046 ctAlarmShutdown = 18, // RD/WR 00047 ctReserved2 = 19, 00048 ctDownCalibrationL = 20, // RR 00049 ctDownCalibrationH = 21, // RD 00050 ctUpCalibrationL = 22, // RD 00051 ctUpCalibrationH = 23, // RD 00052 ctTorqueEnable = 24, // RD/WR 00053 ctLED = 25, // RD/WR 00054 ctCWComplianceMargin = 26, // RD/WR 00055 ctCCWComplianceMargin = 27, // RD/WR 00056 ctCWComplianceSlope = 28, // RD/WR 00057 ctCCWComplianceSlope = 29, // RD/WR 00058 ctGoalPositionL = 30, // RD/WR 00059 ctGoalPositionH = 31, // RD/WR 00060 ctMovingSpeedL = 32, // RD/WR 00061 ctMovingSpeedH = 33, // RD/WR 00062 ctTorqueLimitL = 34, // RD/WR 00063 ctTorqueLimitH = 35, // RD/WR 00064 ctPresentPositionL = 36, // RD 00065 ctPresentPositionH = 37, // RD 00066 ctPresentSpeedL = 38, // RD 00067 ctPresentSpeedH = 39, // RD 00068 ctPresentLoadL = 40, // RD 00069 ctPresentLoadH = 41, // RD 00070 ctPresentVoltage = 42, // RD 00071 ctPresentTemperature = 43, // RD 00072 ctRegisteredInst = 44, // RD/WR 00073 ctReserved3 = 45, 00074 ctMoving = 46, // RD 00075 ctLock = 47, // RD/WR 00076 ctPunchL = 48, // RD/WR 00077 ctPunchH = 49 // RD/WR 00078 }; 00079 00080 // to reduce time reading values from servo, 00081 // we read values as a block from PresentPosition through Moving 00082 // these are cached until ClearCache call 00083 enum CachedControlTable 00084 { 00085 cctPresentPositionL = 36 - 36, 00086 cctPresentPositionH = 37 - 36, 00087 cctPresentSpeedL = 38 - 36, 00088 cctPresentSpeedH = 39 - 36, 00089 cctPresentLoadL = 40 - 36, 00090 cctPresentLoadH = 41 - 36, 00091 cctPresentVoltage = 42 - 36, 00092 cctPresentTemperature = 43 - 36, 00093 cctRegisteredInst = 44 - 36, 00094 cctReserved3 = 45 - 36, 00095 cctMoving = 46 - 36 00096 }; 00097 00098 const unsigned char AX12ReadBlockStart = ctPresentPositionL; 00099 const unsigned char AX12ReadBlockLength = ctLock - ctPresentPositionL; 00100 00101 class AX12 00102 { 00103 00104 public: 00105 AX12(DynamixelBus* pbus, ServoId = 1); 00106 00107 // clear cache to force actual read from servo 00108 void ClearCache(); 00109 00110 // sets the servo ID 00111 StatusCode SetServoId(char newId); 00112 00113 // returns the status of the servo (connected/not connected + errors) 00114 StatusCode Ping(void); 00115 00116 // Sets the goal position of the servo in degrees 00117 StatusCode SetGoal(float degrees); 00118 00119 // determines if the servo is moving 00120 bool IsMoving(void); 00121 00122 // gets the position of the servo in degrees 00123 float GetPosition(void); 00124 00125 // gets the internal temperature of the servo 00126 int GetTemperature(void); 00127 00128 // gets the servo power supply voltage 00129 float GetSupplyVoltage(void); 00130 00131 // Sets the replay delay for dynamixel protocol 00132 StatusCode SetReplyDelay(int us); 00133 00134 // gets the servo load 00135 float GetLoad(void); 00136 00137 // enables/disables holding torque 00138 StatusCode TorqueEnable( bool ); 00139 00140 // get last error 00141 virtual int GetLastError(); 00142 00143 // check if has error 00144 virtual bool HasError(); 00145 00146 00147 private : 00148 ServoId _ID; 00149 DynamixelBus* _pbus; 00150 00151 unsigned char _LastError; 00152 00153 unsigned char _ReadCache[AX12ReadBlockLength]; 00154 bool _HasReadCache; 00155 00156 StatusCode LoadReadCache(); 00157 }; 00158 #endif
Generated on Wed Jul 13 2022 10:43:58 by
1.7.2
