Kuon  1.1.3
RoadNarrows Robotics Large Outdoor Mobile Robot Project
kuonSpec.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Kuon
4 //
5 // Library: libkuon
6 //
7 // File: kuonSpec.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-04-04 17:05:03 -0600 (Fri, 04 Apr 2014) $
12  * $Rev: 3629 $
13  *
14  * \brief \h_kuon product factory 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  * Permission is hereby granted, without written agreement and without
27  * license or royalty fees, to use, copy, modify, and distribute this
28  * software and its documentation for any purpose, provided that
29  * (1) The above copyright notice and the following two paragraphs
30  * appear in all copies of the source code and (2) redistributions
31  * including binaries reproduces these notices in the supporting
32  * documentation. Substantial modifications to this software may be
33  * copyrighted by their authors and need not follow the licensing terms
34  * described here, provided that the new terms are clearly indicated in
35  * all files where they apply.
36  *
37  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
38  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
39  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
40  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
41  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
42  * THE POSSIBILITY OF SUCH DAMAGE.
43  *
44  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
46  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
47  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
48  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
49  *
50  * @EulaEnd@
51  */
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 #include <string>
55 #include <vector>
56 
57 #include "rnr/rnrconfig.h"
58 
59 #include "Kuon/kuon.h"
60 #include "Kuon/kuonSpec.h"
61 #include "Kuon/kuonProdBase.h"
62 
63 using namespace std;
64 using namespace kuon;
65 
66 
67 KuonSpec::KuonSpec()
68 {
69  m_eProdId = KuonProdIdUnknown;
70  m_uHwVer = 0;
71  m_nNumMotors = 0;
72  m_fFrontTireRadius = 0.0;
73  m_fRearTireRadius = 0.0;
74 }
75 
76 KuonSpec::~KuonSpec()
77 {
78 }
79 
80 int KuonSpec::set(int eProdId,
81  uint_t uHwVer,
82  double fFrontTireRadius,
83  double fRearTireRadius)
84 {
85  const KuonSpecMotor_T *pSpecMotors = NULL;
86  int i;
87 
88  clear();
89 
90  switch( eProdId )
91  {
92  //
93  // Standard size Kuon
94  //
95  case KuonProdIdStd:
96  m_nNumMotors = KuonProdBaseStdNumMotors;
97  pSpecMotors = KuonProdBaseStdSpecMotors;
98  break;
99 
100  //
101  // Narrow size Kuon
102  //
103  case KuonProdIdNarrow:
104  break;
105  }
106 
107  if( pSpecMotors != NULL )
108  {
109  for(i=0; i<m_nNumMotors; ++i)
110  {
111  m_vecSpecMotors.push_back(pSpecMotors[i]);
112 
113  if( (pSpecMotors[i].m_nMotorId == KuonMotorIdLF) ||
114  (pSpecMotors[i].m_nMotorId == KuonMotorIdRF) )
115  {
116  m_fFrontTireRadius = pSpecMotors[i].m_fTireRadius;
117  }
118  else if( (pSpecMotors[i].m_nMotorId == KuonMotorIdLR) ||
119  (pSpecMotors[i].m_nMotorId == KuonMotorIdRR) )
120  {
121  m_fRearTireRadius = pSpecMotors[i].m_fTireRadius;
122  }
123  }
124  }
125 
126  m_eProdId = eProdId;
127  m_uHwVer = uHwVer;
128 
129  //
130  // Override factory defaults.
131  //
132  if( fFrontTireRadius > 0.0 )
133  {
134  m_fFrontTireRadius = fFrontTireRadius;
135  }
136  if( fRearTireRadius > 0.0 )
137  {
138  m_fRearTireRadius = fRearTireRadius;
139  }
140 
141  return KUON_OK;
142 }
143 
144 void KuonSpec::clear()
145 {
146  m_eProdId = KuonProdIdUnknown;
147  m_uHwVer = 0;
148  m_vecSpecMotors.clear();
149 }
150 
151 KuonSpecMotor_T *KuonSpec::getMotorSpec(const string &strName)
152 {
153  vector<KuonSpecMotor_T>::iterator iter;
154 
155  for(iter = m_vecSpecMotors.begin(); iter != m_vecSpecMotors.end(); ++iter)
156  {
157  if( iter->m_strName == strName )
158  {
159  return &(*iter);
160  }
161  }
162 
163  return NULL;
164 }
165 
166 KuonSpecMotor_T *KuonSpec::getMotorSpec(int nMotorId)
167 {
168  vector<KuonSpecMotor_T>::iterator iter;
169 
170  for(iter = m_vecSpecMotors.begin(); iter != m_vecSpecMotors.end(); ++iter)
171  {
172  if( iter->m_nMotorId == nMotorId )
173  {
174  return &(*iter);
175  }
176  }
177 
178  return NULL;
179 }
static const int KuonMotorIdLR
left rear
Definition: kuon.h:304
static const int KuonMotorIdLF
left front
Definition: kuon.h:302
static const int KUON_OK
not an error, success
Definition: kuon.h:80
Aggregagte of supported Kuon robotic mobile bases static specifications.
static const int KuonMotorIdRR
right rear
Definition: kuon.h:305
static const int KuonProdIdUnknown
unknown/undefined product id
Definition: kuon.h:144
The <b><i>Kuon</i></b> namespace encapsulates all <b><i>Kuon</i></b> related constructs.
Definition: kuon.h:66
Robotic motor specification.
Definition: kuonSpec.h:111
const KuonSpecMotor_T KuonProdBaseStdSpecMotors[]
Specification of servos.
<b><i>Kuon</i></b> product specification base classes.
const int KuonProdBaseStdNumMotors
number of motors
RoadNarrows Kuon robot top-level header file.
static const int KuonProdIdNarrow
narrow Kuon product id
Definition: kuon.h:146
static const int KuonProdIdStd
standard Kuon product id
Definition: kuon.h:145
double m_fTireRadius
tire radius (mm)
Definition: kuonSpec.h:140
static const int KuonMotorIdRF
right front
Definition: kuon.h:303