Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekateros::HekKinJoint Class Reference

Hekateros powered joint dynamics and kinematics control class. More...

#include <hekKinJoint.h>

Inheritance diagram for hekateros::HekKinJoint:
hekateros::HekKinJointWristRot

Public Types

enum  MoveState {
  MoveStateIdle,
  MoveStateNewMove,
  MoveStateMoving,
  MoveStateStopping
}
 Kinedynamics joint position and velocity control states. More...
 

Public Member Functions

 HekKinJoint ()
 Default constructor.
 
 HekKinJoint (HekRobotJoint *pJoint, DynaServo *pServo, const HekTunes &tunes)
 Initialization constructor. More...
 
virtual ~HekKinJoint ()
 Copy constructor. More...
 
virtual void coupleJoint (HekKinJoint *)
 Couple joint. More...
 
HekKinJointoperator= (const HekKinJoint &rhs)
 Assignment operator. More...
 
virtual void reload (const HekTunes &tunes)
 Reload configuration tuning parameters. More...
 
MoveState getMoveState ()
 Get move control state for this joint. More...
 
bool isMovingToGoal ()
 Test if actively moving joint to goal. More...
 
bool isStopping ()
 Test if actively stopping joint. More...
 
bool isMoving ()
 Test if actively moving joint. More...
 
virtual bool isStopped ()
 Test if joint is stopped (i.e. control is not active). More...
 
bool canStopNow ()
 Test if can stop now without slowing down. More...
 
void getPidKParams (double &fKp, double &fKi, double &fKd) const
 Get the joint's position and velocity PID K parameters. More...
 
void setPidKParams (const double fKp, const double fKi, const double fKd)
 Set the joint's position and velocity PID K parameters. More...
 
double getPidMaxDeltaVParam () const
 Get joint PID maximum delta v (radians/second) parameter. More...
 
void setPidMaxDeltaVParam (const double fMaxDeltaV)
 Set joint PID maximum delta v (radians/second) parameter. More...
 
void getToleranceParams (double &fTolPos, double &fTolVel) const
 Get the position and velocity tolerance parameters. More...
 
void setToleranceParams (const double fTolPos, const double fTolVel)
 Set the position and velocity tolerance parameters. More...
 
void getJointCurPosVel (double &fCurPos, double &fCurVel) const
 Get the instantaneous current joint position and velocity. More...
 
void getFilteredJointCurPosVel (double &fCurPos, double &fCurVel) const
 Get the smoothed (filtered) current joint position and velocity. More...
 
void getServoCurPosSpeed (int &nServoCurPos, int &nServoCurSpeed) const
 Get the instantaneous current servo position and speed. More...
 
void getTgtVelSpeed (double &fTgtVel, int &nTgtSpeed) const
 Get the PID output target joint velocity and the corresponding servo speed estemate. More...
 
virtual bool hasOverTorqueCondition ()
 Test if joint is in an over torque condition. More...
 
virtual int jointPosToServoPos (const double fPos)
 Convert joint position to the equivalent servo position. More...
 
virtual double servoPosToJointPos (const int nOdPos)
 Convert servo position to the equivalent joint position. More...
 
virtual int resetServoOdometer ()
 Reset servo odometer zero point to the current encoder position. More...
 
int specifyMove (const double fGoalPos, const double fGoalVel)
 Specify a new joint goal position and velocity move. More...
 
virtual int senseDynamics (bool bIsControlling)
 Sense (read) the current servo dynamics and transform to useful state. More...
 
virtual int react (bool bIsControlling, SyncMoveMsgs &msgs)
 React to recently read sensor data. More...
 
virtual MoveState planMotion (bool bIsControlling, SyncMoveMsgs &msgs)
 Plan motion. More...
 
virtual int act ()
 Act (write) to effect the servo dynamics for torque and motion control. More...
 
virtual int applyTorqueControl ()
 Apply torque limit control. More...
 
virtual MoveState move ()
 Move joint using joint PID controller. More...
 
virtual int stop ()
 Stop movement and move control of the joint. More...
 

Static Public Attributes

static const size_t POS_WIN_SIZE = 6
 Position sliding window size for low-pass band filtering of input positions.
 
static const size_t DT_WIN_SIZE = 10
 Delta t sliding window size for low-pass band filtering of input delta times.
 
static const size_t VEL_WIN_SIZE = 6
 Velocity sliding window size for low-pass band filtering of input Velocities.
 
static const double SLOW_DERATE_DELTA_V = 1.0
 Stop delta v as a fraction of max_delta_v tune parameter.
 
static const size_t TORQUE_WIN_SIZE = 4
 Torque sliding window size for low-pass band filtering of input torques.
 
static const int TORQUE_CTL_BACKOFF_SPEED = 100
 Torque control backoff speed (raw unitless)
 
static const int TORQUE_CTL_BACKOFF_POS = 5
 Torque control backoff positon (odometer ticks)
 

Protected Member Functions

void lock ()
 Lock the joint kinematics. More...
 
void unlock ()
 Unlock the joint kinematics. More...
 
double delta_t ()
 Calculate the delta time between calls to this. More...
 
double averageDt (double fDtAvg, double fDt)
 Apply a running average for the delta times (seconds). More...
 
int dejitterServoPos (int nServoCurPos, int nServoPrevPos)
 De-jitter servo odometer position. More...
 
double filterPositions (double fPosAvg, double fJointPos)
 Apply a low-pass band filter on the joint positions (radians). More...
 
double filterVelocities (double fVelAvg, double fJointVel)
 Apply a low-pass band filter on the joint velocities (radians/second). More...
 
double filterTorques (double fTorqueAvg, int nServoLoad)
 Apply a low-pass band filter on the sensed torques (loads). More...
 
int getGoalDir ()
 Get the current goal rotation direction. More...
 
int getPlannedDir (int nServoTgtSpeed)
 Get the planned target rotation direction. More...
 
bool canMoveInGoalDir ()
 Test if joint can move in direction of goal position. More...
 
bool canMoveInPlannedDir (int nServoTgtSpeed)
 Test if joint can move in planned direction. More...
 
virtual double jointVelocity (double fPos1, double fPos0, double fDt)
 Calculate the joint velocity from delta servo positions. More...
 
virtual void updateAssoc (double fJointVel, int nServoSpeed)
 Update joint velocity - servo speed association. More...
 
virtual int estimateServoTgtSpeed (double fJointTgtVel)
 Estimate of target servo speed from target joint velocity. More...
 
virtual int estimateServoTgtSpeedSimple (double fJointTgtVel)
 Simple estimate of target servo speed from target joint velocity. More...
 
void moveServo (int nServoGoalSpeed, int nServoGoalPos)
 Move servo. More...
 
void addServoMsgEntries (SyncMoveMsgs &msg, int nServoGoalSpeed, int nServoGoalPos)
 Add servo to synchronous move message(s). More...
 
virtual int nlspecifyMove (const double fGoalPos, const double fGoalVel)
 Specify a new joint goal position and velocity move (no lock version). More...
 
virtual int nlapplyTorqueControl ()
 Apply torque limit control (no lock version). More...
 
virtual MoveState nlmove ()
 Move joint using joint PID controller (no lock version). More...
 
virtual int nlstop ()
 Stop movement and move control of the joint (no lock version). More...
 
virtual int nlslowToStop (SyncMoveMsgs &msg)
 Slow to stop (no lock version). More...
 

Protected Attributes

MoveState m_eState
 joint control state
 
pthread_mutex_t m_mutexSync
 synchonization mutex
 
HekRobotJointm_pJoint
 joint description
 
DynaServo * m_pServo
 joint master servo control
 
double m_fTolPos
 joint position ± tolerance (rads)
 
double m_fTolVel
 joint velocity ± tolerance (rads/s)
 
double m_fStopVelTh
 joint velocity threshold to safely stop move
 
HekPid m_pid
 joint position and velocity PID
 
double m_fJointRadPerTick
 joint radians / odometer tick
 
double m_fJointGoalPos
 joint goal position (radians)
 
int m_nServoGoalPos
 servo goal position (odometer ticks)
 
double m_fJointCurPos
 joint current position (radians)
 
int m_nServoCurPos
 servo current position (odometer ticks)
 
double m_fJointPrevPos
 joint current position (radians)
 
int m_nServoPrevPos
 servo previous pos (odometer ticks)
 
double m_fJointPosOut
 low-pass filtered joint cur position
 
std::deque< double > m_histPosIn
 recent history of joint positions
 
double m_fDt
 delta time between positions reads
 
struct timespec m_tsPrev
 previous time mark
 
double m_fDtAvg
 average delta t
 
std::deque< double > m_histDtIn
 sliding window of delta t's
 
double m_fJointGoalVel
 joint goal velocity (radians/second)
 
double m_fJointCurVel
 joint current velocity (radians/second)
 
int m_nServoCurSpeed
 current motor speed (raw unitless)
 
double m_fVelDerate
 joint velocity derate (normalized)
 
VelSpeedLookupTbl m_tblVelSpeed
 dynamic velocity/speed lookup table
 
double m_fJointVelOut
 low-pass filtered joint cur velocity
 
std::deque< double > m_histVelIn
 sliding window of current velocities
 
double m_fJointTgtVel
 joint target velocity (radians/second)
 
int m_nServoTgtSpeed
 target motor speed (raw unitless)
 
bool m_bOverTorqueCond
 is [not] in torque overload condition
 
double m_fOverTorqueTh
 set over torque condition threshold
 
double m_fClearTorqueTh
 clear over torque condition threshold
 
int m_nServoCurLoad
 servo current load (raw unitless)
 
double m_fTorqueOut
 low-pass filtered torque
 
std::deque< double > m_histTorqueIn
 recent history of joint torques
 

Detailed Description

Hekateros powered joint dynamics and kinematics control class.

One or more motors can power a joint. Two or more joints may be coupled (e.g. wrist pitch and rotation). Motors can be actuators with built in controllers, DC motors, synthetic muscle, or any other physical entity that can provide usefull force and be controlled.

Currently, only Dynamixels actuators (servos) are supported.

Definition at line 387 of file hekKinJoint.h.

Member Enumeration Documentation

enum hekateros::HekKinJoint::MoveState

Kinedynamics joint position and velocity control states.

Note
Actively apply torque control in an over torque condition is somewhat independent of the control states.
Enumerator
MoveStateIdle 

no active goal or stopping control

MoveStateNewMove 

start move to new goal

MoveStateMoving 

actively moving to goal

MoveStateStopping 

actively stopping joint

Definition at line 435 of file hekKinJoint.h.

436  {
437  MoveStateIdle, ///< no active goal or stopping control
438  MoveStateNewMove, ///< start move to new goal
439  MoveStateMoving, ///< actively moving to goal
440  MoveStateStopping, ///< actively stopping joint
441  };
no active goal or stopping control
Definition: hekKinJoint.h:437

Constructor & Destructor Documentation

HekKinJoint::HekKinJoint ( HekRobotJoint pJoint,
DynaServo *  pServo,
const HekTunes tunes 
)

Initialization constructor.

Parameters
pJointPointer to joint description.
pServoPointer to master servo controller.
tunesHekateros tuning parameters.

Definition at line 441 of file hekKinJoint.cxx.

References hekateros::VelSpeedLookupTbl::create(), hekateros::degToRad(), hekateros::HekTunes::getPidKParams(), hekateros::HekTunes::getPidMaxDeltaV(), hekateros::HekTunes::getToleranceParams(), hekateros::HekTunes::getTorqueParams(), hekateros::HekTunes::getVelocityDerate(), m_bOverTorqueCond, m_eState, m_fClearTorqueTh, m_fDt, m_fDtAvg, m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointGoalVel, m_fJointPosOut, m_fJointPrevPos, m_fJointRadPerTick, m_fJointTgtVel, m_fJointVelOut, hekateros::HekRobotJoint::m_fMaxJointRadsPerSec, m_fOverTorqueTh, m_fStopVelTh, hekateros::HekRobotJoint::m_fTicksPerJointRad, m_fTolPos, m_fTolVel, m_fTorqueOut, m_fVelDerate, m_mutexSync, m_nServoCurPos, m_nServoCurSpeed, m_nServoGoalPos, m_nServoPrevPos, m_nServoTgtSpeed, m_pJoint, hekateros::HekRobotJoint::m_strName, m_tblVelSpeed, m_tsPrev, MoveStateIdle, setPidKParams(), setPidMaxDeltaVParam(), and SLOW_DERATE_DELTA_V.

443  :
444  m_pJoint(pJoint), m_pServo(pServo),
446  m_histDtIn(DT_WIN_SIZE, 0.0),
449 {
450  double fKp, fKi, fKd;
451  double fMaxDeltaV;
452  double fRawMaxTorque;
453 
455 
456  pthread_mutex_init(&m_mutexSync, NULL);
457 
458  // joint tolerance tuning parameters (normalized)
460 
461  // joint position and velocity PID tuning parameters
462  tunes.getPidKParams(pJoint->m_strName, fKp, fKi, fKd);
463 
464  // pid constants
465  setPidKParams(fKp, fKi, fKd);
466 
467  // joint pid maximum delta velocity tuning paramter
468  fMaxDeltaV = tunes.getPidMaxDeltaV(m_pJoint->m_strName);
469 
470  // maximum PID output delta v (radians/second)
471  setPidMaxDeltaVParam(fMaxDeltaV);
472 
473  // stop velocity maximum velocity
474  m_fStopVelTh = SLOW_DERATE_DELTA_V * fMaxDeltaV;
475 
476  // position state
478  m_fJointGoalPos = 0.0;
479  m_nServoGoalPos = 0;
480  m_fJointCurPos = 0.0;
481  m_nServoCurPos = 0;
482  m_fJointPrevPos = 0.0;
483  m_nServoPrevPos = 0;
484  m_fJointPosOut = 0.0;
485 
486  // clock
487  m_fDt = 0.0;
488  clock_gettime(CLOCK_REALTIME, &m_tsPrev);
489  m_fDtAvg = 0.0;
490 
491  // velocity state
492  m_fJointGoalVel = 0.0;
493  m_fJointCurVel = 0.0;
494  m_nServoCurSpeed = 0;
495  m_fVelDerate = tunes.getVelocityDerate(); // tuning parameter (norm)
496  m_fJointVelOut = 0.0;
497 
498  m_fJointTgtVel = 0.0;
499  m_nServoTgtSpeed = 0;
500 
501  // To debug any joint(s).
502  //if( m_pJoint->m_strName == "base_rot")
503  //{
504  // m_tblVelSpeed.enableDebugging(m_pJoint->m_strName);
505  //}
506 
508 
509  // normalized joint torque tuning parameters
511 
512  // convert to raw theshold values
513  m_bOverTorqueCond = false;
514  fRawMaxTorque = (double)pServo->GetSpecification().m_uRawTorqueMax;
515  m_fOverTorqueTh *= fRawMaxTorque;
516  m_fClearTorqueTh *= fRawMaxTorque;
517  m_fTorqueOut = 0.0;
518 }
double m_fOverTorqueTh
set over torque condition threshold
Definition: hekKinJoint.h:855
void getToleranceParams(const std::string &strJointName, double &fTolPos, double &fTolVel) const
Get joint tolerance tune parameters.
Definition: hekTune.cxx:101
double m_fVelDerate
joint velocity derate (normalized)
Definition: hekKinJoint.h:844
std::deque< double > m_histPosIn
recent history of joint positions
Definition: hekKinJoint.h:832
double m_fStopVelTh
joint velocity threshold to safely stop move
Definition: hekKinJoint.h:820
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double getPidMaxDeltaV(const std::string &strJointName) const
Get joint PID maximum delta v (radians/second) tune parameter.
Definition: hekTune.cxx:137
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
static const double SLOW_DERATE_DELTA_V
Stop delta v as a fraction of max_delta_v tune parameter.
Definition: hekKinJoint.h:411
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double m_fJointVelOut
low-pass filtered joint cur velocity
Definition: hekKinJoint.h:846
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
double m_fTicksPerJointRad
encoder/odom. ticks per joint radian
Definition: hekJoint.h:157
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: hekKinJoint.h:859
double m_fMaxJointRadsPerSec
maximum joint radians per second
Definition: hekJoint.h:159
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
double getVelocityDerate() const
Get derated velocity tune parameter (normalized).
Definition: hekTune.h:451
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: hekKinJoint.h:813
static const size_t POS_WIN_SIZE
Position sliding window size for low-pass band filtering of input positions.
Definition: hekKinJoint.h:394
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
void setPidKParams(const double fKp, const double fKi, const double fKd)
Set the joint&#39;s position and velocity PID K parameters.
Definition: hekKinJoint.h:589
double m_fDt
delta time between positions reads
Definition: hekKinJoint.h:835
static const size_t DT_WIN_SIZE
Delta t sliding window size for low-pass band filtering of input delta times.
Definition: hekKinJoint.h:400
void create(double fJointMaxVel, double fBucketSize)
Create lookup table.
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
void getTorqueParams(const std::string &strJointName, double &fOverTorqueTh, double &fClearTorqueTh) const
Get joint torque parameters.
Definition: hekTune.cxx:151
double m_fJointPrevPos
joint current position (radians)
Definition: hekKinJoint.h:829
double m_fJointPosOut
low-pass filtered joint cur position
Definition: hekKinJoint.h:831
double m_fTorqueOut
low-pass filtered torque
Definition: hekKinJoint.h:858
std::deque< double > m_histDtIn
sliding window of delta t&#39;s
Definition: hekKinJoint.h:838
int m_nServoPrevPos
servo previous pos (odometer ticks)
Definition: hekKinJoint.h:830
double m_fJointRadPerTick
joint radians / odometer tick
Definition: hekKinJoint.h:824
static const size_t VEL_WIN_SIZE
Velocity sliding window size for low-pass band filtering of input Velocities.
Definition: hekKinJoint.h:406
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
std::deque< double > m_histVelIn
sliding window of current velocities
Definition: hekKinJoint.h:847
std::string m_strName
joint name
Definition: hekJoint.h:149
double degToRad(double d)
Convert degrees to radians.
Definition: hekUtils.h:125
static const size_t TORQUE_WIN_SIZE
Torque sliding window size for low-pass band filtering of input torques.
Definition: hekKinJoint.h:417
no active goal or stopping control
Definition: hekKinJoint.h:437
struct timespec m_tsPrev
previous time mark
Definition: hekKinJoint.h:836
void setPidMaxDeltaVParam(const double fMaxDeltaV)
Set joint PID maximum delta v (radians/second) parameter.
Definition: hekKinJoint.h:609
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
VelSpeedLookupTbl m_tblVelSpeed
dynamic velocity/speed lookup table
Definition: hekKinJoint.h:845
double m_fJointGoalVel
joint goal velocity (radians/second)
Definition: hekKinJoint.h:841
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
double m_fDtAvg
average delta t
Definition: hekKinJoint.h:837
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
double m_fClearTorqueTh
clear over torque condition threshold
Definition: hekKinJoint.h:856
void getPidKParams(const std::string &strJointName, double &fKp, double &fKi, double &fKd) const
Get joint PID K tune parameters.
Definition: hekTune.cxx:118
virtual hekateros::HekKinJoint::~HekKinJoint ( )
inlinevirtual

Copy constructor.

Parameters
srcSource object.

Destructor.

Definition at line 469 of file hekKinJoint.h.

470  {
471  nlstop();
472  pthread_mutex_destroy(&m_mutexSync);
473  }
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: hekKinJoint.h:813

Member Function Documentation

int HekKinJoint::act ( )
virtual

Act (write) to effect the servo dynamics for torque and motion control.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 938 of file hekKinJoint.cxx.

References canMoveInGoalDir(), hekateros::HEK_OK, isMovingToGoal(), lock(), m_bOverTorqueCond, nlapplyTorqueControl(), nlmove(), and unlock().

Referenced by hekateros::HekKinematics::exec().

939 {
940  lock();
941 
942  //
943  // Actively moving joint and there is no over torque condition or the goal
944  // direction will naturally ease the torque.
945  //
946  if( isMovingToGoal() && canMoveInGoalDir() )
947  {
948  nlmove();
949  }
950 
951  //
952  // In over torque condition, apply torque control.
953  //
954  else if( m_bOverTorqueCond )
955  {
957  }
958 
959  unlock();
960 
961  return HEK_OK;
962 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
virtual int nlapplyTorqueControl()
Apply torque limit control (no lock version).
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
bool isMovingToGoal()
Test if actively moving joint to goal.
Definition: hekKinJoint.h:521
bool canMoveInGoalDir()
Test if joint can move in direction of goal position.
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
virtual MoveState nlmove()
Move joint using joint PID controller (no lock version).
void HekKinJoint::addServoMsgEntries ( SyncMoveMsgs msg,
int  nServoGoalSpeed,
int  nServoGoalPos 
)
protected

Add servo to synchronous move message(s).

Parameters
msgsSynchronous move messages container object.
nServoGoalSpeedServo goal speed (raw unitless).
nServoGoalPosServo goal position (odometer ticks).

Definition at line 1118 of file hekKinJoint.cxx.

References hekateros::SyncMoveMsgs::addOdPos(), hekateros::SyncMoveMsgs::addSpeed(), hekateros::cap(), hekateros::iabs(), m_eState, m_nServoTgtSpeed, m_pServo, MoveStateMoving, and MoveStateNewMove.

Referenced by nlslowToStop(), hekateros::HekKinJointWristRot::nlslowToStop(), planMotion(), and hekateros::HekKinJointWristRot::planMotion().

1121 {
1122  //
1123  // See discussion in moveServo() for Dynamixel nuances.
1124  //
1125  if( m_pServo->GetServoMode() == DYNA_MODE_CONTINUOUS )
1126  {
1127  nServoTgtSpeed = cap(nServoTgtSpeed, -DYNA_SPEED_MAX_RAW,
1128  DYNA_SPEED_MAX_RAW);
1129  msgs.addSpeed(m_pServo->GetServoId(), nServoTgtSpeed);
1130  }
1131  else
1132  {
1133  m_nServoTgtSpeed = cap(iabs(nServoTgtSpeed), DYNA_SPEED_MIN_CTL,
1134  DYNA_SPEED_MAX_RAW);
1135  msgs.addSpeed(m_pServo->GetServoId(), nServoTgtSpeed);
1136  if( m_eState == MoveStateNewMove )
1137  {
1138  msgs.addOdPos(m_pServo->GetServoId(), nServoGoalPos);
1140  }
1141  }
1142 }
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int cap(int a, int min, int max)
Cap value within limits [min, max].
Definition: hekUtils.h:177
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
int iabs(int a)
Integer absolute value.
Definition: hekUtils.h:149
int HekKinJoint::applyTorqueControl ( )
virtual

Apply torque limit control.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 964 of file hekKinJoint.cxx.

References hekateros::HEK_OK, lock(), m_pServo, nlapplyTorqueControl(), and unlock().

965 {
966  int rc;
967 
968  if( m_pServo == NULL )
969  {
970  return HEK_OK;
971  }
972 
973  lock();
974 
975  rc = nlapplyTorqueControl();
976 
977  unlock();
978 
979  return rc;
980 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
virtual int nlapplyTorqueControl()
Apply torque limit control (no lock version).
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
double HekKinJoint::averageDt ( double  fDtAvg,
double  fDt 
)
protected

Apply a running average for the delta times (seconds).

A simple moving average (SMa) of delta times with a window size of DT_WIN_SIZE is used.

Parameters
fDtAvgCurrent delta time average (seconds).
fDtNew delta time (seconds).
Returns
New average delta time (seconds).

Definition at line 1305 of file hekKinJoint.cxx.

References DT_WIN_SIZE, and m_histDtIn.

1306 {
1307  double fDt0;
1308  double fDtK;
1309 
1310  fDt0 = fDt / (double)DT_WIN_SIZE;
1311  fDtK = m_histDtIn.back();
1312  m_histDtIn.pop_back();
1313  m_histDtIn.push_front(fDt0);
1314 
1315  return fDtAvg - fDtK + fDt0;
1316 }
static const size_t DT_WIN_SIZE
Delta t sliding window size for low-pass band filtering of input delta times.
Definition: hekKinJoint.h:400
std::deque< double > m_histDtIn
sliding window of delta t&#39;s
Definition: hekKinJoint.h:838
bool HekKinJoint::canMoveInGoalDir ( )
protected

Test if joint can move in direction of goal position.

The joint must not be in an over torque condition or the move will ease the torque, not exacerbate the condition.

Returns
Returns true or false.

Definition at line 749 of file hekKinJoint.cxx.

References getGoalDir(), m_bOverTorqueCond, and m_nServoCurLoad.

Referenced by act(), and hekateros::HekKinJointWristRot::act().

750 {
751  return !m_bOverTorqueCond || (getGoalDir() == DYNA_GET_DIR(m_nServoCurLoad));
752 }
int m_nServoCurLoad
servo current load (raw unitless)
Definition: hekKinJoint.h:857
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
int getGoalDir()
Get the current goal rotation direction.
bool HekKinJoint::canMoveInPlannedDir ( int  nServoTgtSpeed)
protected

Test if joint can move in planned direction.

The joint must not be in an over torque condition or the move will ease the torque, not worsen the condition.

Parameters
nServoTgtSpeedPlanned servo target speed (raw unitless).
Returns
Returns true or false.

Definition at line 754 of file hekKinJoint.cxx.

References getPlannedDir(), m_bOverTorqueCond, and m_nServoCurLoad.

Referenced by planMotion(), and hekateros::HekKinJointWristRot::planMotion().

755 {
756  return !m_bOverTorqueCond ||
757  (getPlannedDir(nServoTgtSpeed) == DYNA_GET_DIR(m_nServoCurLoad));
758 }
int m_nServoCurLoad
servo current load (raw unitless)
Definition: hekKinJoint.h:857
int getPlannedDir(int nServoTgtSpeed)
Get the planned target rotation direction.
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
bool hekateros::HekKinJoint::canStopNow ( )
inline

Test if can stop now without slowing down.

Returns
Returns true or false.

Definition at line 561 of file hekKinJoint.h.

References hekateros::HekOpStateCalibrated, and hekateros::HekTunePidDeltaVNoMax.

Referenced by nlstop(), react(), and hekateros::HekKinJointWristRot::react().

562  {
565  (fabs(m_fJointCurVel) <= m_fStopVelTh);
566  }
HekOpState m_eOpState
current operational state
Definition: hekJoint.h:179
static const double HekTunePidDeltaVNoMax
No maximum PID delta V output special value.
Definition: hekTune.h:319
double m_fStopVelTh
joint velocity threshold to safely stop move
Definition: hekKinJoint.h:820
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
virtual void hekateros::HekKinJoint::coupleJoint ( HekKinJoint )
inlinevirtual

Couple joint.

Parameters
pKinJointCoupledBase class joint has no coupled joint.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 480 of file hekKinJoint.h.

481  {
482  // N/A
483  }
int HekKinJoint::dejitterServoPos ( int  nServoCurPos,
int  nServoPrevPos 
)
protected

De-jitter servo odometer position.

The servo can report encoder position of 1.

Parameters
nServoCurPosServo current odometer position.
nServoPrevPosServo previous odometer position.
Returns
Return de-jittered current servo position.

Definition at line 1318 of file hekKinJoint.cxx.

References hekateros::iabs().

Referenced by senseDynamics().

1319 {
1320  // Same position over two sense cycles - accept new position.
1321  if( nServoCurPos == nServoPrevPos )
1322  {
1323  return nServoCurPos;
1324  }
1325 
1326  // Sufficiently large jump in position, probably not jitter.
1327  else if( hekateros::iabs(nServoCurPos-nServoPrevPos) > 1 )
1328  {
1329  return nServoCurPos;
1330  }
1331 
1332  // Small change is position, treat as sampling and/or random jitter.
1333  else
1334  {
1335  return nServoPrevPos;
1336  }
1337 }
int iabs(int a)
Integer absolute value.
Definition: hekUtils.h:149
double HekKinJoint::delta_t ( )
protected

Calculate the delta time between calls to this.

Returns
Delta time secs.frac (seconds).

Definition at line 1288 of file hekKinJoint.cxx.

References hekateros::dt(), and m_tsPrev.

Referenced by senseDynamics().

1289 {
1290  struct timespec tsNow;
1291  double deltaTime;
1292 
1293  // now
1294  clock_gettime(CLOCK_REALTIME, &tsNow);
1295 
1296  // delta time in seconds
1297  deltaTime = hekateros::dt(tsNow, m_tsPrev);
1298 
1299  // new previous
1300  m_tsPrev = tsNow;
1301 
1302  return deltaTime;
1303 }
double dt(struct timeval &t1, struct timeval &t0)
Calculate delta time.
struct timespec m_tsPrev
previous time mark
Definition: hekKinJoint.h:836
int HekKinJoint::estimateServoTgtSpeed ( double  fJointTgtVel)
protectedvirtual

Estimate of target servo speed from target joint velocity.

The Dynamixel speed value is a raw, unitless (and probably non-linear) value. The estimate is made using linear interpolation from a dynamically maintained velocity,speed lookup table.

Parameters
fJointTgtVelTarget joint velocity (radians/seconds).
Returns
Servo speed estimate matching target velocity.

Definition at line 1264 of file hekKinJoint.cxx.

References hekateros::VelSpeedLookupTbl::estimate(), m_pServo, m_tblVelSpeed, and hekateros::signof().

Referenced by nlmove(), hekateros::HekKinJointWristRot::nlmove(), nlslowToStop(), hekateros::HekKinJointWristRot::nlslowToStop(), planMotion(), and hekateros::HekKinJointWristRot::planMotion().

1265 {
1266  int nSign = (int)signof(fJointTgtVel);
1267 
1268  if( m_pServo->IsOdometerReversed() )
1269  {
1270  nSign = -nSign;
1271  }
1272 
1273  return nSign * m_tblVelSpeed.estimate(fJointTgtVel);
1274 }
int estimate(double fJointGoalVel)
Estimate servo goal speed.
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double signof(double a)
Sign of a.
Definition: hekUtils.h:187
VelSpeedLookupTbl m_tblVelSpeed
dynamic velocity/speed lookup table
Definition: hekKinJoint.h:845
int HekKinJoint::estimateServoTgtSpeedSimple ( double  fJointTgtVel)
protectedvirtual

Simple estimate of target servo speed from target joint velocity.

The Dynamixel speed value is a raw, unitless (and probably non-linear) value. The estimate is made by interpolating the current speed between 0 and the maximum unloaded joint velocity.

Parameters
fJointTgtVelTarget joint velocity (radians/seconds).
Returns
Servo speed estimate matching target velocity.

Definition at line 1276 of file hekKinJoint.cxx.

References hekateros::cap(), getGoalDir(), hekateros::HekRobotJoint::m_fMaxJointRadsPerSec, and m_pJoint.

1277 {
1278  double r;
1279  int nSpeedEst;
1280 
1281  r = fJointTgtVel / m_pJoint->m_fMaxJointRadsPerSec;
1282  nSpeedEst = (int)(DYNA_SPEED_MAX_RAW * r);
1283  nSpeedEst = cap(nSpeedEst, 0, DYNA_SPEED_MAX_RAW) * getGoalDir();
1284 
1285  return nSpeedEst;
1286 }
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double m_fMaxJointRadsPerSec
maximum joint radians per second
Definition: hekJoint.h:159
int cap(int a, int min, int max)
Cap value within limits [min, max].
Definition: hekUtils.h:177
int getGoalDir()
Get the current goal rotation direction.
double HekKinJoint::filterPositions ( double  fPosAvg,
double  fJointPos 
)
protected

Apply a low-pass band filter on the joint positions (radians).

A simple moving average (SMA) of positions with a window size of POS_WIN_SIZE is used as the filter.

Parameters
fPosAvgCurrent joint position average (radians).
fJointPosNew joint position (radians).
Returns
New filtered joint position (radians).

Definition at line 1339 of file hekKinJoint.cxx.

References m_histPosIn, and POS_WIN_SIZE.

Referenced by senseDynamics().

1340 {
1341  double fPos0;
1342  double fPosK;
1343 
1344  fPos0 = fJointPos / (double)POS_WIN_SIZE;
1345  fPosK = m_histPosIn.back();
1346  m_histPosIn.pop_back();
1347  m_histPosIn.push_front(fPos0);
1348 
1349  return fPosAvg - fPosK + fPos0;
1350 }
std::deque< double > m_histPosIn
recent history of joint positions
Definition: hekKinJoint.h:832
static const size_t POS_WIN_SIZE
Position sliding window size for low-pass band filtering of input positions.
Definition: hekKinJoint.h:394
double HekKinJoint::filterTorques ( double  fTorqueAvg,
int  nServoLoad 
)
protected

Apply a low-pass band filter on the sensed torques (loads).

The torques are interpreted from the read servo loads which are unitless values (and probably non-linear).

A simple moving average (SMA) of load values with a window size of TORQUE_WIN_SIZE is used as the filter.

Parameters
fTorqueAvgCurrent torque (load) average value.
nServoLoadNew servo load value (raw unitless).
Returns
New torque average (raw unitless).

Definition at line 1365 of file hekKinJoint.cxx.

References m_histTorqueIn, and TORQUE_WIN_SIZE.

Referenced by nlapplyTorqueControl(), and senseDynamics().

1366 {
1367  double fTorque0;
1368  double fTorqueK;
1369 
1370  fTorque0 = (double)nServoLoad / (double)TORQUE_WIN_SIZE;
1371  fTorqueK = m_histTorqueIn.back();
1372  m_histTorqueIn.pop_back();
1373  m_histTorqueIn.push_front(fTorque0);
1374 
1375  return fTorqueAvg - fTorqueK + fTorque0;
1376 }
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: hekKinJoint.h:859
static const size_t TORQUE_WIN_SIZE
Torque sliding window size for low-pass band filtering of input torques.
Definition: hekKinJoint.h:417
double HekKinJoint::filterVelocities ( double  fVelAvg,
double  fJointVel 
)
protected

Apply a low-pass band filter on the joint velocities (radians/second).

A simple moving average (SMA) of velocities with a window size of VEL_WIN_SIZE is used as the filter.

Parameters
fVelAvgCurrent joint velocitie average (radians/second).
fJointVelNew joint velocity (radians/second).
Returns
New filtered joint velocity (radians/second).

Definition at line 1352 of file hekKinJoint.cxx.

References m_histVelIn, and VEL_WIN_SIZE.

Referenced by senseDynamics().

1353 {
1354  double fVel0;
1355  double fVelK;
1356 
1357  fVel0 = fJointVel / (double)VEL_WIN_SIZE;
1358  fVelK = m_histVelIn.back();
1359  m_histVelIn.pop_back();
1360  m_histVelIn.push_front(fVel0);
1361 
1362  return fVelAvg - fVelK + fVel0;
1363 }
static const size_t VEL_WIN_SIZE
Velocity sliding window size for low-pass band filtering of input Velocities.
Definition: hekKinJoint.h:406
std::deque< double > m_histVelIn
sliding window of current velocities
Definition: hekKinJoint.h:847
void hekateros::HekKinJoint::getFilteredJointCurPosVel ( double &  fCurPos,
double &  fCurVel 
) const
inline

Get the smoothed (filtered) current joint position and velocity.

Parameters
[out]fCurPosCurrent joint position (radians).
[out]fCurVelCurrent joint velocity (radians/second).

Definition at line 662 of file hekKinJoint.h.

663  {
664  fCurPos = m_fJointPosOut;
665  fCurVel = m_fJointVelOut;
666  }
double m_fJointVelOut
low-pass filtered joint cur velocity
Definition: hekKinJoint.h:846
double m_fJointPosOut
low-pass filtered joint cur position
Definition: hekKinJoint.h:831
int HekKinJoint::getGoalDir ( )
protected

Get the current goal rotation direction.

The direction is deterimed by the difference of current odometer value and the goal position.

Normally counter-clockwise is positive, clockwise is negative, but the sence can be reversed in the odometer configuration.

Returns
1 or -1.

Definition at line 737 of file hekKinJoint.cxx.

References m_nServoGoalPos, and m_pServo.

Referenced by canMoveInGoalDir(), and estimateServoTgtSpeedSimple().

738 {
739  int nSign = m_pServo->IsOdometerReversed()? -1: 1;
740 
741  return (m_nServoGoalPos-m_pServo->GetOdometer()) >= 0? nSign: -1 * nSign;
742 }
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
void hekateros::HekKinJoint::getJointCurPosVel ( double &  fCurPos,
double &  fCurVel 
) const
inline

Get the instantaneous current joint position and velocity.

Parameters
[out]fCurPosCurrent joint position (radians).
[out]fCurVelCurrent joint velocity (radians/second).

Definition at line 650 of file hekKinJoint.h.

651  {
652  fCurPos = m_fJointCurPos;
653  fCurVel = m_fJointCurVel;
654  }
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
MoveState hekateros::HekKinJoint::getMoveState ( )
inline

Get move control state for this joint.

Returns
MoveState

Definition at line 511 of file hekKinJoint.h.

Referenced by hekateros::HekKinJointWristRot::coupleJoint().

512  {
513  return m_eState;
514  }
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
void hekateros::HekKinJoint::getPidKParams ( double &  fKp,
double &  fKi,
double &  fKd 
) const
inline

Get the joint's position and velocity PID K parameters.

Parameters
[out]fKpProportional gain parameter.
[out]fKiIntegral gain parameter.
[out]fKdDerivative gain parameter.

Definition at line 575 of file hekKinJoint.h.

576  {
577  m_pid.getKParams(fKp, fKi, fKd);
578  }
void getKParams(double &fKp, double &fKi, double &fKd) const
Get the position and velocity PID K parameters.
Definition: hekPid.h:137
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
double hekateros::HekKinJoint::getPidMaxDeltaVParam ( ) const
inline

Get joint PID maximum delta v (radians/second) parameter.

Returns
Maximum output delta velocity (radians/second).

Definition at line 599 of file hekKinJoint.h.

600  {
601  return m_pid.getMaxDeltaVParam();
602  }
double getMaxDeltaVParam() const
Get the maximum delta V (ramp) parameter (radians/second).
Definition: hekPid.h:165
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
int HekKinJoint::getPlannedDir ( int  nServoTgtSpeed)
protected

Get the planned target rotation direction.

The direction is deterimed sign of the servo speed.

Normally counter-clockwise is positive, clockwise is negative, but the sence can be reversed in the odometer configuration.

Parameters
nServoTgtSpeedPlanned servo target speed (raw unitless). Odometer configuration is already added!
Returns
1 or -1.

Definition at line 744 of file hekKinJoint.cxx.

Referenced by canMoveInPlannedDir().

745 {
746  return nServoTgtSpeed >= 0? 1: -1;
747 }
void hekateros::HekKinJoint::getServoCurPosSpeed ( int &  nServoCurPos,
int &  nServoCurSpeed 
) const
inline

Get the instantaneous current servo position and speed.

Parameters
[out]nServoCurPosCurrent servo position (odometer ticks).
[out]nServoCurSpeedCurrent servo velocity (raw unitless).

Definition at line 674 of file hekKinJoint.h.

675  {
676  nServoCurPos = m_nServoCurPos;
677  nServoCurSpeed = m_nServoCurSpeed;
678  }
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
void hekateros::HekKinJoint::getTgtVelSpeed ( double &  fTgtVel,
int &  nTgtSpeed 
) const
inline

Get the PID output target joint velocity and the corresponding servo speed estemate.

Parameters
[out]fTgtVelTarget joint velocity (radians/second).
[out]nTgtSpeedTarget servo speed (raw unitless).

Definition at line 687 of file hekKinJoint.h.

688  {
689  fTgtVel = m_fJointTgtVel;
690  nTgtSpeed = m_nServoTgtSpeed;
691  }
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
void hekateros::HekKinJoint::getToleranceParams ( double &  fTolPos,
double &  fTolVel 
) const
inline

Get the position and velocity tolerance parameters.

The joint PID will try to control to the goal position ± position tolerance and to the goal velocity ± velocity tolerance.

Parameters
[out]fTolPosJoint position tolerance (radians).
[out]fTolVelJoint velocity tolerance (radians/second).

Definition at line 623 of file hekKinJoint.h.

624  {
625  fTolPos = m_fTolPos;
626  fTolVel = m_fTolVel;
627  }
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
virtual bool hekateros::HekKinJoint::hasOverTorqueCondition ( )
inlinevirtual

Test if joint is in an over torque condition.

Returns
Returns true if in condition, false otherwise.

Definition at line 698 of file hekKinJoint.h.

699  {
700  return m_bOverTorqueCond;
701  }
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
bool hekateros::HekKinJoint::isMoving ( )
inline

Test if actively moving joint.

Returns
Returns true or false.

Definition at line 541 of file hekKinJoint.h.

542  {
543  return isMovingToGoal() || isStopping();
544  }
bool isMovingToGoal()
Test if actively moving joint to goal.
Definition: hekKinJoint.h:521
bool isStopping()
Test if actively stopping joint.
Definition: hekKinJoint.h:531
bool hekateros::HekKinJoint::isMovingToGoal ( )
inline

Test if actively moving joint to goal.

Returns
Returns true or false.

Definition at line 521 of file hekKinJoint.h.

Referenced by act(), hekateros::HekKinJointWristRot::act(), nlmove(), hekateros::HekKinJointWristRot::nlmove(), planMotion(), hekateros::HekKinJointWristRot::planMotion(), react(), and hekateros::HekKinJointWristRot::react().

522  {
524  }
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
virtual bool hekateros::HekKinJoint::isStopped ( )
inlinevirtual

Test if joint is stopped (i.e. control is not active).

Returns
Returns true if stopped, false otherwise.

Definition at line 551 of file hekKinJoint.h.

Referenced by hekateros::HekKinJointWristRot::act(), and hekateros::HekKinJointWristRot::react().

552  {
553  return m_eState == MoveStateIdle;
554  }
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
no active goal or stopping control
Definition: hekKinJoint.h:437
bool hekateros::HekKinJoint::isStopping ( )
inline

Test if actively stopping joint.

Returns
Returns true or false.

Definition at line 531 of file hekKinJoint.h.

Referenced by react(), and hekateros::HekKinJointWristRot::react().

532  {
533  return m_eState == MoveStateStopping;
534  }
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int HekKinJoint::jointPosToServoPos ( const double  fPos)
virtual

Convert joint position to the equivalent servo position.

Parameters
fPosJoint position (radians).
Returns
Equivalent servo position (odometer ticks).

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 1244 of file hekKinJoint.cxx.

References hekateros::HekRobotJoint::m_fTicksPerJointRad, and m_pJoint.

Referenced by hekateros::HekKinJointWristRot::nlmove(), nlspecifyMove(), and hekateros::HekKinJointWristRot::planMotion().

1245 {
1246  return (int)(fPos * m_pJoint->m_fTicksPerJointRad);
1247 }
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double m_fTicksPerJointRad
encoder/odom. ticks per joint radian
Definition: hekJoint.h:157
double HekKinJoint::jointVelocity ( double  fPos1,
double  fPos0,
double  fDt 
)
protectedvirtual

Calculate the joint velocity from delta servo positions.

Parameters
fPos1Later joint position (radians/second).
fPos0Earlier joint position (radians/second).
fDtDelta time in seconds.
Returns
Calculated joint velocity (radians).

Definition at line 1254 of file hekKinJoint.cxx.

Referenced by senseDynamics().

1255 {
1256  return fDt > 0.0? (fPos1 - fPos0) / fDt: 0.0;
1257 }
void hekateros::HekKinJoint::lock ( )
inlineprotected

Lock the joint kinematics.

The calling thread will block while waiting for the mutex to become available. Once locked, the Hekateros kinematics thread will block when accessing this joint.

The lock()/unlock() primitives provide a safe mechanism to modify the joint data, such as the next goals.

Context:
Any.

Definition at line 874 of file hekKinJoint.h.

Referenced by act(), hekateros::HekKinJointWristRot::act(), applyTorqueControl(), move(), planMotion(), hekateros::HekKinJointWristRot::planMotion(), react(), hekateros::HekKinJointWristRot::react(), reload(), resetServoOdometer(), senseDynamics(), specifyMove(), and stop().

875  {
876  pthread_mutex_lock(&m_mutexSync);
877  }
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: hekKinJoint.h:813
HekKinJoint::MoveState HekKinJoint::move ( )
virtual

Move joint using joint PID controller.

Once the move has reached the goal joint position, within tolerence, the move will automatically stop.

Returns
Move control state after call.

Definition at line 1028 of file hekKinJoint.cxx.

References lock(), m_pServo, MoveStateIdle, nlmove(), and unlock().

1029 {
1030  MoveState eState;
1031 
1032  if( m_pServo == NULL )
1033  {
1034  return MoveStateIdle;
1035  }
1036 
1037  lock();
1038 
1039  eState = nlmove();
1040 
1041  unlock();
1042 
1043  return eState;
1044 }
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
no active goal or stopping control
Definition: hekKinJoint.h:437
MoveState
Kinedynamics joint position and velocity control states.
Definition: hekKinJoint.h:435
virtual MoveState nlmove()
Move joint using joint PID controller (no lock version).
void HekKinJoint::moveServo ( int  nServoGoalSpeed,
int  nServoGoalPos 
)
protected

Move servo.

Parameters
nServoGoalSpeedServo goal speed (raw unitless).
nServoGoalPosServo goal position (odometer ticks).
bNewMoveThis is [not] a new move.

Definition at line 1080 of file hekKinJoint.cxx.

References hekateros::cap(), hekateros::iabs(), m_eState, m_pServo, MoveStateMoving, and MoveStateNewMove.

Referenced by nlmove(), and hekateros::HekKinJointWristRot::nlmove().

1081 {
1082  //
1083  // Annoying Dynamixel subtleties are outlined here.
1084  //
1085  // In continuous mode:
1086  // When writing to the goal speed, the servo will immediately begin
1087  // movement. Servo goal position has no effect. A value of 0 will
1088  // stop the servo. The speeds are signed values.
1089  //
1090  // In servo mode:
1091  // When writing the goal position, if different from the current
1092  // position, the servo will immediately move at the goal speed
1093  // loaded in its control table. So always write goal speed first,
1094  // then goal position. The value of 0 cause the servo to go ape shit,
1095  // moving at its maximum speed with no servo control. Avoid this value
1096  // like the Ebola. To stop the servo, write the current position as
1097  // its goal position. One final nit, no negative speeds.
1098  //
1099  if( m_pServo->GetServoMode() == DYNA_MODE_CONTINUOUS )
1100  {
1101  nServoGoalSpeed = cap(nServoGoalSpeed, -DYNA_SPEED_MAX_RAW,
1102  DYNA_SPEED_MAX_RAW);
1103  m_pServo->WriteGoalSpeed(nServoGoalSpeed);
1104  }
1105  else
1106  {
1107  nServoGoalSpeed = cap(iabs(nServoGoalSpeed), DYNA_SPEED_MIN_CTL,
1108  DYNA_SPEED_MAX_RAW);
1109  m_pServo->WriteGoalSpeed(nServoGoalSpeed);
1110  if( m_eState == MoveStateNewMove )
1111  {
1112  m_pServo->WriteGoalPos(nServoGoalPos);
1114  }
1115  }
1116 }
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int cap(int a, int min, int max)
Cap value within limits [min, max].
Definition: hekUtils.h:177
int iabs(int a)
Integer absolute value.
Definition: hekUtils.h:149
int HekKinJoint::nlapplyTorqueControl ( )
protectedvirtual

Apply torque limit control (no lock version).

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 982 of file hekKinJoint.cxx.

References filterTorques(), hekateros::HEK_OK, m_fOverTorqueTh, m_fTorqueOut, m_nServoCurLoad, m_pServo, TORQUE_CTL_BACKOFF_POS, and TORQUE_CTL_BACKOFF_SPEED.

Referenced by act(), hekateros::HekKinJointWristRot::act(), applyTorqueControl(), react(), and hekateros::HekKinJointWristRot::react().

983 {
984  static const int TuneMaxIters = 5; // max iterations to ease torque
985  static const useconds_t TuneWait = 100; // wait between iterations
986 
987  int nSign;
988  int nOffSpeed;
989  int nOffPos;
990 
991  if( fabs(m_fTorqueOut) > m_fOverTorqueTh )
992  {
993  LOGDIAG4("Executing torque control for servo %d.", m_pServo->GetServoId());
994 
995  nSign = DYNA_GET_DIR(m_nServoCurLoad);
996  nOffSpeed = TORQUE_CTL_BACKOFF_SPEED;
997 
998  switch( m_pServo->GetServoMode() )
999  {
1000  case DYNA_MODE_CONTINUOUS:
1001  nOffSpeed *= nSign;
1002  m_pServo->WriteGoalSpeed(nOffSpeed);
1003  for(int i = 0; i < TuneMaxIters; ++i)
1004  {
1005  usleep(TuneWait);
1006  m_pServo->ReadCurLoad(&m_nServoCurLoad);
1008  if( fabs(m_fTorqueOut) <= m_fOverTorqueTh )
1009  {
1010  break;
1011  }
1012  }
1013  m_pServo->Stop();
1014  break;
1015 
1016  case DYNA_MODE_SERVO:
1017  default:
1018  nOffPos = nSign * TORQUE_CTL_BACKOFF_POS;
1019  m_pServo->WriteGoalSpeed(nOffSpeed);
1020  m_pServo->WriteGoalPos(nOffPos);
1021  break;
1022  }
1023  }
1024 
1025  return HEK_OK;
1026 }
double m_fOverTorqueTh
set over torque condition threshold
Definition: hekKinJoint.h:855
static const int TORQUE_CTL_BACKOFF_SPEED
Torque control backoff speed (raw unitless)
Definition: hekKinJoint.h:422
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int m_nServoCurLoad
servo current load (raw unitless)
Definition: hekKinJoint.h:857
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double m_fTorqueOut
low-pass filtered torque
Definition: hekKinJoint.h:858
static const int TORQUE_CTL_BACKOFF_POS
Torque control backoff positon (odometer ticks)
Definition: hekKinJoint.h:427
double filterTorques(double fTorqueAvg, int nServoLoad)
Apply a low-pass band filter on the sensed torques (loads).
HekKinJoint::MoveState HekKinJoint::nlmove ( )
protectedvirtual

Move joint using joint PID controller (no lock version).

Once the move has reached the goal joint position, within tolerence, the move will automatically stop.

Returns
Move control state after move call.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 1046 of file hekKinJoint.cxx.

References hekateros::HekPid::control(), estimateServoTgtSpeed(), isMovingToGoal(), m_eState, m_fDt, m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointTgtVel, m_fTolPos, m_fTolVel, m_nServoGoalPos, m_nServoTgtSpeed, m_pid, moveServo(), MoveStateNewMove, and nlstop().

Referenced by act(), hekateros::HekKinJointWristRot::act(), and move().

1047 {
1048  if( isMovingToGoal() )
1049  {
1050  // still away from goal position
1052  {
1053  // PID target velocity and corresponding target servo speed estimate
1056 
1057  // new move - make it happen
1058  if( m_eState == MoveStateNewMove )
1059  {
1061  }
1062 
1063  // subsequent changes of servo speed - only if sufficently different
1064  else if( fabs(m_fJointTgtVel-m_fJointCurVel) > m_fTolVel )
1065  {
1067  }
1068  }
1069 
1070  // at goal position
1071  else
1072  {
1073  nlstop();
1074  }
1075  }
1076 
1077  return m_eState;
1078 }
virtual int estimateServoTgtSpeed(double fJointTgtVel)
Estimate of target servo speed from target joint velocity.
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fDt
delta time between positions reads
Definition: hekKinJoint.h:835
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
virtual double control(double fJointCurPos, double fJointCurVel, double fDt)
Apply PID control.
Definition: hekPid.h:203
void moveServo(int nServoGoalSpeed, int nServoGoalPos)
Move servo.
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
bool isMovingToGoal()
Test if actively moving joint to goal.
Definition: hekKinJoint.h:521
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
int HekKinJoint::nlslowToStop ( SyncMoveMsgs msg)
protectedvirtual

Slow to stop (no lock version).

Parameters
msgsSynchronous move messages container object.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 1210 of file hekKinJoint.cxx.

References addServoMsgEntries(), estimateServoTgtSpeed(), hekateros::HEK_OK, m_fJointCurVel, m_fStopVelTh, m_nServoGoalPos, and nlstop().

Referenced by react(), and hekateros::HekKinJointWristRot::react().

1211 {
1212  double fJointStopVel;
1213  int nServoStopSpeed;
1214 
1215  if( (fabs(m_fJointCurVel) <= m_fStopVelTh) )
1216  {
1217  //fprintf(stderr, "DBG: %s() SLOWED ENOUGH: curvel=%lf\n",
1218  // LOGFUNCNAME, radToDeg(m_fJointCurVel));
1219 
1220  return nlstop();
1221  }
1222  else
1223  {
1224  if( m_fJointCurVel > 0.0 )
1225  {
1226  fJointStopVel = m_fJointCurVel - m_fStopVelTh;
1227  }
1228  else
1229  {
1230  fJointStopVel = m_fJointCurVel + m_fStopVelTh;
1231  }
1232 
1233  nServoStopSpeed = estimateServoTgtSpeed(fJointStopVel);
1234 
1235  addServoMsgEntries(msgs, nServoStopSpeed, m_nServoGoalPos);
1236 
1237  //fprintf(stderr, "DBG: %s() SLOWING TO: curvel=%lf, stopvel=%lf\n",
1238  // LOGFUNCNAME, radToDeg(m_fJointCurVel), radToDeg(fJointStopVel));
1239 
1240  return HEK_OK;
1241  }
1242 }
virtual int estimateServoTgtSpeed(double fJointTgtVel)
Estimate of target servo speed from target joint velocity.
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
double m_fStopVelTh
joint velocity threshold to safely stop move
Definition: hekKinJoint.h:820
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
void addServoMsgEntries(SyncMoveMsgs &msg, int nServoGoalSpeed, int nServoGoalPos)
Add servo to synchronous move message(s).
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
int HekKinJoint::nlspecifyMove ( const double  fGoalPos,
const double  fGoalVel 
)
protectedvirtual

Specify a new joint goal position and velocity move (no lock version).

The joint PID will begin to control to the new goals, smoothly transitioning (I hope) from the current goals.

Parameters
fGoalPosJoint goal position (radians).
fGoalVelJoint goal velocity (radians/second).
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 675 of file hekKinJoint.cxx.

References hekateros::HEK_OK, hekateros::HekJointTypeContinuous, hekateros::HekOpStateCalibrated, jointPosToServoPos(), hekateros::HekRobotJoint::m_eJointType, hekateros::HekRobotJoint::m_eOpState, m_eState, m_fJointCurPos, m_fJointGoalPos, m_fJointGoalVel, hekateros::HekRobotJoint::m_fMaxSoftLimitRads, hekateros::HekRobotJoint::m_fMinSoftLimitRads, m_fVelDerate, hekateros::HekRobotJoint::m_nMasterServoId, m_nServoGoalPos, m_pid, m_pJoint, hekateros::HekRobotJoint::m_strName, MoveStateNewMove, hekateros::radToDeg(), and hekateros::HekPid::specifySetPoint().

Referenced by hekateros::HekKinJointWristRot::act(), hekateros::HekKinJointWristRot::react(), and specifyMove().

676 {
677  // new goal position
678  m_fJointGoalPos = fGoalPos;
679 
680  //
681  // Check for goal position out of range condition and cap as necessary.
682  //
683  // Note: Only check if the joint has been calibrated. If calibrated, assume
684  // a calibration routine is calling the function and "it knows what
685  // it is doing".
686  //
688  {
690  {
691  if( m_fJointGoalPos < m_pJoint->m_fMinSoftLimitRads )
692  {
693  LOGDIAG3("Joint %s (servo=%d): "
694  "Goal position %.02lf < %.02lf degree limit - capping.",
697 
699  }
701  {
702  LOGDIAG3("Joint %s (servo=%d): "
703  "Goal position %.02lf > %.02lf degree limit - capping.",
706 
708  }
709  }
710  }
711 
712  // joint position to odometer position
714 
715  //
716  // Joint current and goal positions dictate sign of velocity.
717  //
718  m_fJointGoalVel = fabs(fGoalVel);
720  {
722  }
723 
724  // derate
726 
727  // new move
728  //if( fabs(m_fJointGoalPos-m_fJointCurPos) > m_fTolPos )
729  //{
732  //}
733 
734  return HEK_OK;
735 }
virtual int jointPosToServoPos(const double fPos)
Convert joint position to the equivalent servo position.
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
HekOpState m_eOpState
current operational state
Definition: hekJoint.h:179
double m_fMinSoftLimitRads
joint min soft limit (radians)
Definition: hekJoint.h:166
double m_fVelDerate
joint velocity derate (normalized)
Definition: hekKinJoint.h:844
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
int m_eJointType
joint type
Definition: hekJoint.h:154
double radToDeg(double r)
Convert radians to degrees.
Definition: hekUtils.h:137
virtual void specifySetPoint(double fJointGoalPos, double fJointGoalVel)
Specify the PID set point.
Definition: hekPid.cxx:71
int m_nMasterServoId
master servo id
Definition: hekJoint.h:150
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
continuous rotation
Definition: hekSpec.h:78
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
std::string m_strName
joint name
Definition: hekJoint.h:149
double m_fMaxSoftLimitRads
joint max soft limit (radians)
Definition: hekJoint.h:167
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
double m_fJointGoalVel
joint goal velocity (radians/second)
Definition: hekKinJoint.h:841
int HekKinJoint::nlstop ( )
protectedvirtual

Stop movement and move control of the joint (no lock version).

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 1162 of file hekKinJoint.cxx.

References canStopNow(), hekateros::HEK_OK, m_eState, m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointGoalVel, m_fJointPrevPos, m_fJointTgtVel, m_nServoCurPos, m_nServoCurSpeed, m_nServoGoalPos, m_nServoPrevPos, m_nServoTgtSpeed, m_pServo, MoveStateIdle, MoveStateStopping, and servoPosToJointPos().

Referenced by nlmove(), hekateros::HekKinJointWristRot::nlmove(), nlslowToStop(), hekateros::HekKinJointWristRot::nlslowToStop(), react(), hekateros::HekKinJointWristRot::react(), resetServoOdometer(), and stop().

1163 {
1164 #ifdef HEK_KIN_EXEC_ALG_SYNC
1165  //
1166  // Test if moving too fast. If true, use a fast ramp down to slow to a
1167  // stopping speed. The ramp is defined by the maximum delta velocity tune
1168  // parameter.
1169  //
1170  // Note: During calibration stop means stop.
1171  //
1172  if( !canStopNow() )
1173  {
1174  //fprintf(stderr, "DBG: %s() MOVING TO FAST TO STOP: "
1175  // "curvel=%lf, stopvelth=%lf\n",
1176  // LOGFUNCNAME, radToDeg(m_fJointCurVel), radToDeg(m_fStopVelTh));
1177 
1179  return HEK_OK;
1180  }
1181 #endif // HEK_KIN_EXEC_ALG_SYNC
1182 
1183  m_pServo->Stop();
1184 
1185  if( m_pServo->ReadCurPos(&m_nServoCurPos) == DYNA_OK )
1186  {
1188  }
1189 
1192 
1193  m_fJointCurVel = 0.0;
1194  m_nServoCurSpeed = 0;
1195 
1198  m_fJointGoalVel = 0.0;
1199 
1200  m_fJointTgtVel = 0.0;
1201  m_nServoTgtSpeed = 0;
1202 
1204 
1205  //fprintf(stderr, "DBG: STOP: %s\n", m_pJoint->m_strName.c_str());
1206 
1207  return HEK_OK;
1208 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
double m_fJointPrevPos
joint current position (radians)
Definition: hekKinJoint.h:829
int m_nServoPrevPos
servo previous pos (odometer ticks)
Definition: hekKinJoint.h:830
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
no active goal or stopping control
Definition: hekKinJoint.h:437
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
double m_fJointGoalVel
joint goal velocity (radians/second)
Definition: hekKinJoint.h:841
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
bool canStopNow()
Test if can stop now without slowing down.
Definition: hekKinJoint.h:561
virtual double servoPosToJointPos(const int nOdPos)
Convert servo position to the equivalent joint position.
HekKinJoint & HekKinJoint::operator= ( const HekKinJoint rhs)

Assignment operator.

Parameters
rhsRight hand side object.
Returns
*this

Definition at line 520 of file hekKinJoint.cxx.

References m_bOverTorqueCond, m_eState, m_fClearTorqueTh, m_fDt, m_fDtAvg, m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointGoalVel, m_fJointPosOut, m_fJointPrevPos, m_fJointRadPerTick, m_fJointTgtVel, m_fJointVelOut, m_fOverTorqueTh, m_fStopVelTh, m_fTolPos, m_fTolVel, m_fTorqueOut, m_histDtIn, m_histPosIn, m_histTorqueIn, m_histVelIn, m_nServoCurPos, m_nServoCurSpeed, m_nServoGoalPos, m_nServoPrevPos, m_nServoTgtSpeed, m_pid, m_pJoint, m_pServo, m_tblVelSpeed, and m_tsPrev.

521 {
522  m_eState = rhs.m_eState;
523  m_pJoint = rhs.m_pJoint;
524  m_pServo = rhs.m_pServo;
525 
526  m_fTolPos = rhs.m_fTolPos;
527  m_fTolVel = rhs.m_fTolVel;
529  m_pid = rhs.m_pid;
530 
539  m_histPosIn = rhs.m_histPosIn;
540 
541  m_fDt = rhs.m_fDt;
542  m_tsPrev = rhs.m_tsPrev;
543  m_fDtAvg = rhs.m_fDtAvg;
544  m_histDtIn = rhs.m_histDtIn;
545 
551  m_histVelIn = rhs.m_histVelIn;
552 
555 
561 
562  return *this;
563 }
double m_fOverTorqueTh
set over torque condition threshold
Definition: hekKinJoint.h:855
std::deque< double > m_histPosIn
recent history of joint positions
Definition: hekKinJoint.h:832
double m_fStopVelTh
joint velocity threshold to safely stop move
Definition: hekKinJoint.h:820
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double m_fJointVelOut
low-pass filtered joint cur velocity
Definition: hekKinJoint.h:846
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: hekKinJoint.h:859
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fDt
delta time between positions reads
Definition: hekKinJoint.h:835
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
double m_fJointPrevPos
joint current position (radians)
Definition: hekKinJoint.h:829
double m_fJointPosOut
low-pass filtered joint cur position
Definition: hekKinJoint.h:831
double m_fTorqueOut
low-pass filtered torque
Definition: hekKinJoint.h:858
std::deque< double > m_histDtIn
sliding window of delta t&#39;s
Definition: hekKinJoint.h:838
int m_nServoPrevPos
servo previous pos (odometer ticks)
Definition: hekKinJoint.h:830
double m_fJointRadPerTick
joint radians / odometer tick
Definition: hekKinJoint.h:824
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
std::deque< double > m_histVelIn
sliding window of current velocities
Definition: hekKinJoint.h:847
struct timespec m_tsPrev
previous time mark
Definition: hekKinJoint.h:836
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
VelSpeedLookupTbl m_tblVelSpeed
dynamic velocity/speed lookup table
Definition: hekKinJoint.h:845
double m_fJointGoalVel
joint goal velocity (radians/second)
Definition: hekKinJoint.h:841
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
double m_fDtAvg
average delta t
Definition: hekKinJoint.h:837
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
double m_fClearTorqueTh
clear over torque condition threshold
Definition: hekKinJoint.h:856
HekKinJoint::MoveState HekKinJoint::planMotion ( bool  bIsControlling,
SyncMoveMsgs msgs 
)
virtual

Plan motion.

Parameters
bIsControllingJoint is [not] being actively controlled. However, planning may still be desired.
msgsSynchronous move messages container object.
Returns
Move control state after call.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 895 of file hekKinJoint.cxx.

References addServoMsgEntries(), canMoveInPlannedDir(), hekateros::HekPid::control(), estimateServoTgtSpeed(), isMovingToGoal(), lock(), m_eState, m_fDt, m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointTgtVel, m_fTolPos, m_fTolVel, m_nServoGoalPos, m_nServoTgtSpeed, m_pid, m_pServo, MoveStateIdle, MoveStateNewMove, and unlock().

897 {
898  if( m_pServo == NULL )
899  {
900  return MoveStateIdle;
901  }
902  else if( !bIsControlling )
903  {
904  return m_eState;
905  }
906 
907  lock();
908 
909  if( isMovingToGoal() )
910  {
911  // PID target velocity and corresponding target servo speed estimate
914 
915  // still away from goal position
916  if( (fabs(m_fJointGoalPos-m_fJointCurPos) > m_fTolPos) &&
918  {
919  // new move - make it happen
920  if( m_eState == MoveStateNewMove )
921  {
923  }
924 
925  // subsequent changes of servo speed - only if sufficently different
926  else if( fabs(m_fJointTgtVel-m_fJointCurVel) > m_fTolVel )
927  {
929  }
930  }
931  }
932 
933  unlock();
934 
935  return m_eState;
936 }
virtual int estimateServoTgtSpeed(double fJointTgtVel)
Estimate of target servo speed from target joint velocity.
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
bool canMoveInPlannedDir(int nServoTgtSpeed)
Test if joint can move in planned direction.
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
MoveState m_eState
joint control state
Definition: hekKinJoint.h:812
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fDt
delta time between positions reads
Definition: hekKinJoint.h:835
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
virtual double control(double fJointCurPos, double fJointCurVel, double fDt)
Apply PID control.
Definition: hekPid.h:203
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
void addServoMsgEntries(SyncMoveMsgs &msg, int nServoGoalSpeed, int nServoGoalPos)
Add servo to synchronous move message(s).
bool isMovingToGoal()
Test if actively moving joint to goal.
Definition: hekKinJoint.h:521
no active goal or stopping control
Definition: hekKinJoint.h:437
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
int HekKinJoint::react ( bool  bIsControlling,
SyncMoveMsgs msgs 
)
virtual

React to recently read sensor data.

Parameters
bIsControllingJoint is [not] being actively controlled. However, reaction may still be desired.
msgsSynchronous move messages container object.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 854 of file hekKinJoint.cxx.

References canStopNow(), hekateros::HEK_OK, isMovingToGoal(), isStopping(), lock(), m_bOverTorqueCond, m_fJointCurPos, m_fJointGoalPos, m_fTolPos, nlapplyTorqueControl(), nlslowToStop(), nlstop(), and unlock().

855 {
856  if( !bIsControlling )
857  {
858  return HEK_OK;
859  }
860 
861  lock();
862 
863  //
864  // Joint is slowing to a stop.
865  //
866  if( isStopping() )
867  {
868  nlslowToStop(msgs);
869  }
870 
871  //
872  // Joint has moved close enough to goal position, and is slow enough to stop.
873  // Otherwise let the PID do its thing.
874  //
875  else if( isMovingToGoal() &&
877  canStopNow() )
878  {
879  nlstop();
880  }
881 
882  //
883  // In over torque condition, apply torque control.
884  //
885  if( m_bOverTorqueCond )
886  {
888  }
889 
890  unlock();
891 
892  return HEK_OK;
893 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
virtual int nlapplyTorqueControl()
Apply torque limit control (no lock version).
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
virtual int nlslowToStop(SyncMoveMsgs &msg)
Slow to stop (no lock version).
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
bool isMovingToGoal()
Test if actively moving joint to goal.
Definition: hekKinJoint.h:521
bool canStopNow()
Test if can stop now without slowing down.
Definition: hekKinJoint.h:561
bool isStopping()
Test if actively stopping joint.
Definition: hekKinJoint.h:531
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
void HekKinJoint::reload ( const HekTunes tunes)
virtual

Reload configuration tuning parameters.

Parameters
tunesHekateros tuning parameters.

Definition at line 565 of file hekKinJoint.cxx.

References hekateros::HekTunes::getPidKParams(), hekateros::HekTunes::getPidMaxDeltaV(), hekateros::HekTunes::getToleranceParams(), hekateros::HekTunes::getTorqueParams(), hekateros::HekTunes::getVelocityDerate(), lock(), m_fClearTorqueTh, m_fOverTorqueTh, m_fStopVelTh, m_fTolPos, m_fTolVel, m_fVelDerate, m_pJoint, m_pServo, hekateros::HekRobotJoint::m_strName, setPidKParams(), setPidMaxDeltaVParam(), SLOW_DERATE_DELTA_V, and unlock().

566 {
567  double fKp, fKi, fKd;
568  double fMaxDeltaV;
569  double fRawMaxTorque;
570 
571  lock();
572 
573  // joint tolerance tuning parameters (normalized)
575 
576  // joint position and velocity PID tuning parameters
577  tunes.getPidKParams(m_pJoint->m_strName, fKp, fKi, fKd);
578 
579  // set classic pid parameters
580  setPidKParams(fKp, fKi, fKd);
581 
582  // joint pid maximum delta velocity tuning paramter
583  fMaxDeltaV = tunes.getPidMaxDeltaV(m_pJoint->m_strName);
584 
585  // maximum PID output delta v (radians/second)
586  setPidMaxDeltaVParam(fMaxDeltaV);
587 
588  // stop velocity maximum velocity
589  m_fStopVelTh = SLOW_DERATE_DELTA_V * fMaxDeltaV;
590 
591  // velocity derate
593 
594  // normalized joint torque tuning parameters
596 
597  // convert to raw theshold values
598  fRawMaxTorque = (double)m_pServo->GetSpecification().m_uRawTorqueMax;
599  m_fOverTorqueTh *= fRawMaxTorque;
600  m_fClearTorqueTh *= fRawMaxTorque;
601 
602  unlock();
603 }
double m_fOverTorqueTh
set over torque condition threshold
Definition: hekKinJoint.h:855
void getToleranceParams(const std::string &strJointName, double &fTolPos, double &fTolVel) const
Get joint tolerance tune parameters.
Definition: hekTune.cxx:101
double m_fVelDerate
joint velocity derate (normalized)
Definition: hekKinJoint.h:844
double m_fStopVelTh
joint velocity threshold to safely stop move
Definition: hekKinJoint.h:820
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double getPidMaxDeltaV(const std::string &strJointName) const
Get joint PID maximum delta v (radians/second) tune parameter.
Definition: hekTune.cxx:137
static const double SLOW_DERATE_DELTA_V
Stop delta v as a fraction of max_delta_v tune parameter.
Definition: hekKinJoint.h:411
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
double getVelocityDerate() const
Get derated velocity tune parameter (normalized).
Definition: hekTune.h:451
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
void setPidKParams(const double fKp, const double fKi, const double fKd)
Set the joint&#39;s position and velocity PID K parameters.
Definition: hekKinJoint.h:589
void getTorqueParams(const std::string &strJointName, double &fOverTorqueTh, double &fClearTorqueTh) const
Get joint torque parameters.
Definition: hekTune.cxx:151
std::string m_strName
joint name
Definition: hekJoint.h:149
void setPidMaxDeltaVParam(const double fMaxDeltaV)
Set joint PID maximum delta v (radians/second) parameter.
Definition: hekKinJoint.h:609
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
double m_fClearTorqueTh
clear over torque condition threshold
Definition: hekKinJoint.h:856
void getPidKParams(const std::string &strJointName, double &fKp, double &fKi, double &fKd) const
Get joint PID K tune parameters.
Definition: hekTune.cxx:118
int HekKinJoint::resetServoOdometer ( )
virtual

Reset servo odometer zero point to the current encoder position.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 605 of file hekKinJoint.cxx.

References hekateros::boolstr(), hekateros::HEK_ECODE_DYNA, hekateros::HEK_OK, lock(), m_fJointCurPos, m_fJointCurVel, m_fJointGoalPos, m_fJointGoalVel, m_fJointPrevPos, m_fJointTgtVel, hekateros::HekRobotJoint::m_nMasterServoDir, hekateros::HekRobotJoint::m_nMasterServoId, m_nServoCurPos, m_nServoCurSpeed, m_nServoGoalPos, m_nServoPrevPos, m_nServoTgtSpeed, m_pJoint, m_pServo, hekateros::HekRobotJoint::m_strName, nlstop(), and unlock().

606 {
607  uint_t uEncZeroPt; // encoder position mapping to new odometer zero pt
608  bool bIsReverse; // odometer is [not] reverse to that of encoder
609  int rc; // return code
610 
611  if( m_pServo == NULL )
612  {
613  return HEK_OK;
614  }
615 
616  lock();
617 
618  // must be stopped
619  nlstop();
620 
621  // read encoder position (note: should add libDynamixel function)
622  if( (rc = m_pServo->Read(DYNA_ADDR_CUR_POS_LSB, &uEncZeroPt)) != DYNA_OK )
623  {
624  LOGERROR("Joint %s (servo=%d): Cannot read current encoder position.",
626  rc = -HEK_ECODE_DYNA;
627  }
628 
629  else
630  {
631  bIsReverse = m_pJoint->m_nMasterServoDir == DYNA_DIR_CCW? false: true;
632 
633  // reset soft odometer
634  m_pServo->ResetOdometer((int)uEncZeroPt, bIsReverse);
635 
636  LOGDIAG3("Joint %s (servo=%d): Odometer reset at encoder=%u, reverse=%s.",
638  uEncZeroPt, boolstr(bIsReverse));
639 
640  m_fJointGoalPos = 0.0;
641  m_nServoGoalPos = 0;
642  m_fJointCurPos = 0.0;
643  m_nServoCurPos = 0;
644  m_fJointPrevPos = 0.0;
645  m_nServoPrevPos = 0;
646 
647  m_fJointGoalVel = 0.0;
648  m_fJointCurVel = 0.0;
649  m_nServoCurSpeed = 0;
650 
651  m_fJointTgtVel = 0.0;
652  m_nServoTgtSpeed = 0;
653 
654  rc = HEK_OK;
655  }
656 
657  unlock();
658 
659  return rc;
660 }
const char * boolstr(bool b)
Boolean to string.
Definition: hekUtils.h:108
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
int m_nServoGoalPos
servo goal position (odometer ticks)
Definition: hekKinJoint.h:826
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
int m_nMasterServoId
master servo id
Definition: hekJoint.h:150
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
int m_nServoTgtSpeed
target motor speed (raw unitless)
Definition: hekKinJoint.h:851
double m_fJointGoalPos
joint goal position (radians)
Definition: hekKinJoint.h:825
double m_fJointPrevPos
joint current position (radians)
Definition: hekKinJoint.h:829
int m_nServoPrevPos
servo previous pos (odometer ticks)
Definition: hekKinJoint.h:830
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
std::string m_strName
joint name
Definition: hekJoint.h:149
static const int HEK_ECODE_DYNA
dynamixel error
Definition: hekateros.h:86
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
int m_nMasterServoDir
master servo normalized direction
Definition: hekJoint.h:153
double m_fJointGoalVel
joint goal velocity (radians/second)
Definition: hekKinJoint.h:841
double m_fJointTgtVel
joint target velocity (radians/second)
Definition: hekKinJoint.h:850
int HekKinJoint::senseDynamics ( bool  bIsControlling)
virtual

Sense (read) the current servo dynamics and transform to useful state.

Parameters
bIsControllingJoint is [not] being actively controlled.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 760 of file hekKinJoint.cxx.

References dejitterServoPos(), delta_t(), filterPositions(), filterTorques(), filterVelocities(), hekateros::HEK_ECODE_DYNA, hekateros::HEK_OK, hekateros::HekOpStateCalibrated, hekateros::iabs(), jointVelocity(), lock(), m_bOverTorqueCond, hekateros::HekRobotJoint::m_eOpState, m_fClearTorqueTh, m_fDt, m_fJointCurPos, m_fJointCurVel, m_fJointPosOut, m_fJointPrevPos, m_fJointVelOut, m_fOverTorqueTh, hekateros::HekRobotJoint::m_fTicksPerServoRad, m_fTorqueOut, m_nServoCurLoad, m_nServoCurPos, m_nServoCurSpeed, m_nServoPrevPos, m_pJoint, m_pServo, hekateros::HekRobotJoint::m_strName, servoPosToJointPos(), unlock(), and updateAssoc().

Referenced by hekateros::HekKinematics::exec().

761 {
762  int nServoDejitPos;
763  int rc;
764 
765  if( m_pServo == NULL )
766  {
767  return HEK_OK;
768  }
769 
770  lock();
771 
772  // save current servo position as the new previous position
774 
775  // Read the servo dynamics.
776  rc = m_pServo->ReadDynamics(&m_nServoCurPos,
778  &m_nServoCurLoad);
779 
780  // sanity check
783  m_pJoint->m_fTicksPerServoRad * M_PI) )
784  {
785  LOGWARN("Large jump in servo position: prev_odpos=%d, cur_odpos=%d.",
787  }
788 
789  //
790  // Transform.
791  //
792  if( rc == DYNA_OK )
793  {
794  // delta time
795  m_fDt = delta_t();
796 
797  // running average of delta times (not used for now)
798  //m_fDtAvg = averageDt(m_fDtAvg, m_fDt);
799 
800  // de-jitter servo odometer (encoder) position
802 
803  // current joint position (radians)
805  m_fJointCurPos = servoPosToJointPos(nServoDejitPos);
806 
807  // low-pass band filter current positions
809 
810  // current joint velocity (radians/second)
812 
813  // update joint instantaneous velocity-servo speed lookup table
814  if( bIsControlling )
815  {
817  }
818 
819  // low-pass band filter current velocities
821 
822  // low-pass band filter torque (raw unitless load)
824 
825  // set over torque limit condition
826  if( fabs(m_fTorqueOut) > m_fOverTorqueTh )
827  {
828  if( !m_bOverTorqueCond && bIsControlling )
829  {
830  LOGWARN("Joint %s (servo=%d): Entered over-torque condition. "
831  "Load=%lf.",
832  m_pJoint->m_strName.c_str(), m_pServo->GetServoId(), m_fTorqueOut);
833  }
834  m_bOverTorqueCond = true;
835  }
836 
837  // clear over torque limit condition
838  else if( fabs(m_fTorqueOut) < m_fClearTorqueTh )
839  {
840  if( m_bOverTorqueCond && bIsControlling )
841  {
842  LOGDIAG2("Joint %s (servo=%d): Cleared over-torque condition.",
843  m_pJoint->m_strName.c_str(), m_pServo->GetServoId());
844  }
845  m_bOverTorqueCond = false;
846  }
847  }
848 
849  unlock();
850 
851  return rc == DYNA_OK? HEK_OK: -HEK_ECODE_DYNA;
852 }
virtual void updateAssoc(double fJointVel, int nServoSpeed)
Update joint velocity - servo speed association.
double filterPositions(double fPosAvg, double fJointPos)
Apply a low-pass band filter on the joint positions (radians).
double m_fOverTorqueTh
set over torque condition threshold
Definition: hekKinJoint.h:855
int dejitterServoPos(int nServoCurPos, int nServoPrevPos)
De-jitter servo odometer position.
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
HekOpState m_eOpState
current operational state
Definition: hekJoint.h:179
int m_nServoCurLoad
servo current load (raw unitless)
Definition: hekKinJoint.h:857
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
int m_nServoCurPos
servo current position (odometer ticks)
Definition: hekKinJoint.h:828
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
double m_fJointVelOut
low-pass filtered joint cur velocity
Definition: hekKinJoint.h:846
int m_nServoCurSpeed
current motor speed (raw unitless)
Definition: hekKinJoint.h:843
double m_fTicksPerServoRad
encoder/odom. ticks per servo radian
Definition: hekJoint.h:156
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
double delta_t()
Calculate the delta time between calls to this.
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
virtual double jointVelocity(double fPos1, double fPos0, double fDt)
Calculate the joint velocity from delta servo positions.
double m_fDt
delta time between positions reads
Definition: hekKinJoint.h:835
double m_fJointPrevPos
joint current position (radians)
Definition: hekKinJoint.h:829
double m_fJointPosOut
low-pass filtered joint cur position
Definition: hekKinJoint.h:831
double m_fTorqueOut
low-pass filtered torque
Definition: hekKinJoint.h:858
int m_nServoPrevPos
servo previous pos (odometer ticks)
Definition: hekKinJoint.h:830
double m_fJointCurPos
joint current position (radians)
Definition: hekKinJoint.h:827
double filterVelocities(double fVelAvg, double fJointVel)
Apply a low-pass band filter on the joint velocities (radians/second).
std::string m_strName
joint name
Definition: hekJoint.h:149
int iabs(int a)
Integer absolute value.
Definition: hekUtils.h:149
static const int HEK_ECODE_DYNA
dynamixel error
Definition: hekateros.h:86
double m_fJointCurVel
joint current velocity (radians/second)
Definition: hekKinJoint.h:842
virtual double servoPosToJointPos(const int nOdPos)
Convert servo position to the equivalent joint position.
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: hekKinJoint.h:854
double m_fClearTorqueTh
clear over torque condition threshold
Definition: hekKinJoint.h:856
double filterTorques(double fTorqueAvg, int nServoLoad)
Apply a low-pass band filter on the sensed torques (loads).
double HekKinJoint::servoPosToJointPos ( const int  nOdPos)
virtual

Convert servo position to the equivalent joint position.

Parameters
nOdPosServo position (odometer ticks).
Returns
Equivalent joint position (radian).

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 1249 of file hekKinJoint.cxx.

References hekateros::HekRobotJoint::m_fTicksPerJointRad, and m_pJoint.

Referenced by nlstop(), and senseDynamics().

1250 {
1251  return (double)nOdPos / m_pJoint->m_fTicksPerJointRad;
1252 }
HekRobotJoint * m_pJoint
joint description
Definition: hekKinJoint.h:814
double m_fTicksPerJointRad
encoder/odom. ticks per joint radian
Definition: hekJoint.h:157
void hekateros::HekKinJoint::setPidKParams ( const double  fKp,
const double  fKi,
const double  fKd 
)
inline

Set the joint's position and velocity PID K parameters.

Parameters
[in]fKpProportional gain parameter.
[in]fKiIntegral gain parameter.
[in]fKdDerivative gain parameter.
Returns

Definition at line 589 of file hekKinJoint.h.

Referenced by HekKinJoint(), and reload().

590  {
591  m_pid.setKParams(fKp, fKi, fKd);
592  }
void setKParams(const double fKp, const double fKi, const double fKd)
Set the position and velocity PID K parameters.
Definition: hekPid.h:153
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
void hekateros::HekKinJoint::setPidMaxDeltaVParam ( const double  fMaxDeltaV)
inline

Set joint PID maximum delta v (radians/second) parameter.

Parameters
fMaxDeltaVMaximum output delta velocity (radians/second).

Definition at line 609 of file hekKinJoint.h.

Referenced by HekKinJoint(), and reload().

610  {
611  m_pid.setMaxDeltaVParam(fMaxDeltaV);
612  }
void setMaxDeltaVParam(const double fMaxDeltaV)
Set the maximum delta V (ramp) parameter (radians/second).
Definition: hekPid.h:175
HekPid m_pid
joint position and velocity PID
Definition: hekKinJoint.h:821
void hekateros::HekKinJoint::setToleranceParams ( const double  fTolPos,
const double  fTolVel 
)
inline

Set the position and velocity tolerance parameters.

The joint PID will try to control to the goal position ± position tolerance and to the goal velocity ± velocity tolerance.

Parameters
[in]fTolPosJoint position tolerance (radians).
[in]fTolVelJoint velocity tolerance (radians/second).

Definition at line 638 of file hekKinJoint.h.

639  {
640  m_fTolPos = fTolPos;
641  m_fTolVel = fTolVel;
642  }
double m_fTolPos
joint position &plusmn; tolerance (rads)
Definition: hekKinJoint.h:818
double m_fTolVel
joint velocity &plusmn; tolerance (rads/s)
Definition: hekKinJoint.h:819
int HekKinJoint::specifyMove ( const double  fGoalPos,
const double  fGoalVel 
)

Specify a new joint goal position and velocity move.

The joint PID will begin to control to the new goals, smoothly transitioning (I hope) from the current goals.

Parameters
fGoalPosJoint goal position (radians).
fGoalVelJoint goal velocity (radians/second).
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 662 of file hekKinJoint.cxx.

References lock(), nlspecifyMove(), and unlock().

663 {
664  int rc;
665 
666  lock();
667 
668  rc = nlspecifyMove(fGoalPos, fGoalVel);
669 
670  unlock();
671 
672  return rc;
673 }
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
virtual int nlspecifyMove(const double fGoalPos, const double fGoalVel)
Specify a new joint goal position and velocity move (no lock version).
int HekKinJoint::stop ( )
virtual

Stop movement and move control of the joint.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 1144 of file hekKinJoint.cxx.

References hekateros::HEK_ECODE_DYNA, lock(), m_pServo, nlstop(), and unlock().

1145 {
1146  int rc;
1147 
1148  if( m_pServo == NULL )
1149  {
1150  return -HEK_ECODE_DYNA;
1151  }
1152 
1153  lock();
1154 
1155  rc = nlstop();
1156 
1157  unlock();
1158 
1159  return rc;
1160 }
virtual int nlstop()
Stop movement and move control of the joint (no lock version).
DynaServo * m_pServo
joint master servo control
Definition: hekKinJoint.h:815
void lock()
Lock the joint kinematics.
Definition: hekKinJoint.h:874
void unlock()
Unlock the joint kinematics.
Definition: hekKinJoint.h:888
static const int HEK_ECODE_DYNA
dynamixel error
Definition: hekateros.h:86
void hekateros::HekKinJoint::unlock ( )
inlineprotected

Unlock the joint kinematics.

The Hekateros kinematics thread will be available to run when accessing this joint.

Context:
Any.

Definition at line 888 of file hekKinJoint.h.

Referenced by act(), hekateros::HekKinJointWristRot::act(), applyTorqueControl(), move(), planMotion(), hekateros::HekKinJointWristRot::planMotion(), react(), hekateros::HekKinJointWristRot::react(), reload(), resetServoOdometer(), senseDynamics(), specifyMove(), and stop().

889  {
890  pthread_mutex_unlock(&m_mutexSync);
891  }
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: hekKinJoint.h:813
void HekKinJoint::updateAssoc ( double  fJointVel,
int  nServoSpeed 
)
protectedvirtual

Update joint velocity - servo speed association.

Parameters
fJointVelJoint velocity (radians/second).
nServoSpeedServo speed (raw unitless).

Reimplemented in hekateros::HekKinJointWristRot.

Definition at line 1259 of file hekKinJoint.cxx.

References m_tblVelSpeed, and hekateros::VelSpeedLookupTbl::update().

Referenced by senseDynamics().

1260 {
1261  m_tblVelSpeed.update(fJointVel, nServoSpeed);
1262 }
void update(double fJointVel, int nServoSpeed)
Update lookup table entry.
VelSpeedLookupTbl m_tblVelSpeed
dynamic velocity/speed lookup table
Definition: hekKinJoint.h:845

The documentation for this class was generated from the following files: