Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeKin.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Library: liblaelaps
6 //
7 // File: laeKin.h
8 //
9 /*! \file
10  *
11  * \brief The Laelaps kinematics and dynamics class interface.
12  *
13  * The class instance starts a kinematics thread to sense kinematic chain
14  * dynamics, control forward geometry kinematics, and monitor servo health.
15  *
16  * The kinematics includes all physical kinematic chains. The individual chains
17  * are controlled by the higher-level interfaces such as MoveIt!
18  *
19  * The kinematics thread performs several functions:
20  * \li Position, velocity, acceleration (future), and torque monitoring.
21  * \li Goal motor position and velocity PID control.
22  * \li Torque limiting override control.
23  * \li Servo health monitoring.
24  *
25  * \par Kinedynamics Algorithm:
26  * \verbatim
27  * sense()
28  * for each powertrain
29  * sense dynamics (x reads)
30  * react()
31  * for each powertrain
32  * stop motion if necessary (x writes)
33  * plan()
34  * for each powertrain
35  * plan motion.
36  * act()
37  * sync write (x writes)
38  * monitor()
39  * health of motor controller with two motors (x reads)
40  * block wait for next cycle time
41  * \endverbatim
42  *
43  * \author Robin Knight (robin.knight@roadnarrows.com)
44  *
45  * \par Copyright
46  * \h_copy 2015-2017. RoadNarrows LLC.\n
47  * http://www.roadnarrows.com\n
48  * All Rights Reserved
49  */
50 /*
51  * @EulaBegin@
52  *
53  * Unless otherwise stated explicitly, all materials contained are copyrighted
54  * and may not be used without RoadNarrows LLC's written consent,
55  * except as provided in these terms and conditions or in the copyright
56  * notice (documents and software) or other proprietary notice provided with
57  * the relevant materials.
58  *
59  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
60  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
61  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
62  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
63  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
64  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  *
66  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
67  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
68  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
69  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
70  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
71  *
72  * @EulaEnd@
73  */
74 ////////////////////////////////////////////////////////////////////////////////
75 
76 #ifndef _LAE_KIN_H
77 #define _LAE_KIN_H
78 
79 #include <sys/time.h>
80 #include <time.h>
81 #include <pthread.h>
82 
83 #include <vector>
84 #include <map>
85 
86 #include "rnr/rnrconfig.h"
87 #include "rnr/log.h"
88 
89 #include "Laelaps/RoboClaw.h"
90 
91 #include "Laelaps/laelaps.h"
92 #include "Laelaps/laeUtils.h"
93 #include "Laelaps/laeDesc.h"
94 #include "Laelaps/laeTune.h"
95 
96 #include "Laelaps/laeMotor.h"
97 #include "Laelaps/laeGpio.h"
98 #include "Laelaps/laeTraj.h"
99 #include "Laelaps/laePowertrain.h"
100 #include "Laelaps/laePlatform.h"
101 
102 namespace laelaps
103 {
104  //
105  // Forward declaration.
106  //
107  class LaeKinAction;
108 
109  // ---------------------------------------------------------------------------
110  // LaeKinematics Class
111  // ---------------------------------------------------------------------------
112 
113  /*!
114  * \brief Laelaps kinematics class.
115  *
116  * The LaeKinematics class supports control and monitoring of \h_laelaps
117  * powertrains and base kinodynamics.
118  */
120  {
121  public:
122  /*!
123  * \brief Default initializer constructor.
124  */
125  LaeKinematics();
126 
127  /*!
128  * \brief Desctructor.
129  */
130  virtual ~LaeKinematics();
131 
132  /*!
133  * \brief Open communication with the \h_laelaps motor controllers
134  *
135  * Motors controller serial interface support multi-drop, so one serial
136  * device can support up to 8 motor controllers. A GPIO pin selects the
137  * motor controller.
138  *
139  * \param strDevMotorCtlrs Motor controllers serial device name.
140  * \param nBaudRate Motor controllers serial baudrate.
141  * \param fnEnable Motor controllers enable power function.
142  * \param pEnableArg Enable power function argument.
143  *
144  * \copydoc doc_return_std
145  */
146  int open(const std::string &strDevMotorCtlrs,
147  const int nBaudRate,
148  int (*fnEnable)(void *, bool) = NULL,
149  void *pEnableArg = NULL);
150 
151  /*!
152  * \brief Close communication.
153  *
154  * \copydoc doc_return_std
155  */
156  virtual int close();
157 
158  /*!
159  * \brief Test if connection is open.
160  *
161  * \return Returns true or false.
162  */
163  virtual bool isOpen()
164  {
165  return m_commMotorCtlrs.isOpen();
166  }
167 
168  /*!
169  * \brief Test if motors are enabled.
170  *
171  * \return Returns true or false.
172  */
173  virtual bool isEnabled()
174  {
175  return m_bIsEnabled;
176  }
177 
178  /*!
179  * \brief Test if motors are powered.
180  *
181  * \return Returns true or false.
182  */
183  virtual bool areMotorsPowered()
184  {
185  return m_bAreMotorsPowered;
186  }
187 
188  /*!
189  * \brief Configure kinematics chains and data from product description.
190  *
191  * \param desc Product description.
192  *
193  * \copydoc doc_return_std
194  */
195  virtual int configure(const LaeDesc &desc);
196 
197  /*!
198  * \brief Configure kinematics for operation.
199  *
200  * \par Context:
201  * Calling thread.
202  *
203  * \param tunes Laelaps tuning parameters.
204  *
205  * \copydoc doc_return_std
206  */
207  virtual int configure(const LaeTunes &tunes);
208 
209  /*!
210  * \brief Reload configuration tuning parameters.
211  *
212  * \par Context:
213  * Calling thread.
214  *
215  * \param tunes Laelaps tuning parameters.
216  *
217  * \copydoc doc_return_std
218  */
219  virtual int reload(const LaeTunes &tunes);
220 
221  /*!
222  * \brief Get robot platform kinodynamics.
223  *
224  * \return Returns reference to robot platform kinodynamics object.
225  */
227  {
228  return m_kinPlatform;
229  }
230 
231  /*!
232  * \brief Get pointer to motor controller by name (key).
233  *
234  * \param nMotorCtlrId Motor controller unique identifier.
235  *
236  * \return
237  * On success, the pointer to motor controller object is returned.\n
238  * On failure, NULL is returned.
239  */
240  motor::roboclaw::RoboClaw *getMotorCtlr(const int nMotorCtlrId);
241 
242  /*!
243  * \brief Get map of all powertrain kinodynamics.
244  *
245  * \return Returns reference to map of powertrain kinodynamics objects.
246  */
248  {
249  return m_kinPowertrains;
250  }
251 
252  /*!
253  * \brief Get pointer to powertrain by name (key).
254  *
255  * \param strName Powertrain name (key).
256  *
257  * \return
258  * On success, the pointer to powertrain kinodynamics object is returned.\n
259  * On failure, NULL is returned.
260  */
261  LaePowertrain *getPowertrain(const std::string &strName);
262 
263  /*!
264  * \brief Get pointer to powertrain by controller id and motor index.
265  *
266  * \param nCtlr Motor controller id.
267  * \param nMotor Motor index within motor controller.
268  *
269  * \return
270  * On success, the pointer to powertrain kinodynamics object is returned.\n
271  * On failure, NULL is returned.
272  */
273  LaePowertrain *getPowertrain(int nCtlr, int nMotor);
274 
275  /*!
276  * \brief Get pointer to powertrain by motor id.
277  *
278  * \param nMotorId Motor id.
279  *
280  * \return
281  * On success, the pointer to powertrain kinodynamics object is returned.\n
282  * On failure, NULL is returned.
283  */
284  LaePowertrain *getPowertrain(int nMotorId);
285 
286  /*!
287  * \brief Get the current powertrain state.
288  *
289  * \par Context:
290  * Calling thread.
291  *
292  * \param [in] strName Powertrain unique name.
293  * \param [out] state Current powertrain state.
294  *
295  * \copydoc doc_return_std
296  */
297  virtual int getPowertrainState(const std::string &strName,
298  LaePowertrainState &state);
299 
300  /*!
301  * \brief Test if all motors are stopped.
302  *
303  * \return Returns true if all are stopped, false otherwise.
304  */
305  virtual bool isStopped();
306 
307  /*!
308  * \brief Test if a powertrain motor is stopped.
309  *
310  * \param strName Powertrain unique name.
311  *
312  * \return Returns true if stopped, false otherwise.
313  */
314  virtual bool isStopped(const std::string &strName);
315 
316  /*!
317  * \brief Reset all motors' odometers to the current respective encoder
318  * positions.
319  *
320  * \par Context:
321  * Calling thread.
322  *
323  * \return Number of motor odometers reset.
324  */
325  virtual int resetOdometers();
326 
327  /*!
328  * \brief Emergency stop the robot.
329  *
330  * All motors will stop and power to motor controllers disabled.
331  *
332  * \par Context:
333  * Calling thread.
334  */
335  virtual void estop();
336 
337  /*!
338  * \brief Reset emergency stop condition.
339  *
340  * \par Context:
341  * Calling thread.
342  */
343  virtual void resetEStop();
344 
345  /*!
346  * \brief Freeze (stop) all motors at the current position.
347  *
348  * Synomonous with stop().
349  *
350  * \par Context:
351  * Calling thread.
352  *
353  * \copydoc doc_return_std
354  */
355  virtual int freeze()
356  {
357  return stop();
358  }
359 
360  /*!
361  * \brief Release motors.
362  *
363  * Motors will stop, but are free to roll.
364  *
365  * \par Context:
366  * Calling thread.
367  *
368  * \copydoc doc_return_std
369  */
370  virtual int release();
371 
372  /*!
373  * \brief Stop all motors at the current position.
374  *
375  * The motor brakes, if available, are applied.
376  *
377  * \note The current RoboClaw motor controllers do not have electrical
378  * braking and the current Laelaps versions do not have mechanical braking.
379  *
380  * \par Context:
381  * Calling thread.
382  *
383  * \copydoc doc_return_std
384  */
385  virtual int stop();
386 
387  /*!
388  * \brief Stop the set of powertrain motors at the current position.
389  *
390  * \par Context:
391  * Calling thread.
392  *
393  * \param vecName Vector of unique powertrain names.
394  *
395  * \return Number of powertrain motors stopped.
396  */
397  virtual int stop(const std::vector<std::string> &vecNames);
398 
399  /*!
400  * \brief Stop one powertrain motor at the current position.
401  *
402  * \par Context:
403  * Calling thread.
404  *
405  * \param strName Powertrain unique name.
406  *
407  * \copydoc doc_return_std
408  */
409  virtual int stop(const std::string &strName);
410 
411  /*!
412  * \brief Wait for all motors to stop.
413  *
414  * \par Context:
415  * Calling thread.
416  *
417  * \param fSeconds Maximum number of seconds to wait.
418  *
419  * \copydoc doc_return_std
420  */
421  virtual int waitForAllStop(double fSeconds);
422 
423  /*!
424  * \brief Set new or updated motor velocity goals.
425  *
426  * The velocity actions are very simple actions (contrast with a
427  * multi-position task). Therefore, to reduce thread context switching and
428  * increase responsiveness, after the new/updated velocity goals are set,
429  * the plan and execute steps are immediately called.
430  *
431  * \par Context:
432  * Calling thread.
433  *
434  * \param velocity Map of powertrain velocities.\n
435  * Keys are left_front, right_front, left_rear, and
436  * right_rear.\n
437  * Values are wheel shaft angular velocities
438  * (radians/second).
439  *
440  * \copydoc doc_std_return
441  */
442  virtual int setGoalVelocities(const LaeMapVelocity &velocity);
443 
444  /*!
445  * \brief Set new or updated motor duty cycle goals.
446  *
447  * The duty cycle actions are very simple actions (contrast with a
448  * multi-position task). Therefore, to reduce thread context switching and
449  * increase responsiveness, after the new/updated duty goals are set,
450  * the plan and execute steps are immediately called.
451  *
452  * \par Context:
453  * Calling thread.
454  *
455  * \param duty Map of powertrain duty cycles.\n
456  * Keys are left_front, right_front, left_rear, and
457  * right_rear.\n
458  * Values are normalized duty cycle [-1.0, 1.0].
459  *
460  * \copydoc doc_std_return
461  */
462  virtual int setGoalDutyCycles(const LaeMapDutyCycle &duty);
463 
464  /*!
465  * \brief Set new or updated robot twist velocity goals.
466  *
467  * The velocity actions are very simple actions (contrast with a
468  * multi-position task). Therefore, to reduce thread context switching and
469  * increase responsiveness, after the new/updated velocity goals are set,
470  * the plan and execute steps are immediately called.
471  *
472  * \par Context:
473  * Calling thread.
474  *
475  * \param fVelLinear Linear velocity (meters/second).
476  * \param fVelAngular Angular velocity (radians/second).
477  *
478  * \copydoc doc_return_std
479  */
480  virtual int setGoalTwist(double fVelLinear, double fVelAngular);
481 
482  /*!
483  * \brief Execute kinematics task(s).
484  *
485  * \par Context:
486  * Kinematic thread.
487  */
488  virtual void exec();
489 
490  /*!
491  * \brief Monitor kinematics health.
492  *
493  * \par Context:
494  * Kinematics thread.
495  *
496  * \copydoc doc_return_std
497  */
498  virtual int monitorHealth();
499 
500  protected:
501  // state
502  bool m_bIsEnabled; ///< is [not] enabled
503  bool m_bAreMotorsPowered; ///< motors are [not] powered
504  bool m_bIsStopped; ///< all motors are [not] stopped
505 
506  // motor controllers
507 #ifdef LAE_DEPRECATED
508  LaeMotorCtlrChipSelect m_csMotorCtlrs;
509  ///< motor controllers chip select
510  LaeMotorCtlrEnable m_power; ///< enable power in
511 #endif // LAE_DEPRECATED
512 
513  int (*m_fnEnableMotorCtlrs)(void *, bool); ///< enable power function
514  void *m_pEnableArg; ///< argument to enable function
515 
517  ///< serial communication bus
519  ///< RoboClaw motor controllers
520 
521  // the kinematics (abstracted) hardware interfaces
522  LaePlatform m_kinPlatform; ///< robot platform kinematics
523  LaeMapPowertrain m_kinPowertrains; ///< robot powertrain kinematics
524 
525  // actions
526  LaeKinAction *m_pAction; ///< current extended kinematics action
527 
528  // mutual exclusion
529  pthread_mutex_t m_mutex; ///< mutex
530 
531  /*!
532  * \brief Lock the shared resource.
533  *
534  * The lock()/unlock() primitives provide a safe multi-threading.
535  *
536  * \par Context:
537  * Any.
538  */
539  void lock()
540  {
541  pthread_mutex_lock(&m_mutex);
542  }
543 
544  /*!
545  * \brief Unlock the shared resource.
546  *
547  * \par Context:
548  * Any.
549  */
550  void unlock()
551  {
552  pthread_mutex_unlock(&m_mutex);
553  }
554 
555  /*!
556  * \brief Attempt to resynchronize the serial communication between the
557  * host and the motor controllers.
558  */
559  void resyncComm();
560 
561  /*!
562  * \brief Configure motor controller.
563  *
564  * \par Context:
565  * Calling thread.
566  *
567  * \param tunes Laelaps tuning parameters.
568  * \param nCtlr Motor controller id.
569  *
570  * \copydoc doc_return_std
571  */
572  virtual int configureMotorController(const LaeTunes &tunes, int nCtlr);
573 
574  /*!
575  * \brief Configure motor controller battery cutoff voltages.
576  *
577  * \par Context:
578  * Calling thread.
579  *
580  * \param tunes Laelaps tuning parameters.
581  * \param nCtlr Motor controller id.
582  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
583  * non-volatile memory.
584  *
585  * \copydoc doc_return_std
586  */
587  virtual int configMotorCtlrBatteryCutoffs(const LaeTunes &tunes,
588  int nCtlr,
589  bool &bNvmSave);
590 
591  /*!
592  * \brief Configure motor controller logic cutoff voltages.
593  *
594  * \par Context:
595  * Calling thread.
596  *
597  * \param tunes Laelaps tuning parameters.
598  * \param nCtlr Motor controller id.
599  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
600  * non-volatile memory.
601  *
602  * \copydoc doc_return_std
603  */
604  virtual int configMotorCtlrLogicCutoffs(const LaeTunes &tunes,
605  int nCtlr,
606  bool &bNvmSave);
607 
608  /*!
609  * \brief Configure motor controller encoder modes.
610  *
611  * \par Context:
612  * Calling thread.
613  *
614  * \param tunes Laelaps tuning parameters.
615  * \param nCtlr Motor controller id.
616  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
617  * non-volatile memory.
618  *
619  * \copydoc doc_return_std
620  */
621  virtual int configMotorCtlrEncoderModes(const LaeTunes &tunes,
622  int nCtlr,
623  bool &bNvmSave);
624 
625  /*!
626  * \brief Reset all motor controller encoders to zero.
627  *
628  * \par Context:
629  * Calling thread.
630  *
631  * \param nCtlr Motor controller id.
632  *
633  * \copydoc doc_return_std
634  */
635  virtual int resetMotorCtlrEncoders(int nCtlr);
636 
637  /*!
638  * \brief Configure powertrain pair.
639  *
640  * \par Context:
641  * Calling thread.
642  *
643  * \param tunes Laelaps tuning parameters.
644  * \param nCtlr Motor controller id.
645  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
646  * non-volatile memory.
647  *
648  * \copydoc doc_return_std
649  */
650  virtual int configurePtp(const LaeTunes &tunes, int nCtlr, bool &bNvSave);
651 
652  /*!
653  * \brief Configure motor velocity PID parameters.
654  *
655  * \par Context:
656  * Calling thread.
657  *
658  * \param tunes Laelaps tuning parameters.
659  * \param powertrain Powertrain kinodynmics object.
660  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
661  * non-volatile memory.
662  *
663  * \copydoc doc_return_std
664  */
665  virtual int configMotorVelocityPid(const LaeTunes &tunes,
666  LaePowertrain &powertrain,
667  bool &bNvmSave);
668 
669  /*!
670  * \brief Configure motor maximum ampere limit.
671  *
672  * \par Context:
673  * Calling thread.
674  *
675  * \param tunes Laelaps tuning parameters.
676  * \param powertrain Powertrain kinodynmics object.
677  * \param strKey Powertrain key.
678  * \param [out] bNvmSave Do [not] save configuration in motor contoller's
679  * non-volatile memory.
680  *
681  * \copydoc doc_return_std
682  */
683  virtual int configMotorMaxAmpLimit(const LaeTunes &tunes,
684  LaePowertrain &powertrain,
685  bool &bNvmSave);
686 
687  /*!
688  * \brief Save configuration to motor controller's non-volatile memory.
689  *
690  * \par Context:
691  * Calling thread.
692  *
693  * \param nCtlr Motor controller id.
694  *
695  * \copydoc doc_return_std
696  */
697  virtual int saveConfigToNvm(int nCtlr);
698 
699  /*!
700  * \brief Sense real-time state.
701  *
702  * \par Context:
703  * Kinematics thread.
704  *
705  * \copydoc doc_return_std
706  */
707  virtual int sense();
708 
709  /*!
710  * \brief Sense real-time kinodynamics.
711  *
712  * \par Context:
713  * Kinematics thread.
714  *
715  * \copydoc doc_return_std
716  */
717  virtual int senseDynamics();
718 
719  /*!
720  * \brief React to any necessary time-critical events.
721  *
722  * \par Context:
723  * Kinematics thread.
724  *
725  * \copydoc doc_return_std
726  */
727  virtual int react();
728 
729  /*!
730  * \brief Plan kinematic action.
731  *
732  * \par Context:
733  * Kinematics thread.
734  *
735  * \copydoc doc_return_std
736  */
737  virtual int plan();
738 
739  /*!
740  * \brief Act on current action.
741  *
742  * \par Context:
743  * Kinematics thread.
744  *
745  * \copydoc doc_return_std
746  */
747  virtual int act();
748 
749  /*!
750  * \brief Enable power to motor controllers.
751  */
752  virtual void enableMotorCtlrs();
753 
754  /*!
755  * \brief Disable power to motor controllers.
756  */
757  virtual void disableMotorCtlrs();
758 
759  }; // LaeKinematics
760 
761 
762  // ---------------------------------------------------------------------------
763  // LaeKinAction Class
764  // ---------------------------------------------------------------------------
765 
766  /*!
767  * \brief Laelaps kinematics base action class.
768  *
769  * An action spans multiple kinematic control cycles. For example, navigating
770  * to a goal position.
771  *
772  * The base class has no action.
773  */
775  {
776  public:
777  /*!
778  * \brief Supported kinematic extended actions.
779  */
781  {
782  ActionTypeIdle, ///< idle action
783  ActionTypeVelocity, ///< move by angular velocities
784  ActionTypeDutyCycle, ///< move by motor duty cycles
785  ActionTypeTwist, ///< move robot by twist values
786  ActionTypeNavForDist, ///< navigate for distances
787  ActionTypeNavToPos ///< navigate to positions
788  };
789 
790  /*!
791  * \brief Action states.
792  */
794  {
795  ActionStateIdle, ///< no action
796  ActionStateUpdate, ///< update action specific data
797  ActionStatePlan, ///< plan action
798  ActionStateExecute, ///< execute action
799  ActionStateTerminated ///< action terminated
800  };
801 
802  /*!
803  * \brief Default intialization constructor.
804  *
805  * \param kin Bound kinemeatics driver.
806  * \param eAction Action type.
807  */
808  LaeKinAction(LaeKinematics &kin, ActionType eActionType=ActionTypeIdle) :
809  m_kin(kin), m_eActionType(eActionType)
810  {
811  m_eActionState = ActionStateIdle;
812  }
813 
814  /*!
815  * \brief Destructor.
816  */
817  virtual ~LaeKinAction()
818  {
819  }
820 
821  /*!
822  * \brief Archetype constructor to create action type instance.
823  *
824  * \param kin Bound kinemeatics driver.
825  * \param eAction Action type to create.
826  *
827  * \return Pointer to new allocated instance.
828  */
829  static LaeKinAction *newAction(LaeKinematics &kin,
830  const ActionType eActionType);
831 
832  /*!
833  * \brief Archetype constructor to replace action type instance.
834  *
835  * \param kin Bound kinemeatics driver.
836  * \param pAction Pointer to current action to be terminated and deleted.
837  * The pointer is no long valid after this function
838  * returns.
839  * \param eAction New action type to create.
840  *
841  * \return Pointer to new allocated instance.
842  */
843  static LaeKinAction *replaceAction(LaeKinematics &kin,
844  LaeKinAction *pAction,
845  const ActionType eNewActionType);
846 
847  /*!
848  * \brief Plan next execution.
849  *
850  * No hardware is touched.
851  *
852  * \copydoc doc_return_std
853  */
854  virtual int plan()
855  {
856  return LAE_OK;
857  }
858 
859  /*!
860  * \brief Execution [sub]action.
861  *
862  * Hardware is updated as needed.
863  *
864  * \copydoc doc_return_std
865  */
866  virtual int execute()
867  {
868  return LAE_OK;
869  }
870 
871  /*!
872  * \brief Terminate action.
873  *
874  * Hardware is updated as needed. The robot should be stopped.
875  *
876  * \copydoc doc_return_std
877  */
878  virtual int terminate()
879  {
880  m_eActionState = ActionStateTerminated;
881  return LAE_OK;
882  }
883 
884  /*!
885  * \brief Test if action is idle.
886  *
887  * \return Returns true or false.
888  */
889  virtual bool isIdle()
890  {
891  return m_eActionState == ActionStateIdle;
892  }
893 
894  /*!
895  * \brief Test if action requires (re)planning.
896  *
897  * \return Returns true or false.
898  */
899  virtual bool isPlanningRequired()
900  {
901  return m_eActionState == ActionStatePlan;
902  }
903 
904  /*!
905  * \brief Test if more action requires (more) execution.
906  *
907  * \return Returns true or false.
908  */
909  virtual bool isExecutionRequired() const
910  {
911  return m_eActionState == ActionStateExecute;
912  }
913 
914  /*!
915  * \brief Test if action has been terminated.
916  *
917  * \note An action may not have any more tasks to perform, but has NOT
918  * been terminated.
919  *
920  * \return Returns true or false.
921  */
922  virtual bool hasTerminated() const
923  {
924  return m_eActionState == ActionStateTerminated;
925  }
926 
927  /*!
928  * \brief Get the action type for this class.
929  *
930  * \return Action type enum.
931  */
932  virtual ActionType getActionType() const
933  {
934  return m_eActionType;
935  }
936 
937  /*!
938  * \brief Get the action state.
939  *
940  * \return Action state enum.
941  */
942  virtual ActionState getActionState() const
943  {
944  return m_eActionState;
945  }
946 
947  protected:
948  LaeKinematics &m_kin; ///< bound kinematics driver
949  ActionType m_eActionType; ///< action type enum
950  ActionState m_eActionState; ///< action state.
951 
952  }; // LaeKinAction
953 
954 
955  // ---------------------------------------------------------------------------
956  // LaeKinActionVelocity Class
957  // ---------------------------------------------------------------------------
958 
959  /*!
960  * \brief Laelaps kinematics velocity action class.
961  *
962  * A velocity action only sets the velocities of a (sub)set of the powertrain
963  * velocities. Powertrains not specified are kept at their current
964  * velocities.
965  */
967  {
968  public:
969  /*!
970  * \brief Default initialization constructor.
971  *
972  * \param kin Bound kinemeatics driver.
973  */
975 
976  /*!
977  * \brief Destructor.
978  */
980  {
981  }
982 
983  /*!
984  * \brief Update with new velocities.
985  *
986  * \param velocity Map of powertrain velocities.
987  *
988  * \copydoc doc_return_std
989  */
990  int update(const LaeMapVelocity &velocity);
991 
992  /*!
993  * \brief Plan next execution.
994  *
995  * If new velocities, the motor quad pulse per second are calculated.
996  *
997  * \copydoc doc_return_std
998  */
999  virtual int plan();
1000 
1001  /*!
1002  * \brief Execution new velocities.
1003  *
1004  * All motors with new velocities are written with new speeds.
1005  *
1006  * \copydoc doc_return_std
1007  */
1008  virtual int execute();
1009 
1010  /*!
1011  * \brief Terminate action.
1012  *
1013  * All motors are stopped.
1014  *
1015  * \copydoc doc_return_std
1016  */
1017  virtual int terminate();
1018 
1019  protected:
1020  LaeMapVelocity m_mapGoalVel; ///< map of goal velocities
1022  ///< target motor speeds (qpps)
1023 
1024  /*!
1025  * \brief Clear goal.
1026  */
1027  void clear();
1028 
1029  }; // class LaeKinActionVelocity
1030 
1031 
1032  // ---------------------------------------------------------------------------
1033  // LaeKinActionDutyCycle Class
1034  // ---------------------------------------------------------------------------
1035 
1036  /*!
1037  * \brief Laelaps kinematics duty cycle action class.
1038  *
1039  * A velocity action only sets the duty cycles of a (sub)set of the powertrain
1040  * motors. Powertrains not specified are kept at their current duty cycles.
1041  */
1043  {
1044  public:
1045  /*!
1046  * \brief Default initialization constructor.
1047  *
1048  * \param kin Bound kinemeatics driver.
1049  */
1051 
1052  /*!
1053  * \brief Destructor.
1054  */
1056  {
1057  }
1058 
1059  /*!
1060  * \brief Update with new velocities.
1061  *
1062  * \param velocity Map of powertrain velocities.
1063  *
1064  * \copydoc doc_return_std
1065  */
1066  int update(const LaeMapDutyCycle &dutycycle);
1067 
1068  /*!
1069  * \brief Execution new velocities.
1070  *
1071  * All motors with new velocities are written with new speeds.
1072  *
1073  * \copydoc doc_return_std
1074  */
1075  virtual int execute();
1076 
1077  /*!
1078  * \brief Terminate action.
1079  *
1080  * All motors are stopped.
1081  *
1082  * \copydoc doc_return_std
1083  */
1084  virtual int terminate();
1085 
1086  protected:
1087  LaeMapDutyCycle m_mapGoalDutyCycle; ///< map of goal duty cycles
1088 
1089  /*!
1090  * \brief Clear goal.
1091  */
1092  void clear();
1093 
1094  }; // class LaeKinActionDutyCycle
1095 
1096 
1097  // ---------------------------------------------------------------------------
1098  // LaeKinActionTwist Class
1099  // ---------------------------------------------------------------------------
1100 
1101  /*!
1102  * \brief Laelaps kinematics velocity action class.
1103  *
1104  * A velocity action only sets the velocities of a (sub)set of the powertrain
1105  * velocities. Powertrains not specified are kept at their current
1106  * velocities.
1107  */
1109  {
1110  public:
1111  /*!
1112  * \brief Default initialization constructor.
1113  *
1114  * \param kin Bound kinemeatics driver.
1115  */
1117 
1118  /*!
1119  * \brief Destructor.
1120  */
1122  {
1123  }
1124 
1125  /*!
1126  * \brief Update with new velocities.
1127  *
1128  * \param fVelLinear Linear velocity (meters/second).
1129  * \param fVelAngular Angular velocity (radians/second).
1130  *
1131  * \copydoc doc_return_std
1132  */
1133  int update(double fVelLinear, double fVelAngular);
1134 
1135  /*!
1136  * \brief Plan next execution.
1137  *
1138  * If new velocities, the motor quad pulse per second are calculated.
1139  *
1140  * \copydoc doc_return_std
1141  */
1142  virtual int plan();
1143 
1144  /*!
1145  * \brief Execution new velocities.
1146  *
1147  * All motors with new velocities are written with new speeds.
1148  *
1149  * \copydoc doc_return_std
1150  */
1151  virtual int execute();
1152 
1153  /*!
1154  * \brief Terminate action.
1155  *
1156  * All motors are stopped.
1157  *
1158  * \copydoc doc_return_std
1159  */
1160  virtual int terminate();
1161 
1162  protected:
1163  double m_fGoalVelLinear; ///< goal platform linear velocity
1164  double m_fGoalVelAngular; ///< goal platform angular velocity
1166  ///< target motor speeds (qpps)
1167 
1168  /*!
1169  * \brief Clear goal.
1170  */
1171  void clear();
1172 
1173  }; // class LaeKinActionVelocity
1174 
1175 } // namespace laelaps
1176 
1177 #endif // _LAE_KIN_H
int open(const std::string &strDevMotorCtlrs, const int nBaudRate, int(*fnEnable)(void *, bool)=NULL, void *pEnableArg=NULL)
Open communication with the <b><i>Laelaps</i></b> motor controllers.
Definition: laeKin.cxx:141
Laelaps kinematics base action class.
Definition: laeKin.h:774
std::map< std::string, double > LaeMapDutyCycle
Duty cycle trajectory type.
Definition: laeTraj.h:269
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
virtual int waitForAllStop(double fSeconds)
Wait for all motors to stop.
Definition: laeKin.cxx:1253
virtual bool areMotorsPowered()
Test if motors are powered.
Definition: laeKin.h:183
virtual int plan()
Plan kinematic action.
Definition: laeKin.cxx:1501
virtual int stop()
Stop all motors at the current position.
Definition: laeKin.cxx:1125
void resyncComm()
Attempt to resynchronize the serial communication between the host and the motor controllers.
Definition: laeKin.cxx:313
void * m_pEnableArg
argument to enable function
Definition: laeKin.h:514
Laelaps tuning data class.
Definition: laeTune.h:566
Trajectory classes interfaces.
Laelaps robotic mobile platform full description class.
Definition: laeDesc.h:451
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
virtual bool isEnabled()
Test if motors are enabled.
Definition: laeKin.h:173
ActionType
Supported kinematic extended actions.
Definition: laeKin.h:780
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual void enableMotorCtlrs()
Enable power to motor controllers.
Definition: laeKin.cxx:246
virtual ActionType getActionType() const
Get the action type for this class.
Definition: laeKin.h:932
Laelaps kinematics class.
Definition: laeKin.h:119
virtual void exec()
Execute kinematics task(s).
Definition: laeKin.cxx:1600
Laelaps motor controller power enable class.
Definition: laeGpio.h:200
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
virtual bool isOpen()
Test if connection is open.
Definition: laeKin.h:163
virtual int setGoalVelocities(const LaeMapVelocity &velocity)
Set new or updated motor velocity goals.
Definition: laeKin.cxx:1274
virtual int configMotorCtlrEncoderModes(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller encoder modes.
Definition: laeKin.cxx:579
virtual int configurePtp(const LaeTunes &tunes, int nCtlr, bool &bNvSave)
Configure powertrain pair.
Definition: laeKin.cxx:664
move robot by twist values
Definition: laeKin.h:785
virtual int react()
React to any necessary time-critical events.
Definition: laeKin.cxx:1496
virtual int resetMotorCtlrEncoders(int nCtlr)
Reset all motor controller encoders to zero.
Definition: laeKin.cxx:643
RoboClaw motor controller chip select class.
Definition: laeMotor.h:190
virtual int setGoalTwist(double fVelLinear, double fVelAngular)
Set new or updated robot twist velocity goals.
Definition: laeKin.cxx:1370
RoboClaw motor controller class interface.
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
virtual int configMotorVelocityPid(const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
Configure motor velocity PID parameters.
Definition: laeKin.cxx:711
virtual bool hasTerminated() const
Test if action has been terminated.
Definition: laeKin.h:922
ActionType m_eActionType
action type enum
Definition: laeKin.h:949
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
motor::roboclaw::RoboClawComm m_commMotorCtlrs
serial communication bus
Definition: laeKin.h:516
double m_fGoalVelLinear
goal platform linear velocity
Definition: laeKin.h:1163
Laelaps kinematics duty cycle action class.
Definition: laeKin.h:1042
virtual ~LaeKinematics()
Desctructor.
Definition: laeKin.cxx:111
virtual int act()
Act on current action.
Definition: laeKin.cxx:1526
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
motor::roboclaw::RoboClaw * getMotorCtlr(const int nMotorCtlrId)
Get pointer to motor controller by name (key).
Definition: laeKin.cxx:918
virtual int configure(const LaeDesc &desc)
Configure kinematics chains and data from product description.
Definition: laeKin.cxx:331
virtual int freeze()
Freeze (stop) all motors at the current position.
Definition: laeKin.h:355
int(* m_fnEnableMotorCtlrs)(void *, bool)
enable power function
Definition: laeKin.h:513
virtual bool isStopped()
Test if all motors are stopped.
Definition: laeKin.cxx:986
ActionState m_eActionState
action state.
Definition: laeKin.h:950
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
LaeKinematics()
Default initializer constructor.
Definition: laeKin.cxx:89
virtual int configMotorCtlrBatteryCutoffs(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller battery cutoff voltages.
Definition: laeKin.cxx:447
Laelaps Odroid General Purpose I/O class interfaces.
virtual ~LaeKinActionDutyCycle()
Destructor.
Definition: laeKin.h:1055
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps robotic base mobile platform description class interface.
ActionState
Action states.
Definition: laeKin.h:793
LaeMapPowertrain & getPowertrainMap()
Get map of all powertrain kinodynamics.
Definition: laeKin.h:247
virtual void resetEStop()
Reset emergency stop condition.
Definition: laeKin.cxx:1085
virtual int resetOdometers()
Reset all motors&#39; odometers to the current respective encoder positions.
Definition: laeKin.cxx:1026
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bIsStopped
all motors are [not] stopped
Definition: laeKin.h:504
Laelaps common utilities.
virtual bool isIdle()
Test if action is idle.
Definition: laeKin.h:889
Laelaps kinematics velocity action class.
Definition: laeKin.h:1108
Laelaps powertrain class interfaces.
std::map< std::string, LaePowertrain > LaeMapPowertrain
Map of powertrain kinodynamics.
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
virtual int execute()
Execution [sub]action.
Definition: laeKin.h:866
virtual int getPowertrainState(const std::string &strName, LaePowertrainState &state)
Get the current powertrain state.
Definition: laeKin.cxx:970
pthread_mutex_t m_mutex
mutex
Definition: laeKin.h:529
Laelaps tuning.
virtual int senseDynamics()
Sense real-time kinodynamics.
Definition: laeKin.cxx:1435
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
virtual int sense()
Sense real-time state.
Definition: laeKin.cxx:1423
virtual ~LaeKinActionTwist()
Destructor.
Definition: laeKin.h:1121
virtual ActionState getActionState() const
Get the action state.
Definition: laeKin.h:942
Laelaps robotic platform control and dynamics state interface.
virtual void disableMotorCtlrs()
Disable power to motor controllers.
Definition: laeKin.cxx:276
move by motor duty cycles
Definition: laeKin.h:784
double m_fGoalVelAngular
goal platform angular velocity
Definition: laeKin.h:1164
LaePlatform & getPlatform()
Get robot platform kinodynamics.
Definition: laeKin.h:226
virtual int setGoalDutyCycles(const LaeMapDutyCycle &duty)
Set new or updated motor duty cycle goals.
Definition: laeKin.cxx:1322
Laelaps motors, encoder, and controllers hardware abstraction interfaces.
virtual int configMotorMaxAmpLimit(const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
Configure motor maximum ampere limit.
Definition: laeKin.cxx:798
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
virtual ~LaeKinActionVelocity()
Destructor.
Definition: laeKin.h:979
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
LaeMapVelocity m_mapGoalVel
map of goal velocities
Definition: laeKin.h:1020
virtual int close()
Close communication.
Definition: laeKin.cxx:221
move by angular velocities
Definition: laeKin.h:783
LaeMapDutyCycle m_mapGoalDutyCycle
map of goal duty cycles
Definition: laeKin.h:1087
Powertrain state data class.
LaeKinAction(LaeKinematics &kin, ActionType eActionType=ActionTypeIdle)
Default intialization constructor.
Definition: laeKin.h:808
RoboClaw communication class.
Definition: RoboClaw.h:487
virtual int release()
Release motors.
Definition: laeKin.cxx:1094
std::map< std::string, double > LaeMapVelocity
Velocity trajectory type.
Definition: laeTraj.h:258
virtual int configureMotorController(const LaeTunes &tunes, int nCtlr)
Configure motor controller.
Definition: laeKin.cxx:390
virtual bool isOpen() const
Test if connection is open.
Definition: RoboClaw.h:545
virtual int configMotorCtlrLogicCutoffs(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller logic cutoff voltages.
Definition: laeKin.cxx:512
virtual int reload(const LaeTunes &tunes)
Reload configuration tuning parameters.
Definition: laeKin.cxx:897
Powertrain data class.
virtual int saveConfigToNvm(int nCtlr)
Save configuration to motor controller&#39;s non-volatile memory.
Definition: laeKin.cxx:874
Laelaps kinematics velocity action class.
Definition: laeKin.h:966
virtual int plan()
Plan next execution.
Definition: laeKin.h:854
update action specific data
Definition: laeKin.h:796
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
virtual int monitorHealth()
Monitor kinematics health.
Definition: laeKin.cxx:1551
virtual void estop()
Emergency stop the robot.
Definition: laeKin.cxx:1064
Top-level package include file.
virtual ~LaeKinAction()
Destructor.
Definition: laeKin.h:817
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
Robot platform control and state data class.
Definition: laePlatform.h:127