Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekOptical.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekOptical.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-09-18 16:53:49 -0600 (Thu, 18 Sep 2014) $
12  * $Rev: 3748 $
13  *
14  * \brief \h_hek optical limit switches.
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 #ifndef _HEK_OPTICAL_H
50 #define _HEK_OPTICAL_H
51 
52 #include "rnr/rnrconfig.h"
53 
54 #include "Dynamixel/Dynamixel.h"
55 
56 #include "Hekateros/hekateros.h"
57 
58 namespace hekateros
59 {
60  /*!
61  * \ingroup hek_spec
62  * \defgroup hek_optical_spec Hekateros Optical Limits
63  *
64  * All optical joint limits are feed into an \h_i2c I/O expander. In addition
65  * two input/ouput user-defined values are available at the end effector
66  * tool zero point.
67  * \{
68  */
69  static const byte_t HekIOExpI2CAddr = 0x20; ///< i2c 7-bit address
70 
71  // I/O expander commands
72  static const byte_t HekIOExpCmdInput0 = 0; ///< read port 0 command
73  static const byte_t HekIOExpCmdInput1 = 1; ///< read port 1 command
74  static const byte_t HekIOExpCmdOutput0 = 2; ///< write port 0 command
75  static const byte_t HekIOExpCmdOutput1 = 3; ///< write port 1 command
76  static const byte_t HekIOExpCmdPolarity0 = 4; ///< polarity inversion port 0
77  static const byte_t HekIOExpCmdPolarity1 = 5; ///< polarity inversion port 1
78  static const byte_t HekIOExpCmdConfig0 = 6; ///< configuration port 0 cmd
79  static const byte_t HekIOExpCmdConfig1 = 7; ///< configuration port 1 cmd
80 
81  // I/O expander special values
82  static const byte_t HekIOExpUnassigned = 0; ///< unassigned port bit
83  static const byte_t HekIOExpDark = 0; ///< optic switch blocked
84  static const byte_t HekIOExpLight = 0xff; ///< optical switch is lit
85  static const byte_t HekIOExpConstPolarity0 = 0x00; ///< port 0 not inverted
86  static const byte_t HekIOExpConstConfig0 = 0xff; ///< port 0 all input
87 
88  // I/O expander port 0 bits
89 #if 0 //DHP - hack
90  static const byte_t HekIOExpPort0Base0 = 0x20; ///< base 0\h_deg limit
91  static const byte_t HekIOExpPort0Base180 = 0x10; ///< base 180\h_deg lim.
92  static const byte_t HekIOExpPort0Shoulder = 0x08; ///< shoulder limit
93  static const byte_t HekIOExpPort0Elbow = 0x04; ///< elbow limit
94  static const byte_t HekIOExpPort0WristPitch = 0x02; ///< wrist pitch limit
95  static const byte_t HekIOExpPort0WristRot0 = 0x01; ///< wrist rot 0\h_deg
96  static const byte_t HekIOExpPort0Rsrv1 = 0x40; ///< reserved
97  static const byte_t HekIOExpPort0Rsrv2 = 0x80; ///< reserved
98 #endif
99  //DHP - back to normal?
100  static const byte_t HekIOExpPort0Base0 = 0x01; ///< base 0\h_deg limit
101  static const byte_t HekIOExpPort0Base180 = 0x02; ///< base 180\h_deg lim.
102  static const byte_t HekIOExpPort0Shoulder = 0x04; ///< shoulder limit
103  static const byte_t HekIOExpPort0Elbow = 0x08; ///< elbow limit
104  static const byte_t HekIOExpPort0WristPitch = 0x10; ///< wrist pitch limit
105  static const byte_t HekIOExpPort0WristRot0 = 0x20; ///< wrist rot 0\h_deg
106  static const byte_t HekIOExpPort0Rsrv1 = 0x40; ///< reserved
107  static const byte_t HekIOExpPort0Rsrv2 = 0x80; ///< reserved
108 
109  // I/O expander port 1 bits
110  static const byte_t HekIOExpPort1EEUser1 = 0x01; ///< user defined 1
111  static const byte_t HekIOExpPort1EEUser2 = 0x02; ///< user defined 2
112  static const byte_t HekIOExpPort1Rsrv1 = 0x04; ///< reserved
113  static const byte_t HekIOExpPort1Rsrv2 = 0x08; ///< reserved
114  static const byte_t HekIOExpPort1Rsrv3 = 0x10; ///< reserved
115  static const byte_t HekIOExpPort1Rsrv4 = 0x20; ///< reserved
116  static const byte_t HekIOExpPort1Rsrv5 = 0x40; ///< reserved
117  static const byte_t HekIOExpPort1Rsrv6 = 0x80; ///< reserved
118 
119  // Sizes
120  static const int HekOptLimitMaxPerJoint = 2; ///< max limits/joint
121  static const int HekOptLimitMaxEdges = 2; ///< max edges/limit
122 
123 
124  // ---------------------------------------------------------------------------
125  // Struct HekOpticalLimit_T
126  // ---------------------------------------------------------------------------
127 
128  /*!
129  * \brief Optical limit switch.
130  *
131  * An optical limit switch is a binary valued detector that is either
132  * completely on ("closed") or completely off ("open").
133  * The switch is composed of an IR transmitter and a photodiode. When the
134  * photodiode detects the IR beam, the circuit is closed. When the beam is
135  * blocked (occluded)the circuit is open. For \h_hek, the occluson bands serve
136  * one of two purposes:
137  * \li For joints with limited rotation, the band marks the arc of valid
138  * rotation.
139  * \li For continously rotating joints, the band(s) mark key joint reference
140  * points such as top-dead-center (0\h_deg).
141  *
142  * For each \h_hek joint with optical limits, a physical occlusion band is
143  * integrated into robotic structure.
144  *
145  * To read the state of an optical switch, the signal is feed to an \h_i2c
146  * enabled I/O expander. \h_hek software can read the values via \h_i2c.
147  */
149  {
150  /*!
151  * \brief Assignment operator.
152  *
153  * \param rhs Right hand side object.
154  *
155  * \return this.
156  */
158  {
159  m_uBit = rhs.m_uBit;
165  }
166 
167  void clear()
168  {
169  m_uBit = 0x00;
170  m_fMinEdgePos = 0.0;
171  m_fMinBlackPos = 0.0;
172  m_fCenterPos = 0.0;
173  m_fMaxBlackPos = 0.0;
174  m_fMaxEdgePos = 0.0;
175  }
176 
177  byte_t m_uBit; ///< i/o expander bit position
178  double m_fMinEdgePos; ///< mininum edge position of occlusion band
179  double m_fMinBlackPos; ///< minimum complete occlusion position
180  double m_fCenterPos; ///< center of operation position
181  double m_fMaxBlackPos; ///< maximum complete occlusion position
182  double m_fMaxEdgePos; ///< maxinum edge position of occlusion band
183  };
184 
185  /*!
186  * \brief Test if any of the optical limits have been triggered (occluded).
187  *
188  * \param byBits I/O expander mapped optical limit switches.
189  * \param byMask Mask of limits to check.
190  *
191  * \return Returns bit map where 1 at a given mapped position indicates
192  * the optical limit has been triggered, 0 otherwise.
193  */
194  static byte_t getDarkOpticalLimits(byte_t byBits, byte_t byMask)
195  {
196  //fprintf(stderr, "dhp: dark: raw bits, mask = %02x, %02x\n", byBits, byMask);
197  return ~byBits & byMask;
198  }
199 
200  /*!
201  * \brief Test if any of the optical limits are lit (not occluded).
202  *
203  * \param byBits I/O expander mapped optical limit switches.
204  * \param byMask Mask of limits to check.
205  *
206  * \return Returns bit map where 1 at a given mapped position indicates
207  * the optical limit is lit, 0 otherwise.
208  */
209  static byte_t getLitOpticalLimits(byte_t byBits, byte_t byMask)
210  {
211  //fprintf(stderr, "dhp: lit: raw bits, mask = %02x, %02x\n", byBits, byMask);
212  return byBits & byMask;
213  }
214 
215  /*! \} */
216 
217 } // namespace hekateros
218 
219 
220 #endif // _HEK_OPTICAL_H
static const int HekOptLimitMaxEdges
max edges/limit
Definition: hekOptical.h:121
static const byte_t HekIOExpConstPolarity0
port 0 not inverted
Definition: hekOptical.h:85
static const byte_t HekIOExpPort1Rsrv3
reserved
Definition: hekOptical.h:114
static const byte_t HekIOExpPort0Elbow
elbow limit
Definition: hekOptical.h:103
byte_t m_uBit
i/o expander bit position
Definition: hekOptical.h:177
static const byte_t HekIOExpPort0WristRot0
wrist rot 0 &deg;
Definition: hekOptical.h:105
static const byte_t HekIOExpPort0Base180
base 180 &deg; lim.
Definition: hekOptical.h:101
static const byte_t HekIOExpPort0WristPitch
wrist pitch limit
Definition: hekOptical.h:104
static const byte_t HekIOExpUnassigned
unassigned port bit
Definition: hekOptical.h:82
static const byte_t HekIOExpPort1Rsrv2
reserved
Definition: hekOptical.h:113
Optical limit switch.
Definition: hekOptical.h:148
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
double m_fMinBlackPos
minimum complete occlusion position
Definition: hekOptical.h:179
static const byte_t HekIOExpCmdOutput0
write port 0 command
Definition: hekOptical.h:74
static const byte_t HekIOExpPort0Base0
base 0 &deg; limit
Definition: hekOptical.h:100
HekOpticalLimit_T operator=(const HekOpticalLimit_T &rhs)
Assignment operator.
Definition: hekOptical.h:157
static const byte_t HekIOExpPort0Shoulder
shoulder limit
Definition: hekOptical.h:102
double m_fMaxEdgePos
maxinum edge position of occlusion band
Definition: hekOptical.h:182
static const byte_t HekIOExpLight
optical switch is lit
Definition: hekOptical.h:84
double m_fMaxBlackPos
maximum complete occlusion position
Definition: hekOptical.h:181
static const byte_t HekIOExpPort1Rsrv5
reserved
Definition: hekOptical.h:116
double m_fMinEdgePos
mininum edge position of occlusion band
Definition: hekOptical.h:178
static byte_t getDarkOpticalLimits(byte_t byBits, byte_t byMask)
Test if any of the optical limits have been triggered (occluded).
Definition: hekOptical.h:194
static const byte_t HekIOExpPort1EEUser2
user defined 2
Definition: hekOptical.h:111
static const byte_t HekIOExpCmdConfig1
configuration port 1 cmd
Definition: hekOptical.h:79
static const byte_t HekIOExpCmdInput0
read port 0 command
Definition: hekOptical.h:72
static const byte_t HekIOExpPort1Rsrv4
reserved
Definition: hekOptical.h:115
static const int HekOptLimitMaxPerJoint
max limits/joint
Definition: hekOptical.h:120
Top-level package include file.
static const byte_t HekIOExpCmdInput1
read port 1 command
Definition: hekOptical.h:73
static const byte_t HekIOExpPort1Rsrv6
reserved
Definition: hekOptical.h:117
static const byte_t HekIOExpCmdPolarity0
polarity inversion port 0
Definition: hekOptical.h:76
static byte_t getLitOpticalLimits(byte_t byBits, byte_t byMask)
Test if any of the optical limits are lit (not occluded).
Definition: hekOptical.h:209
static const byte_t HekIOExpConstConfig0
port 0 all input
Definition: hekOptical.h:86
static const byte_t HekIOExpPort1EEUser1
user defined 1
Definition: hekOptical.h:110
static const byte_t HekIOExpCmdConfig0
configuration port 0 cmd
Definition: hekOptical.h:78
static const byte_t HekIOExpPort0Rsrv2
reserved
Definition: hekOptical.h:107
static const byte_t HekIOExpPort0Rsrv1
reserved
Definition: hekOptical.h:106
static const byte_t HekIOExpDark
optic switch blocked
Definition: hekOptical.h:83
static const byte_t HekIOExpCmdOutput1
write port 1 command
Definition: hekOptical.h:75
static const byte_t HekIOExpCmdPolarity1
polarity inversion port 1
Definition: hekOptical.h:77
double m_fCenterPos
center of operation position
Definition: hekOptical.h:180
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
static const byte_t HekIOExpPort1Rsrv1
reserved
Definition: hekOptical.h:112