Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekJoint.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekJoint.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-11-18 14:31:49 -0700 (Tue, 18 Nov 2014) $
12  * $Rev: 3810 $
13  *
14  * \brief Hekateros joint classes implementations.
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 <stdio.h>
50 #include <unistd.h>
51 
52 #include <string>
53 #include <map>
54 
55 #include "rnr/rnrconfig.h"
56 #include "rnr/log.h"
57 
58 #include "Dynamixel/Dynamixel.h"
59 
60 #include "Hekateros/hekateros.h"
61 #include "Hekateros/hekTune.h"
62 #include "Hekateros/hekUtils.h"
63 #include "Hekateros/hekSpec.h"
64 #include "Hekateros/hekJoint.h"
65 
66 using namespace std;
67 using namespace hekateros;
68 
69 
70 // -----------------------------------------------------------------------------
71 // Class HekRobotJoint
72 // -----------------------------------------------------------------------------
73 
74 HekRobotJoint::HekRobotJoint()
75 {
76  int i;
77 
78  // (derived) specification
79  m_nMasterServoId = DYNA_ID_NONE;
80  m_nSlaveServoId = DYNA_ID_NONE;
81  m_bIsServoContinuous = false;
82  m_nMasterServoDir = DYNA_DIR_NONE;
83  m_eJointType = HekJointTypeUnknown;
84  m_fGearRatio = 1.0;
85  m_fTicksPerServoRad = 0.0;
86  m_fTicksPerJointRad = 0.0;
87 
88  // discovered limits and positions
89  m_fMaxServoRadsPerSec = 0.0;
90  m_fMaxJointRadsPerSec = 0.0;
91 
92  m_fMinPhyLimitRads = 0.0;
93  m_fMaxPhyLimitRads = 0.0;
94  m_nMinPhyLimitOd = 0;
95  m_nMaxPhyLimitOd = 0;
96 
97  m_fMinSoftLimitRads = 0.0;
98  m_fMaxSoftLimitRads = 0.0;
99  m_nMinSoftLimitOd = 0;
100  m_nMaxSoftLimitOd = 0;
101 
102  m_fCalibPosRads = 0.0;
103  m_fBalPosRads = 0.0;
104  m_fParkPosRads = 0.0;
105 
106  m_eLimitTypes = HekLimitTypeUnknown;
107  m_fOverTorqueThDft = HekTuneOverTorqueThDft;
108 
109  for(i=0; i<HekOptLimitMaxPerJoint; ++i)
110  {
111  m_byOptLimitMask[i] = 0x00;
112  }
113 
114  // state
115  m_eOpState = HekOpStateUncalibrated;
116  m_bStopAtOptLimits = true;
117 }
118 
119 HekRobotJoint::HekRobotJoint(const HekRobotJoint &src)
120 {
121  int i;
122 
123  // (derived) specification
124  m_strName = src.m_strName;
125  m_nMasterServoId = src.m_nMasterServoId;
126  m_nSlaveServoId = src.m_nSlaveServoId;
127  m_bIsServoContinuous = src.m_bIsServoContinuous;
128  m_nMasterServoDir = src.m_nMasterServoDir;
129  m_eJointType = src.m_eJointType;
130  m_fGearRatio = src.m_fGearRatio;
131  m_fTicksPerServoRad = src.m_fTicksPerServoRad;
132  m_fTicksPerJointRad = src.m_fTicksPerJointRad;
133 
134  // discovered limits and positions
135  m_fMaxServoRadsPerSec = src.m_fMaxServoRadsPerSec;
136  m_fMaxJointRadsPerSec = src.m_fMaxJointRadsPerSec;
137 
138  m_fMinPhyLimitRads = src.m_fMinPhyLimitRads;
139  m_fMaxPhyLimitRads = src.m_fMaxPhyLimitRads;
140  m_nMinPhyLimitOd = src.m_nMinPhyLimitOd;
141  m_nMaxPhyLimitOd = src.m_nMaxPhyLimitOd;
142 
143  m_fMinSoftLimitRads = src.m_fMinSoftLimitRads;
144  m_fMaxSoftLimitRads = src.m_fMaxSoftLimitRads;
145  m_nMinSoftLimitOd = src.m_nMinSoftLimitOd;
146  m_nMaxSoftLimitOd = src.m_nMaxSoftLimitOd;
147 
148  m_fCalibPosRads = src.m_fCalibPosRads;
149  m_fBalPosRads = src.m_fBalPosRads;
150  m_fParkPosRads = src.m_fParkPosRads;
151 
152  m_eLimitTypes = src.m_eLimitTypes;
153  m_fOverTorqueThDft = src.m_fOverTorqueThDft;
154 
155  for(i=0; i<HekOptLimitMaxPerJoint; ++i)
156  {
157  m_byOptLimitMask[i] = src.m_byOptLimitMask[i];
158  }
159 
160  // state
161  m_eOpState = src.m_eOpState;
162  m_bStopAtOptLimits = src.m_bStopAtOptLimits;
163 }
164 
165 HekRobotJoint::~HekRobotJoint()
166 {
167 }
168 
169 HekRobotJoint HekRobotJoint::operator=(const HekRobotJoint &rhs)
170 {
171  int i;
172 
173  // (derived) specification
174  m_strName = rhs.m_strName;
175  m_nMasterServoId = rhs.m_nMasterServoId;
176  m_nSlaveServoId = rhs.m_nSlaveServoId;
177  m_bIsServoContinuous = rhs.m_bIsServoContinuous;
178  m_nMasterServoDir = rhs.m_nMasterServoDir;
179  m_eJointType = rhs.m_eJointType;
180  m_fGearRatio = rhs.m_fGearRatio;
181  m_fTicksPerServoRad = rhs.m_fTicksPerServoRad;
182  m_fTicksPerJointRad = rhs.m_fTicksPerJointRad;
183 
184  // discovered limits and positions
185  m_fMaxServoRadsPerSec = rhs.m_fMaxServoRadsPerSec;
186  m_fMaxJointRadsPerSec = rhs.m_fMaxJointRadsPerSec;
187 
188  m_fMinPhyLimitRads = rhs.m_fMinPhyLimitRads;
189  m_fMaxPhyLimitRads = rhs.m_fMaxPhyLimitRads;
190  m_nMinPhyLimitOd = rhs.m_nMinPhyLimitOd;
191  m_nMaxPhyLimitOd = rhs.m_nMaxPhyLimitOd;
192 
193  m_fMinSoftLimitRads = rhs.m_fMinSoftLimitRads;
194  m_fMaxSoftLimitRads = rhs.m_fMaxSoftLimitRads;
195  m_nMinSoftLimitOd = rhs.m_nMinSoftLimitOd;
196  m_nMaxSoftLimitOd = rhs.m_nMaxSoftLimitOd;
197 
198  m_fCalibPosRads = rhs.m_fCalibPosRads;
199  m_fBalPosRads = rhs.m_fBalPosRads;
200  m_fParkPosRads = rhs.m_fParkPosRads;
201 
202  m_eLimitTypes = rhs.m_eLimitTypes;
203  m_fOverTorqueThDft = rhs.m_fOverTorqueThDft;
204 
205  for(i=0; i<HekOptLimitMaxPerJoint; ++i)
206  {
207  m_byOptLimitMask[i] = rhs.m_byOptLimitMask[i];
208  }
209 
210  // state
211  m_eOpState = rhs.m_eOpState;
212  m_bStopAtOptLimits = rhs.m_bStopAtOptLimits;
213 
214  return *this;
215 }
216 
217 
218 // -----------------------------------------------------------------------------
219 // Class HekJointState
220 // -----------------------------------------------------------------------------
221 
222 HekJointState::HekJointState()
223 {
224  m_eOpState = HekOpStateUncalibrated;
225  m_nMasterServoId = DYNA_ID_NONE;
226  m_nSlaveServoId = DYNA_ID_NONE;
227  m_fPosition = 0.0;
228  m_fVelocity = 0.0;
229  m_fEffort = 0.0;
230  m_nOdPos = 0;
231  m_nEncPos = 0;
232  m_nSpeed = 0;
233 
234  for(int i=0; i<HekOptLimitMaxPerJoint; ++i)
235  {
236  m_eOptSwitch[i] = HekTriStateUnknown;
237  }
238 }
239 
240 HekJointState::HekJointState(const HekJointState &src)
241 {
242  m_strName = src.m_strName;
243  m_eOpState = src.m_eOpState;
244  m_nMasterServoId = src.m_nMasterServoId;
245  m_nSlaveServoId = src.m_nSlaveServoId;
246  m_fPosition = src.m_fPosition;
247  m_fVelocity = src.m_fVelocity;
248  m_fEffort = src.m_fEffort;
249  m_nOdPos = src.m_nOdPos;
250  m_nEncPos = src.m_nEncPos;
251  m_nSpeed = src.m_nSpeed;
252 
253  for(int i=0; i<HekOptLimitMaxPerJoint; ++i)
254  {
255  m_eOptSwitch[i] = src.m_eOptSwitch[i];
256  }
257 }
258 
259 HekJointState HekJointState::operator=(const HekJointState &rhs)
260 {
261  m_strName = rhs.m_strName;
262  m_eOpState = rhs.m_eOpState;
263  m_nMasterServoId = rhs.m_nMasterServoId;
264  m_nSlaveServoId = rhs.m_nSlaveServoId;
265  m_fPosition = rhs.m_fPosition;
266  m_fVelocity = rhs.m_fVelocity;
267  m_fEffort = rhs.m_fEffort;
268  m_nOdPos = rhs.m_nOdPos;
269  m_nEncPos = rhs.m_nEncPos;
270  m_nSpeed = rhs.m_nSpeed;
271 
272  for(int i=0; i<HekOptLimitMaxPerJoint; ++i)
273  {
274  m_eOptSwitch[i] = rhs.m_eOptSwitch[i];
275  }
276 
277  return *this;
278 }
279 
280 
281 // -----------------------------------------------------------------------------
282 // Class HekJointStatePoint
283 // -----------------------------------------------------------------------------
284 
285 static HekJointState nojointstate;
286 
287 bool HekJointStatePoint::hasJoint(const string &strJointName)
288 {
289  vector<HekJointState>::iterator iter;
290 
291  for(iter = m_jointState.begin(); iter != m_jointState.end(); ++iter)
292  {
293  if( iter->m_strName == strJointName )
294  {
295  return true;
296  }
297  }
298  return false;
299 }
300 
301 HekJointState &HekJointStatePoint::operator[](const string &strJointName)
302 {
303  vector<HekJointState>::iterator iter;
304 
305  for(iter = m_jointState.begin(); iter != m_jointState.end(); ++iter)
306  {
307  if( iter->m_strName == strJointName )
308  {
309  return *iter;
310  }
311  }
312  return nojointstate;
313 }
int m_nSlaveServoId
linked slave servo id (if any)
Definition: hekJoint.h:151
int m_nMaxSoftLimitOd
joint max soft limit (odometer ticks)
Definition: hekJoint.h:169
HekOpState m_eOpState
current operational state
Definition: hekJoint.h:179
double m_fMinSoftLimitRads
joint min soft limit (radians)
Definition: hekJoint.h:166
int m_nOdPos
current master servo odometer pos (ticks)
Definition: hekJoint.h:323
int m_eLimitTypes
joint limit types
Definition: hekJoint.h:173
Operational robotic joint description class.
Definition: hekJoint.h:80
int m_nSpeed
current master servo raw speed (unitless)
Definition: hekJoint.h:325
double m_fTicksPerJointRad
encoder/odom. ticks per joint radian
Definition: hekJoint.h:157
double m_fTicksPerServoRad
encoder/odom. ticks per servo radian
Definition: hekJoint.h:156
double m_fMaxServoRadsPerSec
maximum servo radians per second
Definition: hekJoint.h:158
int m_eJointType
joint type
Definition: hekJoint.h:154
double m_fMaxJointRadsPerSec
maximum joint radians per second
Definition: hekJoint.h:159
double m_fPosition
current joint position (radians)
Definition: hekJoint.h:320
double m_fVelocity
current joint velocity (% of max)
Definition: hekJoint.h:321
int m_nMinPhyLimitOd
joint min phys limit (odometer ticks)
Definition: hekJoint.h:164
int m_nMasterServoId
master servo id
Definition: hekJoint.h:150
HekOpState m_eOpState
joint operational state
Definition: hekJoint.h:317
double m_fParkPosRads
joint parked position (radians)
Definition: hekJoint.h:172
int m_nMasterServoId
master servo id
Definition: hekJoint.h:318
double m_fCalibPosRads
joint calibrated position (radians)
Definition: hekJoint.h:170
double m_fMinPhyLimitRads
joint min physical limit (radians)
Definition: hekJoint.h:162
bool m_bIsServoContinuous
servo should [not] be continuous mode
Definition: hekJoint.h:152
int m_nMinSoftLimitOd
joint min soft limit (odometer ticks)
Definition: hekJoint.h:168
Hekateros joint classes interfaces.
int m_nMaxPhyLimitOd
joint max phys limit (odometer ticks)
Definition: hekJoint.h:165
byte_t m_byOptLimitMask[HekOptLimitMaxPerJoint]
optical limit mask array
Definition: hekJoint.h:175
bool m_bStopAtOptLimits
do [not] stop at optical limits
Definition: hekJoint.h:180
std::string m_strName
joint name
Definition: hekJoint.h:316
std::string m_strName
joint name
Definition: hekJoint.h:149
Top-level package include file.
double m_fMaxSoftLimitRads
joint max soft limit (radians)
Definition: hekJoint.h:167
double m_fBalPosRads
joint balanced position (radians)
Definition: hekJoint.h:171
int m_nSlaveServoId
linked slave servo id (if any)
Definition: hekJoint.h:319
int m_nMasterServoDir
master servo normalized direction
Definition: hekJoint.h:153
double m_fGearRatio
joint gear ratio
Definition: hekJoint.h:155
Joint state class.
Definition: hekJoint.h:287
<b><i>Hekateros</i></b> product specification base classes.
Hekateros common utilities.
double m_fEffort
current joint effort (servo load)
Definition: hekJoint.h:322
double m_fMaxPhyLimitRads
joint max physical limit (radians)
Definition: hekJoint.h:163
Hekateros tuning.
int m_nEncPos
current master servo encoder pos (ticks)
Definition: hekJoint.h:324
HekTriState m_eOptSwitch[HekOptLimitMaxPerJoint]
current state of optical switch(es)
Definition: hekJoint.h:326
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
double m_fOverTorqueThDft
joint over torque th default (norm).
Definition: hekJoint.h:174