Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaCommSerial.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: libDynamixel
6 //
7 // File: DynaCommSerial.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-04-10 12:42:59 -0600 (Fri, 10 Apr 2015) $
12  * $Rev: 3924 $
13  *
14  * \brief RoadNarrows Dynamixel bus communication over serial interface class.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2011-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #include <unistd.h>
50 #include <ctype.h>
51 #include <pthread.h>
52 
53 #include "rnr/rnrconfig.h"
54 #include "rnr/shm.h"
55 #include "rnr/log.h"
56 #include "rnr/serdev.h"
57 #include "rnr/gpio.h"
58 
59 #include "Dynamixel/dxl/dxl.h"
60 
61 #include "Dynamixel/Dynamixel.h"
62 #include "Dynamixel/DynaError.h"
63 #include "Dynamixel/DynaComm.h"
65 
66 #include "DynaLibInternal.h"
67 
68 using namespace std;
69 using namespace libdxl;
70 
71 // ---------------------------------------------------------------------------
72 // Private Interface
73 // ---------------------------------------------------------------------------
74 
75 
76 // ---------------------------------------------------------------------------
77 // DynaCommSerial Class
78 // ---------------------------------------------------------------------------
79 
81 {
82  m_sSerialDevName = NULL;
83  m_fd = -1;
84  m_nGpioNum = 0;
85  m_fdGpio = -1;
86  m_nGpioVal = -1;
87 }
88 
89 DynaCommSerial::DynaCommSerial(const char *sSerialDevName, int nBaudRate) :
90  DynaComm(sSerialDevName, nBaudRate)
91 {
92  m_sSerialDevName = newstr(sSerialDevName);
93  m_fd = -1;
94  m_nGpioNum = 0;
95  m_fdGpio = -1;
96  m_nGpioVal = -1;
97 
98  Open();
99 }
100 
102 {
103  Close();
104 
105  if( m_sSerialDevName != NULL )
106  {
107  delete[] m_sSerialDevName;
108  }
109 }
110 
111 int DynaCommSerial::Open(const char *sSerialDevName, int nBaudRate)
112 {
113  Close();
114 
115  if( m_sSerialDevName != NULL )
116  {
117  delete[] m_sSerialDevName;
118  }
119 
120  m_sSerialDevName = newstr(sSerialDevName);
121  m_nBaudRate = nBaudRate;
122 
123  return Open();
124 }
125 
127 {
128 #if 0 // old dxl library
129  int nSerialIndex;
130  int nBaudNum;
131 #endif
132  int rc;
133 
134  Close();
135 
136  if( (m_sSerialDevName == NULL) || (*m_sSerialDevName == 0) )
137  {
138  rc = -DYNA_ECODE_BAD_VAL;
139  DYNA_LOG_ERROR(rc, "Unspecified serial device.");
140  }
141 
142 #if 0 // old dxl library
143  // make serial index from serial device
144  else if( (nSerialIndex = MakeSerialIndex(m_sSerialDevName)) < 0 )
145  {
146  DYNA_LOG_ERROR(nSerialIndex, "Bad serial device name: \"%s\".",
148  rc = nSerialIndex;
149  }
150 
151  // map baudrate to internal baud enumeration value
152  else if( (nBaudNum = BaudRateToNum(m_nBaudRate)) < 0 )
153  {
154  DYNA_LOG_ERROR(nBaudNum, "%d: Unsupported baudrate.", m_nBaudRate);
155  rc = nBaudNum;
156  }
157 
158  else if( m_dxl.dxl_initialize(nSerialIndex, nBaudNum) == 0 )
159  {
160  rc = -DYNA_ECODE_BAD_DEV;
161  DYNA_LOG_ERROR(rc, "Serial device \"%s\": Failed to initalize interface.",
163  }
164 #endif
165 
166  else if( m_dxl.open(m_sSerialDevName, m_nBaudRate) == 0 )
167  {
168  rc = -DYNA_ECODE_BAD_DEV;
169  DYNA_LOG_ERROR(rc, "Serial device \"%s\": Failed to initalize interface.",
171  }
172 
173  else
174  {
175  m_bIsOpen = true;
176  m_fd = m_dxl.getFd();
177  rc = DYNA_OK;
178  LOGDIAG3("Dynamixel bus communication opened on \"%s\"@%d.",
180  }
181 
182  return rc;
183 }
184 
186 {
187  if( m_bIsOpen )
188  {
189  m_dxl.close();
190  m_fd = -1;
191  m_bIsOpen = false;
192  }
193  return DYNA_OK;
194 }
195 
196 int DynaCommSerial::SetBaudRate(int nNewBaudRate)
197 {
198  int rc; // return code
199 
200  // check baud rate against supported
201  if( (rc = BaudRateToNum(nNewBaudRate)) < 0 )
202  {
203  DYNA_LOG_ERROR(rc, "%d: Unsupported baudrate.", nNewBaudRate);
204  return rc;
205  }
206 
207  // already open, adjust serial parameters
208  if( m_bIsOpen )
209  {
210  if( !m_dxl.setBaudRate(nNewBaudRate) )
211  {
212  rc = -DYNA_ECODE_SYS;
214  "Serial device \"%s\": Failed to set baud rate %d.",
215  m_sSerialDevName, nNewBaudRate);
216  return rc;
217  }
218  }
219 
220  m_nBaudRate = nNewBaudRate;
221 
222  return DYNA_OK;
223 }
224 
226  DynaComm::HalfDuplexTxFunc_T fnEnableTx,
227  DynaComm::HalfDuplexRxFunc_T fnEnableRx)
228 {
229  switch( nSignal )
230  {
231  case CtlSignalModemRTS: // serial request to send
232  InitRTS();
233  SerDevSetHwFlowControl(m_fd, true);
236  this);
237  break;
238  case CtlSignalModemCTS: // serial clear to send
239  InitCTS();
240  SerDevSetHwFlowControl(m_fd, true);
243  this);
244  break;
245  case CtlSignalNone: // clear callbacks
246  m_dxl.setHalfDuplexCallbacks(NULL, NULL, NULL);
247  break;
248  case CtlSignalCustom: // custom signal
249  m_dxl.setHalfDuplexCallbacks(fnEnableTx, fnEnableRx, this);
250  break;
251  default: // gpio signal
252  InitGPIO(nSignal);
255  this);
256  break;
257  }
258 
259  return DYNA_OK;
260 }
261 
262 int DynaCommSerial::Read8(int nServoId, uint_t uAddr, byte_t *pVal)
263 {
264  int nTries = 0;
265  int rc;
266 
267  DYNA_TRY_COMM(*this);
268 
269  shm_mutex_lock(&m_mutexComm);
270 
271  do
272  {
273  *pVal = (byte_t)m_dxl.readByte(nServoId, (int)uAddr);
274 
275  m_uBusStatus = (uint_t)m_dxl.getResult();
276 
278  {
279  m_uAlarms = (uint_t)m_dxl.getRxPacketErrBits();
280  DYNA_LOG_SERVO_ALARMS(nServoId, m_uAlarms);
281  rc = DYNA_OK;
282  }
283  else
284  {
286  usleep(RetryWait);
287  }
288  } while( (rc == -DYNA_ECODE_RX_TIMEOUT) && (++nTries < RetryMax) );
289 
290  shm_mutex_unlock(&m_mutexComm);
291 
292  if (rc < 0 )
293  {
294  DYNA_LOG_ERROR(rc, "Read8(%d, 0x%02x)", nServoId, uAddr);
295  }
296 
297  return rc;
298 }
299 
300 int DynaCommSerial::Write8(int nServoId, uint_t uAddr, byte_t byVal)
301 {
302  int nTries = 0;
303  int rc;
304 
305  DYNA_TRY_COMM(*this);
306 
307  shm_mutex_lock(&m_mutexComm);
308 
309  do
310  {
311  m_dxl.writeByte(nServoId, (int)uAddr, (int)byVal);
312 
313  m_uBusStatus = (uint_t)m_dxl.getResult();
314 
316  {
317  m_uAlarms = (uint_t)m_dxl.getRxPacketErrBits();
318  DYNA_LOG_SERVO_ALARMS(nServoId, m_uAlarms);
319  rc = DYNA_OK;
320  }
321  else
322  {
324  usleep(RetryWait);
325  }
326  } while( (rc == -DYNA_ECODE_RX_TIMEOUT) && (++nTries < RetryMax) );
327 
328  shm_mutex_unlock(&m_mutexComm);
329 
330  if (rc < 0 )
331  {
332  DYNA_LOG_ERROR(rc, "Write8(%d, 0x%02x, 0x%02x)", nServoId, uAddr, byVal);
333  }
334 
335  return rc;
336 }
337 
338 int DynaCommSerial::Read16(int nServoId, uint_t uAddr, ushort_t *pVal)
339 {
340  int nTries = 0;
341  int rc;
342 
343  DYNA_TRY_COMM(*this);
344 
345  shm_mutex_lock(&m_mutexComm);
346 
347  do
348  {
349  *pVal = (ushort_t)m_dxl.readWord(nServoId, (int)uAddr);
350 
351  m_uBusStatus = (uint_t)m_dxl.getResult();
352 
354  {
355  m_uAlarms = (uint_t)m_dxl.getRxPacketErrBits();
356  DYNA_LOG_SERVO_ALARMS(nServoId, m_uAlarms);
357  rc = DYNA_OK;
358  }
359  else
360  {
362  usleep(RetryWait);
363  }
364  } while( (rc == -DYNA_ECODE_RX_TIMEOUT) && (++nTries < RetryMax) );
365 
366  shm_mutex_unlock(&m_mutexComm);
367 
368  if (rc < 0 )
369  {
370  DYNA_LOG_ERROR(rc, "Read16(%d, 0x%02x)", nServoId, uAddr);
371  }
372 
373  return rc;
374 }
375 
376 int DynaCommSerial::Write16(int nServoId, uint_t uAddr, ushort_t uhVal)
377 {
378  int nTries = 0;
379  int rc;
380 
381  DYNA_TRY_COMM(*this);
382 
383  shm_mutex_lock(&m_mutexComm);
384 
385  do
386  {
387  m_dxl.writeWord(nServoId, (int)uAddr, (int)uhVal);
388 
389  m_uBusStatus = (uint_t)m_dxl.getResult();
390 
392  {
393  m_uAlarms = (uint_t)m_dxl.getRxPacketErrBits();
394  DYNA_LOG_SERVO_ALARMS(nServoId, m_uAlarms);
395  rc = DYNA_OK;
396  }
397  else
398  {
400  usleep(RetryWait);
401  }
402  } while( (rc == -DYNA_ECODE_RX_TIMEOUT) && (++nTries < RetryMax) );
403 
404  shm_mutex_unlock(&m_mutexComm);
405 
406  if (rc < 0 )
407  {
408  DYNA_LOG_ERROR(rc, "Write16(%d, 0x%02x, 0x%04x)", nServoId, uAddr, uhVal);
409  }
410 
411  return rc;
412 }
413 
414 int DynaCommSerial::SyncWrite(uint_t uAddr,
415  uint_t uValSize,
416  DynaSyncWriteTuple_T tuples[],
417  uint_t uCount)
418 {
419  int i;
420  int j;
421  int nTries = 0;
422  int rc;
423 
424  DYNA_TRY_COMM(*this);
425 
426  shm_mutex_lock(&m_mutexComm);
427 
428  //
429  // packet header
430  //
431  j = 0;
432  m_dxl.setTxPacketId(DXL_BROADCAST_ID); // broadcast id
434  m_dxl.setTxPacketParameter(j++, (int)uAddr); // write address
435  m_dxl.setTxPacketParameter(j++, (int)uValSize); // value size at address
436 
437  //
438  // servo_id, val_lsb[, val_msb]
439  //
440  for(i=0; i<(int)uCount; ++i)
441  {
442  m_dxl.setTxPacketParameter(j++, tuples[i].m_nServoId);
443 
444  if( uValSize == 1 )
445  {
446  m_dxl.setTxPacketParameter(j++, m_dxl.getLowByte((int)tuples[i].m_uVal));
447  }
448  else
449  {
450  m_dxl.setTxPacketParameter(j++, m_dxl.getLowByte((int)tuples[i].m_uVal));
451  m_dxl.setTxPacketParameter(j++, m_dxl.getHighByte((int)tuples[i].m_uVal));
452  }
453  }
454 
455  // packet length in header
457 
458  do
459  {
460  // send sync packet
461  m_dxl.txrxPacket();
462 
463  m_uBusStatus = (uint_t)m_dxl.getResult();
464 
466  {
467  rc = DYNA_OK;
468  }
469  else
470  {
472  usleep(RetryWait);
473  }
474  } while( (rc == -DYNA_ECODE_RX_TIMEOUT) && (++nTries < RetryMax) );
475 
476  shm_mutex_unlock(&m_mutexComm);
477 
478  if (rc < 0 )
479  {
480  DYNA_LOG_ERROR(rc, "SyncWrite(0x%02x, %d, tuples, %d)",
481  uAddr, uValSize, uCount);
482  }
483 
484  return rc;
485 }
486 
487 bool DynaCommSerial::Ping(int nServoId)
488 {
489  DYNA_TRY_COMM(*this);
490 
491  shm_mutex_lock(&m_mutexComm);
492 
493  m_dxl.ping(nServoId);
494 
495  shm_mutex_unlock(&m_mutexComm);
496 
497  return m_dxl.getResult() == DXL_COMM_RXSUCCESS? true: false;
498 }
499 
500 int DynaCommSerial::Reset(int nServoId)
501 {
502  int rc;
503 
504  DYNA_TRY_COMM(*this);
505 
506  shm_mutex_lock(&m_mutexComm);
507 
508  // make reset packet
509  m_dxl.setTxPacketId(nServoId);
512 
513  m_dxl.txrxPacket();
514 
515  m_uBusStatus = (uint_t)m_dxl.getResult();
516 
518  {
519  m_uAlarms = (uint_t)m_dxl.getRxPacketErrBits();
520  DYNA_LOG_SERVO_ALARMS(nServoId, m_uAlarms);
521  rc = DYNA_OK;
522  }
523  else
524  {
526  DYNA_LOG_ERROR(rc, "Reset(%d)", nServoId);
527  }
528 
529  shm_mutex_unlock(&m_mutexComm);
530 
531  return rc;
532 }
533 
534 int DynaCommSerial::MakeSerialIndex(const char *sSerialDevName)
535 {
536  int i, j, index;
537 
538  if( (sSerialDevName == NULL) || (*sSerialDevName == 0) )
539  {
540  return -DYNA_ECODE_BAD_VAL;
541  }
542 
543  if( access(sSerialDevName, F_OK) )
544  {
545  return -DYNA_ECODE_BAD_DEV;
546  }
547 
548  for(i=j=(int)strlen(sSerialDevName)-1; i>=0; --i)
549  {
550  if( !isdigit(sSerialDevName[i]) )
551  {
552  break;
553  }
554  }
555 
556  if( (i < 0) || (i == j) )
557  {
558  return -DYNA_ECODE_BAD_VAL;
559  }
560 
561  index = atoi(sSerialDevName+i+1);
562 
563  return index;
564 }
565 
567 {
568  SerDevSetHwFlowControl(m_fd, true);
569 }
570 
572 {
573  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
574 
575  SerDevAssertRTS(pThis->m_fd);
576 }
577 
578 void DynaCommSerial::EnableRxRTS(void *pArg, size_t uNumTxBytes)
579 {
580  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
581 
582  SerDevFIFOOutputDrain(pThis->m_fd);
583  SerDevDeassertRTS(pThis->m_fd);
584 }
585 
587 {
588  SerDevSetHwFlowControl(m_fd, true);
589 }
590 
592 {
593  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
594 
595  SerDevAssertCTS(pThis->m_fd);
596 }
597 
598 void DynaCommSerial::EnableRxCTS(void *pArg, size_t uNumTxBytes)
599 {
600  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
601 
602  SerDevFIFOOutputDrain(pThis->m_fd);
603  SerDevDeassertCTS(pThis->m_fd);
604 }
605 
606 void DynaCommSerial::InitGPIO(int nGpioNum)
607 {
608  if( m_fdGpio >= 0 )
609  {
610  gpioClose(m_fdGpio);
611  m_fdGpio = -1;
612  }
613 
614  m_nGpioNum = nGpioNum;
615  m_nGpioVal = -1;
616 
617  if( (m_fdGpio = gpioOpen(abs(m_nGpioNum))) < 0 )
618  {
619  LOGERROR("GPIO %d: Failed to open.", abs(m_nGpioNum));
620  }
621 }
622 
624 {
625  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
626  int val;
627 
628  if( pThis->m_fdGpio >= 0 )
629  {
630  val = pThis->m_nGpioNum < 0? 0: 1;
631  if( gpioQuickWrite(pThis->m_fdGpio, val) == OK )
632  {
633  pThis->m_nGpioVal = val;
634  }
635  }
636 }
637 
638 void DynaCommSerial::EnableRxGPIO(void *pArg, size_t uNumTxBytes)
639 {
640  static double TuneMargin = -30.0; // sleep margin in usec
641 
642  DynaCommSerial *pThis = (DynaCommSerial *)pArg;
643  int val;
644  float usecTx;
645 
646  if( pThis->m_fdGpio < 0 )
647  {
648  return;
649  }
650 
651  val = pThis->m_nGpioNum < 0? 1: 0;
652 
653  // already in receive mode
654  if( val == pThis->m_nGpioVal )
655  {
656  return;
657  }
658 
659  // tcdrain() takes too long to return - disappointing. so can't use
660  //SerDevFIFOOutputDrain(pThis->m_fd);
661 
662  //
663  // Estimate time to transmit. Each byte = 10 bits with Start and Stop bits.
664  //
665  usecTx = (double)(uNumTxBytes * 10)/(double)pThis->m_nBaudRate * 1000000.0
666  + TuneMargin;
667 
668  if( usecTx > 0.0 )
669  {
670  unsigned int usec = (unsigned int)usecTx;
671 
672  // wait
673  usleep(usec);
674  }
675 
676  // already at this value
677  if( gpioQuickWrite(pThis->m_fdGpio, val) == OK )
678  {
679  pThis->m_nGpioVal = val;
680  }
681 }
uint_t m_uAlarms
servo alarms from last I/O operation
Definition: DynaComm.h:503
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
int DynaMapDxlToEcode(int nDxlError)
Map DXL library error code to Dynamixel error code.
Definition: DynaError.cxx:117
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&#39;s control table.
Definition: dynamixel.cxx:505
#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.
Definition: dynamixel.cxx:173
Dynamixel Serial Bus Communications Class.
#define DXL_INST_SYNC_WRITE
synchronous write servo(s) data
Definition: dxl.h:85
void InitCTS()
Intialize CTS signalling.
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int getLowByte(int word)
Get low byte from word.
Definition: dynamixel.cxx:165
void setTxPacketParameter(int index, int value)
Set transmit packet parameter value.
Definition: dynamixel.cxx:125
int m_nBaudRate
baud rate
Definition: DynaComm.h:500
#define DXL_INST_RESET
reset servo defaults
Definition: dxl.h:84
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.
Definition: dynamixel.cxx:446
#define DYNA_ECODE_RX_TIMEOUT
dynamixel receive packet time out
Definition: Dynamixel.h:93
#define DXL_COMM_RXSUCCESS
receive success
Definition: dxl.h:109
void txrxPacket()
Transmit instruction packet and receive status response packet.
Definition: dynamixel.cxx:431
void setTxPacketId(int id)
Set transmit packet servo id.
Definition: dynamixel.cxx:115
void writeByte(int id, int address, int value)
Write byte to servo&#39;s control table.
Definition: dynamixel.cxx:477
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.
Definition: dynamixel.cxx:99
Definition: dxl.h:32
shm_mutex_t m_mutexComm
synchonization mutex
Definition: DynaComm.h:504
#define DYNA_ECODE_SYS
system (errno) error
Definition: Dynamixel.h:81
bool m_bIsOpen
dynamixel bus communication is [not] open
Definition: DynaComm.h:501
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&#39;ed value
char * m_sSerialDevName
serial device name
#define DYNA_ECODE_BAD_DEV
no or bad serial device
Definition: Dynamixel.h:87
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.
Definition: dynamixel.cxx:120
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.
Definition: DynaComm.h:87
#define DYNA_LOG_SERVO_ALARMS(id, alarms)
Log servo alarms.
void(* HalfDuplexTxFunc_T)(void *pArg)
Half-duplex control transmit function type.
Definition: DynaComm.h:84
The libDynamixel internal declarations.
uint_t m_uBusStatus
bus comminication status
Definition: DynaComm.h:502
static const int RetryMax
maximum number of I/O retries
void InitRTS()
Intialize RTS signalling.
uint_t m_uVal
write value
Definition: DynaTypes.h:297
void InitGPIO(int nGpioNum)
Intialize GPIO signalling.
int open(const char *deviceName, int baudrate)
Open Dynamixel Bus serial interface.
Definition: dynamixel.cxx:59
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.
Definition: dynamixel.cxx:135
custom interface (requires callbacks)
RoadNarrows Dynamixel Top-Level Package Header File.
int setBaudRate(int baudrate)
Set Dynamixel Bus serial device baud rate.
Definition: dynamixel.cxx:94
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.
Definition: dynamixel.cxx:89
DynaCommSerial()
Default constructor.
int getFd()
Get the Dynamixel Bus serial device file descriptor.
Definition: dynamixel.cxx:110
int m_fdGpio
gpio file descriptor
static void EnableTxGPIO(void *pArg)
Enable transmit via GPIO signal.
void ping(int id)
Ping servo.
Definition: dynamixel.cxx:451
#define DYNA_ECODE_BAD_VAL
bad value
Definition: Dynamixel.h:85
int dxl_initialize(int deviceIndex, int baudnum)
Initialize Dynamixel Bus USB serial interface by index.
Definition: dynamixel.cxx:72
void setTxPacketLength(int length)
Set transmit packet length.
Definition: dynamixel.cxx:130
int readByte(int id, int address)
Read byte from servo&#39;s control table.
Definition: dynamixel.cxx:462
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
Definition: dxl.h:92
int readWord(int id, int address)
Read word from servo&#39;s control table.
Definition: dynamixel.cxx:490
static int BaudRateToNum(int nBaudRate)
Map baud rate to Dynamixel baud number.
Definition: DynaComm.cxx:368
Dynamixel Bus Communications Abstract Base Class.
Definition: DynaComm.h:80
#define DYNA_TRY_COMM(comm)
Test if bus communication is available exception macro.