Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekRobot.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekRobot.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-11-18 14:31:49 -0700 (Tue, 18 Nov 2014) $
12  * $Rev: 3810 $
13  *
14  * \brief HekRobot - Hekateros Robot Class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  * \author Daniel Packard (daniel@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 _HEK_ROBOT_H
51 #define _HEK_ROBOT_H
52 
53 #include <pthread.h>
54 
55 #include "rnr/rnrconfig.h"
56 #include "rnr/log.h"
57 #include "rnr/units.h"
58 #include "rnr/i2c.h"
59 
60 #include <string>
61 #include <map>
62 
63 #include "Dynamixel/Dynamixel.h"
64 #include "Dynamixel/DynaComm.h"
65 #include "Dynamixel/DynaServo.h"
66 #include "Dynamixel/DynaChain.h"
67 #include "Dynamixel/DynaBgThread.h"
68 
69 #include "Hekateros/hekateros.h"
70 #include "Hekateros/hekTune.h"
71 #include "Hekateros/hekUtils.h"
72 #include "Hekateros/hekDesc.h"
73 #include "Hekateros/hekJoint.h"
74 #include "Hekateros/hekCalib.h"
76 #include "Hekateros/hekTraj.h"
77 #include "Hekateros/hekKin.h"
78 #include "Hekateros/hekState.h"
79 #include "Hekateros/hekMonitor.h"
80 
81 namespace hekateros
82 {
83  /*!
84  * \brief Hekateros robotic manipulator plus accesories class.
85  *
86  * Includes up to 3 kinematic chains.
87  */
88  class HekRobot
89  {
90  public:
91  /*!
92  * \brief Indirect map of robot joints.
93  *
94  * \termblock
95  * \term key: \termdata joint name \endterm
96  * \term mapped type: \termdata master servo id \endterm
97  * \endtermblock
98  */
99  typedef map<std::string, int> IMapRobotJoints;
100 
101  /*!
102  * \brief Asynchronous task id.
103  */
105  {
106  AsyncTaskIdNone, ///< no task
107  AsyncTaskIdCalibrate ///< calibrate hekateros arm task id
108 
109  // add others here, as needed
110  };
111 
112  /*!
113  * \brief Map of doubles.
114  */
115  typedef std::map<std::string, double> MapDouble;
116 
117  /*!
118  * \brief Default initialization constructor.
119  *
120  * \param bNoExec Do [not] execute arm physical movements. All commands
121  * and responses are supported but the lower level arm
122  * movement commands will not be issued.
123  */
124  HekRobot(bool bNoExec=false);
125 
126  /*!
127  * \brief Destructor.
128  */
129  virtual ~HekRobot();
130 
131 
132  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133  // Communication and Robot Initialization Methods
134  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
135 
136  /*!
137  * \brief Connect to \h_hek.
138  *
139  * \param strDevDynabus Dynabus serial device name.
140  * \param nBaudRateDynabus Dynabus baud rate.
141  * \param strDevArduino Arduino serial device name.
142  * \param nBaudRateArduino Arduino baud rate.
143  *
144  * \copydoc doc_return_std
145  */
146  int connect(const std::string &strDevDynabus = HekDevDynabus,
147  int nBaudRateDynabus = HekBaudRateDynabus,
148  const std::string &strDevArduino = HekDevArduino,
149  int nBaudRateArduino = HekBaudRateArduino);
150 
151  //int connectByProxy(...);
152 
153  /*!
154  * \brief Disconnect from \h_hek.
155  *
156  * \copydoc doc_return_std
157  */
158  int disconnect();
159 
160  /*!
161  * \brief Calibrate \h_hek's odometers and limit switch positions.
162  *
163  * \param bForceRecalib If true, recalibrate all joints.
164  * Otherwise calibrate only the uncalibrated.
165  *
166  * \copydoc doc_return_std
167  */
168  int calibrate(bool bForceRecalib=true);
169 
170  /*!
171  * \brief Asynchronously calibrate \h_hek's odometers and limit switch
172  * positions.
173  *
174  * Call \ref cancelAsync() to cancel operation.
175  *
176  * \param bForceRecalib If true, recalibrate all joints.
177  * Otherwise calibrate only the uncalibrated.
178  *
179  * \copydoc doc_return_std
180  */
181  int calibrateAsync(bool bForceRecalib=true);
182 
183  /*!
184  * \brief Reload \h_hek's reloadable configuration and reset operational
185  * parameters.
186  *
187  * The robot connection and calibration states are uneffected.
188  */
189  void reload();
190 
191 
192  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
193  // Canned Movements
194  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
195 
196  /*!
197  * \brief Move robotic arm to its pre-defined balanced position.
198  *
199  * \par Some Considerations:
200  * This move assumes an unrestricted workspace save for an horizontal plane
201  * defined by the platform on which the \h_hek is mounted to. Strategy:
202  * \li The shoulder movement is the most critical as it will lift away
203  * the horizontal plane, and hopefully away from any obstructions.
204  * \li The elbow joint may swing out, possibly causing a collision before
205  * the shoulder has sufficiently moved to a safer position. Therefore the
206  * elbow joint's velocity is slower than the shoulder's velocity.
207  * \li The rotating base, if present, swings left or right, possibly
208  * dragging the arm across the horizontal plane. Therefore, this joint
209  * also moves slower than the shoulder.
210  * \li The other joints are of no consequence.
211  *
212  * \copydoc doc_return_std
213  */
214  int gotoBalancedPos();
215 
216  /*!
217  * \brief Move robotic arm to its pre-defined parked position.
218  *
219  * See discussion at \ref gotoBalancedPos about pre-defined movements.
220  *
221  * \copydoc doc_return_std
222  */
223  int gotoParkedPos();
224 
225  /*!
226  * \brief Move robotic arm to its pre-defined calibrated zero point
227  * position.
228  *
229  * See discussion at \ref gotoBalancedPos about pre-defined movements.
230  *
231  * \copydoc doc_return_std
232  */
233  int gotoZeroPtPos();
234 
235  /*!
236  * \brief Open gripper to its maximum opened position.
237  *
238  * \copydoc doc_return_std
239  */
240  int openGripper();
241 
242  /*!
243  * \brief Close gripper to its minimum closed position.
244  *
245  * \copydoc doc_return_std
246  */
247  int closeGripper();
248 
249 
250  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
251  // Fundamental Arm Operations
252  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
253 
254  /*!
255  * \brief Emergency stop.
256  *
257  * All servos will stop driving, so arm or accessories may fall.
258  * Emergency stop requires recalibration.
259  *
260  * \copydoc doc_return_std
261  */
262  int estop();
263 
264  /*!
265  * \brief Freeze arm and accessories at current position.
266  *
267  * Servos are still being driven.
268  *
269  * \copydoc doc_return_std
270  */
271  int freeze();
272 
273  /*!
274  * \brief Release arm and accessories.
275  *
276  * Servos will stop driving, so the arm may fall. This call is assumed to
277  * be under control, so recalibration is not required. Typically, the arm
278  * is released during manual repositioning or teaching.
279  *
280  * \copydoc doc_return_std
281  */
282  int release();
283 
284  /*!
285  * \brief Stops specified joints at current position.
286  *
287  * Servos are still being driven.
288  *
289  * \param vecNames Vector of joint names.
290  *
291  * \copydoc Returns the number of joints stopped.
292  */
293  int stop(const std::vector<std::string> &vecNames);
294 
295  /*!
296  * \brief Attempt to clear all servo alarms in all kinematic chains.
297  *
298  * \note Not all alarms are clearable (e.g. temperature).
299  *
300  * \copydoc doc_return_std
301  */
302  int clearAlarms();
303 
304  /*!
305  * \brief Reset (clears) emergency stop condition.
306  *
307  * \note Servos are not re-powered until an move or freeze action is called.
308  */
309  void resetEStop()
310  {
311  m_bIsEStopped = false;
313  }
314 
315  /*!
316  * \brief Move arm through trajectory point.
317  *
318  * \param trajectoryPoint Trajectory end point.
319  *
320  * \copydoc doc_return_std
321  */
322  int moveArm(HekJointTrajectoryPoint &trajectoryPoint);
323 
324 
325  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
326  // Arm State and Status
327  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
328 
329  /*!
330  * \brief Get the robot current state.
331  *
332  * \param [in,out] robotState Robot state.
333  *
334  * \copydoc doc_return_std
335  */
336  int getRobotState(HekRobotState &robotState);
337 
338  /*!
339  * \brief Get the joint states of a kinematic chain.
340  *
341  * \param [in,out] jointStatePoint Joint state point.
342  *
343  * \copydoc doc_return_std
344  */
345  int getJointState(HekJointStatePoint &jointStatePoint);
346 
347  /*!
348  * \brief Get trajectory feedback.
349  *
350  * \param [in,out] trajectoryFeedback Joint state point.
351  *
352  * \copydoc doc_return_std
353  */
354  int getTrajectoryState(HekJointTrajectoryFeedback &trajectoryFeedback);
355 
356  /*!
357  * \brief Set robot's operational mode.
358  *
359  * \return eRobotMode Robot operation mode. See \ref HekRobotMode.
360  */
361  void setRobotMode(HekRobotMode eRobotMode)
362  {
363  m_eRobotMode = eRobotMode;
364  }
365 
366  /*!
367  * \brief Test if any joint in any of the kinematic chains is moving.
368  *
369  * \return Returns true or false.
370  */
371  bool isInMotion();
372 
373  /*!
374  * \brief Cancel any asynchronous task.
375  *
376  * \note There may be a little delay between canceling an async task
377  * and the task actually stopping.
378  */
379  void cancelAsyncTask();
380 
381  /*!
382  * \brief Get the current asynchronous task state.
383  *
384  * \return \ref HekAsyncTaskState enum value.
385  */
387 
388  /*!
389  * \brief Get the last asynchronous task return code.
390  *
391  * \return
392  * Returns HEK_OK when task terminated successfully.
393  * Otherwise, returns \h_lt 0 \ref hek_ecodes.
394  */
395  int getAsyncRc();
396 
397 
398  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
399  // Attribute Methods
400  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
401 
402  /*!
403  * \brief Test if connected to \h_hek hardware.
404  *
405  * \return Returns true or false.
406  */
407  bool isConnected()
408  {
409  return (m_pDynaComm != NULL) && m_pDynaComm->IsOpen()? true: false;
410  }
411 
412  /*!
413  * \brief Get the \h_hek robotic arm hardware version numbers.
414  *
415  * \param [out] nVerMajor Major version number.
416  * \param [out] nVerMinor Minor version number.
417  * \param [out] nVerRevision Revision version number.
418  */
419  void getVersion(int &nVerMajor, int &nVerMinor, int &nRevision)
420  {
421  uint_t uHwVer;
422 
424  nVerMajor = HEK_VER_MAJOR(uHwVer);
425  nVerMinor = HEK_VER_MINOR(uHwVer);
426  nRevision = HEK_VER_REV(uHwVer);
427  }
428 
429  /*!
430  * \brief Get the \h_hek robotic arm hardware version compact number.
431  *
432  * \return Return byte-packed comparable verion number.
433  */
434  uint_t getVersionNum()
435  {
437  }
438 
439  /*!
440  * \brief Get the \h_hek robotic arm hardware version string.
441  *
442  * Version number strings are of the dotted form maj.min.rev.
443  *
444  * \return Version string.
445  */
446  std::string getVersion()
447  {
448  return m_descHek.getArmDesc()->getProdHwVer();
449  }
450 
451  /*!
452  * \brief Get the \h_hek product description.
453  *
454  * \return Returns pointer to description.
455  */
457  {
458  return &m_descHek;
459  }
460 
461  /*!
462  * \brief Convenience function to get this \h_hek description's base
463  * product id.
464  *
465  * \return Returns product id. See \ref HekProdId.
466  */
467  int getProdId()
468  {
469  return m_descHek.getArmDesc()->getProdId();
470  }
471 
472  /*!
473  * \brief Convenience function to get this \h_hek description's base
474  * product name.
475  *
476  * \return Returns product name. See \ref HekProdName.
477  */
478  std::string getProdName()
479  {
480  return m_descHek.getArmDesc()->getProdName();
481  }
482 
483  /*!
484  * \brief Get the \h_hek full brief descirption.
485  *
486  * \return Returns product brief description.
487  */
488  std::string getFullProdBrief()
489  {
490  return m_descHek.getFullProdBrief();
491  }
492 
493  /*!
494  * \brief Test if robot is fully described via configuration XML.
495  *
496  * \return Returns true or false.
497  */
499  {
500  return m_descHek.isDescribed();
501  }
502 
503  /*!
504  * \brief Test if robot is calibrated.
505  *
506  * \return Returns true or false.
507  */
509  {
511  }
512 
513  /*!
514  * \brief Test if robot is current emergency stopped.
515  *
516  * \return Returns true or false.
517  */
519  {
520  return m_bIsEStopped;
521  }
522 
523  /*!
524  * \brief Test if robot servos are currently being driven (powered).
525  *
526  * \return Returns true or false.
527  */
529  {
530  return m_bAreServosPowered;
531  }
532 
533  /*!
534  * \brief Test if robot is alarmed.
535  *
536  * \return Returns true or false.
537  */
538  int isAlarmed()
539  {
540  // monitor always has the latest alarm conditions. Robot simple shadows.
542  return m_bAlarmState;
543  }
544 
545  /*!
546  * \brief Test if robot is as pre-defined balanced position.
547  *
548  * \return Returns true or false.
549  */
551  {
552  return m_bAtBalancedPos;
553  }
554 
555  /*!
556  * \brief Test if robot is as pre-defined parked position.
557  *
558  * \return Returns true or false.
559  */
561  {
562  return m_bAtParkedPos;
563  }
564 
565  /*!
566  * \brief Get the dynamixel chain object.
567  *
568  * \return Returns point to DynaChain object.
569  */
570  DynaChain *getDynaChain()
571  {
572  return m_pDynaChain;
573  }
574 
575  /*!
576  * \brief Get trajectory parameters.
577  *
578  * \param [out] eNorm Distance norm.
579  * \param [out] fEpsilon Waypoint precision (radians)
580  */
581  void getTrajectoryParams(HekNorm &eNorm, double &fEpsilon)
582  {
583  m_tunes.getTrajectoryParams(eNorm, fEpsilon);
584  }
585 
586 
587  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
588  // Kinematic Access and Mapping Methods
589  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
590 
591  /*!
592  * \brief Get robotic joint in arm+ee kinematic chain at the given index.
593  *
594  * \param index Joint index.
595  *
596  * \return If found, returns pointer to joint. Otherwise returns NULL.
597  */
599  {
600  return index < m_jointsArm.size()? &m_jointsArm.at(index): NULL;
601  }
602 
603  /*!
604  * \brief Get robotic joint in arm+ee kinematic chain.
605  *
606  * \param strName Joint name (key).
607  *
608  * \return If found, returns pointer to joint. Otherwise returns NULL.
609  */
610  HekRobotJoint *getArmJoint(const std::string &strName)
611  {
612  IMapRobotJoints::iterator iter;
613 
614  if( (iter = m_imapJoints.find(strName)) != m_imapJoints.end() )
615  {
616  return &(m_jointsArm[iter->second]);
617  }
618  else
619  {
620  return NULL;
621  }
622  }
623 
624  /*!
625  * \brief Get robotic joint in arm+ee kinematic chain.
626  *
627  * \param nServoId Master servo id (primary key).
628  *
629  * \return If found, returns pointer to joint. Otherwise returns NULL.
630  */
631  HekRobotJoint *getArmJoint(int nServoId)
632  {
633  MapRobotJoints::iterator iter;
634 
635  if( (iter = m_jointsArm.find(nServoId)) != m_jointsArm.end() )
636  {
637  return &(iter->second);
638  }
639  else
640  {
641  return NULL;
642  }
643  }
644 
645  /*!
646  * \brief Get robotic joint's master servo.
647  *
648  * \param joint Robotic joint.
649  *
650  * \return If found, returns pointer to servo. Otherwise returns NULL.
651  */
652  DynaServo *getMasterServo(HekRobotJoint &joint)
653  {
654  return m_pDynaChain!=NULL? m_pDynaChain->GetServo(joint.m_nMasterServoId):
655  NULL;
656  }
657 
658  /*!
659  * \brief Convert percent of maximum to joint velocity.
660  *
661  * The maximum joint velocity is the theoretical maximum joint velocity
662  * based on joint servo specs of unloaded maximum RPMs and the Hekateros
663  * external gear ratios.
664  *
665  * \param joint Joint description.
666  * \param fValPct Joint velocity (%).
667  *
668  * \return Joint velocity (radians/second).
669  */
670  double pctOfMaxJointVelocity(HekRobotJoint &joint, double fVelPct)
671  {
672  return fVelPct < 100.0? fVelPct/100.0 * joint.m_fMaxJointRadsPerSec:
673  joint.m_fMaxJointRadsPerSec;
674  }
675 
676  protected:
677  // state
678  bool m_bNoExec; ///< do [not] execute physical movements
679  HekDesc m_descHek; ///< \h_hek description
680  HekRobotMode m_eRobotMode; ///< robot operating mode
681  HekOpState m_eOpState; ///< arm operational state
682  bool m_bIsEStopped; ///< arm is [not] emergency stopped
683  bool m_bAlarmState; ///< robot is [not] alarmed
684  bool m_bAreServosPowered;///< arm servos are [not] driven
685  bool m_bAtBalancedPos; ///< arm is [not] at balanced position
686  bool m_bAtParkedPos; ///< arm is [not] at parked position
687 
688  // tuning
689  HekTunes m_tunes; ///< tune parameters
690 
691  // dynamixel i/f
692  DynaComm *m_pDynaComm; ///< dynamixel communication
693  DynaChain *m_pDynaChain; ///< dynamixel chain
694  DynaBgThread *m_pDynaBgThread; ///< dynamixel background thread
695 
696  // joint descriptions
697  MapRobotJoints m_jointsArm; ///< robot arm + end effector joints
698  MapRobotJoints m_jointsEquipDeck;///< robot equipement deck kin. joints
699  MapRobotJoints m_jointsAux; ///< robot auxiliary kinematic joints
700  IMapRobotJoints m_imapJoints; ///< joints indirect map
701 
702  // dynamics and kinematics
703  HekKinematics *m_pKin; ///< dynamics and kinematics
704 
705  // motion state
706  HekJointTrajectoryPoint m_lastTrajArm; ///< last trajectory point for arm
707 
708  // monitor
709  HekMonitor m_monitor; ///< power, health, and safety monitor
710 
711  // asynchronous task control and synchronization
712  HekAsyncTaskState m_eAsyncTaskState; ///< asynchronous task state
713  int m_rcAsyncTask; ///< last async task return code
714  AsyncTaskId m_eAsyncTaskId; ///< asynchronous task id
715  void *m_pAsyncTaskArg; ///< asynchronous argument
716  pthread_t m_threadAsync; ///< async pthread identifier
717  pthread_mutex_t m_mutex; ///< synchronization mutex
718 
719  friend class HekCalib;
720  friend class HekCalibStretch;
721 
722  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
723  // Scan Hardware Methods
724  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
725 
726  /*!
727  * \brief Scan \h_hek hardware and match against description.
728  *
729  * \copydoc doc_return_std
730  */
731  int scanHw();
732 
733  /*!
734  * \brief Scan \h_hek dynamixel bus hardware and match against description.
735  *
736  * \param nMaxTries Maximums number of scan attempts before failing.
737  *
738  * \copydoc doc_return_std
739  */
740  int scanDynaBus(int nMaxTries);
741 
742 
743  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
744  // Convert Static Specifications Methods
745  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
746 
747  /*!
748  * \brief Convert specification(s) to operational parameters.
749  *
750  * The specifications must be defined and the connecton to the \h_hek
751  * hardware must be open.
752  *
753  * There are up to 3 kinematic chains, given the specifications and the
754  * hardware:
755  * \li arm + end effector
756  * \li equipment deck effector
757  * \li auxiliary effector
758  *
759  * \note A kinematic chain differs from the dynamixel chain. \h_hek
760  * supports one dynamixel bus in which all servos hang. A dynamixel chain
761  * defines this communication bus. Servos on the bus can be associated with
762  * any of the above three kinematic chains.
763  *
764  * \copydoc doc_return_std
765  */
766  int convertSpecs();
767 
768  /*!
769  * \brief Add a joint to robot's kinematic chain.
770  *
771  * \param [in] pSpecJoint Pointer to joint spcecification.
772  * \param [in] pSpecServo Pointer to master servo spcecification.
773  * \param [out] kin Modified kinematics chain of joints.
774  * \param [out] imap Indirect map of kinematic chain.
775  *
776  * \copydoc doc_return_std
777  */
778  int addRobotJoint(HekSpecJoint_T *pSpecJoint,
779  HekSpecServo_T *pSpecServo,
780  MapRobotJoints &kin,
781  IMapRobotJoints &imap);
782 
783  /*!
784  * \brief Adjust tuning parameters for values in compiled product
785  * specifications.
786  */
787  void adjustTuningFromSpecs();
788 
789 
790  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
791  // Hardware and Software Methods
792  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
793 
794  /*!
795  * \brief Faux calibrate \h_hek.
796  *
797  * \par DANGER:
798  * This function should in place of calibrate() for debugging.
799  * Make suere the arm is placed at the zero point prior to starting.
800  */
801  void fauxcalibrate();
802 
803  /*!
804  * \brief Configure \h_hek servos.
805  *
806  * Each servo's EEPROM and RAM control tables must match the joint
807  * descriptions.
808  *
809  * \copydoc doc_return_std
810  */
811  int configServos();
812 
813  /*!
814  * \brief Configure the EEPROM for all \h_hek servos in kinematic chain.
815  *
816  * For each servo, ensure that the proper servo EEPROM values are set.
817  *
818  * \param kin Kinematic chain of joints.
819  *
820  * \copydoc doc_return_std
821  */
823 
824  /*!
825  * \brief Configure one \h_hek servo EEPROM.
826  *
827  * A read, then write if necessary is performed to limit EEPROM wear.
828  *
829  * \note System reads, writes, and sleeps are pthread cancelation points.
830  *
831  * \param nServoId Servo id.
832  * \param joint Associated robotic joint.
833  *
834  * \copydoc doc_return_std
835  */
836  int configEEPROMForServo(int nServoId, HekRobotJoint &joint);
837 
838  /*!
839  * \brief Configure the RAM for all \h_hek servos in kinematic chain.
840  *
841  * For each servo, ensure that the proper servo RAM values are set.
842  *
843  * \param kin Kinematic chain of joints.
844  *
845  * \copydoc doc_return_std
846  */
848 
849  /*!
850  * \brief Configure one \h_hek servo RAM.
851  *
852  * \note System reads, writes, and sleeps are pthread cancelation points.
853  *
854  * \param nServoId Servo id.
855  * \param joint Associated robotic joint.
856  *
857  * \copydoc doc_return_std
858  */
859  int configRAMForServo(int nServoId, HekRobotJoint &joint);
860 
861  /*!
862  * \brief Mark all relevant joints for recalibration.
863  *
864  * \param bForceRecalib If true, force recalibration all joints.
865  * Otherwise calibrate only the uncalibrated.
866  */
867  void resetCalibStateForAllJoints(bool bForceRecalib);
868 
869  /*!
870  * \brief Determine robot operational state from collective joint
871  * operational states.
872  *
873  * \return Determined robot operational state synchronized with joint
874  * states.
875  */
877 
878  /*!
879  * \brief Move servo to position.
880  *
881  * This call blocks until move is complete.
882  *
883  * \param pServo Pointer to servo.
884  * \param nOdGoalPos Goal position in raw odometer units.
885  * \param nSpeed Speed in raw units.
886  *
887  * \return New odometer position.
888  */
889  int moveWait(DynaServo *pServo, int nOdGoalPos, int nSpeed);
890 
891  /*!
892  * \brief Wait for the specified joints to stop moving.
893  *
894  * A maximum number of wait-test tries is performed until either all of the
895  * joints haved stopped or the maximum number of tries has been reached. The
896  * between-test wait is 10 milliseconds.
897  *
898  * \param vecNames Vector of joint names.
899  * \param nMaxTries Maximum number of test-wait tries.
900  */
901  void stopWait(const std::vector<std::string> &vecNames, int nMaxTries=10);
902 
903  /*!
904  * \brief Callback to control wrist rotation.
905  *
906  * The wrist rotation is coupled to wrist pitch.
907  *
908  * \param pUserArg Point to this.
909  */
910  static void cbWristRot(void *pUserArg);
911 
912  /*!
913  * \brief Move wrist rotation for any necessary final position adjustments.
914  *
915  * The wrist coupled pitch and rotation joints can have their respective
916  * goal trajectories change by various actions.
917  */
918  void moveWristRot();
919 
920  /*!
921  * \brief Set all joint goals to a null trajectory.
922  *
923  * A null trajectory for a joint is the joint's current position and zero
924  * velocity.
925  */
926  void setAllJointGoalsToNull();
927 
928  /*!
929  * \brief Set a set of joint goals to a null trajectory.
930  *
931  * A null trajectory for a joint is the joint's current position and zero
932  * velocity.
933  *
934  * \param vecNames Vector of joint names.
935  */
936  void setJointGoalsToNull(const std::vector<std::string> &vecNames);
937 
938  /*!
939  * \brief Set joint goal to null a trajectory.
940  *
941  * A null trajectory for a joint is the joint's current position and zero
942  * velocity.
943  *
944  * \param strName Joint name.
945  */
946  void setJointGoalToNull(const std::string &strName);
947 
948 
949  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
950  // Asynchronous Operation Methods and Synchronization
951  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
952 
953  /*!
954  * \brief Create the asynchronous thread.
955  *
956  * \par Context:
957  * Calling thread.
958  *
959  * \copydoc doc_return_std
960  */
961  int createAsyncThread();
962 
963  /*!
964  * \brief Asynchronous operation thread.
965  *
966  * \param pArg Thread argument (point to HekRobot object).
967  *
968  * \return Returns NULL on thread exit.
969  */
970  static void *asyncThread(void *pArg);
971 
972  /*!
973  * \brief Lock the robot mutex.
974  *
975  * The lock()/unlock() primitives provide thread-safe access.
976  *
977  * \par Context:
978  * Any.
979  */
980  void lock()
981  {
982  pthread_mutex_lock(&m_mutex);
983  }
984 
985  /*!
986  * \brief Unlock the robot mutex.
987  *
988  * \par Context:
989  * Any.
990  */
991  void unlock()
992  {
993  pthread_mutex_unlock(&m_mutex);
994  }
995 
996  /*!
997  * \brief Try to lock the robot mutex.
998  *
999  * \par Context:
1000  * Any.
1001  *
1002  * \return Returns true if lock acquired, else returns false.
1003  */
1004  bool trylock()
1005  {
1006  return pthread_mutex_trylock(&m_mutex) == 0? true: false;
1007  }
1008  };
1009 
1010 } // namespace hekateros
1011 
1012 
1013 #endif // _HEK_ROBOT_H
void * m_pAsyncTaskArg
asynchronous argument
Definition: hekRobot.h:715
HekRobotJoint * getArmJoint(const std::string &strName)
Get robotic joint in arm+ee kinematic chain.
Definition: hekRobot.h:610
#define HEK_VER_REV(ver)
Get revision number from version.
Definition: hekateros.h:213
Robot overall state.
Definition: hekState.h:114
HekRobotMode m_eRobotMode
robot operating mode
Definition: hekRobot.h:680
int createAsyncThread()
Create the asynchronous thread.
Definition: hekRobot.cxx:1635
HekCalib - Hekateros calibration abstract base class interface.
int getAsyncRc()
Get the last asynchronous task return code.
Definition: hekRobot.cxx:1704
MapRobotJoints m_jointsAux
robot auxiliary kinematic joints
Definition: hekRobot.h:699
void resetEStop()
Reset (clears) emergency stop condition.
Definition: hekRobot.h:309
Hekateros robotic manipulator calibration by stretching class.
void setRobotMode(HekRobotMode eRobotMode)
Set robot&#39;s operational mode.
Definition: hekRobot.h:361
DynaChain * getDynaChain()
Get the dynamixel chain object.
Definition: hekRobot.h:570
HekDesc * getHekDesc()
Get the <b><i>Hekateros</i></b> product description.
Definition: hekRobot.h:456
int configEEPROMForAllServos(MapRobotJoints &kin)
Configure the EEPROM for all <b><i>Hekateros</i></b> servos in kinematic chain.
Definition: hekRobot.cxx:1430
int getJointState(HekJointStatePoint &jointStatePoint)
Get the joint states of a kinematic chain.
Definition: hekRobot.cxx:979
int isAlarmed()
Test if robot is alarmed.
Definition: hekRobot.h:538
void fauxcalibrate()
Faux calibrate <b><i>Hekateros</i></b>.
Definition: hekRobot.cxx:1397
HekDesc - Hekateros full robotic manipulator descripition class interface.
Joint trajectory feedback class.
Definition: hekTraj.h:313
void markEStopCond(bool bEStopCond)
Mark emergency stop condition.
Definition: hekMonitor.cxx:403
bool m_bAtBalancedPos
arm is [not] at balanced position
Definition: hekRobot.h:685
bool m_bAreServosPowered
arm servos are [not] driven
Definition: hekRobot.h:684
int estop()
Emergency stop.
Definition: hekRobot.cxx:771
int closeGripper()
Close gripper to its minimum closed position.
Definition: hekRobot.cxx:739
int configRAMForServo(int nServoId, HekRobotJoint &joint)
Configure one <b><i>Hekateros</i></b> servo RAM.
Definition: hekRobot.cxx:1574
virtual ~HekRobot()
Destructor.
Definition: hekRobot.cxx:220
MapRobotJoints m_jointsArm
robot arm + end effector joints
Definition: hekRobot.h:697
int scanHw()
Scan <b><i>Hekateros</i></b> hardware and match against description.
void reload()
Reload <b><i>Hekateros</i></b>&#39;s reloadable configuration and reset operational parameters.
Definition: hekRobot.cxx:499
HekRobotJoint * getArmJointAt(int index)
Get robotic joint in arm+ee kinematic chain at the given index.
Definition: hekRobot.h:598
Joint trajectory point class.
Definition: hekTraj.h:180
bool m_bNoExec
do [not] execute physical movements
Definition: hekRobot.h:678
Operational robotic joint description class.
Definition: hekJoint.h:80
DynaServo * getMasterServo(HekRobotJoint &joint)
Get robotic joint&#39;s master servo.
Definition: hekRobot.h:652
int m_rcAsyncTask
last async task return code
Definition: hekRobot.h:713
void adjustTuningFromSpecs()
Adjust tuning parameters for values in compiled product specifications.
Definition: hekRobot.cxx:1379
int configRAMForAllServos(MapRobotJoints &kin)
Configure the RAM for all <b><i>Hekateros</i></b> servos in kinematic chain.
Definition: hekRobot.cxx:1550
int scanDynaBus(int nMaxTries)
Scan <b><i>Hekateros</i></b> dynamixel bus hardware and match against description.
Definition: hekRobot.cxx:1090
double m_fMaxJointRadsPerSec
maximum joint radians per second
Definition: hekJoint.h:159
HekCalibStretch - Hekateros calibration by stretching class interface.
calibrate hekateros arm task id
Definition: hekRobot.h:107
const int HekBaudRateDynabus
dynabus baudrate
Definition: hekateros.h:438
#define HEK_VER_MAJOR(ver)
Get version major number from version.
Definition: hekateros.h:195
int addRobotJoint(HekSpecJoint_T *pSpecJoint, HekSpecServo_T *pSpecServo, MapRobotJoints &kin, IMapRobotJoints &imap)
Add a joint to robot&#39;s kinematic chain.
Definition: hekRobot.cxx:1271
Joint points and trajectory class interfaces.
HekRobotMode
<b><i>Hekateros</i></b> mode of operation.
Definition: hekateros.h:506
bool isConnected()
Test if connected to <b><i>Hekateros</i></b> hardware.
Definition: hekRobot.h:407
const char *const HekDevDynabus
dynabus device name
Definition: hekateros.h:429
HekKinematics * m_pKin
dynamics and kinematics
Definition: hekRobot.h:703
HekAsyncTaskState
Asynchronous task state.
Definition: hekateros.h:526
int m_nMasterServoId
master servo id
Definition: hekJoint.h:150
int connect(const std::string &strDevDynabus=HekDevDynabus, int nBaudRateDynabus=HekBaudRateDynabus, const std::string &strDevArduino=HekDevArduino, int nBaudRateArduino=HekBaudRateArduino)
Connect to <b><i>Hekateros</i></b>.
Definition: hekRobot.cxx:226
map< std::string, int > IMapRobotJoints
Indirect map of robot joints.
Definition: hekRobot.h:99
bool m_bAtParkedPos
arm is [not] at parked position
Definition: hekRobot.h:686
int stop(const std::vector< std::string > &vecNames)
Stops specified joints at current position.
Definition: hekRobot.cxx:830
Hekateros tuning data class.
Definition: hekTune.h:408
void setAllJointGoalsToNull()
Set all joint goals to a null trajectory.
int areServosPowered()
Test if robot servos are currently being driven (powered).
Definition: hekRobot.h:528
Hekateros Robot State classes interface.
AsyncTaskId
Asynchronous task id.
Definition: hekRobot.h:104
HekTunes m_tunes
tune parameters
Definition: hekRobot.h:689
void cancelAsyncTask()
Cancel any asynchronous task.
Definition: hekRobot.cxx:1662
void lock()
Lock the robot mutex.
Definition: hekRobot.h:980
double pctOfMaxJointVelocity(HekRobotJoint &joint, double fVelPct)
Convert percent of maximum to joint velocity.
Definition: hekRobot.h:670
The Hekateros kinematics and dynamics class interface.
IMapRobotJoints m_imapJoints
joints indirect map
Definition: hekRobot.h:700
Hekateros Monitor Class interface.
int release()
Release arm and accessories.
Definition: hekRobot.cxx:812
int gotoParkedPos()
Move robotic arm to its pre-defined parked position.
Definition: hekRobot.cxx:578
int calibrateAsync(bool bForceRecalib=true)
Asynchronously calibrate <b><i>Hekateros</i></b>&#39;s odometers and limit switch positions.
Definition: hekRobot.cxx:483
void getTrajectoryParams(HekNorm &eNorm, double &fEpsilon) const
Get trajectory tune parameters.
Definition: hekTune.h:462
HekDescArm * getArmDesc()
Get the <b><i>Hekateros</i></b> base product description.
Definition: hekDesc.h:177
Hekateros joint classes interfaces.
void getVersion(int &nVerMajor, int &nVerMinor, int &nRevision)
Get the <b><i>Hekateros</i></b> robotic arm hardware version numbers.
Definition: hekRobot.h:419
int clearAlarms()
Attempt to clear all servo alarms in all kinematic chains.
Definition: hekRobot.cxx:847
int isCalibrated()
Test if robot is calibrated.
Definition: hekRobot.h:508
static void * asyncThread(void *pArg)
Asynchronous operation thread.
Definition: hekRobot.cxx:1709
std::string getProdName()
Convenience function to get this <b><i>Hekateros</i></b> description&#39;s base product name...
Definition: hekRobot.h:478
HekOpState
Robot or joint operational states.
Definition: hekateros.h:516
DynaComm * m_pDynaComm
dynamixel communication
Definition: hekRobot.h:692
bool m_bAlarmState
robot is [not] alarmed
Definition: hekRobot.h:683
bool isInMotion()
Test if any joint in any of the kinematic chains is moving.
Definition: hekRobot.cxx:1067
MapRobotJoints m_jointsEquipDeck
robot equipement deck kin. joints
Definition: hekRobot.h:698
void unlock()
Unlock the robot mutex.
Definition: hekRobot.h:991
HekRobot(bool bNoExec=false)
Default initialization constructor.
Definition: hekRobot.cxx:194
int freeze()
Freeze arm and accessories at current position.
Definition: hekRobot.cxx:794
int isAtParkedPos()
Test if robot is as pre-defined parked position.
Definition: hekRobot.h:560
int getRobotState(HekRobotState &robotState)
Get the robot current state.
Definition: hekRobot.cxx:904
int openGripper()
Open gripper to its maximum opened position.
Definition: hekRobot.cxx:707
std::map< int, HekRobotJoint > MapRobotJoints
Map of robot joints.
Definition: hekJoint.h:202
void getTrajectoryParams(HekNorm &eNorm, double &fEpsilon)
Get trajectory parameters.
Definition: hekRobot.h:581
int getTrajectoryState(HekJointTrajectoryFeedback &trajectoryFeedback)
Get trajectory feedback.
Definition: hekRobot.cxx:1035
Hekateros robotic manipulator full description class.
Definition: hekDesc.h:75
DynaChain * m_pDynaChain
dynamixel chain
Definition: hekRobot.h:693
std::map< std::string, double > MapDouble
Map of doubles.
Definition: hekRobot.h:115
DynaBgThread * m_pDynaBgThread
dynamixel background thread
Definition: hekRobot.h:694
void setJointGoalToNull(const std::string &strName)
Set joint goal to null a trajectory.
Hekateros robotic manipulator calibration abstract base class.
Definition: hekCalib.h:73
pthread_t m_threadAsync
async pthread identifier
Definition: hekRobot.h:716
int configServos()
Configure <b><i>Hekateros</i></b> servos.
Definition: hekRobot.cxx:1411
std::string getProdHwVer()
Get this base description&#39;s hardware version.
Definition: hekDescArm.h:165
int isDescribed()
Test if robot is fully described via configuration XML.
Definition: hekRobot.h:498
Top-level package include file.
HekOpState determineRobotOpState()
Determine robot operational state from collective joint operational states.
Definition: hekRobot.cxx:1620
#define HEK_VER_MINOR(ver)
Get version minor number from version.
Definition: hekateros.h:204
void moveWristRot()
Move wrist rotation for any necessary final position adjustments.
int isAtBalancedPos()
Test if robot is as pre-defined balanced position.
Definition: hekRobot.h:550
uint_t getVersionNum()
Get the <b><i>Hekateros</i></b> robotic arm hardware version compact number.
Definition: hekRobot.h:434
int calibrate(bool bForceRecalib=true)
Calibrate <b><i>Hekateros</i></b>&#39;s odometers and limit switch positions.
Definition: hekRobot.cxx:436
std::string getFullProdBrief()
Get the <b><i>Hekateros</i></b> full brief descirption.
Definition: hekRobot.h:488
HekMonitor m_monitor
power, health, and safety monitor
Definition: hekRobot.h:709
HekJointTrajectoryPoint m_lastTrajArm
last trajectory point for arm
Definition: hekRobot.h:706
const int HekBaudRateArduino
arduino baudrate
Definition: hekateros.h:456
void stopWait(const std::vector< std::string > &vecNames, int nMaxTries=10)
Wait for the specified joints to stop moving.
static void cbWristRot(void *pUserArg)
Callback to control wrist rotation.
Joint state point class.
Definition: hekJoint.h:344
HekNorm
Length/Distance Norm.
Definition: hekateros.h:535
uint_t strToVersion(const std::string &str)
Convert version dotted string to integer equivalent.
int gotoZeroPtPos()
Move robotic arm to its pre-defined calibrated zero point position.
Definition: hekRobot.cxx:643
int gotoBalancedPos()
Move robotic arm to its pre-defined balanced position.
Definition: hekRobot.cxx:513
AsyncTaskId m_eAsyncTaskId
asynchronous task id
Definition: hekRobot.h:714
<b><i>Hekateros</i></b> power, joint limits, and alarm monitoring class.
Definition: hekMonitor.h:100
int moveWait(DynaServo *pServo, int nOdGoalPos, int nSpeed)
Move servo to position.
int isEStopped()
Test if robot is current emergency stopped.
Definition: hekRobot.h:518
Hekateros robotic manipulator plus accesories class.
Definition: hekRobot.h:88
std::string getProdName()
Get this base description&#39;s name.
Definition: hekDescArm.h:145
Hekateros common utilities.
pthread_mutex_t m_mutex
synchronization mutex
Definition: hekRobot.h:717
const char *const HekDevArduino
arduino device name
Definition: hekateros.h:447
Hekateros tuning.
HekDesc m_descHek
<b><i>Hekateros</i></b> description
Definition: hekRobot.h:679
HekAsyncTaskState m_eAsyncTaskState
asynchronous task state
Definition: hekRobot.h:712
int convertSpecs()
Convert specification(s) to operational parameters.
Definition: hekRobot.cxx:1175
int disconnect()
Disconnect from <b><i>Hekateros</i></b>.
Definition: hekRobot.cxx:394
Robotic joint specification.
Definition: hekSpec.h:139
Robotic servo specification.
Definition: hekSpec.h:199
bool isDescribed()
Test if required descriptions are described.
Definition: hekDesc.h:165
void setJointGoalsToNull(const std::vector< std::string > &vecNames)
Set a set of joint goals to a null trajectory.
HekRobotJoint * getArmJoint(int nServoId)
Get robotic joint in arm+ee kinematic chain.
Definition: hekRobot.h:631
int moveArm(HekJointTrajectoryPoint &trajectoryPoint)
Move arm through trajectory point.
Definition: hekRobot.cxx:880
void resetCalibStateForAllJoints(bool bForceRecalib)
Mark all relevant joints for recalibration.
Definition: hekRobot.cxx:1607
int getAlarmCond()
Get monitoring alarm condition.
Definition: hekMonitor.h:371
bool trylock()
Try to lock the robot mutex.
Definition: hekRobot.h:1004
int getProdId()
Get this base description&#39;s base product id.
Definition: hekDescArm.h:135
std::string getVersion()
Get the <b><i>Hekateros</i></b> robotic arm hardware version string.
Definition: hekRobot.h:446
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
std::string getFullProdBrief()
Get the <b><i>Hekateros</i></b> full brief descirption.
Definition: hekDesc.h:208
HekOpState m_eOpState
arm operational state
Definition: hekRobot.h:681
int configEEPROMForServo(int nServoId, HekRobotJoint &joint)
Configure one <b><i>Hekateros</i></b> servo EEPROM.
Definition: hekRobot.cxx:1464
HekAsyncTaskState getAsyncState()
Get the current asynchronous task state.
Definition: hekRobot.cxx:1699
bool m_bIsEStopped
arm is [not] emergency stopped
Definition: hekRobot.h:682
int getProdId()
Convenience function to get this <b><i>Hekateros</i></b> description&#39;s base product id...
Definition: hekRobot.h:467