![]() |
Hekateros
3.4.3
RoadNarrows Robotics Robot Arm Project
|
#include <hekKin.h>
Public Types | |
| enum | ThreadState { ThreadStateUninit, ThreadStateReady, ThreadStateRunning, ThreadStateExit } |
| Kinematics thread states. More... | |
| typedef map< std::string, HekKinJoint * > | KinChain |
| Associative Map of kinematic joints. | |
| typedef vector< std::string > | TaskList |
| Order list of tasks. | |
Public Member Functions | |
| HekKinematics (DynaChain &dynaChain, MapRobotJoints &kinJointDesc, const HekTunes &tunes) | |
| Default initializer constructor. More... | |
| virtual | ~HekKinematics () |
| Desctructor. | |
| virtual void | buildTaskList () |
| Build ordered list of tasks to execute. More... | |
| virtual void | reload (const HekTunes &tunes) |
| Reload configuration tuning parameters for all joints. More... | |
| virtual void | getJointCurPosVel (const std::string &strJointName, double &fJointCurPos, double &fJointCurVel) |
| Get the current instantaneous joint position and velocity. More... | |
| virtual void | getFilteredJointCurPosVel (const std::string &strJointName, double &fJointCurPos, double &fJointCurVel) |
| Get the smoothed (filtered) current joint position and velocity. More... | |
| void | getServoCurPosSpeed (const std::string &strJointName, int &nServoCurPos, int &nServoCurSpeed) |
| Get the current servo position and speed. More... | |
| int | jointPosToServoPos (const std::string &strJointName, const double fPos) |
| Convert joint position to the equivalent servo position. More... | |
| double | servoPosToJointPos (const std::string &strJointName, const int nOdPos) |
| Convert servo position to the equivalent joint position. More... | |
| virtual bool | isStopped (const std::string &strJointName) |
| Test if joint is moving. More... | |
| virtual bool | hasOverTorqueCondition (const std::string &strJointName) |
| Test if joint is in an over torque condition. More... | |
| virtual int | resetServoOdometersForAllJoints () |
| Reset all joints' master servos odometers to the current respective encoder positions. More... | |
| virtual int | resetServoOdometer (const std::string &strJointName) |
| Reset joint's master servo odometer to the current encoder position. More... | |
| virtual void | estop () |
| Emergency stop the kinematics chain. More... | |
| virtual void | freeze () |
| Freeze kinematics chain at the current position. More... | |
| virtual void | release () |
| Release kinematics chain. More... | |
| virtual int | stop () |
| Stop kinematics chain at the current position. More... | |
| virtual int | stop (const std::vector< std::string > &vecJointNames) |
| Stop the set of joints at the current position. More... | |
| virtual int | stop (const std::string &strJointName) |
| Stop one joint at the current position. More... | |
| virtual int | waitForAllStop (double fSeconds) |
| Wait for all joints to stop. More... | |
| virtual int | move (HekJointTrajectoryPoint &trajectoryPoint) |
| Move kinematic chain through a trajectory point. More... | |
| virtual int | move (const std::string &strJointName, const double fJointGoalPos, const double fJointGoalVel) |
| Move single joint. More... | |
| virtual void | setHz (const double fHz) |
| Set thread run rate and ancillary data. More... | |
| int | runThread (const double fHz=HekTuneKinHzDft) |
| Run the kinematics thread. More... | |
| void | waitOneCycle () |
| Wait one full cycle. More... | |
Protected Member Functions | |
| void | lock () |
| Lock the kinematics thread. More... | |
| void | unlock () |
| Unlock the kinematics thread. More... | |
| virtual void | sense () |
| Sense the state of all joints. More... | |
| virtual void | react () |
| React to any necessary time-critical joint events. More... | |
| virtual void | sense_react () |
| Sense-react the state of all joints. More... | |
| virtual void | plan () |
| Plan motions for all joints. More... | |
| virtual int | act () |
| Move all joints. More... | |
| virtual void | monitorHealth () |
| Monitor servo health thread task. More... | |
| virtual void | exec () |
| Execute kinematics task(s). More... | |
| void | createThread () |
| Create the kinematics thread. More... | |
| void | terminateThread () |
| Terminate the kinematics thread. More... | |
| void | changeState (ThreadState eNewState) |
| Change the kinematics thread state. More... | |
| void | readyWait () |
| Wait indefinitely while in the ready state. More... | |
| void | timedWait (const struct timespec &tsTimeout) |
| Timed wait until state change or time out. More... | |
| void | schedWait () |
| Block kinematics thread until the next subcycle task is to be run. More... | |
Static Protected Member Functions | |
| static void * | thread (void *pArg) |
| The kinematics thread. More... | |
Protected Attributes | |
| ThreadState | m_eState |
| thread state | |
| pthread_mutex_t | m_mutexSync |
| synchonization mutex | |
| pthread_cond_t | m_condSync |
| synchonization condition | |
| pthread_t | m_thread |
| pthread identifier | |
| DynaChain & | m_dynaChain |
| dynamixel chain | |
| KinChain | m_kinChain |
| kinematic chain | |
| int | m_nNumJoints |
| number of joints to control | |
| int | m_nNumServos |
| number of servos to monitor | |
| double | m_fHz |
| thread run rate (Hertz) | |
| double | m_fTExec |
| task execution period (seconds) | |
| struct timespec | m_tsExecPeriod |
| task execution period (converted) | |
| struct timespec | m_tsSched |
| working scheduler time stamp | |
| bool | m_bIsControlling |
| [not] actively controlling joints | |
| TaskList | m_taskList |
| list of tasks to exec per cycle | |
| TaskList::iterator | m_iterTask |
| task iterator | |
| std::string | m_strTaskOneCycle |
| task name one cycle away | |
| int | m_iterHealth |
| servo health iterator | |
| int | m_nHealthServoId |
| health monitoring servo id | |
Hekateros kinematics class.
The HekKinematics class supports background control and monitoring of registered joints and servos.
| enum hekateros::HekKinematics::ThreadState |
| HekKinematics::HekKinematics | ( | DynaChain & | dynaChain, |
| MapRobotJoints & | kinJointDesc, | ||
| const HekTunes & | tunes | ||
| ) |
Default initializer constructor.
| dynaChain | Bound Dynamixel chain of all motors (servos). |
| kinJointDesc | Joint descriptions in kinematic chain to control. |
| tunes | Hekateros tuning parameters. |
Definition at line 87 of file hekKin.cxx.
References buildTaskList(), createThread(), hekateros::HekRobotJoint::getJointName(), hekateros::HekRobotJoint::getMasterServoId(), hekateros::HekTuneKinHzMin, m_bIsControlling, m_condSync, m_dynaChain, m_eState, m_fHz, m_iterHealth, m_iterTask, m_kinChain, m_mutexSync, m_nHealthServoId, m_nNumJoints, m_nNumServos, m_taskList, and ThreadStateUninit.
|
protectedvirtual |
Move all joints.
Definition at line 608 of file hekKin.cxx.
References hekateros::HEK_ECODE_DYNA, hekateros::HEK_OK, m_bIsControlling, and m_dynaChain.
Referenced by monitorHealth(), and unlock().
|
virtual |
Build ordered list of tasks to execute.
Definition at line 174 of file hekKin.cxx.
References m_kinChain, and m_taskList.
Referenced by HekKinematics().
|
inlineprotected |
Change the kinematics thread state.
The thread, if blocked, will be immediately woken up.
| eNewState | New state. |
Definition at line 598 of file hekKin.h.
References readyWait(), schedWait(), and timedWait().
Referenced by runThread(), and terminateThread().
|
protected |
Create the kinematics thread.
The thread remains blocked in the ready state until runThread() is called.
Definition at line 809 of file hekKin.cxx.
References lock(), m_condSync, m_eState, m_mutexSync, m_thread, thread(), ThreadStateExit, and unlock().
Referenced by HekKinematics(), and unlock().
|
virtual |
Emergency stop the kinematics chain.
All servos will stop driving, so chain may fall.
Definition at line 356 of file hekKin.cxx.
References lock(), m_bIsControlling, m_dynaChain, stop(), unlock(), and waitForAllStop().
|
protectedvirtual |
Execute kinematics task(s).
Definition at line 687 of file hekKin.cxx.
References hekateros::HekKinJoint::act(), lock(), m_bIsControlling, m_condSync, m_iterTask, m_kinChain, m_strTaskOneCycle, m_taskList, monitorHealth(), hekateros::HekKinJoint::senseDynamics(), and unlock().
Referenced by monitorHealth(), thread(), and unlock().
|
virtual |
Freeze kinematics chain at the current position.
The joint servos are still being driven. However, all active joint motion control will cease.
Definition at line 373 of file hekKin.cxx.
References m_bIsControlling, stop(), and waitForAllStop().
|
virtual |
Get the smoothed (filtered) current joint position and velocity.
| [in] | strJointName | Joint name. |
| [out] | fJointCurPos | Current joint position (radians). |
| [out] | fJointCurVel | Current joint velocity (radians/second). |
Definition at line 254 of file hekKin.cxx.
References m_kinChain.
|
virtual |
Get the current instantaneous joint position and velocity.
| [in] | strJointName | Joint name. |
| [out] | fJointCurPos | Current joint position (radians). |
| [out] | fJointCurVel | Current joint velocity (radians/second). |
Definition at line 242 of file hekKin.cxx.
References m_kinChain.
| void HekKinematics::getServoCurPosSpeed | ( | const std::string & | strJointName, |
| int & | nServoCurPos, | ||
| int & | nServoCurSpeed | ||
| ) |
Get the current servo position and speed.
| [in] | strJointName | Joint name. |
| [out] | nServoCurPos | Current servo position (odometer ticks). |
| [out] | nServoCurSpeed | Current servo velocity (raw unitless). |
Definition at line 266 of file hekKin.cxx.
References m_kinChain.
|
virtual |
Test if joint is in an over torque condition.
| strJointName | Joint name. |
Definition at line 322 of file hekKin.cxx.
References m_kinChain.
|
virtual |
Test if joint is moving.
| strJointName | Joint name. |
Definition at line 308 of file hekKin.cxx.
References m_kinChain.
| int HekKinematics::jointPosToServoPos | ( | const std::string & | strJointName, |
| const double | fPos | ||
| ) |
Convert joint position to the equivalent servo position.
| strJointName | Joint name. |
| fPos | Joint position (radians). |
Definition at line 278 of file hekKin.cxx.
References m_kinChain.
|
inlineprotected |
Lock the kinematics thread.
The calling thread will block while waiting for the mutex to become available. Once locked, the kinematics thread will block.
The lock()/unlock() primitives provide a safe mechanism to modify the registered vServo data.
Definition at line 483 of file hekKin.h.
Referenced by createThread(), estop(), exec(), monitorHealth(), move(), readyWait(), release(), resetServoOdometersForAllJoints(), terminateThread(), timedWait(), and waitOneCycle().
|
protectedvirtual |
Monitor servo health thread task.
Definition at line 633 of file hekKin.cxx.
References act(), exec(), lock(), m_condSync, m_dynaChain, m_iterHealth, m_nHealthServoId, plan(), sense_react(), and unlock().
Referenced by exec(), and unlock().
|
virtual |
Move kinematic chain through a trajectory point.
| trajectoryPoint | Trajectory end point. |
Definition at line 500 of file hekKin.cxx.
References hekateros::HekJointTrajectoryPoint::getNumPoints(), lock(), m_bIsControlling, m_kinChain, and unlock().
|
virtual |
Move single joint.
| strJointName | Joint name. |
| fJointGoalPos | Joint goal position (radians). |
| fJointGoalVel | Joint goal velocity (radians/second). |
Definition at line 542 of file hekKin.cxx.
References hekateros::HEK_ECODE_BAD_VAL, lock(), m_bIsControlling, m_kinChain, and unlock().
|
protectedvirtual |
Plan motions for all joints.
Definition at line 598 of file hekKin.cxx.
References m_bIsControlling, m_kinChain, and m_taskList.
Referenced by monitorHealth(), and unlock().
|
protectedvirtual |
React to any necessary time-critical joint events.
Definition at line 577 of file hekKin.cxx.
References m_bIsControlling, m_kinChain, and m_taskList.
Referenced by unlock().
|
protected |
Wait indefinitely while in the ready state.
Definition at line 941 of file hekKin.cxx.
References lock(), m_condSync, m_eState, m_mutexSync, ThreadStateReady, and unlock().
Referenced by changeState(), and thread().
|
virtual |
Release kinematics chain.
Servos will stop driving, so the chain may fall. This call is assumed to be under control, so recalibration is not required. Typically, the chain is released during manual repositioning or teaching.
All active joint motion control will cease.
Definition at line 382 of file hekKin.cxx.
References lock(), m_bIsControlling, m_dynaChain, stop(), unlock(), and waitForAllStop().
|
virtual |
Reload configuration tuning parameters for all joints.
| tunes | Hekateros tuning parameters. |
Definition at line 208 of file hekKin.cxx.
References hekateros::HekTunes::m_fKinematicsHz, m_kinChain, and setHz().
|
virtual |
Reset joint's master servo odometer to the current encoder position.
| strJointName | Name of joint with master servo to reset. |
Definition at line 336 of file hekKin.cxx.
References hekateros::HEK_ECODE_BAD_VAL, m_kinChain, and waitOneCycle().
|
virtual |
Reset all joints' master servos odometers to the current respective encoder positions.
Definition at line 220 of file hekKin.cxx.
References hekateros::HEK_OK, lock(), m_kinChain, unlock(), and waitOneCycle().
| int HekKinematics::runThread | ( | const double | fHz = HekTuneKinHzDft | ) |
Run the kinematics thread.
| fHZ | Thread run rate (Hertz). |
Definition at line 871 of file hekKin.cxx.
References changeState(), hekateros::HEK_ECODE_GEN, hekateros::HEK_OK, m_eState, setHz(), ThreadStateExit, ThreadStateReady, and ThreadStateRunning.
|
protected |
Block kinematics thread until the next subcycle task is to be run.
Definition at line 965 of file hekKin.cxx.
References m_iterTask, m_tsExecPeriod, m_tsSched, and timedWait().
Referenced by changeState(), and thread().
|
protectedvirtual |
Sense the state of all joints.
Definition at line 567 of file hekKin.cxx.
References m_bIsControlling, m_kinChain, and m_taskList.
Referenced by unlock().
|
protectedvirtual |
Sense-react the state of all joints.
Definition at line 587 of file hekKin.cxx.
References m_bIsControlling, m_kinChain, and m_taskList.
Referenced by monitorHealth(), and unlock().
| double HekKinematics::servoPosToJointPos | ( | const std::string & | strJointName, |
| const int | nOdPos | ||
| ) |
Convert servo position to the equivalent joint position.
| strJointName | Joint name. |
| nOdPos | Servo position (odometer ticks). |
Definition at line 293 of file hekKin.cxx.
References m_kinChain.
|
virtual |
Set thread run rate and ancillary data.
| fHZ | Thread run rate (Hertz). |
Definition at line 850 of file hekKin.cxx.
References hekateros::fcap(), hekateros::HekTuneKinHzMin, m_fHz, m_fTExec, m_taskList, and m_tsExecPeriod.
Referenced by reload(), and runThread().
|
virtual |
Stop kinematics chain at the current position.
The joint servos are still being driven. However, all active joint motion control will cease.
Definition at line 399 of file hekKin.cxx.
References hekateros::HEK_ECODE_BAD_OP, hekateros::HEK_ECODE_BAD_VAL, hekateros::HEK_OK, m_bIsControlling, and m_kinChain.
Referenced by estop(), freeze(), and release().
|
virtual |
Stop the set of joints at the current position.
The joint servos are still being driven. However, all active joint motion control will cease.
| vecJointName | Vector list of joint names to stop. |
|
virtual |
Stop one joint at the current position.
The joint servos are still being driven. However, all active joint motion control will cease.
| strJointName | Name of joint. |
|
protected |
Terminate the kinematics thread.
This function does not return until the thread actually terminates.
Definition at line 895 of file hekKin.cxx.
References changeState(), lock(), m_condSync, m_mutexSync, m_thread, ThreadStateExit, unlock(), and waitOneCycle().
Referenced by unlock(), and ~HekKinematics().
|
staticprotected |
The kinematics thread.
| pArg | Thread argument (point to HekKinematics object). |
Definition at line 736 of file hekKin.cxx.
References exec(), m_eState, m_fHz, m_fTExec, m_tsSched, readyWait(), schedWait(), ThreadStateExit, ThreadStateReady, and ThreadStateRunning.
Referenced by createThread(), and unlock().
|
protected |
Timed wait until state change or time out.
| lMicroSec | Maximum wait duration (microseconds). |
Definition at line 956 of file hekKin.cxx.
References lock(), m_condSync, m_mutexSync, and unlock().
Referenced by changeState(), and schedWait().
|
inlineprotected |
Unlock the kinematics thread.
The kinematics thread will be available to run.
Definition at line 497 of file hekKin.h.
References act(), createThread(), exec(), monitorHealth(), plan(), react(), sense(), sense_react(), terminateThread(), and thread().
Referenced by createThread(), estop(), exec(), monitorHealth(), move(), readyWait(), release(), resetServoOdometersForAllJoints(), terminateThread(), timedWait(), and waitOneCycle().
|
virtual |
Wait for all joints to stop.
| fSeconds | Maximum number of seconds to wait. |
Definition at line 464 of file hekKin.cxx.
References hekateros::HEK_ECODE_TIMEDOUT, hekateros::HEK_OK, and m_kinChain.
Referenced by estop(), freeze(), and release().
| void HekKinematics::waitOneCycle | ( | ) |
Wait one full cycle.
Definition at line 915 of file hekKin.cxx.
References lock(), m_condSync, m_iterTask, m_mutexSync, m_strTaskOneCycle, m_taskList, and unlock().
Referenced by resetServoOdometer(), resetServoOdometersForAllJoints(), and terminateThread().