Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekSpec.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekSpec.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-12-10 10:43:51 -0700 (Thu, 10 Dec 2015) $
12  * $Rev: 4239 $
13  *
14  * \brief \h_hek product specification base implimentations.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2013-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 <string>
50 #include <vector>
51 
52 #include "rnr/rnrconfig.h"
53 
54 #include "Dynamixel/Dynamixel.h"
55 
56 #include "Hekateros/hekateros.h"
57 #include "Hekateros/hekProdArm.h"
58 #include "Hekateros/hekProdEE.h"
59 #include "Hekateros/hekProdEquip.h"
60 #include "Hekateros/hekProdAux.h"
61 
62 using namespace std;
63 using namespace hekateros;
64 
65 
66 HekSpec::HekSpec()
67 {
68  m_eProdFamily = HekProdFamilyUnknown;
69  m_eProdId = HekProdIdUnknown;
70  m_uHwVer = 0;
71  m_nNumLinks = 0;
72  m_nDoF = 0;
73  m_nNumOptLimits = 0;
74  m_nNumServos = 0;
75 }
76 
77 HekSpec::~HekSpec()
78 {
79 }
80 
81 int HekSpec::set(int eProdId, uint_t uHwVer)
82 {
83  const HekSpecLink_T *pSpecLinks;
84  const HekSpecJoint_T *pSpecJoints;
85  const HekSpecServo_T *pSpecServos;
86  int i;
87 
88  clear();
89 
90  switch( eProdId )
91  {
92  //
93  // Arms
94  //
95  case HekProdArm5LBetaId: // defunct
96  break;
97  case HekProdArm4SId:
98  break;
99  case HekProdArm4LId:
100  m_eProdFamily = HEK_ARM_FAMILY;
101  m_nNumLinks = HekProdArm4LNumLinks;
102  m_nDoF = HekProdArm4LDoF;
103  m_nNumOptLimits = HekProdArm4LNumOptLimits;
104  m_nNumServos = HekProdArm4LNumServos;
105  if( uHwVer < HEK_VERSION(1, 2, 0) )
106  {
107  pSpecLinks = HekProdArm4LSpecLinks;
108  pSpecJoints = HekProdArm4LSpecJoints_1_1;
109  pSpecServos = HekProdArm4LSpecServos_1_1;
110  }
111  else
112  {
113  LOGWARN("Unsupported 4L v%u.%u.%u, defaulting to v1.1 specs.",
114  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
115  pSpecLinks = HekProdArm4LSpecLinks;
116  pSpecJoints = HekProdArm4LSpecJoints_1_1;
117  pSpecServos = HekProdArm4LSpecServos_1_1;
118  }
119  LOGDIAG3("Hekateros 4L v%u.%u.%u specification loaded.",
120  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
121  break;
122  case HekProdArm5SId:
123  break;
124  case HekProdArm5LId:
125  m_eProdFamily = HEK_ARM_FAMILY;
126  m_nNumLinks = HekProdArm5LNumLinks;
127  m_nDoF = HekProdArm5LDoF;
128  m_nNumOptLimits = HekProdArm5LNumOptLimits;
129  m_nNumServos = HekProdArm5LNumServos;
130  if( uHwVer < HEK_VERSION(1, 2, 0) )
131  {
132  pSpecLinks = HekProdArm5LSpecLinks;
133  pSpecJoints = HekProdArm5LSpecJoints_1_1;
134  pSpecServos = HekProdArm5LSpecServos_1_1;
135  }
136  else if( uHwVer < HEK_VERSION(1, 3, 0) )
137  {
138  pSpecLinks = HekProdArm5LSpecLinks;
139  pSpecJoints = HekProdArm5LSpecJoints_1_2;
140  pSpecServos = HekProdArm5LSpecServos_1_2;
141  }
142  else if( uHwVer < HEK_VERSION(1, 4, 0) )
143  {
144  if( uHwVer == HEK_VERSION(1, 3, 5) ) // special SIUE arm hybrid
145  {
146  pSpecLinks = HekProdArm5LSpecLinks;
147  pSpecJoints = HekProdArm5LSpecJoints_1_3_5;
148  pSpecServos = HekProdArm5LSpecServos_1_3_5;
149  }
150  else
151  {
152  pSpecLinks = HekProdArm5LSpecLinks;
153  pSpecJoints = HekProdArm5LSpecJoints_1_3;
154  pSpecServos = HekProdArm5LSpecServos_1_3;
155  }
156  }
157  else if( uHwVer < HEK_VERSION(1, 5, 0) )
158  {
159  pSpecLinks = HekProdArm5LSpecLinks;
160  pSpecJoints = HekProdArm5LSpecJoints_1_4;
161  pSpecServos = HekProdArm5LSpecServos_1_4;
162  }
163  else if( uHwVer < HEK_VERSION(2, 2, 0) )
164  {
165  pSpecLinks = HekProdArm5LSpecLinks;
166  pSpecJoints = HekProdArm5LSpecJoints_2_0;
167  pSpecServos = HekProdArm5LSpecServos_2_0;
168  }
169  else
170  {
171  LOGWARN("Unsupported 5L v%u.%u.%u, defaulting to v1.3 specs.",
172  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
173  pSpecLinks = HekProdArm5LSpecLinks;
174  pSpecJoints = HekProdArm5LSpecJoints_1_3;
175  pSpecServos = HekProdArm5LSpecServos_1_3;
176  }
177  LOGDIAG3("Hekateros 5L v%u.%u.%u specification loaded.",
178  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
179  break;
180 
181  //
182  // End Effectors
183  //
184  case HekProdEEGraboidId:
185  m_eProdFamily = HekProdEEGraboidFamily;
186  m_nNumLinks = HekProdEEGraboidNumLinks;
187  m_nDoF = HekProdEEGraboidDoF;
188  m_nNumOptLimits = HekProdEEGraboidNumOptLimits;
189  m_nNumServos = HekProdEEGraboidNumServos;
190  if( uHwVer < HEK_VERSION(1, 1, 0) )
191  {
192  pSpecLinks = HekProdEEGraboidSpecLinks;
193  pSpecJoints = HekProdEEGraboidSpecJoints_1_0;
194  pSpecServos = HekProdEEGraboidSpecServos_1_0;
195  }
196  else if( uHwVer < HEK_VERSION(1, 2, 0) )
197  {
198  pSpecLinks = HekProdEEGraboidSpecLinks;
199  pSpecJoints = HekProdEEGraboidSpecJoints_1_1;
200  pSpecServos = HekProdEEGraboidSpecServos_1_1;
201  }
202  else
203  {
204  LOGWARN("Unsupported Graboid EE v%u.%u.%u, "
205  "defaulting to v1.1 specs.",
206  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
207  pSpecLinks = HekProdEEGraboidSpecLinks;
208  pSpecJoints = HekProdEEGraboidSpecJoints_1_1;
209  pSpecServos = HekProdEEGraboidSpecServos_1_1;
210  }
211  LOGDIAG3("Graboid EE v%u.%u.%u specification loaded.",
212  HEK_VER_MAJOR(uHwVer), HEK_VER_MINOR(uHwVer), HEK_VER_REV(uHwVer));
213  break;
214 
215  // error
216  default:
217  LOGERROR("0x%08x: Unknown or unsupported product id.", eProdId);
218  return -HEK_ECODE_BAD_VAL;
219  }
220 
221  if( pSpecLinks != NULL )
222  {
223  for(i=0; i<m_nNumLinks; ++i)
224  {
225  m_vecSpecLinks.push_back(pSpecLinks[i]);
226  }
227  }
228 
229  if( pSpecJoints != NULL )
230  {
231  for(i=0; i<m_nDoF; ++i)
232  {
233  m_vecSpecJoints.push_back(pSpecJoints[i]);
234  }
235  }
236 
237  if( pSpecServos != NULL )
238  {
239  for(i=0; i<m_nNumServos; ++i)
240  {
241  m_vecSpecServos.push_back(pSpecServos[i]);
242  }
243  }
244 
245  m_eProdId = eProdId;
246  m_uHwVer = uHwVer;
247 
248  return HEK_OK;
249 }
250 
251 void HekSpec::clear()
252 {
253  m_eProdId = HekProdIdUnknown;
254  m_uHwVer = 0;
255  m_vecSpecLinks.clear();
256  m_vecSpecJoints.clear();
257  m_vecSpecServos.clear();
258 }
259 
260 HekSpecJoint_T *HekSpec::getJointSpec(string &strName)
261 {
262  vector<HekSpecJoint_T>::iterator iter;
263 
264  for(iter = m_vecSpecJoints.begin(); iter != m_vecSpecJoints.end(); ++iter)
265  {
266  if( iter->m_strName == strName )
267  {
268  return &(*iter);
269  }
270  }
271 
272  return NULL;
273 }
274 
275 HekSpecJoint_T *HekSpec::getJointSpec(int nServoId)
276 {
277  vector<HekSpecJoint_T>::iterator iter;
278 
279  for(iter = m_vecSpecJoints.begin(); iter != m_vecSpecJoints.end(); ++iter)
280  {
281  if( iter->m_nMasterServoId == nServoId )
282  {
283  return &(*iter);
284  }
285  }
286 
287  return NULL;
288 }
289 
290 HekSpecServo_T *HekSpec::getServoSpec(int nServoId)
291 {
292  vector<HekSpecServo_T>::iterator iter;
293 
294  for(iter = m_vecSpecServos.begin(); iter != m_vecSpecServos.end(); ++iter)
295  {
296  if( iter->m_nServoId == nServoId )
297  {
298  return &(*iter);
299  }
300  }
301 
302  return NULL;
303 }
304 
305 bool HekSpec::hasServo(int nServoId)
306 {
307  vector<HekSpecServo_T>::iterator iter;
308 
309  for(iter = m_vecSpecServos.begin(); iter != m_vecSpecServos.end(); ++iter)
310  {
311  if( iter->m_nServoId == nServoId )
312  {
313  return true;
314  }
315  }
316  return false;
317 }
#define HEK_VER_REV(ver)
Get revision number from version.
Definition: hekateros.h:213
#define HEK_VER_MAJOR(ver)
Get version major number from version.
Definition: hekateros.h:195
Aggregate of supported <b><i>Hekateros</i></b> auxiliary add-ons static specifications.
Aggregate of supported <b><i>Hekateros</i></b> end effectors static specifications.
#define HEK_ARM_FAMILY
only 1 family of arm products so define here
Definition: hekProdArm.h:56
Aggregate of supported <b><i>Hekateros</i></b> equipment deck effectors static specifications.
Top-level package include file.
#define HEK_VER_MINOR(ver)
Get version minor number from version.
Definition: hekateros.h:204
#define HEK_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
Definition: hekateros.h:185
Robotic joint specification.
Definition: hekSpec.h:139
Aggregagte of supported Hekateros robotic arms static specifications.
Robotic servo specification.
Definition: hekSpec.h:199
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56