53 #include "rnr/rnrconfig.h" 56 #include "rnr/serdev.h" 128 #if 0 // old dxl library 142 #if 0 // old dxl library 161 DYNA_LOG_ERROR(rc,
"Serial device \"%s\": Failed to initalize interface.",
169 DYNA_LOG_ERROR(rc,
"Serial device \"%s\": Failed to initalize interface.",
178 LOGDIAG3(
"Dynamixel bus communication opened on \"%s\"@%d.",
214 "Serial device \"%s\": Failed to set baud rate %d.",
233 SerDevSetHwFlowControl(
m_fd,
true);
240 SerDevSetHwFlowControl(
m_fd,
true);
332 DYNA_LOG_ERROR(rc,
"Write8(%d, 0x%02x, 0x%02x)", nServoId, uAddr, byVal);
408 DYNA_LOG_ERROR(rc,
"Write16(%d, 0x%02x, 0x%04x)", nServoId, uAddr, uhVal);
440 for(i=0; i<(int)uCount; ++i)
481 uAddr, uValSize, uCount);
538 if( (sSerialDevName == NULL) || (*sSerialDevName == 0) )
543 if( access(sSerialDevName, F_OK) )
548 for(i=j=(
int)strlen(sSerialDevName)-1; i>=0; --i)
550 if( !isdigit(sSerialDevName[i]) )
556 if( (i < 0) || (i == j) )
561 index = atoi(sSerialDevName+i+1);
568 SerDevSetHwFlowControl(
m_fd,
true);
575 SerDevAssertRTS(pThis->
m_fd);
582 SerDevFIFOOutputDrain(pThis->
m_fd);
583 SerDevDeassertRTS(pThis->
m_fd);
588 SerDevSetHwFlowControl(
m_fd,
true);
595 SerDevAssertCTS(pThis->
m_fd);
602 SerDevFIFOOutputDrain(pThis->
m_fd);
603 SerDevDeassertCTS(pThis->
m_fd);
619 LOGERROR(
"GPIO %d: Failed to open.", abs(
m_nGpioNum));
631 if( gpioQuickWrite(pThis->
m_fdGpio, val) == OK )
640 static double TuneMargin = -30.0;
665 usecTx = (double)(uNumTxBytes * 10)/(double)pThis->
m_nBaudRate * 1000000.0
670 unsigned int usec = (
unsigned int)usecTx;
677 if( gpioQuickWrite(pThis->
m_fdGpio, val) == OK )
uint_t m_uAlarms
servo alarms from last I/O operation
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
int DynaMapDxlToEcode(int nDxlError)
Map DXL library error code to Dynamixel error code.
Modified dynamixel SDK interface.
virtual int Write16(int nServoId, uint_t uAddr, ushort_t uhVal)
Write a 16-bit value to Dynamixel servo control table.
char * newstr(const char *s)
Allocate new duplicated string.
void writeWord(int id, int address, int value)
Write word to servo's control table.
#define DYNA_LOG_SYS_ERROR(ecode, efmt,...)
Log System Error.
virtual int Read16(int nServoId, uint_t uAddr, ushort_t *pVal)
Read a 16-bit value from Dynamixel servo control table.
int getHighByte(int word)
Get high byte from word.
Dynamixel Serial Bus Communications Class.
#define DXL_INST_SYNC_WRITE
synchronous write servo(s) data
void InitCTS()
Intialize CTS signalling.
#define DYNA_OK
not an error, success
int getLowByte(int word)
Get low byte from word.
void setTxPacketParameter(int index, int value)
Set transmit packet parameter value.
#define DXL_INST_RESET
reset servo defaults
virtual int Write8(int nServoId, uint_t uAddr, byte_t byVal)
Write an 8-bit value to Dynamixel servo control table.
virtual int SetHalfDuplexCtl(int nSignal, HalfDuplexTxFunc_T fnEnableTx=NULL, HalfDuplexRxFunc_T fnEnableRx=NULL)
int getResult()
Get last transmit/receive result.
#define DYNA_ECODE_RX_TIMEOUT
dynamixel receive packet time out
#define DXL_COMM_RXSUCCESS
receive success
void txrxPacket()
Transmit instruction packet and receive status response packet.
void setTxPacketId(int id)
Set transmit packet servo id.
void writeByte(int id, int address, int value)
Write byte to servo's control table.
virtual int Read8(int nServoId, uint_t uAddr, byte_t *pVal)
Read an 8-bit value from Dynamixel servo control table.
not a signal, but a value to clear signal
int setHalfDuplexCallbacks(dxl_hdctl_tx_cb_t enable_tx_cb, dxl_hdctl_rx_cb_t enable_rx_cb, void *arg)
Set serial half-duplex callbacks.
shm_mutex_t m_mutexComm
synchonization mutex
#define DYNA_ECODE_SYS
system (errno) error
bool m_bIsOpen
dynamixel bus communication is [not] open
virtual int SetBaudRate(int nNewBaudRate)
Set the Dynamixel Bus new baud rate.
static void EnableRxRTS(void *pArg, size_t uNumTxBytes)
Enable receive via RTS signal.
int m_nGpioVal
gpio shadow'ed value
char * m_sSerialDevName
serial device name
#define DYNA_ECODE_BAD_DEV
no or bad serial device
virtual int Reset(int nServoId)
Reset a servo back to default values.
#define DYNA_LOG_ERROR(ecode, efmt,...)
Log Error.
int MakeSerialIndex(const char *sSerialDevName)
Make serial index from serial device name.
void setTxPacketInstruction(int instruction)
Set transmit packet instruction.
static void EnableRxGPIO(void *pArg, size_t uNumTxBytes)
Enable receive via GPIO signal.
static void EnableRxCTS(void *pArg, size_t uNumTxBytes)
Enable receive via CTS signal.
libdxl::dxl m_dxl
dxl low-level interface
virtual int Open()
(Re)Open serial communication to dynamixel bus.
void(* HalfDuplexRxFunc_T)(void *pArg, size_t uNumTxBytes)
Half-duplex control receive function type.
#define DYNA_LOG_SERVO_ALARMS(id, alarms)
Log servo alarms.
void(* HalfDuplexTxFunc_T)(void *pArg)
Half-duplex control transmit function type.
The libDynamixel internal declarations.
uint_t m_uBusStatus
bus comminication status
static const int RetryMax
maximum number of I/O retries
void InitRTS()
Intialize RTS signalling.
void InitGPIO(int nGpioNum)
Intialize GPIO signalling.
int open(const char *deviceName, int baudrate)
Open Dynamixel Bus serial interface.
virtual ~DynaCommSerial()
Destructor.
RoadNarrows Dynamixel Bus Communication over Serial Interface Class Interface.
virtual int Close()
Close serial communication to dynamixel bus.
unsigned int getRxPacketErrBits()
Get receive packet error bits field.
custom interface (requires callbacks)
RoadNarrows Dynamixel Top-Level Package Header File.
int setBaudRate(int baudrate)
Set Dynamixel Bus serial device baud rate.
int m_fd
serial file descriptor
virtual bool Ping(int nServoId)
Ping the servo.
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.
void close()
Close the Dynamixel Bus serial interface.
DynaCommSerial()
Default constructor.
int getFd()
Get the Dynamixel Bus serial device file descriptor.
int m_fdGpio
gpio file descriptor
static void EnableTxGPIO(void *pArg)
Enable transmit via GPIO signal.
void ping(int id)
Ping servo.
#define DYNA_ECODE_BAD_VAL
bad value
int dxl_initialize(int deviceIndex, int baudnum)
Initialize Dynamixel Bus USB serial interface by index.
void setTxPacketLength(int length)
Set transmit packet length.
int readByte(int id, int address)
Read byte from servo's control table.
static void EnableTxRTS(void *pArg)
Enable transmit via RTS signal.
static const int RetryWait
microsecond wait between retries
RoadNarrows Dynamixel Library Error and Logging Routines.
static void EnableTxCTS(void *pArg)
Enable transmit via CTS signal.
int m_nGpioNum
gpio number
#define DXL_BROADCAST_ID
broadcast "servo" id
int readWord(int id, int address)
Read word from servo's control table.
static int BaudRateToNum(int nBaudRate)
Map baud rate to Dynamixel baud number.
Dynamixel Bus Communications Abstract Base Class.
#define DYNA_TRY_COMM(comm)
Test if bus communication is available exception macro.