Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaServo.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: librnr_dynamixel
6 //
7 // File: DynaServo.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-01-12 10:56:06 -0700 (Mon, 12 Jan 2015) $
12  * $Rev: 3845 $
13  *
14  * \ingroup dyna_lib_hdrs
15  *
16  * \brief RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  *
20  * \copyright
21  * \h_copy 2011-2017. RoadNarrows LLC.\n
22  * http://www.roadnarrows.com\n
23  * All Rights Reserved
24  */
25 /*
26  * @EulaBegin@
27  *
28  * Unless otherwise stated explicitly, all materials contained are copyrighted
29  * and may not be used without RoadNarrows LLC's written consent,
30  * except as provided in these terms and conditions or in the copyright
31  * notice (documents and software) or other proprietary notice provided with
32  * the relevant materials.
33  *
34  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
35  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
36  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
37  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
38  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
39  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
42  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
43  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
44  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
45  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
46  *
47  * @EulaEnd@
48  */
49 ////////////////////////////////////////////////////////////////////////////////
50 
51 #ifndef _DYNA_SERVO_H
52 #define _DYNA_SERVO_H
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/units.h"
56 #include "rnr/log.h"
57 
58 #include "Dynamixel/Dynamixel.h"
59 #include "Dynamixel/DynaTypes.h"
60 #include "Dynamixel/DynaError.h"
61 #include "Dynamixel/DynaOlio.h"
62 #include "Dynamixel/DynaComm.h"
63 #include "Dynamixel/DynaPidSpeed.h"
64 
65 
66 // ---------------------------------------------------------------------------
67 // Dynamixel Servo Abstract Base Class
68 // ---------------------------------------------------------------------------
69 
70 /*!
71  * \ingroup dyna_lib_classes
72  *
73  * \brief Dynamixel Servo Abstract Base Class
74  *
75  * The DynaServo abstract class provides the archetype functions to bootstrap
76  * into a specific DynaServo class object.
77  */
78 class DynaServo
79 {
80 public:
81  /*!
82  * \brief Default initialization constructor.
83  *
84  * \param comm Dynamixel bus communication instance.
85  * \param nServoId Servo Id.
86  * \param uModelNum Servo model number.
87  * \param uFwVer Servo firmware version.
88  */
89  DynaServo(DynaComm &comm, int nServoId, uint_t uModelNum, uint_t uFwVer) :
90  m_comm(comm)
91  {
92  Init(nServoId, uModelNum, uFwVer);
93  }
94 
95  /*!
96  * \brief Destructor.
97  */
98  virtual ~DynaServo();
99 
100  /*!
101  * \brief Archetype constructor to create a new Dynamixel servo instance.
102  *
103  * The specific DynaServo object created depends on both the servo's model
104  * number and firmware version stored in the servo's EEPROM.
105  *
106  * \param comm Dynamixel bus communication instance.
107  * \param nServoId Servo id.
108  *
109  * \return On succes, returns pointer to the allocated DynaServo derived
110  * object.\n
111  * On failure, NULL is returned.
112  */
113  static DynaServo *New(DynaComm &comm, int nServoId);
114 
115 
116  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
117  // General Attribute Functions
118  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
119 
120  /*!
121  * \brief Get servo model number.
122  *
123  * \return Model number.
124  */
125  virtual uint_t GetModelNumber() const
126  {
127  return m_cfg.m_uModelNum;
128  }
129 
130  /*!
131  * \brief Get servo firmware version.
132  *
133  * \return Model number.
134  */
135  virtual uint_t GetFirmwareVersion() const
136  {
137  return m_cfg.m_uFwVer;
138  }
139 
140  /*!
141  * \brief Get servo model name string.
142  *
143  * \return Model name.
144  */
145  virtual const char *GetModelName() const
146  {
147  return m_spec.m_sModelName;
148  }
149 
150  /*!
151  * \brief Get servo id.
152  *
153  * \return Servo id.
154  */
155  virtual uint_t GetServoId() const
156  {
157  return m_nServoId;
158  }
159 
160  /*!
161  * \brief Get the servo operational mode.
162  *
163  * \return Servo mode.
164  */
165  virtual uint_t GetServoMode() const
166  {
167  return m_cfg.m_uServoMode;
168  }
169 
170  /*!
171  * \brief Test if servo has 360\h_deg positioning information.
172  *
173  * \return Returns true or false.
174  */
175  virtual uint_t Has360PosInfo() const
176  {
177  return m_spec.m_bHas360Pos;
178  }
179 
180  /*!
181  * \brief Get servo specification.
182  *
183  * \return Reference to shadowed specification data.
184  */
185  virtual const DynaServoSpec_T &GetSpecification() const
186  {
187  return m_spec;
188  }
189 
190  /*!
191  * \brief Get servo configuration.
192  *
193  * \return Reference to shadowed configuration data.
194  */
195  virtual const DynaServoCfg_T &GetConfiguration() const
196  {
197  return m_cfg;
198  }
199 
200  /*!
201  * \brief Get servo state.
202  *
203  * \return Reference to shadowed state data.
204  */
205  virtual const DynaServoState_T &GetState() const
206  {
207  return m_state;
208  }
209 
210 
211  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
212  // Linking Functions
213  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
214 
215  /*!
216  * \brief Test if this servo is a master.
217  *
218  * A master is either the master servo in a linked master-slave configuration,
219  * or an unlinked servo (a master unto thyself).
220  *
221  * \return Returns true if a master, false otherwise.
222  */
223  bool IsMaster() const
224  {
225  return ((m_link.m_uLinkType == DYNA_LINK_NONE) ||
226  (m_link.m_uLinkType == DYNA_LINK_MASTER))? true: false;
227  }
228 
229  /*!
230  * \brief Test if this servo is a linked master.
231  *
232  * A linked master is the master servo in a linked master-slave configuration.
233  *
234  * \return Returns true if a linked master, false otherwise.
235  */
236  bool IsLinkedMaster() const
237  {
238  return (m_link.m_uLinkType == DYNA_LINK_MASTER)? true: false;
239  }
240 
241  /*!
242  * \brief Test if this servo is unlinked.
243  *
244  * \return Returns true if unlinked, false otherwise.
245  */
246  bool IsUnlinked() const
247  {
248  return (m_link.m_uLinkType == DYNA_LINK_NONE)? true: false;
249  }
250 
251  /*!
252  * \brief Get linked information.
253  *
254  * \return Reference to linked data.
255  */
256  virtual const DynaServoLink_T GetLinkInfo() const
257  {
258  DynaServoLink_T link;
259 
261  link.m_nServoIdMate = m_link.m_pServoMate != NULL?
264 
265  return link;
266  }
267 
268  /*!
269  * \brief Link this servo to another.
270  *
271  * \param uLinkType This servo's linked type.
272  * See \ref dyna_servo_link_type.
273  * \param pServoMate This servo's linked mate.
274  * \param bRotReversed The linked servos do [not] rotate in opposite
275  * directions.
276  */
277  virtual void Link(uint_t uLinkType, DynaServo *pServoMate, bool bRotReversed)
278  {
279  m_link.m_uLinkType = uLinkType;
280  m_link.m_pServoMate = pServoMate;
281  m_link.m_bRotReversed = bRotReversed;
282  }
283 
284  /*!
285  * \brief Unlink this servo.
286  */
287  virtual void Unlink()
288  {
290  m_link.m_pServoMate = NULL;
291  m_link.m_bRotReversed = false;
292  }
293 
294 
295  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
296  // Servo Virtual Odometer Functions
297  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
298 
299  /*!
300  * \brief Get the current virtual odometer value.
301  *
302  * \return Odometer value.
303  */
305  {
306  return m_state.m_od.m_nOdometer;
307  }
308 
309  /*!
310  * \brief Test if virtual odometer mapping is enabled.
311  *
312  * \return Returns true or false.
313  */
315  {
316  return m_state.m_od.m_bOdEnabled;
317  }
318 
319  /*!
320  * \brief Get the virtual odometer zero point.
321  *
322  * \return Servo zero point.
323  */
325  {
326  return m_state.m_od.m_nEncZeroPt;
327  }
328 
329  /*!
330  * \brief Test if the virtual odometer is reversed.
331  *
332  * \return Returns true if reversed, false otherwise.
333  */
335  {
336  return m_state.m_od.m_nOdDir == -1? true: false;
337  }
338 
339  /*!
340  * \brief Calculate the odometer value at the minimum (zero) encoder value.
341  *
342  * \return Odometer value.
343  */
345  {
347  }
348 
349  /*!
350  * \brief Calculate the odometer value at the maximum encoder value.
351  *
352  * \return Odometer value.
353  */
355  {
358  }
359 
360  /*!
361  * \brief Convert virtual odometer units to servo encoder units.
362  *
363  * \param nOdPos Odometer position.
364  *
365  * \return Encoder ticks.
366  */
367  int OdometerToEncoder(int nOdPos)
368  {
369  return imod(m_state.m_od.m_nEncZeroPt + nOdPos * m_state.m_od.m_nOdDir,
371  }
372 
373  /*!
374  * \brief Calculate serve direction to goal odometer position.
375  *
376  * \param nOdGoalPos Odometer goal position.
377  *
378  * \return 1 or -1
379  */
380  int CalcSpeedDir(int nOdGoalPos)
381  {
383  {
384  return nOdGoalPos >= m_state.m_od.m_nOdometer?
387  }
388  else
389  {
390  return 1;
391  }
392  }
393 
394  /*!
395  * \brief Reset the servo's virtual odometer.
396  *
397  * The odometer mapping is enabled.
398  *
399  * \param nEncZeroPt Zero point position in servo raw encoder position units.
400  * \param bIsReverse Do [not] reverse rotation sense.
401  *
402  * \return Returns the new, odometer position [-OdModulo+1, OdModulo-1] in
403  * virtual raw position units.
404  */
405  virtual int ResetOdometer(int nEncZeroPt, bool bIsReverse);
406 
407  /*!
408  * \brief Update the odometer from the current servo position and rotation
409  * direction.
410  *
411  * \param nEncCurPos Servo encoder current position in raw ticks.
412  *
413  * \return Returns the new, odometer position [-OdModulo+1, OdModulo-1] in
414  * virtual raw position units.
415  */
416  virtual int UpdateOdometer(int nEncCurPos);
417 
418  /*!
419  * \brief Disable odometer mapping.
420  *
421  * The odometer will always equal the encoder value.
422  */
423  virtual void DisableOdometer();
424 
425 
426  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
427  // State Attribute Functions
428  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
429 
430  /*!
431  * \brief Get the current servo alarms.
432  *
433  * \return Alarm bits.
434  */
435  virtual uint_t GetAlarms() const
436  {
437  return m_state.m_uAlarms;
438  }
439 
440  /*!
441  * \brief Get the current servo position.
442  *
443  * \return Current position.
444  */
445  virtual uint_t GetCurPos() const
446  {
447  return m_state.m_uCurPos;
448  }
449 
450  /*!
451  * \brief Get the current servo speed.
452  *
453  * \return Current speed.
454  */
455  virtual int GetCurSpeed() const
456  {
457  return m_state.m_nCurSpeed;
458  }
459 
460  /*!
461  * \brief Get the goal servo speed.
462  *
463  * \return Goal speed.
464  */
465  virtual int GetGoalSpeed() const
466  {
467  return m_state.m_nGoalSpeed;
468  }
469 
470  /*!
471  * \brief Get the current servo load.
472  *
473  * \return Current speed.
474  */
475  virtual int GetCurLoad() const
476  {
477  return m_state.m_nCurLoad;
478  }
479 
480  /*!
481  * \brief Get the current temperature.
482  *
483  * \return Current temperature in raw units.
484  */
485  virtual uint_t GetCurTemp() const
486  {
487  return m_state.m_uCurTemp;
488  }
489 
490  /*!
491  * \brief Convert raw temperature coding to degrees Celsius.
492  *
493  * \param uTemp Raw temperature value.
494  *
495  * \return Celsius.
496  */
497  virtual float CvtRawTempToC(uint uTemp) = 0;
498 
499  /*!
500  * \brief Get the current voltage.
501  *
502  * \return Current voltage in raw units.
503  */
504  virtual uint_t GetCurVolt() const
505  {
506  return m_state.m_uCurVolt;
507  }
508 
509  /*!
510  * \brief Convert raw volts coding to volts.
511  *
512  * \param uTemp Raw volts value.
513  *
514  * \return Volatage.
515  */
516  virtual float CvtRawVoltToVolts(uint uVolts) = 0;
517 
518  /*!
519  * \brief Set soft torque thresholds.
520  *
521  * The thresholds are used as a hystersis to software control servo torque.
522  *
523  * \param uOverTorqueTh High threshold where the servo is set in an over
524  * torque condition.
525  * \param uClearTorqueTh Low threshold where the servo is cleared of an over
526  * torque condition.
527  */
528  virtual void SetSoftTorqueThresholds(uint_t uOverTorqueTh,
529  uint_t uClearTorqueTh)
530  {
531  m_state.m_uOverTorqueTh = uOverTorqueTh;
532  m_state.m_uClearTorqueTh = uClearTorqueTh;
533  m_state.m_bOverTorqueCond = false;
534  }
535 
536  /*!
537  * \brief Get soft torque thresholds.
538  *
539  * The thresholds are used as a hystersis to software control servo torque.
540  *
541  * \param [out] uOverTorqueTh High threshold where the servo is set in an
542  * over torque condition.
543  * \param [out] uClearTorqueTh Low threshold where the servo is cleared of
544  * an over torque condition.
545  */
546  virtual void GetSoftTorqueThresholds(uint_t &uOverTorqueTh,
547  uint_t &uClearTorqueTh)
548  {
549  uOverTorqueTh = m_state.m_uOverTorqueTh;
550  uClearTorqueTh = m_state.m_uClearTorqueTh;
551  }
552 
553  /*!
554  * \brief Set or clear servo in soft over torque condition.
555  *
556  * \param bNewCond Servo [not] in over torque condition.
557  */
558  virtual void SetSoftTorqueOverCond(bool bNewCond)
559  {
560  m_state.m_bOverTorqueCond = bNewCond;
561  }
562 
563  /*!
564  * \brief Test if servo is in a soft over torque condition.
565  *
566  * \return Returns current in over torque condition.
567  */
568  virtual bool HasSoftTorqueOverCond()
569  {
570  return m_state.m_bOverTorqueCond;
571  }
572 
573 
574  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
575  // Servo Proxy Agent Functions
576  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
577 
578  /*!
579  * \brief Register servo proxy agent.
580  *
581  * \param pAgent Pointer to agent calls.
582  * \param pAgentArg Agent supplied Argument passed back to calls.
583  */
584  virtual void RegisterAgent(DynaAgent_T *pAgent,
585  void *pAgentArg)
586  {
587  m_pAgent = pAgent;
588  m_pAgentArg = pAgentArg;
589  }
590 
591  /*!
592  * \brief Unregister servo proxy agent.
593  */
594  virtual void UnregisterAgent()
595  {
596  m_pAgent = NULL;
597  m_pAgentArg = NULL;
598  }
599 
600  /*!
601  * \brief Tests if servo has a registered agent.
602  * \return Returns true or false.
603  */
604  virtual bool HasAgent()
605  {
606  return m_pAgent != NULL? true: false;
607  }
608 
609  virtual int AgentWriteGoalPos(int nGoalPos) = 0;
610  virtual int AgentWriteGoalSpeed(int nGoalSpeed) = 0;
611  virtual int AgentWriteGoalSpeedPos(int nGoalSpeed, int nGoalPos) = 0;
612 
613 
614  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
615  // Abstract Servo Move Functions
616  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
617  virtual int MoveTo(int nGoalPos) = 0;
618  virtual int MoveAtSpeedTo(int nGoalSpeed, int nGoalPos) = 0;
619  virtual int MoveAtSpeed(int nGoalSpeed) = 0;
620 
621  virtual int EStop() = 0;
622  virtual int Stop() = 0;
623  virtual int Freeze() = 0;
624  virtual int Release() = 0;
625 
626 
627  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
628  // Servo Read/Write Functions
629  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
630 
631  /*!
632  * \brief Read the servo model number from the servo's EEPROM.
633  *
634  * \par Control Table:
635  * \ref dyna_servo_memmap_model_num
636  *
637  * \param comm Dynamixel bus communication instance.
638  * \param nServoId Servo id.
639  * \param [out] pModelNum Pointer to read servo model number.
640  *
641  * \copydoc doc_return_std
642  */
643  static int ReadModelNumber(DynaComm &comm, int nServoId, uint_t *pModelNum);
644 
645  /*!
646  * \brief Read the servo's firmware version from the servo's EEPROM.
647  *
648  * \par Control Table:
649  * \ref dyna_servo_memmap_fwver
650  *
651  * \param comm Dynamixel bus communication instance.
652  * \param nServoId Servo id.
653  * \param [out] pFwVer Pointer to read servo firmware version.
654  *
655  * \copydoc doc_return_std
656  */
657  static int ReadFirmwareVersion(DynaComm &comm, int nServoId, uint_t *pFwVer);
658 
659  /*!
660  * \brief Read the servo's id from the servo's EEPROM.
661  *
662  * \par Control Table:
663  * \ref dyna_servo_memmap_id
664  *
665  * \param comm Dynamixel bus communication instance.
666  * \param nServoId Servo id.
667  * \param [out] pServoId Pointer to read servo servo id.
668  *
669  * \copydoc doc_return_std
670  */
671  static int ReadServoId(DynaComm &comm, int nServoId, int *pServoId);
672 
673  /*!
674  * \brief Write the new servo id to the servo's EEPROM.
675  *
676  * \par Control Table:
677  * \ref dyna_servo_memmap_id
678  *
679  * \param comm Dynamixel bus communication instance.
680  * \param nServoId Servo id.
681  * \param nNewServoId New servo id.
682  *
683  * \copydoc doc_return_std
684  */
685  static int WriteServoId(DynaComm &comm, int nServoId, int nNewServoId);
686 
687  /*!
688  * \brief Read the servo's baud rate from the servo's EEPROM.
689  *
690  * \par Control Table:
691  * \ref dyna_servo_memmap_baud_rate
692  *
693  * \param comm Dynamixel bus communication instance.
694  * \param nServoId Servo id.
695  * \param [out] pBaudRate Baud rate.
696  *
697  * \copydoc doc_return_std
698  */
699  static int ReadBaudRate(DynaComm &comm, int nServoId, int *pBaudRate);
700 
701  /*!
702  * \brief Write the new baud rate to the servo's EEPROM.
703  *
704  * \par Control Table:
705  * \ref dyna_servo_memmap_baud_rate
706  *
707  * \param comm Dynamixel bus communication instance.
708  * \param nServoId Servo id.
709  * \param nNewBaudRate New baud rate.
710  *
711  * \copydoc doc_return_std
712  */
713  static int WriteBaudRate(DynaComm &comm, int nServoId, int nNewBaudRate);
714 
715  /*!
716  * \brief Ping the given servo.
717  *
718  * \param comm Dynamixel bus communication instance.
719  * \param nServoId Servo id.
720  *
721  * \return Returns true if the servo responded, else false.
722  */
723  static bool Ping(DynaComm &comm, int nServoId);
724 
725  /*!
726  * \brief Reset the given servo back to default values.
727  *
728  * \warning All configuration data are lost.
729  *
730  * \param comm Dynamixel bus communication instance.
731  * \param nServoId Servo id.
732  *
733  * \copydoc doc_std_return
734  */
735  static int Reset(DynaComm &comm, int nServoId);
736 
737  //
738  // Abstract read/write functions.
739  //
740 
741  virtual int CfgReadRotationLimits(uint_t *pCwLim, uint_t *pCcwLim) = 0;
742 
743  virtual int CfgWriteRotationLimits(uint_t uCwLim, uint_t uCcwLim) = 0;
744 
745  virtual int CfgReadTemperatureLimit(uint_t *pTempLim) = 0;
746 
747  virtual int CfgWriteTemperatureLimit(uint_t uTempLim) = 0;
748 
749  virtual int CfgReadVoltageLimits(uint_t *pMinVoltLim,
750  uint_t *pMaxVoltLim) = 0;
751 
752  virtual int CfgWriteVoltageLimits(uint_t uMinVoltLim,
753  uint_t uMaxVoltLim) = 0;
754 
755  virtual int CfgReadMaxTorqueLimit(uint_t *pMaxTorqueLim) = 0;
756 
757  virtual int CfgWriteMaxTorqueLimit(uint_t uMaxTorqueLim) = 0;
758 
759  virtual int CfgReadAlarmShutdownMask(uint_t *pAlarmMask) = 0;
760 
761  virtual int CfgWriteAlarmShutdownMask(uint_t uAlarmMask) = 0;
762 
763  virtual int CfgReadServoMode(uint_t *pServoMode) = 0;
764 
765  virtual int CfgWriteServoMode(uint_t uCwLim, uint_t uCcwLim) = 0;
766 
767  virtual int CfgWriteServoModeContinuous() = 0;
768 
769  virtual int ReadTorqueEnable(bool *pState) = 0;
770 
771  virtual int WriteTorqueEnable(bool bState) = 0;
772 
773  virtual int ReadLed(bool *pState) = 0;
774 
775  virtual int WriteLed(bool bState) = 0;
776 
777  virtual int ReadControlMethod(DynaServoCtlMethod_T *pCtlMethod) = 0;
778 
779  virtual int WriteControlMethod(DynaServoCtlMethod_T &ctlMethod) = 0;
780 
781  virtual int ReadGoalPos(int *pGoalPos) = 0;
782 
783  virtual int WriteGoalPos(int nGoalPos) = 0;
784 
785  virtual int ReadGoalSpeed(int *pGoalSpeed) = 0;
786 
787  virtual int WriteGoalSpeed(int nGoalSpeed) = 0;
788 
789  virtual int ReadMaxTorqueLimit(uint_t *pMaxTorqueLim) = 0;
790 
791  virtual int WriteMaxTorqueLimit(uint_t uMaxTorqueLim) = 0;
792 
793  virtual int ReloadMaxTorqueLimit() = 0;
794 
795  virtual int ReadCurPos(int *pCurPos) = 0;
796 
797  virtual int ReadCurSpeed(int *pCurSpeed) = 0;
798 
799  virtual int ReadCurLoad(int *pCurLoad) = 0;
800 
801  virtual int ReadDynamics(int *pCurPos, int *pCurSpeed, int *pCurLoad) = 0;
802 
803  virtual int ReadHealth(uint_t *pAlarms,
804  int *pCurLoad,
805  uint_t *pCurVolt,
806  uint_t *pCurTemp) = 0;
807 
808  virtual int ReadIsMoving(bool *pState) = 0;
809 
810  virtual int Read(uint_t uAddr, uint_t *pVal) = 0;
811 
812  virtual int Write(uint_t uAddr, uint_t uVal) = 0;
813 
814  virtual bool Ping() = 0;
815 
816  virtual int Reset() = 0;
817 
818  virtual int SyncData() = 0;
819 
820  virtual int SyncCfg() = 0;
821 
822  virtual int SyncState() = 0;
823 
824  virtual void Dump() = 0;
825 
826 protected:
827  /*! servo linkage */
828  typedef struct
829  {
830  uint_t m_uLinkType; ///< linked type \ref dyna_servo_link_type
831  DynaServo *m_pServoMate; ///< linked servo mate
832  bool m_bRotReversed; ///< do [not] rotate in opposite directions
833  } CrossLink_T;
834 
835  DynaComm &m_comm; ///< attached Dynamixel bus comm. object
836  int m_nServoId; ///< servo id
837  DynaServoSpec_T m_spec; ///< servo specification
838  DynaServoCfg_T m_cfg; ///< servo shadowed EEPROM configuration
839  DynaServoState_T m_state; ///< servo shadowed RAM state
840  CrossLink_T m_link; ///< servo cross linkage
841  DynaAgent_T *m_pAgent; ///< servo agent
842  void *m_pAgentArg; ///< servo agent callback argument
843  int m_nErrorCode; ///< class instance errored state
844 
845  friend class DynaServoGeneric;
846  friend class DynaServoAX12;
847  friend class DynaServoEX106P;
848  friend class DynaServoMX28;
849  friend class DynaServoMX64;
850  friend class DynaServoMX106;
851  friend class DynaServoRX10;
852  friend class DynaServoRX24F;
853  friend class DynaServoRX28;
854  friend class DynaServoRX64;
855  friend class DynaChain;
856 
857  /*!
858  * \brief Initialize servo class instance.
859  *
860  * \param comm Dynamixel bus communication instance.
861  * \param nServoId Servo Id.
862  * \param uModelNum Servo model number.
863  * \param uFwVer Servo firmware version.
864  */
865  void Init(int nServoId, uint_t uModelNum, uint_t uFwVer);
866 
867  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
868  // Linking Functions
869  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
870 
871  virtual int CalcMatesGoalPos(int nGoalPos, int *pGoalPosMate) = 0;
872 
873  virtual int CalcMatesGoalSpeed(int nGoalSpeed) = 0;
874 
875  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
876  // Field Packing Functions
877  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
878  virtual uint_t PackGoalSpeed(int nGoalSpeed) = 0;
879 
880  virtual int UnpackGoalSpeed(uint_t uVal) = 0;
881 
882  virtual int UnpackCurSpeed(uint_t uVal) = 0;
883 
884  virtual int UnpackCurLoad(uint_t uVal) = 0;
885 
886  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
887  // Other Functions
888  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
889 
890  /*!
891  * \brief Dump the servo control tabl values to stdout.
892  *
893  * \param sTblName Name of the control table.
894  * \param tblInfo Control table info.
895  * \param uSize Control table info size (number of entries).
896  */
897  void DumpCtlTbl(const char *sTblName,
898  const DynaCtlTblEntry_T tblInfo[],
899  size_t uSize);
900 };
901 
902 
903 #endif // _DYNA_SERVO_H
virtual uint_t GetCurPos() const
Get the current servo position.
Definition: DynaServo.h:445
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
virtual int UpdateOdometer(int nEncCurPos)
Update the odometer from the current servo position and rotation direction.
Definition: DynaServo.cxx:207
virtual uint_t GetServoMode() const
Get the servo operational mode.
Definition: DynaServo.h:165
static int WriteBaudRate(DynaComm &comm, int nServoId, int nNewBaudRate)
Write the new baud rate to the servo&#39;s EEPROM.
Definition: DynaServo.cxx:357
virtual int GetCurLoad() const
Get the current servo load.
Definition: DynaServo.h:475
virtual const DynaServoState_T & GetState() const
Get servo state.
Definition: DynaServo.h:205
virtual void SetSoftTorqueOverCond(bool bNewCond)
Set or clear servo in soft over torque condition.
Definition: DynaServo.h:558
void DumpCtlTbl(const char *sTblName, const DynaCtlTblEntry_T tblInfo[], size_t uSize)
Dump the servo control tabl values to stdout.
Definition: DynaServo.cxx:422
bool IsLinkedMaster() const
Test if this servo is a linked master.
Definition: DynaServo.h:236
Dynamixel Servo Specification Structure.
Definition: DynaTypes.h:81
MX-28 Dynamixel Servo Class.
Definition: DynaServoMX28.h:77
DynaServo(DynaComm &comm, int nServoId, uint_t uModelNum, uint_t uFwVer)
Default initialization constructor.
Definition: DynaServo.h:89
static int ReadBaudRate(DynaComm &comm, int nServoId, int *pBaudRate)
Read the servo&#39;s baud rate from the servo&#39;s EEPROM.
Definition: DynaServo.cxx:327
int m_nOdDir
odometer direction: normal or reverse
Definition: DynaTypes.h:182
virtual int GetCurSpeed() const
Get the current servo speed.
Definition: DynaServo.h:455
virtual ~DynaServo()
Destructor.
Definition: DynaServo.cxx:94
virtual float CvtRawVoltToVolts(uint uVolts)=0
Convert raw volts coding to volts.
bool IsUnlinked() const
Test if this servo is unlinked.
Definition: DynaServo.h:246
virtual void UnregisterAgent()
Unregister servo proxy agent.
Definition: DynaServo.h:594
DynaAgent_T * m_pAgent
servo agent
Definition: DynaServo.h:841
RX-64 Dynamixel Servo Class.
Definition: DynaServoRX64.h:77
The Dynamixel Speed PID Class.
int m_nCurLoad
current load
Definition: DynaTypes.h:208
DynaServoCfg_T m_cfg
servo shadowed EEPROM configuration
Definition: DynaServo.h:838
AX-12, AX-12+, AX-12A Dynamixel Servo Class.
Definition: DynaServoAX12.h:77
static int ReadModelNumber(DynaComm &comm, int nServoId, uint_t *pModelNum)
Read the servo model number from the servo&#39;s EEPROM.
Definition: DynaServo.cxx:256
virtual const DynaServoCfg_T & GetConfiguration() const
Get servo configuration.
Definition: DynaServo.h:195
virtual uint_t GetCurTemp() const
Get the current temperature.
Definition: DynaServo.h:485
virtual bool HasAgent()
Tests if servo has a registered agent.
Definition: DynaServo.h:604
virtual uint_t GetFirmwareVersion() const
Get servo firmware version.
Definition: DynaServo.h:135
virtual void SetSoftTorqueThresholds(uint_t uOverTorqueTh, uint_t uClearTorqueTh)
Set soft torque thresholds.
Definition: DynaServo.h:528
virtual const DynaServoLink_T GetLinkInfo() const
Get linked information.
Definition: DynaServo.h:256
EX-106+ Dynamixel Servo Class.
Miscellaneous collection of useful utilities.
uint_t m_uFwVer
firmware version
Definition: DynaTypes.h:123
Dynamixel Servo Configuration Structure.
Definition: DynaTypes.h:120
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
uint_t m_uCurVolt
current voltage
Definition: DynaTypes.h:209
void * m_pAgentArg
servo agent callback argument
Definition: DynaServo.h:842
virtual uint_t GetCurVolt() const
Get the current voltage.
Definition: DynaServo.h:504
uint_t m_uRawPosModulo
raw position modulo
Definition: DynaTypes.h:103
virtual void DisableOdometer()
Disable odometer mapping.
Definition: DynaServo.cxx:242
int CalcSpeedDir(int nOdGoalPos)
Calculate serve direction to goal odometer position.
Definition: DynaServo.h:380
int m_nCurSpeed
current speed (raw)
Definition: DynaTypes.h:207
static int WriteServoId(DynaComm &comm, int nServoId, int nNewServoId)
Write the new servo id to the servo&#39;s EEPROM.
Definition: DynaServo.cxx:316
static int Reset(DynaComm &comm, int nServoId)
Reset the given servo back to default values.
Definition: DynaServo.cxx:391
bool IsMaster() const
Test if this servo is a master.
Definition: DynaServo.h:223
static int ReadFirmwareVersion(DynaComm &comm, int nServoId, uint_t *pFwVer)
Read the servo&#39;s firmware version from the servo&#39;s EEPROM.
Definition: DynaServo.cxx:276
Dynamixel Control Method Structure.
Definition: DynaTypes.h:146
Servo Control Table Entry.
Definition: DynaTypes.h:369
bool m_bOverTorqueCond
over torque condition state
Definition: DynaTypes.h:205
uint_t m_uModelNum
servo model number
Definition: DynaTypes.h:122
char * m_sModelName
model name
Definition: DynaTypes.h:83
static DynaServo * New(DynaComm &comm, int nServoId)
Archetype constructor to create a new Dynamixel servo instance.
Definition: DynaServo.cxx:102
uint_t m_uClearTorqueTh
clear over torque cond. threshold
Definition: DynaTypes.h:204
int IsOdometerEnabled()
Test if virtual odometer mapping is enabled.
Definition: DynaServo.h:314
virtual void Link(uint_t uLinkType, DynaServo *pServoMate, bool bRotReversed)
Link this servo to another.
Definition: DynaServo.h:277
Generic Dynamixel Servo Base Class.
int m_nOdometer
current odometer reading (accumulator)
Definition: DynaTypes.h:179
virtual uint_t Has360PosInfo() const
Test if servo has 360 &deg; positioning information.
Definition: DynaServo.h:175
int m_nErrorCode
class instance errored state
Definition: DynaServo.h:843
Servo Proxy Agents Calls Structure.
Definition: DynaTypes.h:230
MX-106 Dynamixel Servo Class.
uint_t m_uOverTorqueTh
set over torque cond. threshold
Definition: DynaTypes.h:203
uint_t m_uAlarms
current servo alarms and errors
Definition: DynaTypes.h:196
INLINE_IN_H int imod(int a, int b)
a mod b, &ge; 0.
Definition: DynaOlio.h:119
#define DYNA_MODE_CONTINUOUS
continuous mode with/without position
Definition: Dynamixel.h:171
int m_nEncZeroPt
servo encoder zero point position
Definition: DynaTypes.h:185
Dynamixel Chain Container Base Class.
Definition: DynaChain.h:75
int GetOdometerZeroPt()
Get the virtual odometer zero point.
Definition: DynaServo.h:324
RoadNarrows Dynamixel Fundatmental Types.
static bool Ping(DynaComm &comm, int nServoId)
Ping the given servo.
Definition: DynaServo.cxx:383
virtual void Unlink()
Unlink this servo.
Definition: DynaServo.h:287
bool m_bOdEnabled
odometer mapping [not] enabled
Definition: DynaTypes.h:181
RX-28 Dynamixel Servo Class.
Definition: DynaServoRX28.h:77
MX-64 Dynamixel Servo Class.
Definition: DynaServoMX64.h:77
int m_nGoalSpeed
goal speed (raw)
Definition: DynaTypes.h:201
bool IsOdometerReversed()
Test if the virtual odometer is reversed.
Definition: DynaServo.h:334
void Init(int nServoId, uint_t uModelNum, uint_t uFwVer)
Initialize servo class instance.
Definition: DynaServo.cxx:406
CrossLink_T m_link
servo cross linkage
Definition: DynaServo.h:840
DynaServoOdometer_T m_od
servo virtual odometer
Definition: DynaTypes.h:212
virtual const DynaServoSpec_T & GetSpecification() const
Get servo specification.
Definition: DynaServo.h:185
uint_t m_uCurPos
current position (encoder ticks)
Definition: DynaTypes.h:206
virtual bool HasSoftTorqueOverCond()
Test if servo is in a soft over torque condition.
Definition: DynaServo.h:568
virtual float CvtRawTempToC(uint uTemp)=0
Convert raw temperature coding to degrees Celsius.
int m_nServoId
servo id
Definition: DynaServo.h:836
virtual uint_t GetAlarms() const
Get the current servo alarms.
Definition: DynaServo.h:435
int OdometerToEncoder(int nOdPos)
Convert virtual odometer units to servo encoder units.
Definition: DynaServo.h:367
RoadNarrows Dynamixel Top-Level Package Header File.
virtual uint_t GetModelNumber() const
Get servo model number.
Definition: DynaServo.h:125
RX-24F Dynamixel Servo Class.
Dynamixel Servo State Structure.
Definition: DynaTypes.h:194
virtual uint_t GetServoId() const
Get servo id.
Definition: DynaServo.h:155
DynaComm & m_comm
attached Dynamixel bus comm. object
Definition: DynaServo.h:835
uint_t m_uRawPosMax
maximum raw position value (servo mode)
Definition: DynaTypes.h:102
uint_t m_uServoMode
servo mode Dynamixel Operational Modes
Definition: DynaTypes.h:136
int CalcOdometerAtEncMin()
Calculate the odometer value at the minimum (zero) encoder value.
Definition: DynaServo.h:344
DynaServoState_T m_state
servo shadowed RAM state
Definition: DynaServo.h:839
static int ReadServoId(DynaComm &comm, int nServoId, int *pServoId)
Read the servo&#39;s id from the servo&#39;s EEPROM.
Definition: DynaServo.cxx:296
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
DynaServoSpec_T m_spec
servo specification
Definition: DynaServo.h:837
virtual void RegisterAgent(DynaAgent_T *pAgent, void *pAgentArg)
Register servo proxy agent.
Definition: DynaServo.h:584
int CalcOdometerAtEncMax()
Calculate the odometer value at the maximum encoder value.
Definition: DynaServo.h:354
virtual int ResetOdometer(int nEncZeroPt, bool bIsReverse)
Reset the servo&#39;s virtual odometer.
Definition: DynaServo.cxx:188
virtual const char * GetModelName() const
Get servo model name string.
Definition: DynaServo.h:145
RX-10 Dynamixel Servo Class.
Definition: DynaServoRX10.h:77
bool m_bHas360Pos
does [not] have full 360 position info
Definition: DynaTypes.h:95
virtual int GetGoalSpeed() const
Get the goal servo speed.
Definition: DynaServo.h:465
uint_t m_uCurTemp
current temperature
Definition: DynaTypes.h:210
RoadNarrows Dynamixel Library Error and Logging Routines.
int GetOdometer()
Get the current virtual odometer value.
Definition: DynaServo.h:304
virtual void GetSoftTorqueThresholds(uint_t &uOverTorqueTh, uint_t &uClearTorqueTh)
Get soft torque thresholds.
Definition: DynaServo.h:546
Dynamixel Bus Communications Abstract Base Class.
Definition: DynaComm.h:80