54 #include "rnr/rnrconfig.h" 57 #include "rnr/units.h" 119 "Servos %d and/or %d: Already have linkage.",
120 nServoIdMaster, nServoIdSlave);
129 "servo %d model %s(%d) != servo %d model %s(%d).",
166 (
m_links[nServoIdSlave].m_nServoIdMate == nServoIdMaster)),
168 "Servos %d and/or %d: Not linked.",
169 nServoIdMaster, nServoIdSlave);
214 if( !DynaServo::Ping(
m_comm, nServoId) )
217 DYNA_LOG_ERROR(rc,
"Pinging servo %d failed. Cannot add.", nServoId);
245 if( DynaServo::Ping(
m_comm, nServoId) )
326 DYNA_LOG_ERROR(rc,
"Failed to create servo %d. Cannot add.", nServoId);
340 LOGDIAG3(
"%s servo %d (model number 0x%04x) added to chain.",
354 if( (pServo =
m_pChain[nServoId]) == NULL )
377 LOGDIAG3(
"%s servo %d (model number 0x%04x) removed from chain.",
383 m_pChain[nServoId] = NULL;
402 pServoThis =
m_pChain[nServoIdThis];
405 if( pServoThis == NULL )
416 ((pServoMate =
m_pChain[nServoIdMate]) == NULL) )
491 return pServo->MoveTo(nGoalOdPos);
500 va_start(ap, uCount);
505 tuplesPos[i].
m_nPos = va_arg(ap,
int);
539 rc = pServo->MoveTo(tuplesPos[i].m_nPos);
545 tuple[j].
m_nServoId = tuplesPos[i].m_nServoId;
546 tuple[j].
m_nPos = tuplesPos[i].m_nPos;
551 if( (rc ==
DYNA_OK) && (j > 0) )
571 return pServo->MoveAtSpeedTo(nGoalSpeed, nGoalOdPos);
582 va_start(ap, uCount);
586 tuplesSpeedPos[i].
m_nServoId = va_arg(ap,
int);
587 tuplesSpeedPos[i].
m_nSpeed = va_arg(ap,
int);
588 tuplesSpeedPos[i].
m_nPos = va_arg(ap,
int);
623 rc = pServo->MoveAtSpeedTo(tuplesSpeedPos[i].m_nSpeed,
624 tuplesSpeedPos[i].m_nPos);
632 tuplesSpeed[j].
m_nServoId = tuplesSpeedPos[i].m_nServoId;
633 tuplesSpeed[j].
m_nSpeed = tuplesSpeedPos[i].m_nSpeed;
635 tuplesPos[j].
m_nServoId = tuplesSpeedPos[i].m_nServoId;
636 tuplesPos[j].
m_nPos = tuplesSpeedPos[i].m_nPos;
642 if( (j > 0) && (rc ==
DYNA_OK) )
666 return pServo->MoveAtSpeed(nGoalSpeed);
677 va_start(ap, uCount);
682 tuplesSpeed[i].
m_nSpeed = va_arg(ap,
int);
722 for(nTries=0; nTries<nMaxTries; ++nTries)
800 tuples[uCount].
m_uVal = uVal;
807 for(iter=0; iter<(int)uCount; ++iter)
824 va_start(ap, uCount);
829 tuplesPos[i].
m_nPos = va_arg(ap,
int);
859 nGoalOdPosM = tuplesPos[i].
m_nPos;
872 (nEncPos <= pServoM->m_spec.m_uRawPosMax)),
874 "Master servo %d: Goal odometer position %d(encoder=%d): Out of range.",
879 tuples[j].
m_uVal = (uint_t)nEncPos;
892 rc = pServoM->CalcMatesGoalPos(nGoalOdPosM, &nGoalOdPosS);
894 DYNA_TRY_RC(rc,
"Slave servo %d: Failed.", nServoIdS);
899 tuples[j].
m_uVal = (uint_t)nEncPos;
927 va_start(ap, uCount);
932 tuplesSpeed[i].
m_nSpeed = va_arg(ap,
int);
958 nGoalSpeedM = tuplesSpeed[i].
m_nSpeed;
968 "Master servo %d: Goal speed %d: Out of range.",
972 tuples[j].
m_uVal = pServoM->PackGoalSpeed(nGoalSpeedM);
981 nGoalSpeedS = pServoM->CalcMatesGoalSpeed(nGoalSpeedM);
984 tuples[j].
m_uVal = pServoS->PackGoalSpeed(nGoalSpeedS);
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
int m_nServoIdMate
linked mate's servo id
virtual uint_t GetServoMode() const
Get the servo operational mode.
Synchronous Write Speed Tuple Structure.
Synchronous Write Speed-Position Tuple Structure.
virtual int SyncWriteGoalSpeed(DynaSpeedTuple_T tuplesSpeed[], uint_t uCount)
Synchronous write new goal speed for servos.
#define DYNA_TRY_SERVO_ID(id)
Testing if the servo id is in range exception macro.
#define DYNA_OK
not an error, success
#define DYNA_TORQUE_EN_OFF
disable power drive to the motor
virtual int SyncMoveTo(DynaPosTuple_T tuplesPos[], uint_t uCount)
Synchronous move servos to new goal positions in tuple list.
virtual ~DynaChain()
Destructor.
virtual int Freeze()
Freeze all servos at current position.
#define DYNA_ADDR_GOAL_SPEED_LSB
goal speed lsb (RW)
#define DYNA_MODE_SERVO
servo mode with limited rotation
virtual int MoveAtSpeedTo(int nServoId, int nGoalSpeed, int nGoalOdPos)
Move at speed to the goal postition.
virtual int vSyncMoveTo(uint_t uCount,...)
Synchronous move servos to new goal positions.
virtual int MoveAtSpeed(int nServoId, int nGoalSpeed)
Move at speed.
#define DYNA_LINK_MASTER
servo is linked, serving as the master
int m_nIIdx[DYNA_ID_NUMOF]
indirect index
uint_t m_uRawPosMin
minimum raw position value (servo mode)
const DynaServo * operator[](int nServoId)
Subscript operator.
uint_t m_uRawSpeedMax
maximum raw speed magnitude value
#define DYNA_TRY_EXPR(expr, ecode, efmt,...)
Test if the servo is in the required mode(s) exception macro.
DynaComm & m_comm
bus communication instance
void Init()
Initialize chain class instance.
virtual uint_t GetNumberOfMastersInChain()
Get the number of servos currently in chain.
virtual int vSyncWriteGoalPos(uint_t uCount,...)
Synchronous write new goal positions for servos.
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
virtual int vSyncMoveAtSpeed(uint_t uCount,...)
Synchronous move servos at the given speeds.
INLINE_IN_H int iabs(int a)
Return absolute value of a.
#define DYNA_ECODE_NO_SERVO
no servo found
virtual int MoveTo(int nServoId, int nGoalOdPos)
Move to the goal postition.
virtual int ChainEntryDelete(int nServoId)
Remove servo from chain and delete.
uint_t m_uNumInChain
number of servos in chain
#define DYNA_ID_MIN
minimum servo id
virtual bool HasAgent()
Tests if servo has a registered agent.
virtual int vSyncWriteGoalSpeed(uint_t uCount,...)
Synchronous write new goal speed for for servos.
#define DYNA_TRY_IS_MASTER(pservo)
Test if the servo is a master servo.
#define DYNA_ECODE_NOT_SUPP
feature/function not supported
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
#define DYNA_ID_NUMOF
number of unique servo id's
virtual int ChainEntryNew(int nServoId)
Create new dervied DyanServo object and insert into chain.
Miscellaneous collection of useful utilities.
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
virtual int LinkServos(int nServoIdMaster, int nServoIdSlave, bool bIsReversed)
Software link two unlinked servos in a master-slave configuration.
#define DYNA_LINK_NONE
servo is not linked to another servo
DynaServoLink_T m_links[DYNA_ID_NUMOF]
servo linked info
Dynamixel Servo Abstract Base Class.
virtual void ClearLinkData(int nServoId)
Clear local link data for the given servo.
virtual int AddNewServosByScan()
Scan and add all discovered and created servos to the Dynamixel chain.
virtual int AddNewServoForced(int nServoId, uint_t uModelNum)
Force create and add a servo to the Dynamixel chain.
#define DYNA_LOG_ERROR(ecode, efmt,...)
Log Error.
bool_t m_bTorqueEnabled
torque [not] enabled
#define DYNA_ID_MAX
maximum servo id
virtual int SyncMoveAtSpeed(DynaSpeedTuple_T tuplesSpeed[], uint_t uCount)
Synchronous move servos at the given speeds.
virtual int SyncWriteTorqueEnable(bool bState)
Synchronous write to all of the servos in the chain to enable/disable applied torque.
The libDynamixel internal declarations.
static DynaServo * New(DynaComm &comm, int nServoId)
Archetype constructor to create a new Dynamixel servo instance.
virtual void Link(uint_t uLinkType, DynaServo *pServoMate, bool bRotReversed)
Link this servo to another.
virtual int Stop()
Stop all servos.
virtual int vSyncMoveAtSpeedTo(uint_t uCount,...)
Synchronous move servos to new goal positions at the given speeds.
virtual int Release()
Release all servos from any applied torque.
virtual int RemoveAllServos()
Remove all servos from chain and delete.
DynaServo * m_pChain[DYNA_ID_NUMOF]
chain of servos
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
#define DYNA_MODE_CONTINUOUS
continuous mode with/without position
virtual void Unlink()
Unlink this servo.
#define DYNA_LINK_SLAVE
servo is linked, serving as the slave
int m_nGoalSpeed
goal speed (raw)
virtual int SyncWriteGoalPos(DynaPosTuple_T tuplesPos[], uint_t uCount)
Synchronous write new goal positions for servos.
virtual void AuditLinks()
Audit servo links and repair or delete.
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
#define DYNA_TRY_SERVO_HAS_POS_CTL(pservo)
Test if the servo has positiion control.
virtual int RemoveServo(int nServoId)
Remove from chain and delete.
virtual int SyncWrite(uint_t uAddr, uint_t uValSize, DynaSyncWriteTuple_T tuples[], uint_t uCount)=0
Synchronous Write 8/16-bit values to a list of Dynamixel servos.
int OdometerToEncoder(int nOdPos)
Convert virtual odometer units to servo encoder units.
RoadNarrows Dynamixel Top-Level Package Header File.
virtual uint_t GetModelNumber() const
Get servo model number.
virtual uint_t GetServoId() const
Get servo id.
DynaChain(DynaComm &comm)
Default initialization constructor.
virtual bool IsMaster(int nServoId) const
Test if the servo is a master.
uint_t m_uNumMastersInChain
num of master servos in chain
bool m_bRotReversed
linked do [not] rotate in opposite directions
DynaServoState_T m_state
servo shadowed RAM state
#define DYNA_ECODE_LINKED
linked servos error
#define DYNA_ID_NONE
no servo id
DynaServoSpec_T m_spec
servo specification
uint_t m_uGoalPos
goal position (encoder ticks)
#define DYNA_TORQUE_EN_ON
enable power drive to the motor
virtual int AddNewServo(int nServoId)
Create a new servo and add it to the Dynamixel chain.
virtual int EStop()
Emergency stop all servos.
virtual int UnlinkServos(int nServoIdMaster)
Unlink two software linked servos.
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
virtual void SetLinkData(int nServoId, uint_t uLinkType, int nServoIdMate, bool bRotReversed)
Set local link data for the given servo.
#define DYNA_ADDR_GOAL_POS_LSB
goal position lsb (RW)
#define DYNA_ECODE_BAD_VAL
bad value
virtual const char * GetModelName() const
Get servo model name string.
Position Tuple Structure.
#define DYNA_ADDR_TORQUE_EN
torque enable (RW)
#define DYNA_TRY_SERVO_IN_CHAIN(pchain, id)
Test if the servo id is valid and present in chain exception macro.
#define DYNA_TRY_SERVO_IN_MODE(pservo, mode)
Test if the servo is in the given mode.
uint_t m_uLinkType
linked type Dynamixel Servo Link Types
virtual int SyncMoveAtSpeedTo(DynaSpeedPosTuple_T tuplesSpeedPos[], uint_t uCount)
Synchronous move servos to new goal positions at the given speeds.
#define DYNA_TRY_RC(rc, fmt,...)
Test if Dynamixel return code is not an error.
RoadNarrows Dynamixel Library Error and Logging Routines.
Dynamixel Bus Communications Abstract Base Class.
#define DYNA_TRY_COMM(comm)
Test if bus communication is available exception macro.