58 #ifndef _DYNA_BG_THREAD_H 59 #define _DYNA_BG_THREAD_H 67 #include "rnr/rnrconfig.h" 94 static const size_t TORQUE_WIN_SIZE = 10;
96 static const int GOAL_SPEED_DFT = 100;
138 pthread_mutex_destroy(&m_mutexSync);
156 void setToleranceInTicks(
DynaServo *pServo,
double fTolerance);
171 double filterTorques(
int nServoLoad);
190 return (m_nOdGoalPos-pServo->
GetOdometer()) >= 0? nSign: -1*nSign;
208 pthread_mutex_lock(&m_mutexSync);
222 pthread_mutex_unlock(&m_mutexSync);
267 double fTolerance = TOLERANCE_DFT);
286 virtual void RegisterServoAgent(
DynaServo *pServo);
300 virtual void RegisterChainAgent(
DynaChain *pChain);
312 virtual void UnregisterAgent();
322 m_fnUserCb = fnUserCb;
323 m_pUserArg = pUserArg;
408 virtual int Resume();
436 static int WriteGoalPos(
int nServoId,
int nOdGoalPos,
void *pUserArg);
438 static int WriteGoalSpeed(
int nServoId,
int nGoalSpeed,
void *pUserArg);
440 static int WriteGoalSpeedPos(
int nServoId,
450 void setHz(
double fHz);
471 MapVServo::iterator pos;
473 if( (pos = m_mapVServo.find(nServoId)) != m_mapVServo.end() )
506 void (*m_fnUserCb)(
void*);
512 struct timeval m_tvSched;
535 pthread_mutex_lock(&m_mutexSync);
549 pthread_mutex_unlock(&m_mutexSync);
578 void timeWait(
long lMicroSecs);
588 m_fTolerance = fTolerance > 0.0? fTolerance: 0.0;
598 virtual DynaServo *getRegisteredServo(
int nServoId);
610 if( m_mapVServo.size() == 0 )
617 if( iter == m_mapVServo.end() )
619 iter = m_mapVServo.begin();
622 nServoId = iter->first;
623 return &(iter->second);
636 if( m_mapVServo.size() == 0 )
641 if( iter == m_mapVServo.begin() )
643 iter = m_mapVServo.end();
648 nServoId = iter->first;
649 return &(iter->second);
659 virtual void sched(
long lPeriod);
718 virtual void stopMotion(
DynaServo *pServo);
751 static void *bgThread(
void *pArg);
769 void terminateThread();
772 #endif // _DYNA_BG_THREAD_H RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
MapVServo m_mapVServo
virtual servo associative map
pthread_t m_thread
pthread identifier
DynaAgent_T m_agent
servo/chain agent
BgThreadState
Background thread states.
zombie instance - no thread exists
int m_nGoalSpeed
current goal speed
double m_fHz
thread execution hertz
void unlock()
Unlock the background thread.
std::deque< double > m_histTorqueIn
recent history of joint torques
virtual void RegisterUserCallback(void(*fnUserCb)(void *), void *pUserArg)
Register user-defined callback function.
double m_fTorqueOut
low-pass filtered torque
MapVServo::iterator m_iterDynamics
dynamics iterator
static const double TOLERANCE_DFT
default pos. tolerance (deg)
thread created and ready to run
double m_fTolerance
position ± tolerance (degrees)
void setTolerance(double fTolerance)
Set position tolerance.
bool m_bOverTorqueCtl
[not] in torque overload control
BgThreadState GetCurrentState()
Get current background thread state.
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
pthread_cond_t m_condSync
synchonization condition
static const double HZ_EXEC_DFT
default exec hertz
VServoState
Servo dynamics position control state.
pthread_mutex_t m_mutexSync
synchonization mutex
virtual DynaVServo * getPrevVServo(MapVServo::iterator &iter, int &nServoId)
Get the previous virtual servo.
uint_t m_uNumServos
number of servos to monitor
The Dynamixel Position PID Class.
double getHz()
Get control and monitoring hetrz rate.
Dynamixel Servo Abstract Base Class.
long m_TSched
scheduler μs period
bool m_bOverTorqueCond
is [not] in torque overload condition
void unlock()
Unlock the virtual servo.
int m_nHealthServoId
current health monitoring servo id
BgThreadState m_eState
thread state
void * m_pUserArg
user callback argument
pthread_mutex_t m_mutexSync
synchonization mutex
int getGoalDir(DynaServo *pServo)
Get the current goal rotation direction.
VServoState m_eState
virtual servo state
Background Thread Virtual Servo Class.
Servo Proxy Agents Calls Structure.
DynaServo * m_pServo
registered dynamixel servo
map< int, DynaVServo > MapVServo
Virtual Servo Associative Map Type.
Dynamixel Chain Container Base Class.
static const double HZ_EXEC_MIN
minimum exec hertz
bool IsOdometerReversed()
Test if the virtual odometer is reversed.
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
no active position control
bool isServoBeingControlled(int nServoId)
Checks if servo is currently being controlled.
virtual DynaVServo * getNextVServo(MapVServo::iterator &iter, int &nServoId)
Get the next virtual servo.
RoadNarrows Dynamixel Top-Level Package Header File.
int m_nOdGoalPos
current goal position
static const long T_EXEC_MIN
task exec period min (100usec)
MapVServo::iterator m_iterHealth
health iterator
void lock()
Lock the virtual servo.
DynaPidPos m_pidPos
servo position PID
long m_TExec
full execution cycle μs period
void lock()
Lock the background thread.
long m_dTSched
scheduler delta time
virtual void UnregisterUserCallback()
Unregister user-defined callback function.
DynaChain * m_pChain
or registered dynamixel chain
RoadNarrows Dynamixel Library Error and Logging Routines.
int GetOdometer()
Get the current virtual odometer value.
int m_nTolerance
position ± tolerance (ticks)