Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaCommBotSense.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Library: librnr_dynamixel
6 //
7 // File: DynaCommBotSense.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-03-04 12:38:36 -0700 (Wed, 04 Mar 2015) $
12  * $Rev: 3873 $
13  *
14  * \ingroup dyna_lib_hdrs
15  *
16  * \brief RoadNarrows Botsene IP Proxied Dynamixel Bus Communication Class
17  * Interface.
18  *
19  * \author Robin Knight (robin.knight@roadnarrows.com)
20  *
21  * \copyright
22  * \h_copy 2011-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Unless otherwise stated explicitly, all materials contained are copyrighted
30  * and may not be used without RoadNarrows LLC's written consent,
31  * except as provided in these terms and conditions or in the copyright
32  * notice (documents and software) or other proprietary notice provided with
33  * the relevant materials.
34  *
35  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
36  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
37  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
38  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
39  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
40  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
43  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
44  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
45  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
46  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
47  *
48  * @EulaEnd@
49  */
50 ////////////////////////////////////////////////////////////////////////////////
51 
52 #ifndef _DYNA_COMM_BOTSENSE_H
53 #define _DYNA_COMM_BOTSENSE_H
54 
55 #include "rnr/rnrconfig.h"
56 #include "rnr/log.h"
57 
58 #include "botsense/BotSense.h"
59 #include "botsense/libBotSense.h"
60 
61 #include "Dynamixel/Dynamixel.h"
62 #include "Dynamixel/DynaError.h"
63 #include "Dynamixel/DynaComm.h"
64 
65 
66 // ---------------------------------------------------------------------------
67 // Dynamixel BotSense IP Proxied Bus Communications Class
68 // ---------------------------------------------------------------------------
69 
70 /*!
71  * \ingroup dyna_lib_classes
72  *
73  * \brief BotSense IP Proxied Dynamixel Bus Communications Class.
74  *
75  * The host with the direct serial connection acts as the bsProxy server.
76  */
77 class DynaCommBotSense : public DynaComm
78 {
79 public:
80  /*!
81  * \brief Default constructor.
82  */
84 
85  /*!
86  * \brief Initialization constructor.
87  *
88  * The given proxied serial device is opened at the baud rate on the host of
89  * the given BotSense proxy server.
90  *
91  * \param sSerialDevName Proxied serial device name.
92  * \param nBaudRate Proxied serial device baud rate.
93  * \param sBsProxyHostName BotSense proxy server host name
94  * (domain name or IP address).
95  * \param nBsProxyIPPort BotSense proxy server IP port number.
96  */
97  DynaCommBotSense(const char *sSerialDevName,
98  int nBaudRate,
99  const char *sBsProxyHostName = BSPROXY_URI_HOSTNAME_DFT,
100  int nBsProxyIPPort = BSPROXY_LISTEN_PORT_DFT);
101 
102  /*!
103  * \brief Destructor.
104  */
105  virtual ~DynaCommBotSense();
106 
107  /*!
108  * \brief Get the Dynamixel Bus serial device name.
109  *
110  * \return Returns name.
111  */
112  const char *GetSerialDeviceName()
113  {
114  return m_sSerialDevName;
115  }
116 
117  /*!
118  * \brief Get the BotSense proxy server host name.
119  *
120  * \return Returns name.
121  */
123  {
124  return m_sBsProxyHostName;
125  }
126 
127  /*!
128  * \brief Get the BotSense proxy server port.
129  *
130  * \return Returns port number.
131  */
132  const int GetProxyServerPort() const
133  {
134  return m_nBsProxyIPPort;
135  }
136 
137  /*!
138  * \brief Get this BotSense proxy client.
139  *
140  * \return Returns port number.
141  */
142  const BsClient_P GetProxyClient() const
143  {
144  return m_pBsClient;
145  }
146 
147  /*!
148  * \brief Get System-unique resource identifier.
149  *
150  * \return Resource id.
151  */
152  virtual int GetResourceId() const
153  {
154  return (int)m_hndBsVConn;
155  }
156 
157  /*!
158  * \brief Open serial communication to dynamixel bus.
159  *
160  * The given proxied serial device is opened at the baud rate on the
161  * local host with default port number.
162  *
163  * \param sSerialDevName Proxied serial device name.
164  * \param nBaudRate Proxied serial device baud rate.
165  *
166  * \copydoc doc_std_return
167  */
168  virtual int Open(const char *sSerialDevName, int nBaudRate)
169  {
170  DynaCommBotSense(sSerialDevName, nBaudRate, BSPROXY_URI_HOSTNAME_DFT,
171  BSPROXY_LISTEN_PORT_DFT);
172  }
173 
174  /*!
175  * \brief Open serial communication to dynamixel bus.
176  *
177  * The given proxied serial device is opened at the baud rate on the host of
178  * the given BotSense proxy server.
179  *
180  * \param sSerialDevName Proxied serial device name.
181  * \param nBaudRate Proxied serial device baud rate.
182  * \param sBsProxyHostName BotSense proxy server host name
183  * (domain name or IP address).
184  * \param sBsProxyHostName BotSense proxy server host.
185  * \param nBsProxyIPPort BotSense proxy server IP port number.
186  *
187  * \copydoc doc_std_return
188  */
189  virtual int Open(const char *sSerialDevName,
190  int nBaudRate,
191  const char *sBsProxyHostName = BSPROXY_URI_HOSTNAME_DFT,
192  int nBsProxyIPPort = BSPROXY_LISTEN_PORT_DFT);
193 
194  /*!
195  * \brief (Re)Open serial communication to dynamixel bus.
196  *
197  * \copydoc doc_std_return
198  */
199  virtual int Open();
200 
201  /*!
202  * \brief Close serial communication to dynamixel bus and connection to
203  * BotSense proxy server.
204  *
205  * \copydoc doc_std_return
206  */
207  virtual int Close();
208 
209  /*!
210  * Set the Dynamixel Bus new baud rate.
211  *
212  * \param nNewBaudRate New baudrate.
213  *
214  * \copydoc doc_return_std
215  */
216  virtual int SetBaudRate(int nNewBaudRate);
217 
218  /*!
219  * \breif Set Dynamixel Bus half-duplex software control.
220  *
221  * The Dynamixel 3-wire bus is half-duplex. Hardware may automatically
222  * control toggling between transmit and receive (e.g. RoadNarrows
223  * DynaUSB dongle). If there is no hardware support, then software must
224  * provide the tx/rx toggle functions.
225  *
226  * \param nSignal Signal assign to toggle.
227  * \param fnEnableTx Enable transmit function.
228  * \param fnEnableRx Enable receive function.
229  *
230  * \copydoc doc_return_std
231  */
232  virtual int SetHalfDuplexCtl(int nSignal,
233  HalfDuplexTxFunc_T fnEnableTx = NULL,
234  HalfDuplexRxFunc_T fnEnableRx = NULL);
235 
236  /*!
237  * Enable/disable botsense message tracing.
238  *
239  * \param bEnable Enable [disable].
240  *
241  * \copydoc doc_return_std
242  */
243  virtual int SetMsgTracing(bool bEnabled);
244 
245  /*!
246  * \brief Read an 8-bit value from Dynamixel servo control table.
247  *
248  * \param nServoId Servo id.
249  * \param uAddr Servo control table address.
250  * \param [out] pVal Value read.
251  *
252  * \copydoc doc_std_return
253  */
254  virtual int Read8(int nServoId, uint_t uAddr, byte_t *pVal);
255 
256  /*!
257  * \brief Write an 8-bit value to Dynamixel servo control table.
258  *
259  * \param nServoId Servo id.
260  * \param uAddr Servo control table address.
261  * \param byVal Value written.
262  *
263  * \copydoc doc_std_return
264  */
265  virtual int Write8(int nServoId, uint_t uAddr, byte_t byVal);
266 
267  /*!
268  * \brief Read a 16-bit value from Dynamixel servo control table.
269  *
270  * \param nServoId Servo id.
271  * \param uAddr Servo control table address.
272  * \param [out] pVal Value read.
273  *
274  * \copydoc doc_std_return
275  */
276  virtual int Read16(int nServoId, uint_t uAddr, ushort_t *pVal);
277 
278  /*!
279  * \brief Write a 16-bit value to Dynamixel servo control table.
280  *
281  * \param nServoId Servo id.
282  * \param uAddr Servo control table address.
283  * \param uhVal Value written.
284  *
285  * \copydoc doc_std_return
286  */
287  virtual int Write16(int nServoId, uint_t uAddr, ushort_t uhVal);
288 
289  /*!
290  * \brief Synchronous Write 8/16-bit values to a list of Dynamixel servos.
291  *
292  * \param uAddr Servo control table write address.
293  * \param uValSize Value storage size at addtess. 1 or 2 bytes.
294  * \param tuples Array of servo id, write value tuples.
295  * \param uCount Number of tuples.
296  *
297  * \copydoc doc_std_return
298  */
299  virtual int SyncWrite(uint_t uAddr,
300  uint_t uValSize,
301  DynaSyncWriteTuple_T tuples[],
302  uint_t uCount);
303 
304  /*!
305  * \brief Ping the servo.
306  *
307  * \param nServoId Servo id.
308  *
309  * \return Returns true if the servo responded, else false.
310  */
311  virtual bool Ping(int nServoId);
312 
313  /*!
314  * \brief Reset a servo back to default values.
315  *
316  * \warning All configuration is lost.
317  *
318  * \param nServoId Servo id.
319  *
320  * \copydoc doc_std_return
321  */
322  virtual int Reset(int nServoId);
323 
324 protected:
325  char *m_sSerialDevName; ///< proxied serial device name
326  char *m_sBsProxyHostName; ///< BotSense proxy server domain/IP address
327  int m_nBsProxyIPPort; ///< BotSense proxy server IP port number
328  BsClient_P m_pBsClient; ///< BotSense client
329  BsVConnHnd_T m_hndBsVConn; ///< virtual connection to proxied device
330  bool m_bBsTrace; ///< do [not] trace messaging
331 };
332 
333 
334 #endif // _DYNA_COMM_BOTSENSE_H
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
virtual int Open(const char *sSerialDevName, int nBaudRate)
Open serial communication to dynamixel bus.
virtual int GetResourceId() const
Get System-unique resource identifier.
virtual int SetMsgTracing(bool bEnabled)
char * m_sSerialDevName
proxied serial device name
virtual int Read8(int nServoId, uint_t uAddr, byte_t *pVal)
Read an 8-bit value from Dynamixel servo control table.
const int GetProxyServerPort() const
Get the BotSense proxy server port.
virtual bool Ping(int nServoId)
Ping the servo.
BsClient_P m_pBsClient
BotSense client.
BsVConnHnd_T m_hndBsVConn
virtual connection to proxied device
virtual int SetBaudRate(int nNewBaudRate)
virtual ~DynaCommBotSense()
Destructor.
const BsClient_P GetProxyClient() const
Get this BotSense proxy client.
char * m_sBsProxyHostName
BotSense proxy server domain/IP address.
int m_nBsProxyIPPort
BotSense proxy server IP port number.
void(* HalfDuplexRxFunc_T)(void *pArg, size_t uNumTxBytes)
Half-duplex control receive function type.
Definition: DynaComm.h:87
virtual int Reset(int nServoId)
Reset a servo back to default values.
void(* HalfDuplexTxFunc_T)(void *pArg)
Half-duplex control transmit function type.
Definition: DynaComm.h:84
virtual int Open()
(Re)Open serial communication to dynamixel bus.
bool m_bBsTrace
do [not] trace messaging
const char * GetProxyServerHostName()
Get the BotSense proxy server host name.
virtual int Write8(int nServoId, uint_t uAddr, byte_t byVal)
Write an 8-bit value to Dynamixel servo control table.
DynaCommBotSense()
Default constructor.
BotSense IP Proxied Dynamixel Bus Communications Class.
RoadNarrows Dynamixel Top-Level Package Header File.
virtual int Close()
Close serial communication to dynamixel bus and connection to BotSense proxy server.
const char * GetSerialDeviceName()
Get the Dynamixel Bus serial device name.
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.
virtual int Read16(int nServoId, uint_t uAddr, ushort_t *pVal)
Read a 16-bit value from Dynamixel servo control table.
virtual int SetHalfDuplexCtl(int nSignal, HalfDuplexTxFunc_T fnEnableTx=NULL, HalfDuplexRxFunc_T fnEnableRx=NULL)
virtual int Write16(int nServoId, uint_t uAddr, ushort_t uhVal)
Write a 16-bit value to Dynamixel servo control table.
RoadNarrows Dynamixel Library Error and Logging Routines.
Dynamixel Bus Communications Abstract Base Class.
Definition: DynaComm.h:80