Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaBgThread.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: librnr_dynamixel
6 //
7 // File: DynaBgThread.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-07-08 12:19:29 -0600 (Wed, 08 Jul 2015) $
12  * $Rev: 4024 $
13  *
14  * \brief Dynamixel background thread class declarations.
15  *
16  * The background thread performs several functions:
17  * \li Position control for servos configured in continuous (wheel) mode and
18  * provide 360\h_deg position data available. For example: EX-106P and the MX
19  * series servos.
20  * \li Background monitoring of the dynamics of registered servos. Dynamics
21  * data are the current position, rotation speed and direction, and torque.
22  * \li Background monitoring of the health of registered servos. Servo health
23  * data are current alarms, temperature, voltage, and torque.
24  *
25  * \author Robin Knight (robin.knight@roadnarrows.com)
26  *
27  * \copyright
28  * \h_copy 2011-2018. RoadNarrows LLC.\n
29  * http://www.roadnarrows.com\n
30  * All Rights Reserved
31  */
32 /*
33  * @EulaBegin@
34  *
35  * Unless otherwise stated explicitly, all materials contained are copyrighted
36  * and may not be used without RoadNarrows LLC's written consent,
37  * except as provided in these terms and conditions or in the copyright
38  * notice (documents and software) or other proprietary notice provided with
39  * the relevant materials.
40  *
41  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
42  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
43  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
44  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
45  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
46  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  *
48  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
49  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
50  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
51  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
52  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
53  *
54  * @EulaEnd@
55  */
56 ////////////////////////////////////////////////////////////////////////////////
57 
58 #ifndef _DYNA_BG_THREAD_H
59 #define _DYNA_BG_THREAD_H
60 
61 #include <sys/time.h>
62 #include <pthread.h>
63 
64 #include <map>
65 #include <deque>
66 
67 #include "rnr/rnrconfig.h"
68 #include "rnr/log.h"
69 
70 #include "Dynamixel/Dynamixel.h"
71 #include "Dynamixel/DynaError.h"
72 #include "Dynamixel/DynaPidPos.h"
73 #include "Dynamixel/DynaComm.h"
74 #include "Dynamixel/DynaServo.h"
75 #include "Dynamixel/DynaChain.h"
76 
77 using namespace std;
78 
79 
80 // ---------------------------------------------------------------------------
81 // Virtual Servo Class
82 // ---------------------------------------------------------------------------
83 
84 /*!
85  * \brief Background Thread Virtual Servo Class
86  */
88 {
89 public:
90  /*!
91  * \brief Torque sliding window size for low-pass band filtering of input
92  * torques.
93  */
94  static const size_t TORQUE_WIN_SIZE = 10;
95 
96  static const int GOAL_SPEED_DFT = 100; ///< default virutal goal speed
97 
98  /*!
99  * \brief Servo dynamics position control state.
100  */
102  {
103  StateIdle, ///< no active position control
104  StateBegin, ///< start position control
105  StateControl ///< in poistion control
106  };
107 
108  /*
109  * Virtual servo control variables.
110  */
111  VServoState m_eState; ///< virtual servo state
112  DynaPidPos m_pidPos; ///< servo position PID
113  int m_nTolerance; ///< position \h_plusmn tolerance (ticks)
114  int m_nOdGoalPos; ///< current goal position
115  int m_nGoalSpeed; ///< current goal speed
116  bool m_bOverTorqueCond; ///< is [not] in torque overload condition
117  bool m_bOverTorqueCtl; ///< [not] in torque overload control
118  double m_fTorqueOut; ///< low-pass filtered torque
119  std::deque<double> m_histTorqueIn; ///< recent history of joint torques
120 
121  /*!
122  * \brief Default constructor.
123  */
124  DynaVServo();
125 
126  /*!
127  * \brief Copy constructor.
128  *
129  * \param src Source object.
130  */
131  DynaVServo(const DynaVServo &src);
132 
133  /*!
134  * \brief Destructor.
135  */
137  {
138  pthread_mutex_destroy(&m_mutexSync);
139  }
140 
141  /*!
142  * \brief Assignment operator
143  *
144  * \param rhs Right hand side object.
145  *
146  * \return This object.
147  */
148  DynaVServo operator=(const DynaVServo &rhs);
149 
150  /*!
151  * \brief Set position tolerance in encoder ticks.
152  *
153  * \param pServo Pointer to servo.
154  * \param fTolerance Tolerance (degrees).
155  */
156  void setToleranceInTicks(DynaServo *pServo, double fTolerance);
157 
158  /*!
159  * \brief Apply a low-pass band filter on the sensed torques (loads).
160  *
161  * The torques are interpreted from the unitless load values read from the
162  * servo (and probably non-linear).
163  *
164  * A simple moving average (SMA) of load values with a window size of
165  * \ref TORQUE_WIN_SIZE is used as the filter.
166  *
167  * \param nServoLoad New servo load value (raw unitless).
168  *
169  * \return New torque average (raw unitless).
170  */
171  double filterTorques(int nServoLoad);
172 
173  /*!
174  * \brief Get the current goal rotation direction.
175  *
176  * The direct is deterimed by the difference of current odometer value and
177  * the goal position.
178  *
179  * Normally counter-clockwise is positive, clockwise is negative, but the
180  * sence can be reversed in the odometer configuration.
181  *
182  * \param pServer Pointer to servo.
183  *
184  * \return 1 or -1.
185  */
186  int getGoalDir(DynaServo *pServo)
187  {
188  int nSign = pServo->IsOdometerReversed()? -1: 1;
189 
190  return (m_nOdGoalPos-pServo->GetOdometer()) >= 0? nSign: -1*nSign;
191  }
192 
193  /*!
194  * \brief Lock the virtual servo.
195  *
196  * The calling thread will block while waiting for the mutex to become
197  * available. Once locked, the background thread will block when accessing
198  * this vitural servo.
199  *
200  * The lock()/unlock() primitives provide a safe mechanism to modify the
201  * registered vServo data.
202  *
203  * \par Context:
204  * Any.
205  */
206  void lock()
207  {
208  pthread_mutex_lock(&m_mutexSync);
209  }
210 
211  /*!
212  * \brief Unlock the virtual servo.
213  *
214  * The background thread will be available to run when accessing
215  * this vitural servo.
216  *
217  * \par Context:
218  * Any.
219  */
220  void unlock()
221  {
222  pthread_mutex_unlock(&m_mutexSync);
223  }
224 
225 protected:
226  pthread_mutex_t m_mutexSync; ///< synchonization mutex
227 };
228 
229 
230 // ---------------------------------------------------------------------------
231 // Dynamixel Background Thread Class
232 // ---------------------------------------------------------------------------
233 
234 /*!
235  * Dynamixel background thread.
236  *
237  * The DynaBgThread class supports background control and monitoring of
238  * registered servos.
239  */
241 {
242 public:
243  static const double HZ_EXEC_MIN; ///< minimum exec hertz
244  static const double HZ_EXEC_DFT; ///< default exec hertz
245  static const long T_EXEC_MIN; ///< task exec period min (100usec)
246  static const double TOLERANCE_DFT; ///< default pos. tolerance (deg)
247 
248  /*!
249  * \brief Background thread states.
250  */
251  typedef enum
252  {
253  BgThreadStateZombie, ///< zombie instance - no thread exists
254  BgThreadStateReady, ///< thread created and ready to run
255  BgThreadStateRunning, ///< thread running
256  BgThreadStatePaused, ///< thread paused
257  BgThreadStateExit ///< thread exiting
258  } BgThreadState;
259 
260  /*!
261  * \brief Default initializer constructor.
262  *
263  * \param fHz Execution hertz.
264  * \param fTolerance Position tolerance (degrees).
265  */
266  DynaBgThread(double fHz = HZ_EXEC_DFT,
267  double fTolerance = TOLERANCE_DFT);
268 
269  /*!
270  * \brief Desctructor.
271  */
272  virtual ~DynaBgThread();
273 
274  /*!
275  * \brief Register the Dynamixel servo for control and monitoring.
276  *
277  * The servo will replace the currently monitored servo or chain.
278  *
279  * If the thread is running, it should be paused or locked prior to calling
280  * this function.
281  *
282  * The time periods are automatically recalculated.
283  *
284  * \param pServo Dynamixel servo. May be NULL to deregister.
285  */
286  virtual void RegisterServoAgent(DynaServo *pServo);
287 
288  /*!
289  * \brief Register the Dynamixel chain for control and monitoring.
290  *
291  * The chain will replace the currently monitored servo or chain.
292  *
293  * If the thread is running, it should be paused or locked prior to calling
294  * this function.
295  *
296  * The time periods are automatically recalculated.
297  *
298  * \param pChain Dynamixel chain. May be NULL to deregister.
299  */
300  virtual void RegisterChainAgent(DynaChain *pChain);
301 
302  /*!
303  * \brief Unregister any chain or servo from control and monitoring.
304  *
305  * If the thread is running, it should be paused or locked prior to calling
306  * this function.
307  *
308  * The time periods are automatically recalculated.
309  *
310  * \param pChain Dynamixel chain. May be NULL to deregister.
311  */
312  virtual void UnregisterAgent();
313 
314  /*!
315  * \brief Register user-defined callback function.
316  *
317  * \param fnUserCb User callback function.
318  * \param pUserArg User callback argument.
319  */
320  virtual void RegisterUserCallback(void (*fnUserCb)(void*), void *pUserArg)
321  {
322  m_fnUserCb = fnUserCb;
323  m_pUserArg = pUserArg;
324  }
325 
326  /*!
327  * \brief Unregister user-defined callback function.
328  */
329  virtual void UnregisterUserCallback()
330  {
331  m_fnUserCb = NULL;
332  m_pUserArg = NULL;
333  }
334 
335  /*!
336  * \brief Run the background thread control and monitoring tasks.
337  *
338  * \par Valid Current States:
339  * \ref BgThreadStateReady
340  *
341  * \par New State:
342  * \ref BgThreadStateRunning
343  *
344  * \par Context:
345  * Calling thread.
346  *
347  * \copydoc doc_std_return
348  */
349  virtual int Run();
350 
351  /*!
352  * \brief Stop control and monitoring tasks.
353  *
354  * Any servos being actively position controlled will be erased from the
355  * position control map.
356  *
357  * \par Valid Current States:
358  * \ref BgThreadStateReady
359  * \ref BgThreadStateRunning
360  * \ref BgThreadStatePaused
361  *
362  * \par New State:
363  * \ref BgThreadStateReady
364  *
365  * \par Context:
366  * Calling thread.
367  *
368  * \copydoc doc_std_return
369  */
370  virtual int Stop();
371 
372  /*!
373  * \brief Pause control and monitoring tasks.
374  *
375  * The Pause()/Resume() actions provide a safe mechanism to modify the
376  * registered dynamixel chain and/or alter the time periods. When the thread
377  * is resumed, the time periods are automatically recalculated since the mix
378  * of servos in the chain could have changed.
379  *
380  * \par Valid Current States:
381  * \ref BgThreadStateRunning
382  * \ref BgThreadStatePaused
383  *
384  * \par New State:
385  * \ref BgThreadStatePaused
386  *
387  * \par Context:
388  * Calling thread.
389  *
390  * \copydoc doc_std_return
391  */
392  virtual int Pause();
393 
394  /*!
395  * \brief Resume control and monitoring tasks.
396  *
397  * \par Valid Current States:
398  * \ref BgThreadStatePaused
399  *
400  * \par New State:
401  * \ref BgThreadStateRunning
402  *
403  * \par Context:
404  * Calling thread.
405  *
406  * \copydoc doc_std_return
407  */
408  virtual int Resume();
409 
410  /*!
411  * \brief Get current background thread state.
412  *
413  * \return DynaBgThread::BgThreadState
414  */
415  BgThreadState GetCurrentState()
416  {
417  return m_eState;
418  }
419 
420  /*!
421  * \brief Start controlling servo to rotate it to the given goal position.
422  *
423  * When the servo attains the given goal position within tolerance, the
424  * servo will be stopped. The servo speed to the goal position is controlled
425  * externally.
426  *
427  * The servo is expected to be in continuous mode and to support 306\h_deg
428  * position information.
429  *
430  * \param nServoId Servo id.
431  * \param uGoalPos Goal position in odometer virtual raw units.
432  * \param pUserArg Pointer to this class instance.
433  *
434  * \copydoc doc_return_std
435  */
436  static int WriteGoalPos(int nServoId, int nOdGoalPos, void *pUserArg);
437 
438  static int WriteGoalSpeed(int nServoId, int nGoalSpeed, void *pUserArg);
439 
440  static int WriteGoalSpeedPos(int nServoId,
441  int nGoalSpeed,
442  int nGoalPos,
443  void *pUserArg);
444 
445  /*!
446  * \brief Set new control and monitoring execution hertz rate.
447  *
448  * \param fHz New execution hertz.
449  */
450  void setHz(double fHz);
451 
452  /*!
453  * \brief Get control and monitoring hetrz rate.
454  *
455  * \return Execution hertz.
456  */
457  double getHz()
458  {
459  return m_fHz;
460  }
461 
462  /*!
463  * \brief Checks if servo is currently being controlled.
464  *
465  * \param nServoId Servo Id.
466  *
467  * \return Returns true or false.
468  */
469  bool isServoBeingControlled(int nServoId)
470  {
471  MapVServo::iterator pos;
472 
473  if( (pos = m_mapVServo.find(nServoId)) != m_mapVServo.end() )
474  {
475  return pos->second.m_eState == DynaVServo::StateControl? true: false;
476  }
477  else
478  {
479  return false;
480  }
481  }
482 
483 protected:
484  /*!
485  * \brief Virtual Servo Associative Map Type.
486  */
487  typedef map<int,DynaVServo> MapVServo;
488 
489  // thread, state, and synchronization
490  BgThreadState m_eState; ///< thread state
491  pthread_mutex_t m_mutexSync; ///< synchonization mutex
492  pthread_cond_t m_condSync; ///< synchonization condition
493  pthread_t m_thread; ///< pthread identifier
494 
495  // the servos
496  DynaServo *m_pServo; ///< registered dynamixel servo
497  DynaChain *m_pChain; ///< or registered dynamixel chain
498  MapVServo m_mapVServo; ///< virtual servo associative map
499  uint_t m_uNumServos; ///< number of servos to monitor
500  double m_fTolerance; ///< position \h_plusmn tolerance (degrees)
501 
502  // servo/chain agent
503  DynaAgent_T m_agent; ///< servo/chain agent
504 
505  // user-defined registered callback
506  void (*m_fnUserCb)(void*); ///< user callback function
507  void *m_pUserArg; ///< user callback argument
508 
509  // scheduler
510  double m_fHz; ///< thread execution hertz
511  long m_TExec; ///< full execution cycle \h_usec period
512  struct timeval m_tvSched; ///< working scheduler time stamp
513  long m_TSched; ///< scheduler \h_usec period
514  long m_dTSched; ///< scheduler delta time
515 
516  // iterators
517  MapVServo::iterator m_iterDynamics; ///< dynamics iterator
518  MapVServo::iterator m_iterHealth; ///< health iterator
519  int m_nHealthServoId; ///< current health monitoring servo id
520 
521  /*!
522  * \brief Lock the background thread.
523  *
524  * The calling thread will block while waiting for the mutex to become
525  * available. Once locked, the background thread will block.
526  *
527  * The lock()/unlock() primitives provide a safe mechanism to modify the
528  * registered vServo data.
529  *
530  * \par Context:
531  * Any.
532  */
533  void lock()
534  {
535  pthread_mutex_lock(&m_mutexSync);
536  }
537 
538 
539  /*!
540  * \brief Unlock the background thread.
541  *
542  * The background thread will be available to run.
543  *
544  * \par Context:
545  * Any.
546  */
547  void unlock()
548  {
549  pthread_mutex_unlock(&m_mutexSync);
550  }
551 
552  /*!
553  * \brief Change the background thread state.
554  *
555  * \param eNewState New state.
556  *
557  * \par Context:
558  * Calling thread or background thread.
559  */
560  void changeState(DynaBgThread::BgThreadState eNewState);
561 
562  /*!
563  * \brief Wait indefinitely in ready state.
564  *
565  * \par Context:
566  * Calling thread or background thread.
567  */
568  void readyWait();
569 
570  /*!
571  * \brief Wait until state change or time out.
572  *
573  * \param lMicroSec Maximum wait duration (microseconds).
574  *
575  * \par Context:
576  * Calling thread or background thread.
577  */
578  void timeWait(long lMicroSecs);
579 
580  /*!
581  * \brief Set position tolerance.
582  *
583  * The servo is considered at a goal position when it is within \h_plusmn of
584  * the tolerance.
585  */
586  void setTolerance(double fTolerance)
587  {
588  m_fTolerance = fTolerance > 0.0? fTolerance: 0.0;
589  }
590 
591  /*!
592  * \brief Get registered servo.
593  *
594  * \param nServoId Servo id.
595  *
596  * \return Returns pointer to servo on success. NULL on failure.
597  */
598  virtual DynaServo *getRegisteredServo(int nServoId);
599 
600  /*!
601  * \brief Get the next virtual servo.
602  *
603  * \param [in,out] iter Iterator at current position.
604  * \param [out] nServoId Servo id.
605  *
606  * \return Returns pointer to virtual servo on success. NULL on failure.
607  */
608  virtual DynaVServo *getNextVServo(MapVServo::iterator &iter, int &nServoId)
609  {
610  if( m_mapVServo.size() == 0 )
611  {
612  return NULL;
613  }
614 
615  ++iter;
616 
617  if( iter == m_mapVServo.end() )
618  {
619  iter = m_mapVServo.begin();
620  }
621 
622  nServoId = iter->first;
623  return &(iter->second);
624  }
625 
626  /*!
627  * \brief Get the previous virtual servo.
628  *
629  * \param [in,out] iter Iterator at current position.
630  * \param [out] nServoId Servo id.
631  *
632  * \return Returns pointer to virtual servo on success. NULL on failure.
633  */
634  virtual DynaVServo *getPrevVServo(MapVServo::iterator &iter, int &nServoId)
635  {
636  if( m_mapVServo.size() == 0 )
637  {
638  return NULL;
639  }
640 
641  if( iter == m_mapVServo.begin() )
642  {
643  iter = m_mapVServo.end();
644  }
645 
646  --iter;
647 
648  nServoId = iter->first;
649  return &(iter->second);
650  }
651 
652  /*!
653  * \brief Schedule the Dynamixel background thread for the next task(s) to
654  * perform.
655  *
656  * \par Context:
657  * Background thread.
658  */
659  virtual void sched(long lPeriod);
660 
661  /*!
662  * \brief Execute background tasks.
663  *
664  * \par Context:
665  * Background thread.
666  */
667  virtual void exec();
668 
669  /*!
670  * \brief Execute servo dynamics monitoring and control.
671  *
672  * \param pServo Pointer to registered servo.
673  * \param pVServo Pointer to associated virtual servo.
674  *
675  * \par Context:
676  * Background thread.
677  */
678  virtual void execDynamics(DynaServo *pServo, DynaVServo *pVServo);
679 
680  /*!
681  * \brief Execute servo torque control.
682  *
683  * \param pServo Pointer to registered servo.
684  * \param pVServo Pointer to associated virtual servo.
685  *
686  * \par Context:
687  * Background thread.
688  */
689  virtual void execTorqueCtl(DynaServo *pServo, DynaVServo *pVServo);
690 
691  /*!
692  * \brief Execute servo position control.
693  *
694  * \param pServo Pointer to registered servo.
695  * \param pVServo Pointer to associated virtual servo.
696  *
697  * \par Context:
698  * Background thread.
699  */
700  virtual void execPosCtl(DynaServo *pServo, DynaVServo *pVServo);
701 
702  /*!
703  * \brief Stop servo position control.
704  *
705  * \param pServo Pointer to registered servo.
706  * \param pVServo Pointer to associated virtual servo.
707  *
708  * \par Context:
709  * Background thread.
710  */
711  virtual void stopPosCtl(DynaServo *pServo, DynaVServo *pVServo);
712 
713  /*!
714  * \brief Stop servo motion.
715  *
716  * \param pServo Pointer to registered servo.
717  */
718  virtual void stopMotion(DynaServo *pServo);
719 
720  /*!
721  * \brief Execute servo dynamics monitoring background task.
722  *
723  * \param pServo Pointer to registered servo.
724  * \param pVServo Pointer to associated virtual servo.
725  *
726  * \par Context:
727  * Background thread.
728  */
729  virtual void monitorDynamics(DynaServo *pServo, DynaVServo *pVServo);
730 
731  /*!
732  * \brief Execute servo health monitoring background task.
733  *
734  * \param pServo Pointer to registered servo.
735  * \param pVServo Pointer to associated virtual servo.
736  *
737  * \par Context:
738  * Background thread.
739  */
740  virtual void monitorHealth(DynaServo *pServo, DynaVServo *pVServo);
741 
742  /*!
743  * \brief Dynamixel background thread.
744  *
745  * \warn Cannot have gui calls in this thread.
746  *
747  * \param pArg Thread argument (point to DynaBgThread object).
748  *
749  * \return Returns NULL on thread exit.
750  */
751  static void *bgThread(void *pArg);
752 
753  /*!
754  * \brief Create the background thread.
755  *
756  * \par Context:
757  * Calling thread.
758  */
759  void createThread();
760 
761  /*!
762  * \brief Terminate the background thread.
763  *
764  * This function does not return until the thread actually terminates.
765  *
766  * \par Context:
767  * Calling thread.
768  */
769  void terminateThread();
770 };
771 
772 #endif // _DYNA_BG_THREAD_H
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
MapVServo m_mapVServo
virtual servo associative map
Definition: DynaBgThread.h:498
pthread_t m_thread
pthread identifier
Definition: DynaBgThread.h:493
DynaAgent_T m_agent
servo/chain agent
Definition: DynaBgThread.h:503
BgThreadState
Background thread states.
Definition: DynaBgThread.h:251
zombie instance - no thread exists
Definition: DynaBgThread.h:253
~DynaVServo()
Destructor.
Definition: DynaBgThread.h:136
int m_nGoalSpeed
current goal speed
Definition: DynaBgThread.h:115
double m_fHz
thread execution hertz
Definition: DynaBgThread.h:510
void unlock()
Unlock the background thread.
Definition: DynaBgThread.h:547
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: DynaBgThread.h:119
virtual void RegisterUserCallback(void(*fnUserCb)(void *), void *pUserArg)
Register user-defined callback function.
Definition: DynaBgThread.h:320
double m_fTorqueOut
low-pass filtered torque
Definition: DynaBgThread.h:118
start position control
Definition: DynaBgThread.h:104
MapVServo::iterator m_iterDynamics
dynamics iterator
Definition: DynaBgThread.h:517
static const double TOLERANCE_DFT
default pos. tolerance (deg)
Definition: DynaBgThread.h:246
thread created and ready to run
Definition: DynaBgThread.h:254
double m_fTolerance
position &plusmn; tolerance (degrees)
Definition: DynaBgThread.h:500
void setTolerance(double fTolerance)
Set position tolerance.
Definition: DynaBgThread.h:586
bool m_bOverTorqueCtl
[not] in torque overload control
Definition: DynaBgThread.h:117
BgThreadState GetCurrentState()
Get current background thread state.
Definition: DynaBgThread.h:415
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
pthread_cond_t m_condSync
synchonization condition
Definition: DynaBgThread.h:492
static const double HZ_EXEC_DFT
default exec hertz
Definition: DynaBgThread.h:244
VServoState
Servo dynamics position control state.
Definition: DynaBgThread.h:101
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: DynaBgThread.h:491
virtual DynaVServo * getPrevVServo(MapVServo::iterator &iter, int &nServoId)
Get the previous virtual servo.
Definition: DynaBgThread.h:634
uint_t m_uNumServos
number of servos to monitor
Definition: DynaBgThread.h:499
The Dynamixel Position PID Class.
double getHz()
Get control and monitoring hetrz rate.
Definition: DynaBgThread.h:457
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
long m_TSched
scheduler &mu;s period
Definition: DynaBgThread.h:513
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: DynaBgThread.h:116
void unlock()
Unlock the virtual servo.
Definition: DynaBgThread.h:220
int m_nHealthServoId
current health monitoring servo id
Definition: DynaBgThread.h:519
BgThreadState m_eState
thread state
Definition: DynaBgThread.h:490
void * m_pUserArg
user callback argument
Definition: DynaBgThread.h:507
in poistion control
Definition: DynaBgThread.h:105
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: DynaBgThread.h:226
int getGoalDir(DynaServo *pServo)
Get the current goal rotation direction.
Definition: DynaBgThread.h:186
VServoState m_eState
virtual servo state
Definition: DynaBgThread.h:111
Background Thread Virtual Servo Class.
Definition: DynaBgThread.h:87
Servo Proxy Agents Calls Structure.
Definition: DynaTypes.h:230
DynaServo * m_pServo
registered dynamixel servo
Definition: DynaBgThread.h:496
map< int, DynaVServo > MapVServo
Virtual Servo Associative Map Type.
Definition: DynaBgThread.h:487
Dynamixel Chain Container Base Class.
Definition: DynaChain.h:75
static const double HZ_EXEC_MIN
minimum exec hertz
Definition: DynaBgThread.h:243
bool IsOdometerReversed()
Test if the virtual odometer is reversed.
Definition: DynaServo.h:334
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
no active position control
Definition: DynaBgThread.h:103
Position PID class.
Definition: DynaPidPos.h:74
bool isServoBeingControlled(int nServoId)
Checks if servo is currently being controlled.
Definition: DynaBgThread.h:469
virtual DynaVServo * getNextVServo(MapVServo::iterator &iter, int &nServoId)
Get the next virtual servo.
Definition: DynaBgThread.h:608
RoadNarrows Dynamixel Top-Level Package Header File.
int m_nOdGoalPos
current goal position
Definition: DynaBgThread.h:114
static const long T_EXEC_MIN
task exec period min (100usec)
Definition: DynaBgThread.h:245
MapVServo::iterator m_iterHealth
health iterator
Definition: DynaBgThread.h:518
void lock()
Lock the virtual servo.
Definition: DynaBgThread.h:206
DynaPidPos m_pidPos
servo position PID
Definition: DynaBgThread.h:112
long m_TExec
full execution cycle &mu;s period
Definition: DynaBgThread.h:511
void lock()
Lock the background thread.
Definition: DynaBgThread.h:533
long m_dTSched
scheduler delta time
Definition: DynaBgThread.h:514
virtual void UnregisterUserCallback()
Unregister user-defined callback function.
Definition: DynaBgThread.h:329
DynaChain * m_pChain
or registered dynamixel chain
Definition: DynaBgThread.h:497
RoadNarrows Dynamixel Library Error and Logging Routines.
int GetOdometer()
Get the current virtual odometer value.
Definition: DynaServo.h:304
int m_nTolerance
position &plusmn; tolerance (ticks)
Definition: DynaBgThread.h:113