Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaVServo Class Reference

Background Thread Virtual Servo Class. More...

#include <DynaBgThread.h>

Public Types

enum  VServoState {
  StateIdle,
  StateBegin,
  StateControl
}
 Servo dynamics position control state. More...
 

Public Member Functions

 DynaVServo ()
 Default constructor.
 
 DynaVServo (const DynaVServo &src)
 Copy constructor. More...
 
 ~DynaVServo ()
 Destructor.
 
DynaVServo operator= (const DynaVServo &rhs)
 Assignment operator. More...
 
void setToleranceInTicks (DynaServo *pServo, double fTolerance)
 Set position tolerance in encoder ticks. More...
 
double filterTorques (int nServoLoad)
 Apply a low-pass band filter on the sensed torques (loads). More...
 
int getGoalDir (DynaServo *pServo)
 Get the current goal rotation direction. More...
 
void lock ()
 Lock the virtual servo. More...
 
void unlock ()
 Unlock the virtual servo. More...
 

Public Attributes

VServoState m_eState
 virtual servo state
 
DynaPidPos m_pidPos
 servo position PID
 
int m_nTolerance
 position ± tolerance (ticks)
 
int m_nOdGoalPos
 current goal position
 
int m_nGoalSpeed
 current goal speed
 
bool m_bOverTorqueCond
 is [not] in torque overload condition
 
bool m_bOverTorqueCtl
 [not] in torque overload control
 
double m_fTorqueOut
 low-pass filtered torque
 
std::deque< double > m_histTorqueIn
 recent history of joint torques
 

Static Public Attributes

static const size_t TORQUE_WIN_SIZE = 10
 Torque sliding window size for low-pass band filtering of input torques.
 
static const int GOAL_SPEED_DFT = 100
 default virutal goal speed
 

Protected Attributes

pthread_mutex_t m_mutexSync
 synchonization mutex
 

Detailed Description

Background Thread Virtual Servo Class.

Definition at line 87 of file DynaBgThread.h.

Member Enumeration Documentation

Servo dynamics position control state.

Enumerator
StateIdle 

no active position control

StateBegin 

start position control

StateControl 

in poistion control

Definition at line 101 of file DynaBgThread.h.

102  {
103  StateIdle, ///< no active position control
104  StateBegin, ///< start position control
105  StateControl ///< in poistion control
106  };
start position control
Definition: DynaBgThread.h:104
in poistion control
Definition: DynaBgThread.h:105
no active position control
Definition: DynaBgThread.h:103

Constructor & Destructor Documentation

DynaVServo::DynaVServo ( const DynaVServo src)

Copy constructor.

Parameters
srcSource object.

Definition at line 205 of file DynaBgThread.cxx.

References m_bOverTorqueCond, m_bOverTorqueCtl, m_eState, m_fTorqueOut, m_histTorqueIn, m_mutexSync, m_nGoalSpeed, m_nOdGoalPos, m_nTolerance, and m_pidPos.

206 {
207  m_eState = src.m_eState;
208  m_pidPos = src.m_pidPos;
216 
217  pthread_mutex_init(&m_mutexSync, NULL);
218 }
int m_nGoalSpeed
current goal speed
Definition: DynaBgThread.h:115
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: DynaBgThread.h:119
double m_fTorqueOut
low-pass filtered torque
Definition: DynaBgThread.h:118
bool m_bOverTorqueCtl
[not] in torque overload control
Definition: DynaBgThread.h:117
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: DynaBgThread.h:116
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: DynaBgThread.h:226
VServoState m_eState
virtual servo state
Definition: DynaBgThread.h:111
int m_nOdGoalPos
current goal position
Definition: DynaBgThread.h:114
DynaPidPos m_pidPos
servo position PID
Definition: DynaBgThread.h:112
int m_nTolerance
position &plusmn; tolerance (ticks)
Definition: DynaBgThread.h:113

Member Function Documentation

double DynaVServo::filterTorques ( int  nServoLoad)

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

The torques are interpreted from the unitless load values read from the servo (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
nServoLoadNew servo load value (raw unitless).
Returns
New torque average (raw unitless).

Definition at line 261 of file DynaBgThread.cxx.

References DynaBgThread::HZ_EXEC_DFT, DynaBgThread::HZ_EXEC_MIN, m_fTorqueOut, m_histTorqueIn, DynaBgThread::T_EXEC_MIN, DynaBgThread::TOLERANCE_DFT, and TORQUE_WIN_SIZE.

Referenced by DynaBgThread::monitorDynamics().

262 {
263  double fTorque0;
264  double fTorqueK;
265 
266  fTorque0 = (double)nServoLoad / (double)TORQUE_WIN_SIZE;
267  fTorqueK = m_histTorqueIn.back();
268  m_histTorqueIn.pop_back();
269  m_histTorqueIn.push_front(fTorque0);
270 
271  m_fTorqueOut = m_fTorqueOut - fTorqueK + fTorque0;
272 
273  return m_fTorqueOut;
274 }
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: DynaBgThread.h:119
double m_fTorqueOut
low-pass filtered torque
Definition: DynaBgThread.h:118
static const size_t TORQUE_WIN_SIZE
Torque sliding window size for low-pass band filtering of input torques.
Definition: DynaBgThread.h:94
int DynaVServo::getGoalDir ( DynaServo pServo)
inline

Get the current goal rotation direction.

The direct 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.

Parameters
pServerPointer to servo.
Returns
1 or -1.

Definition at line 186 of file DynaBgThread.h.

References DynaServo::GetOdometer(), and DynaServo::IsOdometerReversed().

Referenced by DynaBgThread::execDynamics().

187  {
188  int nSign = pServo->IsOdometerReversed()? -1: 1;
189 
190  return (m_nOdGoalPos-pServo->GetOdometer()) >= 0? nSign: -1*nSign;
191  }
bool IsOdometerReversed()
Test if the virtual odometer is reversed.
Definition: DynaServo.h:334
int m_nOdGoalPos
current goal position
Definition: DynaBgThread.h:114
int GetOdometer()
Get the current virtual odometer value.
Definition: DynaServo.h:304
void DynaVServo::lock ( )
inline

Lock the virtual servo.

The calling thread will block while waiting for the mutex to become available. Once locked, the background thread will block when accessing this vitural servo.

The lock()/unlock() primitives provide a safe mechanism to modify the registered vServo data.

Context:
Any.

Definition at line 206 of file DynaBgThread.h.

Referenced by DynaBgThread::execDynamics(), DynaBgThread::readyWait(), DynaBgThread::timeWait(), and DynaBgThread::WriteGoalPos().

207  {
208  pthread_mutex_lock(&m_mutexSync);
209  }
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: DynaBgThread.h:226
DynaVServo DynaVServo::operator= ( const DynaVServo rhs)

Assignment operator.

Parameters
rhsRight hand side object.
Returns
This object.

Definition at line 220 of file DynaBgThread.cxx.

References m_bOverTorqueCond, m_bOverTorqueCtl, m_eState, m_fTorqueOut, m_histTorqueIn, m_nGoalSpeed, m_nOdGoalPos, m_nTolerance, and m_pidPos.

221 {
222  m_eState = rhs.m_eState;
223  m_pidPos = rhs.m_pidPos;
231 
232  return *this;
233 }
int m_nGoalSpeed
current goal speed
Definition: DynaBgThread.h:115
std::deque< double > m_histTorqueIn
recent history of joint torques
Definition: DynaBgThread.h:119
double m_fTorqueOut
low-pass filtered torque
Definition: DynaBgThread.h:118
bool m_bOverTorqueCtl
[not] in torque overload control
Definition: DynaBgThread.h:117
bool m_bOverTorqueCond
is [not] in torque overload condition
Definition: DynaBgThread.h:116
VServoState m_eState
virtual servo state
Definition: DynaBgThread.h:111
int m_nOdGoalPos
current goal position
Definition: DynaBgThread.h:114
DynaPidPos m_pidPos
servo position PID
Definition: DynaBgThread.h:112
int m_nTolerance
position &plusmn; tolerance (ticks)
Definition: DynaBgThread.h:113
void DynaVServo::setToleranceInTicks ( DynaServo pServo,
double  fTolerance 
)

Set position tolerance in encoder ticks.

Parameters
pServoPointer to servo.
fToleranceTolerance (degrees).

Definition at line 235 of file DynaBgThread.cxx.

References DYNA_MODE_CONTINUOUS, DynaServo::GetServoMode(), DynaServo::GetSpecification(), DynaServoSpec_T::m_fAngleMax, DynaServoSpec_T::m_fAngleMin, m_nTolerance, and DynaServoSpec_T::m_uRawPosModulo.

Referenced by DynaBgThread::RegisterChainAgent(), and DynaBgThread::RegisterServoAgent().

236 {
237  double fTicks;
238  double fAngleMin;
239  double fAngleMax;
240  double fDegrees;
241 
242  //
243  // Servo rotation range.
244  //
245  if( pServo->GetServoMode() == DYNA_MODE_CONTINUOUS )
246  {
247  fDegrees = 360.0;
248  }
249  else
250  {
251  fAngleMin = pServo->GetSpecification().m_fAngleMin;
252  fAngleMax = pServo->GetSpecification().m_fAngleMax;
253  fDegrees = fAngleMax - fAngleMin;
254  }
255 
256  fTicks = (double)pServo->GetSpecification().m_uRawPosModulo;
257 
258  m_nTolerance = (int)(fTicks * fTolerance / fDegrees);
259 }
virtual uint_t GetServoMode() const
Get the servo operational mode.
Definition: DynaServo.h:165
double m_fAngleMin
min rotation angle in servo mode (deg)
Definition: DynaTypes.h:92
uint_t m_uRawPosModulo
raw position modulo
Definition: DynaTypes.h:103
#define DYNA_MODE_CONTINUOUS
continuous mode with/without position
Definition: Dynamixel.h:171
virtual const DynaServoSpec_T & GetSpecification() const
Get servo specification.
Definition: DynaServo.h:185
double m_fAngleMax
max rotation angle in servo mode (deg)
Definition: DynaTypes.h:93
int m_nTolerance
position &plusmn; tolerance (ticks)
Definition: DynaBgThread.h:113
void DynaVServo::unlock ( )
inline

Unlock the virtual servo.

The background thread will be available to run when accessing this vitural servo.

Context:
Any.

Definition at line 220 of file DynaBgThread.h.

Referenced by DynaBgThread::execDynamics(), DynaBgThread::readyWait(), DynaBgThread::timeWait(), and DynaBgThread::WriteGoalPos().

221  {
222  pthread_mutex_unlock(&m_mutexSync);
223  }
pthread_mutex_t m_mutexSync
synchonization mutex
Definition: DynaBgThread.h:226

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