![]() |
Dynamixel
2.9.5
RoadNarrows Robotics Dynamixel Package
|
Dynamixel Serial Bus Communications Class. More...
#include <DynaCommSerial.h>
Public Types | |
enum | CtlSignal { CtlSignalMinGPIO = -999, CtlSignalMaxGPIO = 999, CtlSignalModemRTS = 1000, CtlSignalModemCTS = 1001, CtlSignalCustom = 1010, CtlSignalNone = 1011 } |
Half-duplex control signals. More... | |
![]() | |
typedef void(* | HalfDuplexTxFunc_T) (void *pArg) |
Half-duplex control transmit function type. | |
typedef void(* | HalfDuplexRxFunc_T) (void *pArg, size_t uNumTxBytes) |
Half-duplex control receive function type. | |
Public Member Functions | |
DynaCommSerial () | |
Default constructor. | |
DynaCommSerial (const char *sSerialDevName, int nBaudRate) | |
Initialization constructor. More... | |
virtual | ~DynaCommSerial () |
Destructor. | |
const char * | GetSerialDeviceName () const |
virtual int | GetResourceId () const |
Get system-unique resource identifier. More... | |
virtual int | Open (const char *sSerialDevName, int nBaudRate) |
Open serial communication to dynamixel bus. More... | |
virtual int | Open () |
(Re)Open serial communication to dynamixel bus. More... | |
virtual int | Close () |
Close serial communication to dynamixel bus. More... | |
virtual int | SetBaudRate (int nNewBaudRate) |
Set the Dynamixel Bus new baud rate. More... | |
virtual int | SetHalfDuplexCtl (int nSignal, HalfDuplexTxFunc_T fnEnableTx=NULL, HalfDuplexRxFunc_T fnEnableRx=NULL) |
virtual int | Read8 (int nServoId, uint_t uAddr, byte_t *pVal) |
Read an 8-bit value from Dynamixel servo control table. More... | |
virtual int | Write8 (int nServoId, uint_t uAddr, byte_t byVal) |
Write an 8-bit value to Dynamixel servo control table. More... | |
virtual int | Read16 (int nServoId, uint_t uAddr, ushort_t *pVal) |
Read a 16-bit value from Dynamixel servo control table. More... | |
virtual int | Write16 (int nServoId, uint_t uAddr, ushort_t uhVal) |
Write a 16-bit value to Dynamixel servo control table. More... | |
virtual int | SyncWrite (uint_t uAddr, uint_t uValSize, DynaSyncWriteTuple_T tuples[], uint_t uCount) |
Synchronous Write 8/16-bit values to a list of Dynamixel servos. More... | |
virtual bool | Ping (int nServoId) |
Ping the servo. More... | |
virtual int | Reset (int nServoId) |
Reset a servo back to default values. More... | |
![]() | |
DynaComm () | |
DynaComm (const char *sUri, int nBaudRate) | |
virtual | ~DynaComm () |
Destructor. | |
const char * | GetDeviceUri () const |
const int | GetBaudRate () const |
virtual int | Read8 (int nServoId, uint_t uAddr, uint_t *pVal) |
Read an 8-bit value from Dynamixel servo control table. More... | |
virtual int | Write8 (int nServoId, uint_t uAddr, uint_t uVal) |
Write an 8-bit value to Dynamixel servo control table. More... | |
virtual int | Read16 (int nServoId, uint_t uAddr, uint_t *pVal) |
Read a 16-bit value from Dynamixel servo control table. More... | |
virtual int | Write16 (int nServoId, uint_t uAddr, uint_t uVal) |
Write a 16-bit value to Dynamixel servo control table. More... | |
virtual int | vSyncWrite (uint_t uAddr, uint_t uValSize, uint_t uCount,...) |
Synchronous write 8/16-bit values to a list of Dynamixel servos. More... | |
virtual bool | IsOpen () |
Test if Dynamixel Bus is open. More... | |
virtual uint_t | GetAlarms () |
Get current alarms. More... | |
virtual void | ClearAlarms () |
Clear current alarms. | |
virtual uint_t | GetBusStatus () |
Get the Dynamixel Bus status. More... | |
Static Public Attributes | |
static const int | RetryMax = 5 |
maximum number of I/O retries | |
static const int | RetryWait = 20000 |
microsecond wait between retries | |
Protected Member Functions | |
int | MakeSerialIndex (const char *sSerialDevName) |
Make serial index from serial device name. More... | |
void | InitRTS () |
Intialize RTS signalling. | |
void | InitCTS () |
Intialize CTS signalling. | |
void | InitGPIO (int nGpioNum) |
Intialize GPIO signalling. More... | |
Static Protected Member Functions | |
static void | EnableTxRTS (void *pArg) |
Enable transmit via RTS signal. More... | |
static void | EnableRxRTS (void *pArg, size_t uNumTxBytes) |
Enable receive via RTS signal. More... | |
static void | EnableTxCTS (void *pArg) |
Enable transmit via CTS signal. More... | |
static void | EnableRxCTS (void *pArg, size_t uNumTxBytes) |
Enable receive via CTS signal. More... | |
static void | EnableTxGPIO (void *pArg) |
Enable transmit via GPIO signal. More... | |
static void | EnableRxGPIO (void *pArg, size_t uNumTxBytes) |
Enable receive via GPIO signal. More... | |
Protected Attributes | |
char * | m_sSerialDevName |
serial device name | |
int | m_fd |
serial file descriptor | |
int | m_nGpioNum |
gpio number | |
int | m_fdGpio |
gpio file descriptor | |
int | m_nGpioVal |
gpio shadow'ed value | |
libdxl::dxl | m_dxl |
dxl low-level interface | |
![]() | |
char * | m_sDevUri |
dynamixel bus device URI | |
int | m_nBaudRate |
baud rate | |
bool | m_bIsOpen |
dynamixel bus communication is [not] open | |
uint_t | m_uBusStatus |
bus comminication status | |
uint_t | m_uAlarms |
servo alarms from last I/O operation | |
shm_mutex_t | m_mutexComm |
synchonization mutex | |
Additional Inherited Members | |
![]() | |
static DynaComm * | New (const char *sUri, int nBaudRate) |
Archetype constructor to create a new Dynamixel bus communication derived instance. More... | |
static std::string | GetAlarmsString (const uint_t uAlarms, const std::string &strSep="; ") |
Get a formatted servo alarms string associated with the alarms. More... | |
static std::string | GetAlarmsShortString (const uint_t uAlarms, const std::string &strSep=",") |
Get a formatted servo alarms short string associated with the alarms. More... | |
static const char * | GetBusStatusString (uint_t uBusStatus) |
Get the string describing the Dynamixel servo communication status. More... | |
static int | BaudRateToNum (int nBaudRate) |
Map baud rate to Dynamixel baud number. More... | |
static int | BaudNumToRate (int nBaudRate) |
Map baud number to Dynamixel baud rate. More... | |
static int | BaudRateAt (int nIndex) |
Get the baud rate associated with the given index. More... | |
static int | BaudNumAt (int nIndex) |
Get the baud number associated with the given index. More... | |
![]() | |
static const key_t | ShmKey = 0x70add12a |
shared memory key More... | |
Dynamixel Serial Bus Communications Class.
Definition at line 74 of file DynaCommSerial.h.
Half-duplex control signals.
Definition at line 86 of file DynaCommSerial.h.
DynaCommSerial::DynaCommSerial | ( | const char * | sSerialDevName, |
int | nBaudRate | ||
) |
Initialization constructor.
The given serial device is opened at the baud rate.
sSerialDevName | Serial device name. |
nBaudRate | Serial device baud rate. |
Definition at line 89 of file DynaCommSerial.cxx.
References m_fd, m_fdGpio, m_nGpioNum, m_nGpioVal, m_sSerialDevName, newstr(), and Open().
|
virtual |
Close serial communication to dynamixel bus.
Implements DynaComm.
Definition at line 185 of file DynaCommSerial.cxx.
References libdxl::dxl::close(), DYNA_OK, DynaComm::m_bIsOpen, m_dxl, and m_fd.
Referenced by GetResourceId(), Open(), and ~DynaCommSerial().
|
staticprotected |
Enable receive via CTS signal.
pArg | Pointer to this. |
uNumTxBytes | Number of transmit bytes (being) transmitted. |
Definition at line 598 of file DynaCommSerial.cxx.
References m_fd.
Referenced by SetHalfDuplexCtl().
|
staticprotected |
Enable receive via GPIO signal.
pArg | Pointer to this. |
uNumTxBytes | Number of transmit bytes (being) transmitted. |
Definition at line 638 of file DynaCommSerial.cxx.
References m_fdGpio, DynaComm::m_nBaudRate, m_nGpioNum, and m_nGpioVal.
Referenced by SetHalfDuplexCtl().
|
staticprotected |
Enable receive via RTS signal.
pArg | Pointer to this. |
uNumTxBytes | Number of transmit bytes (being) transmitted. |
Definition at line 578 of file DynaCommSerial.cxx.
References m_fd.
Referenced by SetHalfDuplexCtl().
|
staticprotected |
Enable transmit via CTS signal.
pArg | Pointer to this. |
Definition at line 591 of file DynaCommSerial.cxx.
References m_fd.
Referenced by SetHalfDuplexCtl().
|
staticprotected |
Enable transmit via GPIO signal.
pArg | Pointer to this. |
Definition at line 623 of file DynaCommSerial.cxx.
References m_fdGpio, m_nGpioNum, and m_nGpioVal.
Referenced by SetHalfDuplexCtl().
|
staticprotected |
Enable transmit via RTS signal.
pArg | Pointer to this. |
Definition at line 571 of file DynaCommSerial.cxx.
References m_fd.
Referenced by SetHalfDuplexCtl().
|
inlinevirtual |
Get system-unique resource identifier.
Implements DynaComm.
Definition at line 136 of file DynaCommSerial.h.
References Close(), m_fd, Open(), Ping(), Read16(), Read8(), Reset(), SetBaudRate(), SetHalfDuplexCtl(), SyncWrite(), Write16(), and Write8().
|
inline |
Get the Dynamixel Bus serial device name.
Definition at line 126 of file DynaCommSerial.h.
References m_sSerialDevName.
|
protected |
Intialize GPIO signalling.
nGpioNum | GPIO number. |
Definition at line 606 of file DynaCommSerial.cxx.
References m_fdGpio, m_nGpioNum, and m_nGpioVal.
Referenced by SetHalfDuplexCtl().
|
protected |
Make serial index from serial device name.
sSeriaDevName | Serial device name. |
Definition at line 534 of file DynaCommSerial.cxx.
References DYNA_ECODE_BAD_DEV, and DYNA_ECODE_BAD_VAL.
Referenced by Open().
|
virtual |
Open serial communication to dynamixel bus.
The given serial device is opened at the given baud rate.
sSerialDevName | Serial device name. |
nBaudRate | Serial device baud rate. |
Implements DynaComm.
Definition at line 111 of file DynaCommSerial.cxx.
References Close(), DynaComm::m_nBaudRate, m_sSerialDevName, newstr(), and Open().
|
virtual |
(Re)Open serial communication to dynamixel bus.
Implements DynaComm.
Definition at line 126 of file DynaCommSerial.cxx.
References DynaComm::BaudRateToNum(), Close(), libdxl::dxl::dxl_initialize(), DYNA_ECODE_BAD_DEV, DYNA_ECODE_BAD_VAL, DYNA_LOG_ERROR, DYNA_OK, libdxl::dxl::getFd(), DynaComm::m_bIsOpen, m_dxl, m_fd, DynaComm::m_nBaudRate, m_sSerialDevName, MakeSerialIndex(), and libdxl::dxl::open().
Referenced by DynaCommSerial(), GetResourceId(), and Open().
|
virtual |
Ping the servo.
nServoId | Servo id. |
Implements DynaComm.
Definition at line 487 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DYNA_TRY_COMM, libdxl::dxl::getResult(), m_dxl, DynaComm::m_mutexComm, and libdxl::dxl::ping().
Referenced by GetResourceId().
|
virtual |
Read a 16-bit value from Dynamixel servo control table.
nServoId | Servo id. | |
uAddr | Servo control table address. | |
[out] | pVal | Value read. |
Implements DynaComm.
Definition at line 338 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DYNA_ECODE_RX_TIMEOUT, DYNA_LOG_ERROR, DYNA_LOG_SERVO_ALARMS, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getResult(), libdxl::dxl::getRxPacketErrBits(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uAlarms, DynaComm::m_uBusStatus, libdxl::dxl::readWord(), RetryMax, and RetryWait.
Referenced by GetResourceId().
|
virtual |
Read an 8-bit value from Dynamixel servo control table.
nServoId | Servo id. | |
uAddr | Servo control table address. | |
[out] | pVal | Value read. |
Implements DynaComm.
Definition at line 262 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DYNA_ECODE_RX_TIMEOUT, DYNA_LOG_ERROR, DYNA_LOG_SERVO_ALARMS, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getResult(), libdxl::dxl::getRxPacketErrBits(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uAlarms, DynaComm::m_uBusStatus, libdxl::dxl::readByte(), RetryMax, and RetryWait.
Referenced by GetResourceId().
|
virtual |
Reset a servo back to default values.
nServoId | Servo id. |
Implements DynaComm.
Definition at line 500 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DXL_INST_RESET, DYNA_LOG_ERROR, DYNA_LOG_SERVO_ALARMS, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getResult(), libdxl::dxl::getRxPacketErrBits(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uAlarms, DynaComm::m_uBusStatus, libdxl::dxl::setTxPacketId(), libdxl::dxl::setTxPacketInstruction(), libdxl::dxl::setTxPacketLength(), and libdxl::dxl::txrxPacket().
Referenced by GetResourceId().
|
virtual |
Set the Dynamixel Bus new baud rate.
nNewBaudRate | New baud rate. |
Implements DynaComm.
Definition at line 196 of file DynaCommSerial.cxx.
References DynaComm::BaudRateToNum(), DYNA_ECODE_SYS, DYNA_LOG_ERROR, DYNA_LOG_SYS_ERROR, DYNA_OK, DynaComm::m_bIsOpen, m_dxl, DynaComm::m_nBaudRate, m_sSerialDevName, and libdxl::dxl::setBaudRate().
Referenced by GetResourceId().
|
virtual |
Set Dynamixel Bus half-duplex software control.
The Dynamixel 3-wire bus is half-duplex. Hardware may automatically control toggling between transmit and receive (e.g. RoadNarrows DynaUSB dongle). If there is no hardware support, then software must provide the tx/rx toggle functions.
nSignal | Signal assign to toggle. |
fnEnableTx | Enable transmit function. |
fnEnableRx | Enable receive function. |
Implements DynaComm.
Definition at line 225 of file DynaCommSerial.cxx.
References CtlSignalCustom, CtlSignalModemCTS, CtlSignalModemRTS, CtlSignalNone, DYNA_OK, EnableRxCTS(), EnableRxGPIO(), EnableRxRTS(), EnableTxCTS(), EnableTxGPIO(), EnableTxRTS(), InitCTS(), InitGPIO(), InitRTS(), m_dxl, m_fd, and libdxl::dxl::setHalfDuplexCallbacks().
Referenced by GetResourceId().
|
virtual |
Synchronous Write 8/16-bit values to a list of Dynamixel servos.
uAddr | Servo control table write address. |
uValSize | Value storage size at addtess. 1 or 2 bytes. |
tuples | Array of servo id, write value 2-tuples. |
uCount | Number of tuples. |
Implements DynaComm.
Definition at line 414 of file DynaCommSerial.cxx.
References DXL_BROADCAST_ID, DXL_COMM_RXSUCCESS, DXL_INST_SYNC_WRITE, DYNA_ECODE_RX_TIMEOUT, DYNA_LOG_ERROR, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getHighByte(), libdxl::dxl::getLowByte(), libdxl::dxl::getResult(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uBusStatus, DynaSyncWriteTuple_T::m_uVal, RetryMax, RetryWait, libdxl::dxl::setTxPacketId(), libdxl::dxl::setTxPacketInstruction(), libdxl::dxl::setTxPacketLength(), libdxl::dxl::setTxPacketParameter(), and libdxl::dxl::txrxPacket().
Referenced by GetResourceId().
|
virtual |
Write a 16-bit value to Dynamixel servo control table.
nServoId | Servo id. |
uAddr | Servo control table address. |
uhVal | Value written. |
Implements DynaComm.
Definition at line 376 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DYNA_ECODE_RX_TIMEOUT, DYNA_LOG_ERROR, DYNA_LOG_SERVO_ALARMS, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getResult(), libdxl::dxl::getRxPacketErrBits(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uAlarms, DynaComm::m_uBusStatus, RetryMax, RetryWait, and libdxl::dxl::writeWord().
Referenced by GetResourceId().
|
virtual |
Write an 8-bit value to Dynamixel servo control table.
nServoId | Servo id. |
uAddr | Servo control table address. |
byVal | Value written. |
Implements DynaComm.
Definition at line 300 of file DynaCommSerial.cxx.
References DXL_COMM_RXSUCCESS, DYNA_ECODE_RX_TIMEOUT, DYNA_LOG_ERROR, DYNA_LOG_SERVO_ALARMS, DYNA_OK, DYNA_TRY_COMM, DynaMapDxlToEcode(), libdxl::dxl::getResult(), libdxl::dxl::getRxPacketErrBits(), m_dxl, DynaComm::m_mutexComm, DynaComm::m_uAlarms, DynaComm::m_uBusStatus, RetryMax, RetryWait, and libdxl::dxl::writeByte().
Referenced by GetResourceId().