Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaChain.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: librnr_dynamixel
6 //
7 // File: DynaChain.h
8 //
9 /*! \file
10  * $LastChangedDate: 2015-01-12 11:54:07 -0700 (Mon, 12 Jan 2015) $
11  * $Rev: 3846 $
12  *
13  * \ingroup dyna_lib_hdrs
14  *
15  * \brief RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
16  *
17  * \author Robin Knight (robin.knight@roadnarrows.com)
18  *
19  * \copyright
20  * \h_copy 2011-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26  *
27  * Unless otherwise stated explicitly, all materials contained are copyrighted
28  * and may not be used without RoadNarrows LLC's written consent,
29  * except as provided in these terms and conditions or in the copyright
30  * notice (documents and software) or other proprietary notice provided with
31  * the relevant materials.
32  *
33  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
34  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
35  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
36  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
37  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
38  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
41  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
42  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
43  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
44  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45  *
46  * @EulaEnd@
47  */
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 #ifndef _DYNA_CHAIN_H
51 #define _DYNA_CHAIN_H
52 
53 #include "rnr/rnrconfig.h"
54 #include "rnr/log.h"
55 
56 #include "Dynamixel/Dynamixel.h"
57 #include "Dynamixel/DynaTypes.h"
58 #include "Dynamixel/DynaError.h"
59 #include "Dynamixel/DynaComm.h"
60 #include "Dynamixel/DynaServo.h"
61 
62 
63 // ---------------------------------------------------------------------------
64 // Dynamixel Chain Container Base Class
65 // ---------------------------------------------------------------------------
66 
67 /*!
68  * \ingroup dyna_lib_classes
69  *
70  * \brief Dynamixel Chain Container Base Class.
71  *
72  * The DynaChain base class provides a coherent and synchronized interface to
73  * a set of servos communicating on the same Dynamixel bus.
74  */
75 class DynaChain
76 {
77 public:
78  /*!
79  * \brief Default initialization constructor.
80  *
81  * The chain is bound to the given Dynamixel bus communication object.
82  * No servos are present in the chain until explicitly added.
83  *
84  * A background thread may be automatically started (default) to:
85  * \li control the positioning of servos configured in continuous mode.
86  * \li monitor the dynamics of the servos in the chain.
87  * \li monitor the health of the servos in the chain.
88  *
89  * It is recommended that if any of the servos in the chain are in continuous
90  * (wheel) mode and have 360\h_deg positioning data, that the background
91  * thread be started.
92  *
93  * \param comm Dynamixel bus communication instance.
94  */
95  DynaChain(DynaComm &comm);
96 
97  /*!
98  * \brief Destructor.
99  */
100  virtual ~DynaChain();
101 
102  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103  // Attribute Functions
104  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
105 
106  /*!
107  * Test if servo is in the chain.
108  *
109  * \param nServoId Servo id.
110  *
111  * \return Returns true if servo is the chain, false otherwise.
112  */
113  virtual bool HasServo(int nServoId) const
114  {
115  return ((nServoId >= DYNA_ID_MIN) &&
116  (nServoId <= DYNA_ID_MAX) &&
117  (m_pChain[nServoId] != NULL))? true: false;
118  }
119 
120  /*!
121  * Get the servo in the chain
122  *
123  * \param nServoId Servo id.
124  *
125  * \return
126  * Returns pointer to the servo if servo is the chain.\n
127  * Returns NULL otherwise.
128  */
129  virtual DynaServo *GetServo(int nServoId)
130  {
131  return ((nServoId < DYNA_ID_MIN) || (nServoId > DYNA_ID_MAX))?
132  NULL: m_pChain[nServoId];
133  }
134 
135  /*!
136  * \brief Get the number of servos currently in chain.
137  *
138  * \return Number in chain.
139  */
140  virtual uint_t GetNumberInChain() const
141  {
142  return m_uNumInChain;
143  }
144 
145  /*!
146  * \brief Software link two unlinked servos in a master-slave configuration.
147  *
148  * The servos must be of the same Dynamixel model number.
149  *
150  * \param nServoIdMaster Master servo id.
151  * \param nServoIdSlave Slave servo id.
152  * \param bRotReversed The linked servos do [not] rotate in opposite
153  * directions.
154  *
155  * \copydoc doc_return_std
156  */
157  virtual int LinkServos(int nServoIdMaster,
158  int nServoIdSlave,
159  bool bIsReversed);
160 
161  /*!
162  * \brief Unlink two software linked servos.
163  *
164  * \param nServoIdMaster Master servo id.
165  *
166  * \copydoc doc_return_std
167  */
168  virtual int UnlinkServos(int nServoIdMaster);
169 
170  /*!
171  * \brief Test if the servo is a master.
172  *
173  * A master is either the master servo in a linked master-slave configuration,
174  * or an unlinked servo (a master unto thyself).
175  *
176  * \param nServoId Servo id.
177  *
178  * \return Returns true if a master, false otherwise.
179  */
180  virtual bool IsMaster(int nServoId) const
181  {
182  return ((nServoId >= DYNA_ID_MIN) && (nServoId <= DYNA_ID_MAX) &&
183  ((m_links[nServoId].m_uLinkType == DYNA_LINK_MASTER) ||
184  (m_links[nServoId].m_uLinkType == DYNA_LINK_NONE)))? true: false;
185  }
186 
187  /*!
188  * \brief Test if this servo is a linked master.
189  *
190  * A linked master is the master servo in a linked master-slave configuration.
191  *
192  * \param nServoId Servo id.
193  *
194  * \return Returns true if a linked master, false otherwise.
195  */
196  bool IsLinkedMaster(int nServoId) const
197  {
198  return ((nServoId >= DYNA_ID_MIN) && (nServoId <= DYNA_ID_MAX) &&
199  (m_links[nServoId].m_uLinkType == DYNA_LINK_MASTER))? true: false;
200  }
201 
202  /*!
203  * \brief Test if this servo is a linked slave.
204  *
205  * A linked slave is the slave servo in a linked master-slave configuration.
206  *
207  * \param nServoId Servo id.
208  *
209  * \return Returns true if a linked slave, false otherwise.
210  */
211  bool IsLinkedSlave(int nServoId) const
212  {
213  return ((nServoId >= DYNA_ID_MIN) && (nServoId <= DYNA_ID_MAX) &&
214  (m_links[nServoId].m_uLinkType == DYNA_LINK_SLAVE))? true: false;
215  }
216 
217  /*!
218  * \brief Test if this servo is unlinked.
219  *
220  * \param nServoId Servo id.
221  *
222  * \return Returns true if unlinked (or non-existent), false otherwise.
223  */
224  bool IsUnlinked(int nServoId) const
225  {
226  return ((nServoId >= DYNA_ID_MIN) && (nServoId <= DYNA_ID_MAX) &&
227  (m_links[nServoId].m_uLinkType == DYNA_LINK_NONE))? true: false;
228  }
229 
230  /*!
231  * \brief Get linked mate.
232  *
233  * \param nServoId Servo id.
234  *
235  * \return If the servo is linked, returns its linked mate's servo id.\n
236  * Else returns \ref DYNA_ID_NONE.
237  */
238  int GetLinkedMateId(int nServoId) const
239  {
240  return ((nServoId >= DYNA_ID_MIN) && (nServoId <= DYNA_ID_MAX))?
242  }
243 
244  /*!
245  * \brief Get the number of servos currently in chain.
246  *
247  * \return Number of masters in chain.
248  */
249  virtual uint_t GetNumberOfMastersInChain();
250 
251  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
252  // Chain Servo Add/Remove Functions
253  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
254 
255  /*!
256  * \brief Create a new servo and add it to the Dynamixel chain.
257  *
258  * Communication with servo is checked prior to adding the servo.
259  *
260  * \note
261  * Any existing servo with the same servo id will be replaced by this servo.\n
262  * Any existing linked servo configuration will be preserved if possible.
263  *
264  * \param nServoId Servo id to add.
265  *
266  * \copydoc doc_return_std
267  */
268  virtual int AddNewServo(int nServoId);
269 
270  /*!
271  * \brief Scan and add all discovered and created servos to the Dynamixel
272  * chain.
273  *
274  * \note
275  * All existing servos in the chain are removed and deleted prior to the
276  * scan.\n
277  * Any existing linked servo configuration will be preserved if possible.
278  *
279  * \return Returns the number of servos added.
280  */
281  virtual int AddNewServosByScan();
282 
283  /*!
284  * \brief Force create and add a servo to the Dynamixel chain.
285  *
286  * No communication with servo is attempted, nor any data validation
287  * performed.
288  *
289  * \note
290  * Any existing servo with the same servo id will be replaced by this servo.\n
291  * Any existing linked servo configuration will be preserved if possible.
292  *
293  * \param nServoId Servo id to add.
294  * \param uModelNum Servo model number.
295  *
296  * \copydoc doc_return_std
297  */
298  virtual int AddNewServoForced(int nServoId, uint_t uModelNum);
299 
300  /*!
301  * \brief Remove from chain and delete.
302  *
303  * \param nServoId Servo Id to delete.
304  *
305  * \copydoc doc_return_std
306  */
307  virtual int RemoveServo(int nServoId);
308 
309  /*!
310  * \brief Remove all servos from chain and delete.
311  *
312  * \copydoc doc_return_std
313  */
314  virtual int RemoveAllServos();
315 
316  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
317  // Master and Synchronous Move Functions
318  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
319 
320  /*!
321  * \brief Move to the goal postition.
322  *
323  * The move will proceed at the current goal speed. If the servo is in
324  * continuous mode, but supports 360\h_deg positioning data, then a registered
325  * external user control function is required.
326  *
327  * If this servo is the master in a linked pair of servos, both servos will
328  * move synchronously.
329  *
330  * \par Operational Modes:
331  * Servo mode (\ref DYNA_MODE_SERVO).\n
332  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
333  *
334  * \param nServoId Servo Id
335  * \param uGoalOdPos Goal positon (odometer ticks).
336  *
337  * \copydoc doc_return_std
338  */
339  virtual int MoveTo(int nServoId, int nGoalOdPos);
340 
341  /*!
342  * \brief Synchronous move servos to new goal positions.
343  *
344  * If any servo is a linked master, the linked pair will moved synchronously
345  * to the appropriate end positions.
346  *
347  * The moves will proceed at the current goal speeds.
348  *
349  * \par Operational Modes:
350  * Servo mode (\ref DYNA_MODE_SERVO).\n
351  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
352  *
353  * \param uCount Number of tuples.
354  * \param ... A variable argument list of uCount 2-tuples of type
355  * (int,int) specifying the servo id and the goal end
356  * position (odometer ticks).
357  *
358  * \copydoc doc_return_std
359  */
360  virtual int vSyncMoveTo(uint_t uCount, ...);
361 
362  /*!
363  * \brief Synchronous move servos to new goal positions in tuple list.
364  *
365  * If any servo is a linked master, the linked pair will moved synchronously
366  * to the appropriate end positions.
367  *
368  * The moves will proceed at the current goal speeds.
369  *
370  * \par Operational Modes:
371  * Servo mode (\ref DYNA_MODE_SERVO).\n
372  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
373  *
374  * \param tuplesPos Array of servo id, goal odometer position tuples.
375  * \param uCount Number of tuples.
376  *
377  * \copydoc doc_return_std
378  */
379  virtual int SyncMoveTo(DynaPosTuple_T tuplesPos[], uint_t uCount);
380 
381  /*!
382  * \brief Move at speed to the goal postition.
383  *
384  * For servos in continuous mode, speeds are in the range [-max,max] where the
385  * values \h_lt 0, 0, and \h_gt 0 specify rotation in the clockwise direction,
386  * stop, or rotation in the counterclockwise direction, respectively.
387  *
388  * For servos in servo mode, the goal direction is not applicable, and
389  * therefore, the speeds are in the range [0,max]. The special value 0 is
390  * equivalent to the maximum rpm speed without servo speed control.
391  *
392  * If the servo is in continuous mode, but supports 360\h_deg positioning
393  * data, then a registered external user control function is required.
394  *
395  * If this servo is the master in a linked pair of servos, both servos will
396  * move synchronously.
397  *
398  * \par Operational Modes:
399  * Servo mode (\ref DYNA_MODE_SERVO). The direction will be ignored.\n
400  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
401  *
402  * \param nServoId Servo Id
403  * \param uGoalSpeed Goal speed (raw).
404  * \param uGoalOdPos Goal position (odometer ticks).
405  *
406  * \copydoc doc_return_std
407  */
408  virtual int MoveAtSpeedTo(int nServoId, int nGoalSpeed, int nGoalOdPos);
409 
410  /*!
411  * \brief Synchronous move servos to new goal positions at the given speeds.
412  *
413  * If any servo is a linked master, the linked pair will moved synchronously
414  * to the appropriate end positions at the appropriate speeds.
415  *
416  * \par Operational Modes:
417  * Servo mode (\ref DYNA_MODE_SERVO).\n
418  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
419  *
420  * \param uCount Number of tuples.
421  * \param ... A variable argument list of uCount 3-tuples of type
422  * (int,int,int) specifying the servo id, goal speed, and
423  * the end goal odometer position.
424  *
425  * \copydoc doc_return_std
426  */
427  virtual int vSyncMoveAtSpeedTo(uint_t uCount, ...);
428 
429  /*!
430  * \brief Synchronous move servos to new goal positions at the given speeds.
431  *
432  * If any servo is a linked master, the linked pair will moved synchronously
433  * to the appropriate end positions at the appropriate speeds.
434  *
435  * \todo Optimize. Add support for bg task continuous mode sync write, then
436  * control.
437  *
438  * \par Operational Modes:
439  * Servo mode (\ref DYNA_MODE_SERVO).\n
440  * Continuous mode (\ref DYNA_MODE_CONTINUOUS) with 360\h_deg position data.\n
441  *
442  * \param tuplesSpeedPos Array of servo id, goal speed, and goal odometer
443  * position 3-tuples.
444  *
445  * \copydoc doc_return_std
446  */
447  virtual int SyncMoveAtSpeedTo(DynaSpeedPosTuple_T tuplesSpeedPos[],
448  uint_t uCount);
449 
450  /*!
451  * \brief Move at speed.
452  *
453  * Speeds are in the range [-max,max] where the
454  * values \h_lt 0, 0, and \h_gt 0 specify rotation in the clockwise direction,
455  * stop, or rotation in the counterclockwise direction, respectively.
456  *
457  * For servos in servo mode, the goal direction is not applicable, and
458  * therefore, the speeds are in the range [0,max]. The special value 0 is
459  * equivalent to the maximum rpm speed without servo speed control.
460  *
461  * If this servo is the master in a linked pair of servos, both servos will
462  * move synchronously.
463  *
464  * \par Operational Modes:
465  * Continuous mode (\ref DYNA_MODE_CONTINUOUS).
466  *
467  * \param nServoId Servo Id
468  * \param nGoalSpeed Goal speed.
469  *
470  * \copydoc doc_return_std
471  */
472  virtual int MoveAtSpeed(int nServoId, int nGoalSpeed);
473 
474  /*!
475  * \brief Synchronous move servos at the given speeds.
476  *
477  * If any servo is a linked master, the linked pair will moved synchronously
478  * at the appropriate speeds and directions.
479  *
480  * \par Servo Operational Modes:
481  * Continuous mode (\ref DYNA_MODE_CONTINUOUS).
482  *
483  * \param uCount Number of tuples.
484  * \param ... A variable argument list of uCount 2-tuples of type
485  * (int,int) specifying the servo id and goal speed.
486  *
487  * \copydoc doc_return_std
488  */
489  virtual int vSyncMoveAtSpeed(uint_t uCount, ...);
490 
491  /*!
492  * \brief Synchronous move servos at the given speeds.
493  *
494  * If any servo is a linked master, the linked pair will moved synchronously
495  * at the appropriate speeds and directions.
496  *
497  * \par Servo Operational Modes:
498  * Continuous mode (\ref DYNA_MODE_CONTINUOUS).
499  *
500  * \param tuplesSpeed Array of servo id, goal speed 2-tuples.
501  * \param uCount Number of tuples.
502  *
503  * \copydoc doc_return_std
504  */
505  virtual int SyncMoveAtSpeed(DynaSpeedTuple_T tuplesSpeed[],
506  uint_t uCount);
507 
508  /*!
509  * \brief Emergency stop all servos.
510  *
511  * All torque is removed.
512  *
513  * \copydoc doc_return_std
514  */
515  virtual int EStop();
516 
517  /*!
518  * \brief Stop all servos.
519  *
520  * Current torque settings are kept.
521  *
522  * \copydoc doc_return_std
523  */
524  virtual int Stop();
525 
526  /*!
527  * \brief Freeze all servos at current position.
528  *
529  * Torque is applied.
530  *
531  * \copydoc doc_return_std
532  */
533  virtual int Freeze();
534 
535  /*!
536  * \brief Release all servos from any applied torque.
537  *
538  * Servos are free to rotate.
539  *
540  * \copydoc doc_return_std
541  */
542  virtual int Release();
543 
544  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
545  // Master and Synchronous Read/Write Functions
546  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
547 
548  /*!
549  * \brief Synchronous write to all of the servos in the chain to
550  * enable/disable applied torque.
551  *
552  * If the torque state is false (off), no power is applied to the servo,
553  * allowing it to be free rotated by any external force.
554  *
555  * \par Control Table:
556  * \ref dyna_servo_memmap_torque_en.\n
557  *
558  * \param bState Torque enabled (true) or disabled (off) state.
559  *
560  * \copydoc doc_return_std
561  */
562  virtual int SyncWriteTorqueEnable(bool bState);
563 
564  /*!
565  * \brief Synchronous write new goal positions for servos.
566  *
567  * If any servo is a linked master, the linked pair will moved synchronously
568  * to the appropriate end positions.
569  *
570  * \par Control Table:
571  * \ref dyna_servo_memmap_goal_pos.\n
572  * \ref dyna_servo_pos.
573  *
574  * \param uCount Number of tuples.
575  * \param ... A variable argument list of uCount 2-tuples of type
576  * (int,int) specifying the servo id and the goal end
577  * position (odometer ticks).
578  *
579  * \copydoc doc_return_std
580  */
581  virtual int vSyncWriteGoalPos(uint_t uCount, ...);
582 
583  /*!
584  * \brief Synchronous write new goal positions for servos.
585  *
586  * If any servo is a linked master, the linked pair will moved synchronously
587  * to the appropriate end positions.
588  *
589  * \par Control Table:
590  * \ref dyna_servo_memmap_goal_pos.\n
591  * \ref dyna_servo_pos.
592  *
593  * \param tuplesPos Array of servo id, goal odometer position tuples.
594  * \param uCount Number of tuples.
595  *
596  * \copydoc doc_return_std
597  */
598  virtual int SyncWriteGoalPos(DynaPosTuple_T tuplesPos[], uint_t uCount);
599 
600  /*!
601  * \brief Synchronous write new goal speed for for servos.
602  *
603  * For servos in continuous mode, speeds are in the range [-max,max] where the
604  * values \h_lt 0, 0, and \h_gt 0 specify rotation in the clockwise direction,
605  * stop, or rotation in the counterclockwise direction, respectively.
606  *
607  * For servos in servo mode, the goal direction is not applicable, and
608  * therefore, the speeds are in the range [0,max]. The special value 0 is
609  * equivalent to the maximum rpm speed without servo speed control.
610  *
611  * If any servo is a linked master, the linked pair will moved synchronously
612  * at the appropriate speeds and directions.
613  *
614  * \param uCount Number of tuples.
615  * \param ... A variable argument list of uCount 2-tuples of type
616  * (int,int) specifying the servo id and the goal speed.
617  *
618  * \copydoc doc_return_std
619  */
620  virtual int vSyncWriteGoalSpeed(uint_t uCount, ...);
621 
622  /*!
623  * \brief Synchronous write new goal speed for servos.
624  *
625  * If a servo is in continuous mode, rotation will occur indefinitely
626  * in the direction specified and at the given speed.
627  *
628  * If the servo is in servo mode, rotation will occur until the goal position
629  * is achieved.
630  *
631  * If any servo is a linked master, the linked pair will moved synchronously
632  * at the appropriate speeds and directions.
633  *
634  * \par Control Table:
635  * \ref dyna_servo_memmap_goal_speed.\n
636  * \ref dyna_servo_speed.\n
637  * \ref dyna_servo_dir.
638  *
639  * \param tuplesSpeed Array of servo id,speed 2-tuples.
640  * \param uCount Number of tuples.
641  *
642  * \copydoc doc_return_std
643  */
644  virtual int SyncWriteGoalSpeed(DynaSpeedTuple_T tuplesSpeed[], uint_t uCount);
645 
646 
647  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
648  // Iterators
649  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
650 
651  /*!
652  * \brief Start iteration over of entire servo chain.
653  *
654  * \param pIter Pointer to iterator.
655  *
656  * \return
657  * On success, returns the starting servo id.\n
658  * On end of chain or error, \ref DYNA_ID_NONE is returned.
659  */
660  virtual int IterStart(int *pIter);
661 
662  /*!
663  * \brief Next iteration over of entire servo chain.
664  *
665  * \param pIter Pointer to iterator.
666  *
667  * \return
668  * On success, returns the next servo id.\n
669  * On end of chain or error, \ref DYNA_ID_NONE is returned.
670  */
671  virtual int IterNext(int *pIter);
672 
673  /*!
674  * \brief Start iteration master servos over of entire servo chain.
675  *
676  * \param pIter Pointer to iterator.
677  *
678  * \return
679  * On success, returns the starting servo id.\n
680  * On end of chain or error, \ref DYNA_ID_NONE is returned.
681  */
682  virtual int IterStartMaster(int *pIter);
683 
684  /*!
685  * \brief Next iteration of master servos over of entire servo chain.
686  *
687  * \param pIter Pointer to iterator.
688  *
689  * \return
690  * On success, returns the next servo id.\n
691  * On end of chain or error, \ref DYNA_ID_NONE is returned.
692  */
693  virtual int IterNextMaster(int *pIter);
694 
695 
696  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
697  // Operators
698  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
699 
700  /*!
701  * \brief Subscript operator.
702  *
703  * \param nServoId Servo id.
704  *
705  * \return
706  * On success, returns pointer to servo object in chain.\n
707  * On failure, return NULL.
708  */
709  const DynaServo *operator[](int nServoId);
710 
711 protected:
712  DynaComm &m_comm; ///< bus communication instance
713  DynaServo *m_pChain[DYNA_ID_NUMOF]; ///< chain of servos
714  int m_nIIdx[DYNA_ID_NUMOF]; ///< indirect index
715  DynaServoLink_T m_links[DYNA_ID_NUMOF]; ///< servo linked info
716  uint_t m_uNumInChain; ///< number of servos in chain
717  uint_t m_uNumMastersInChain; ///< num of master servos in chain
718 
719  /*!
720  * \brief Initialize chain class instance.
721  */
722  void Init();
723 
724  /*!
725  * \brief Create new dervied DyanServo object and insert into chain.
726  *
727  * \param nServoId Servo Id to delete.
728  *
729  * \copydoc doc_return_std
730  */
731  virtual int ChainEntryNew(int nServoId);
732 
733  /*!
734  * \brief Remove servo from chain and delete.
735  *
736  * \param nServoId Servo Id to delete.
737  *
738  * \copydoc doc_return_std
739  */
740  virtual int ChainEntryDelete(int nServoId);
741 
742  /*!
743  * \brief Audit servo links and repair or delete.
744  *
745  * \copydoc doc_return_std
746  */
747  virtual void AuditLinks();
748 
749  /*!
750  * \brief Set local link data for the given servo.
751  *
752  * \param nServiId Servo id.
753  * \param uLinkType This servo's link type.
754  * \param nServoIdMate Mate servo id.
755  * \param bRotReversed The linked servos do [not] rotate in opposite
756  * directions.
757  */
758  virtual void SetLinkData(int nServoId,
759  uint_t uLinkType,
760  int nServoIdMate,
761  bool bRotReversed);
762 
763  /*!
764  * \brief Clear local link data for the given servo.
765  */
766  virtual void ClearLinkData(int nServoId);
767 };
768 
769 
770 #endif // _DYNA_CHAIN_H
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
Synchronous Write Speed Tuple Structure.
Definition: DynaTypes.h:314
Synchronous Write Speed-Position Tuple Structure.
Definition: DynaTypes.h:324
virtual int SyncWriteGoalSpeed(DynaSpeedTuple_T tuplesSpeed[], uint_t uCount)
Synchronous write new goal speed for servos.
Definition: DynaChain.cxx:940
virtual int SyncMoveTo(DynaPosTuple_T tuplesPos[], uint_t uCount)
Synchronous move servos to new goal positions in tuple list.
Definition: DynaChain.cxx:513
virtual ~DynaChain()
Destructor.
Definition: DynaChain.cxx:87
int GetLinkedMateId(int nServoId) const
Get linked mate.
Definition: DynaChain.h:238
virtual int Freeze()
Freeze all servos at current position.
Definition: DynaChain.cxx:751
virtual int MoveAtSpeedTo(int nServoId, int nGoalSpeed, int nGoalOdPos)
Move at speed to the goal postition.
Definition: DynaChain.cxx:559
virtual int vSyncMoveTo(uint_t uCount,...)
Synchronous move servos to new goal positions.
Definition: DynaChain.cxx:494
virtual int MoveAtSpeed(int nServoId, int nGoalSpeed)
Move at speed.
Definition: DynaChain.cxx:655
int m_nIIdx[DYNA_ID_NUMOF]
indirect index
Definition: DynaChain.h:714
const DynaServo * operator[](int nServoId)
Subscript operator.
Definition: DynaChain.cxx:1085
DynaComm & m_comm
bus communication instance
Definition: DynaChain.h:712
void Init()
Initialize chain class instance.
Definition: DynaChain.cxx:297
bool IsUnlinked(int nServoId) const
Test if this servo is unlinked.
Definition: DynaChain.h:224
virtual uint_t GetNumberOfMastersInChain()
Get the number of servos currently in chain.
Definition: DynaChain.cxx:182
virtual int vSyncWriteGoalPos(uint_t uCount,...)
Synchronous write new goal positions for servos.
Definition: DynaChain.cxx:816
virtual int vSyncMoveAtSpeed(uint_t uCount,...)
Synchronous move servos at the given speeds.
Definition: DynaChain.cxx:669
virtual int MoveTo(int nServoId, int nGoalOdPos)
Move to the goal postition.
Definition: DynaChain.cxx:480
virtual int ChainEntryDelete(int nServoId)
Remove servo from chain and delete.
Definition: DynaChain.cxx:346
uint_t m_uNumInChain
number of servos in chain
Definition: DynaChain.h:716
bool IsLinkedMaster(int nServoId) const
Test if this servo is a linked master.
Definition: DynaChain.h:196
#define DYNA_ID_MIN
minimum servo id
Definition: Dynamixel.h:146
virtual int vSyncWriteGoalSpeed(uint_t uCount,...)
Synchronous write new goal speed for for servos.
Definition: DynaChain.cxx:919
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
Definition: DynaChain.cxx:1036
#define DYNA_ID_NUMOF
number of unique servo id&#39;s
Definition: Dynamixel.h:148
virtual int ChainEntryNew(int nServoId)
Create new dervied DyanServo object and insert into chain.
Definition: DynaChain.cxx:312
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
Definition: DynaChain.cxx:1058
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Definition: DynaChain.h:140
virtual int LinkServos(int nServoIdMaster, int nServoIdSlave, bool bIsReversed)
Software link two unlinked servos in a master-slave configuration.
Definition: DynaChain.cxx:105
DynaServoLink_T m_links[DYNA_ID_NUMOF]
servo linked info
Definition: DynaChain.h:715
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
virtual void ClearLinkData(int nServoId)
Clear local link data for the given servo.
Definition: DynaChain.cxx:468
virtual int AddNewServosByScan()
Scan and add all discovered and created servos to the Dynamixel chain.
Definition: DynaChain.cxx:229
virtual int AddNewServoForced(int nServoId, uint_t uModelNum)
Force create and add a servo to the Dynamixel chain.
Definition: DynaChain.cxx:259
#define DYNA_ID_MAX
maximum servo id
Definition: Dynamixel.h:147
virtual int SyncMoveAtSpeed(DynaSpeedTuple_T tuplesSpeed[], uint_t uCount)
Synchronous move servos at the given speeds.
Definition: DynaChain.cxx:695
virtual int SyncWriteTorqueEnable(bool bState)
Synchronous write to all of the servos in the chain to enable/disable applied torque.
Definition: DynaChain.cxx:782
virtual int Stop()
Stop all servos.
Definition: DynaChain.cxx:733
virtual int vSyncMoveAtSpeedTo(uint_t uCount,...)
Synchronous move servos to new goal positions at the given speeds.
Definition: DynaChain.cxx:574
virtual int Release()
Release all servos from any applied torque.
Definition: DynaChain.cxx:770
virtual int RemoveAllServos()
Remove all servos from chain and delete.
Definition: DynaChain.cxx:275
DynaServo * m_pChain[DYNA_ID_NUMOF]
chain of servos
Definition: DynaChain.h:713
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
virtual DynaServo * GetServo(int nServoId)
Definition: DynaChain.h:129
Dynamixel Chain Container Base Class.
Definition: DynaChain.h:75
RoadNarrows Dynamixel Fundatmental Types.
virtual int SyncWriteGoalPos(DynaPosTuple_T tuplesPos[], uint_t uCount)
Synchronous write new goal positions for servos.
Definition: DynaChain.cxx:837
virtual bool HasServo(int nServoId) const
Definition: DynaChain.h:113
virtual void AuditLinks()
Audit servo links and repair or delete.
Definition: DynaChain.cxx:388
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
virtual int RemoveServo(int nServoId)
Remove from chain and delete.
Definition: DynaChain.cxx:265
bool IsLinkedSlave(int nServoId) const
Test if this servo is a linked slave.
Definition: DynaChain.h:211
RoadNarrows Dynamixel Top-Level Package Header File.
DynaChain(DynaComm &comm)
Default initialization constructor.
Definition: DynaChain.cxx:82
virtual bool IsMaster(int nServoId) const
Test if the servo is a master.
Definition: DynaChain.h:180
uint_t m_uNumMastersInChain
num of master servos in chain
Definition: DynaChain.h:717
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int AddNewServo(int nServoId)
Create a new servo and add it to the Dynamixel chain.
Definition: DynaChain.cxx:206
virtual int EStop()
Emergency stop all servos.
Definition: DynaChain.cxx:714
virtual int UnlinkServos(int nServoIdMaster)
Unlink two software linked servos.
Definition: DynaChain.cxx:146
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
Definition: DynaChain.cxx:1020
virtual void SetLinkData(int nServoId, uint_t uLinkType, int nServoIdMate, bool bRotReversed)
Set local link data for the given servo.
Definition: DynaChain.cxx:458
Position Tuple Structure.
Definition: DynaTypes.h:304
virtual int SyncMoveAtSpeedTo(DynaSpeedPosTuple_T tuplesSpeedPos[], uint_t uCount)
Synchronous move servos to new goal positions at the given speeds.
Definition: DynaChain.cxx:596
RoadNarrows Dynamixel Library Error and Logging Routines.
Dynamixel Bus Communications Abstract Base Class.
Definition: DynaComm.h:80