AnimatLab  2
Test
RbDynamixelServo.h
1 // RbDynamixelServo.h: interface for the RbDynamixelServo class.
2 //
4 
5 #pragma once
6 
7 
8 // Dynamixel Control table address
9 #define P_MODEL_NUMBER_L 0x00
10 #define P_MODEL_NUMBER_H 0x01
11 #define P_FIRMWARE_VERSION 0x02
12 #define P_ID 0x03
13 #define P_BAUD_RATE 0x04
14 #define P_RETURN_DELAY_TIME 0x05
15 #define P_CW_ANGLE_LIMIT_L 0x06
16 #define P_CW_ANGLE_LIMIT_H 0x07
17 #define P_CCW_ANGLE_LIMIT_L 0x08
18 #define P_CCW_ANGLE_LIMIT_H 0x09
19 #define P_INTERNAL_HIGHEST_TEMP 0x0B
20 #define P_LOWEST_LIMIT_VOLTAGE 0x0C
21 #define P_HIGHEST_LIMIT_VOLTAGE 0x0D
22 #define P_MAX_TORQUE_L 0x0E
23 #define P_MAX_TORQUE_H 0x0F
24 #define P_STATUS_RETURN_LEVEL 0x10
25 #define P_ALARM_LED 0x11
26 #define P_ALARM_SHUTDOWN 0x12
27 #define P_TORQUE_ENABLE 0x18
28 #define P_LED 0x19
29 #define P_CW_COMPLIANCE_MARGIN 0x1A
30 #define P_CCW_COMPLIANCE_MARGIN 0x1B
31 #define P_CW_COMPLIANCE_SLOPE 0x1C
32 #define P_CCW_COMPLIANCE_SLOPE 0x1D
33 #define P_GOAL_POSITION_L 0x1E
34 #define P_GOAL_POSITION_H 0x1F
35 #define P_MOVING_SPEED_L 0x20
36 #define P_MOVING_SPEED_H 0x21
37 #define P_TORQUE_LIMIT_L 0x22
38 #define P_TORQUE_LIMIT_H 0x23
39 #define P_PRESENT_POSITION_L 0x24
40 #define P_PRESENT_POSITION_H 0x25
41 #define P_PRESENT_SPEED_L 0x26
42 #define P_PRESENT_SPEED_H 0x27
43 #define P_PRESENT_LOAD_L 0x28
44 #define P_PRESENT_LOAD_H 0x29
45 #define P_PRESENT_VOLTAGE 0x2A
46 #define P_PRESENT_TEMPERATURE 0x2B
47 #define P_REGISTERED 0x2C
48 #define P_MOVING 0x2E
49 #define P_LOCK 0x2F
50 #define P_PUNCH_L 0x30
51 #define P_PUNCH_H 0x31
52 
53 
54 namespace RoboticsAnimatSim
55 {
56  namespace Robotics
57  {
58  namespace RobotIOControls
59  {
60 
61 class ROBOTICS_PORT RbDynamixelMotorUpdateData
62 {
63 public:
64  int m_iID;
65  int m_iGoalPos;
66  int m_iGoalVelocity;
67 
69  {
70  m_iID = 0;
71  m_iGoalPos = 0;
72  m_iGoalVelocity = 0;
73  }
74 
75  RbDynamixelMotorUpdateData(int iID, int iGoalPos, int iGoalVelocity)
76  {
77  m_iID = iID;
78  m_iGoalPos = iGoalPos;
79  m_iGoalVelocity = iGoalVelocity;
80  }
81 
82 };
83 
84 class ROBOTICS_PORT RbDynamixelServo
85 {
86 protected:
89 
92 
95 
98 
101 
104 
107 
110 
113 
116 
119 
122 
125 
128 
131 
132  //true if a hinge joint, false otherwise.
133  bool m_bIsHinge;
134 
137 
140 
143 
146 
149 
152 
155 
158 
161 
164 
167 
170 
173 
176 
179 
182 
185 
188 
191 
194 
197 
200 
202  int m_iLoad;
203 
205  float m_fltLoad;
206 
209 
212 
215 
218 
221 
225 
228 
231 
233  float m_fltIOPos;
234 
237 
241 
244 
247 
249  MotorizedJoint *m_lpMotorJoint;
250 
253 
256 
259 
262 
265 
266  virtual void RecalculateParams();
267 
268  virtual void WriteGoalPosition(int iServoID, int iPos) = 0;
269  virtual int ReadGoalPosition(int iServoID) = 0;
270  virtual int ReadPresentPosition(int iServoID) = 0;
271 
272  virtual void WriteMovingSpeed(int iServoID, int iVelocity) = 0;
273  virtual int ReadMovingSpeed(int iServoID) = 0;
274  virtual int ReadPresentSpeed(int iServoID) = 0;
275 
276  virtual int ReadPresentLoad(int iServoID) = 0;
277  virtual int ReadPresentVoltage(int iServoID) = 0;
278  virtual int ReadPresentTemperature(int iServoID) = 0;
279  virtual int ReadIsMoving(int iServoID) = 0;
280  virtual int ReadLED(int iServoID) = 0;
281  virtual int ReadAlarmShutdown(int iServoID) = 0;
282  virtual int ReadModelNumber(int iServoID) = 0;
283  virtual int ReadID(int iServoID) = 0;
284  virtual int ReadFirmwareVersion(int iServoID) = 0;
285 
286  virtual void WriteCWComplianceMargin(int iServoID, int iVal) = 0;
287  virtual int ReadCWComplianceMargin(int iServoID) = 0;
288 
289  virtual void WriteCCWComplianceMargin(int iServoID, int iVal) = 0;
290  virtual int ReadCCWComplianceMargin(int iServoID) = 0;
291 
292  virtual void WriteCWComplianceSlope(int iServoID, int iVal) = 0;
293  virtual int ReadCWComplianceSlope(int iServoID) = 0;
294 
295  virtual void WriteCCWComplianceSlope(int iServoID, int iVal) = 0;
296  virtual int ReadCCWComplianceSlope(int iServoID) = 0;
297 
298  virtual void WriteMaxTorque(int iServoID, int iVal) = 0;
299  virtual int ReadMaxTorque(int iServoID) = 0;
300 
301  virtual void WriteReturnDelayTime(int iServoID, int iVal) = 0;
302  virtual int ReadReturnDelayTime(int iServoID) = 0;
303 
304  virtual void WriteCCWAngleLimit(int iServoID, int iVal) = 0;
305  virtual int ReadCCWAngleLimit(int iServoID) = 0;
306 
307  virtual void WriteCWAngleLimit(int iServoID, int iVal) = 0;
308  virtual int ReadCWAngleLimit(int iServoID) = 0;
309 
310  virtual void WriteTorqueLimit(int iServoID, int iVal) = 0;
311  virtual int ReadTorqueLimit(int iServoID) = 0;
312 
313  virtual void AddMotorUpdate(int iPos, int iSpeed) = 0;
314  virtual void SetMotorPosVel();
315 
316  virtual float *GetDataPointer(const std::string &strDataType);
317  virtual bool SetData(const std::string &strDataType, const std::string &strValue);
318  virtual void QueryProperties(CStdPtrArray<TypeProperty> &aryProperties);
319  virtual void StepSimulation();
320  virtual void Load(StdUtils::CStdXml &oXml);
321 
322  virtual void GetLimitValues();
323 
324  virtual void ResetSimulation();
325 
326  virtual void SetRegister(unsigned char reg, unsigned char length, unsigned int value) = 0;
327  virtual int GetRegister(unsigned char reg, unsigned char length) = 0;
328 
329  virtual void ConfigureServo();
330 
331 public:
333  virtual ~RbDynamixelServo();
334 
335  virtual void QueryMotorData(bool bVal);
336  virtual bool QueryMotorData();
337 
338  virtual void MinPosFP(int iVal);
339  virtual int MinPosFP();
340 
341  virtual void MaxPosFP(int iVal);
342  virtual int MaxPosFP();
343 
344  virtual void MinAngle(float fltVal);
345  virtual float MinAngle();
346 
347  virtual void MaxAngle(float fltVal);
348  virtual float MaxAngle();
349 
350  virtual void MinVelocityFP(int iVal);
351  virtual int MinVelocityFP();
352 
353  virtual void MaxVelocityFP(int iVal);
354  virtual int MaxVelocityFP();
355 
356  virtual void RPMPerFPUnit(float fltVal);
357  virtual float RPMPerFPUnit();
358 
359  virtual void MinLoadFP(int iVal);
360  virtual int MinLoadFP();
361 
362  virtual void MaxLoadFP(int iVal);
363  virtual int MaxLoadFP();
364 
365  virtual void CWComplianceMargin(int iVal);
366  virtual int CWComplianceMargin();
367 
368  virtual void CCWComplianceMargin(int iVal);
369  virtual int CCWComplianceMargin();
370 
371  virtual void CWComplianceSlope(int iVal);
372  virtual int CWComplianceSlope();
373 
374  virtual void CCWComplianceSlope(int iVal);
375  virtual int CCWComplianceSlope();
376 
377  virtual void MaxTorque(int iVal);
378  virtual int MaxTorque();
379 
380  virtual float ConvertPosFPToFloat(int iPos);
381  virtual int ConvertPosFloatToFP(float fltPos);
382 
383  virtual float TranslationRange();
384  virtual void TranslationRange(float fltVal);
385 
386  virtual float ConvertFPVelocity(int iVel);
387  virtual int ConvertFloatVelocity(float fltVelocity);
388 
389  virtual float ConvertFPLoad(int iLoad);
390 
391  virtual void ServoID(int iID);
392  virtual int ServoID();
393 
394  virtual void SetGoalVelocity_FP(int iVelocity);
395  virtual void SetNextGoalVelocity_FP(int iVelocity);
396  virtual int GetGoalVelocity_FP();
397 
398  virtual void SetMaximumVelocity();
399  virtual void SetNextMaximumVelocity();
400 
401  virtual void SetGoalVelocity(float fltVelocity);
402  virtual void SetNextGoalVelocity(float fltVelocity);
403  virtual float GetGoalVelocity();
404 
405  virtual void SetGoalPosition_FP(int iPos);
406  virtual void SetNextGoalPosition_FP(int iPos);
407  virtual int GetGoalPosition_FP();
408 
409  virtual void SetGoalPosition(float fltPos);
410  virtual void SetNextGoalPosition(float fltPos);
411  virtual float GetGoalPosition();
412 
413  virtual void Stop();
414 
415  virtual int LastGoalPosition_FP();
416 
417  virtual int GetActualPosition_FP();
418  virtual float GetActualPosition();
419 
420  virtual int GetActualVelocity_FP();
421  virtual float GetActualVelocity();
422 
423  virtual int LastGoalVelocity_FP();
424 
425  virtual int GetActualLoad_FP();
426  virtual float GetActualLoad();
427 
428  virtual int GetActualVoltage_FP();
429  virtual float GetActualVoltage();
430 
431  virtual float GetActualTemperatureFahrenheit();
432  virtual float GetActualTemperatureCelcius();
433 
434  virtual float GetPresentPosition() {return m_fltPresentPos;}
435  virtual float GetPresentVelocity() {return m_fltPresentVelocity;}
436  virtual float GetPresentLoad() {return m_fltLoad;}
437  virtual float GetPresentVoltage() {return m_fltVoltage;}
438  virtual float GetPresentTemperature() {return m_fltTemperature;}
439 
440  virtual bool GetIsMoving();
441  virtual void GetIsLEDOn(bool &bIsBlueOn, bool &bIsGreenOn, bool &bIsRedOn);
442  virtual bool GetIsAlarmShutdown();
443 
444  virtual int GetModelNumber();
445  virtual int GetIDNumber();
446  virtual int GetFirmwareVersion();
447 
448  virtual void InitMotorData();
449  virtual void ShutdownMotor();
450 
451  virtual void SetReturnDelayTime_FP(int iVal);
452  virtual int GetReturnDelayTime_FP();
453 
454  virtual void SetCWAngleLimit_FP(int iVal);
455  virtual void SetCWAngleLimit(float fltLimit);
456  virtual int GetCWAngleLimit_FP();
457  virtual float GetCWAngleLimit();
458 
459  virtual void SetCCWAngleLimit_FP(int iVal);
460  virtual void SetCCWAngleLimit(float fltLimit);
461  virtual int GetCCWAngleLimit_FP();
462  virtual float GetCCWAngleLimit();
463 
464  virtual void SetCWComplianceMargin_FP(int iVal);
465  virtual int GetCWComplianceMargin_FP();
466 
467  virtual void SetCCWComplianceMargin_FP(int iVal);
468  virtual int GetCCWComplianceMargin_FP();
469 
470  virtual void SetCWComplianceSlope_FP(int iVal);
471  virtual int GetCWComplianceSlope_FP();
472 
473  virtual void SetCCWComplianceSlope_FP(int iVal);
474  virtual int GetCCWComplianceSlope_FP();
475 
476  virtual void SetMaxTorque_FP(int iVal);
477  virtual int GetMaxTorque_FP();
478 
479  virtual int GetMinSimPos_FP();
480  virtual float GetMinSimPos();
481  virtual void SetMinSimPos(float fltVal);
482 
483  virtual int GetMaxSimPos_FP();
484  virtual float GetMaxSimPos();
485  virtual void SetMaxSimPos(float fltVal);
486 
487  virtual void SetTorqueLimit_FP(int iVal);
488  virtual int GetTorqueLimit_FP();
489 
490  virtual bool ResetToStartPos();
491  virtual void ResetToStartPos(bool bVal);
492 
493  virtual float QuantizeServoPosition(float fltPos);
494  virtual float QuantizeServoVelocity(float fltVel);
495 
496  virtual void MicroSleep(unsigned int iTime) = 0;
497  virtual Simulator *GetSimulator() = 0;
498 
499  virtual void Move(float fltPos, float fltVel);
500  virtual void WaitForMoveToFinish();
501 };
502 
503  } //RobotIOControls
504  } // Robotics
505 } //RoboticsAnimatSim
506 
float m_fltPosFloatToFPSlope
The conversion factor to convert radians to FP position.
int m_iTotalAngle
Maximum angle the servo can move in fixed point number. m_iMaxPosFP - m_iMinPosFP.
int m_iCWComplianceSlope
Used to set the CW compliance slope of the servo.
int m_iMaxVelocityFP
Maximum value that can be set for the velocity.
int m_iMinSimPos
This is the minimum angle in fixed point that can be used for this servo as specified in the simulati...
float m_fltConvertFPToPosS
The conversion factor to convert FP velocity value to rad/s.
int m_iMaxTorque
Used to set the maximum torque of the servo.
bool m_bVelStopPosSet
Keeps track of whether we have already set velocity to stop when doing velocity control.
int m_iCCWComplianceMargin
Used to set the CCW compliance margin of the servo.
int m_iMaxLoadFP
Maximum value that can be set for the load.
float m_fltMaxAngle
Maximum value that can be set for the position in floating point number.
int m_iMaxSimPos
This is the maximum angle in fixed point that can be used for this servo as specified in the simulati...
int m_iVoltage
The current voltage that was last read in for this servo.
float m_fltConvertPosSToFP
The conversion factor to convert rad/s to FP velocity.
float m_fltMinAngle
Minimum value that can be set for the position in floating point number.
int m_iLastGoalVelocity
Keeps track of the last servo goal velocity that we set.
int m_iServoID
ID used for communications with this servo.
int m_iMinLoadFP
Minimum value that can be set for the load.
int m_iNextGoalVelocity
This is the goal velocity that you would like to use in the next time step.
int m_iLastGoalPos
Keeps track of the last servo goal position that we set.
float m_fltFloatToFPTranslation
Conversion factor for when we are doing prismatic joints. Converts rotations to linear movements...
int m_iMinPosFP
Minimum value that can be set for the position in fixed point number.
float m_fltPresentPos
The current position that was last read in for this servo.
int m_iTemperature
The current temperature that was last read in for this servo.
int m_iPresentPos
The current position that was last read in for this servo.
float m_fltReadParamTime
The time taken to read the params of this motor for the current step.
int m_iNextGoalPos
This is the goal position that you would like to use in the next time step.
float m_fltPosFloatToFPIntercept
The conversion factor to convert radians to FP position.
A standard xml manipulation class.
Definition: StdXml.h:19
float m_fltMaxPosSec
Stores the maximum rad/sec for this motor.
int m_iMinVelocityFP
Minimum value that can be set for the velocity.
int m_iLoad
The current load that was last read in for this servo.
float m_fltConvertFPToLoad
Used to conver the load fixed point value back to a percentage of load.
float m_fltMaxSimPos
This is the maximum angle in radians that can be used for this servo as specified in the simulation...
float m_fltPresentVelocity
The current velocity that was last read in for this servo.
MotorizedJoint * m_lpMotorJoint
Pointer to an associated motorized joint.
float m_fltFPToFloatTranslation
Conversion factor for when we are doing prismatic joints. Converts rotations to linear movements...
float m_fltLoad
The current load that was last read in for this servo.
int m_iCWComplianceMargin
Used to set the CW compliance margin of the servo.
float m_fltTranslationRange
The total translation range over which a prismatic joint can move. This does not apply to hinge joint...
float m_fltRPMPerFPUnit
Stores the maximum rot/min for this motor. The max rotations (rad) per fixed point unit...
int m_iCCWComplianceSlope
Used to set the CCW compliance slope of the servo.
float m_fltCenterPos
The center point value in radians.
float m_fltTotalAngle
Maximum angle the servo can move in floating point number. m_iMaxPosFP - m_iMinPosFP.
bool m_bResetToStartPos
If true then we should reset to the start position at the beginning of the simulation.
float m_fltIOPos
Used to report back the IO position of the servo at each step.
int m_iMaxPosFP
Maximum value that can be set for the position in fixed point number.
float m_fltVoltage
The current voltage that was last read in for this servo.
float m_fltPosFPToFloatIntercept
The conversion factor to convert FP position to floating point position..
float m_fltMinSimPos
This is the minimum angle in radians that can be used for this servo as specified in the simulation...
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
float m_fltTemperature
The current temperature that was last read in for this servo.
float m_fltIOVelocity
Used to report back the IO velocity of the servo at each step.
int m_iPresentVelocity
The current velocity that was last read in for this servo.
int m_iCenterPosFP
The center point value in fixed point numbers.
float m_fltPosFPToFloatSlope
The conversion factor to convert FP position to floating point position.