Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef __DYNAMIXEL_H_INCLUDED__
00007 #define __DYNAMIXEL_H_INCLUDED__
00008
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <errno.h>
00012 #include <math.h>
00013 #include <threemxl/platform/io/logging/Log2.h>
00014
00015 #include "../Byte.h"
00016 #include "../CDxlGeneric.h"
00017 #include "../CDxlPacket.hpp"
00018 #include "../CDxlConfig.h"
00019 #include "DynamixelControlTable.h"
00020
00021 #define __DBG__
00022
00023 #define INITIAL_RETURN_DELAY_TIME 500
00024 #define INITIAL_TEMPERATURE_LIMIT 80
00025 #define INITIAL_VOLTAGE_LOWER_LIMIT 6.0
00026 #define INITIAL_VOLTAGE_UPPER_LIMIT 24.0
00027 #define INITIAL_TORQUE_LIMIT 1.0
00028 #define INITIAL_COMPLIENCE_MARGIN 1
00029 #define INITIAL_COMPLIENCE_SLOPE 32
00030 #define INITIAL_PUNCH 32
00031
00032
00033
00034
00035
00036
00037 #define DXL_ERR_INPUT_VOLTAGE 1
00038 #define DXL_ERR_ANGLE_LIMIT 2
00039 #define DXL_ERR_OVERHEATING 4
00040 #define DXL_ERR_RANGE 8
00041 #define DXL_ERR_CHECKSUM 16
00042 #define DXL_ERR_OVERLOAD 32
00043 #define DXL_ERR_INSTRUCTION 64
00044
00045
00046
00047 #define DXL_OFF 0
00048 #define DXL_ON 1
00049 #define DXL_TOGGLE 2
00050
00051 class CDynamixel: public CDxlGeneric
00052 {
00053 protected:
00054 CLog2 mLog;
00055
00056
00057 CDxlConfig mConfig;
00058 double mAngleLUT[DXL_NUM_POSITIONS];
00059 double mDirection;
00060 double mNullAngle;
00061
00062
00063 double mPosition;
00064 double mSpeed;
00065 double mLoad;
00066 double mVoltage;
00067 double mTemperature;
00068
00070
00077 WORD mCWAngleLimit;
00078 WORD mCCWAngleLimit;
00079
00080 bool mEndlessTurnMode;
00081
00082 int clip(const int value, const int min, const int max)
00083 {
00084 int result = value;
00085 if (result < min)
00086 result = min;
00087 if (result > max)
00088 result = max;
00089 return result;
00090 }
00091
00092 int round(double val)
00093 {
00094 return (int)floor(val+0.5);
00095 }
00096
00097
00098 double dxlPosToInternalPos(WORD pos);
00099 int internalPosToDxlPos(double pos);
00100 double dxlSpeedToInternalSpeed(WORD speed);
00101 int internalSpeedToDxlSpeed(double speed);
00102 double dxlTorqueToInternalTorque(WORD torque);
00103 WORD internalTorqueToDxlTorque(double torque);
00104
00105 public:
00106 CDynamixel();
00107 virtual ~CDynamixel();
00108
00109 virtual int getID() {return mID;}
00110 virtual void setConfig(CDxlConfig* config);
00111 virtual void setSerialPort(LxSerial* serialPort);
00112 virtual int init(bool sendConfigToMotor=true);
00113
00114 virtual void setPositiveDirection(bool clockwiseIsPositive);
00115 virtual void setNullAngle(double nullAngle);
00116 virtual int setPos(double pos, double absSpeed, bool shouldSyncWrite=false);
00117
00119
00124 virtual int setSpeed(double speed, bool shouldSyncWrite=false);
00125 virtual int setRetlevel(const int returnlevel);
00126 virtual int setBaudRateIndex(const BYTE baudRateIndex);
00127 virtual int setBaudRate(const int baudRate);
00128 virtual int setReturnDelayTime(const int microsecondsReturnDelay);
00129 virtual int setInitialTorqueLimit(double absMaxTorque);
00130 virtual int setTorqueLimit(double absMaxTorque);
00131 virtual int setAngleLimits(double lowerLimit, double upperLimit);
00132 virtual int setVoltageLimits(double minVoltage, double maxVoltage);
00133 virtual int setTemperatureLimit(const int maxTemp);
00134 virtual int setAngleLowerLimit(double limit);
00135 virtual int setAngleUpperLimit(double limit);
00136 virtual int setCompliance(BYTE complianceMargin, BYTE complianceSlope);
00137 virtual int setPunch(WORD punch);
00138 virtual int setAlarmLEDMask(const BYTE mask);
00139 virtual int setOperatingMode(const BYTE mode);
00140 virtual int setAlarmShutdownMask(const BYTE mask);
00141 virtual int changeID(const int newID);
00142 virtual int enableLED(int state);
00143 virtual int enableTorque(int state);
00144 virtual int setEndlessTurnMode(bool enabled, bool shouldSyncWrite=false);
00145 virtual int setEndlessTurnTorque(double torqueRatio, bool shouldSyncWrite=false);
00146
00147 virtual int getPos();
00148 virtual int getPosAndSpeed();
00149 virtual int getTemp();
00150 virtual int getState();
00151 virtual int getAngleLimits();
00152
00153 virtual double presentPos() {return mPosition;}
00154 virtual double presentLinearPos() {mLogWarningLn("presentLinearPos function not implemented");return 0;}
00155 virtual double presentSpeed() {return mSpeed;}
00156 virtual double presentAcceleration() {mLogWarningLn("presentAcceleration function not implemented");return 0;};
00157 virtual double presentLinearAcceleration() {mLogWarningLn("presentLinearAcceleration function not implemented");return 0;};
00158 virtual double presentLoad() {return mLoad;}
00159 virtual double presentVoltage() {return mVoltage;}
00160 virtual double presentBusVoltage() {mLogWarningLn("presentBusVoltage function not implemented"); return 0;}
00161 virtual double presentCurrentADCVoltage() {mLogWarningLn("presentCurrentADCVoltage function not implemented"); return 0;}
00162 virtual double presentAnalog1Voltage() {mLogWarningLn("presentAnalog1Voltage function not implemented"); return 0;}
00163 virtual double presentAnalog2Voltage() {mLogWarningLn("presentAnalog2Voltage function not implemented"); return 0;}
00164 virtual double presentAnalog3Voltage() {mLogWarningLn("presentAnalog3Voltage function not implemented"); return 0;}
00165 virtual double presentAnalog4Voltage() {mLogWarningLn("presentAnalog4Voltage function not implemented"); return 0;}
00166 virtual double presentTemp() {return mTemperature;}
00167 virtual double presentCurrent() {mLogWarningLn("presentCurrent function not implemented");return 0;}
00168 virtual double presentTorque() {mLogWarningLn("presentTorque function not implemented");return 0;}
00169 virtual WORD presentCWAngleLimit() {return mCWAngleLimit;}
00170 virtual WORD presentCCWAngleLimit() {return mCCWAngleLimit;}
00171 virtual double presentAngleLowerLimit();
00172 virtual double presentAngleUpperLimit();
00173
00174 virtual int printReport(FILE* fOut);
00175 };
00176
00177 #endif