rec::robotino::api2 C++ interface
CompactBHASimple.h
1 // Copyright (C) 2004-2012, Robotics Equipment Corporation GmbH
2 
3 //Copyright (c) ...
4 //
5 //REC Robotics Equipment Corporation GmbH, Planegg, Germany. All rights reserved.
6 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 //1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 //2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 //
10 //THIS SOFTWARE IS PROVIDED BY REC ROBOTICS EQUIPMENT CORPORATION GMBH �AS IS� AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
11 //THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REC ROBOTICS EQUIPMENT CORPORATION GMBH
12 //BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
13 //GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 //
16 //Copyright (c) ...
17 //
18 //REC Robotics Equipment Corporation GmbH, Planegg, Germany. Alle Rechte vorbehalten.
19 //Weiterverbreitung und Verwendung in nichtkompilierter oder kompilierter Form, mit oder ohne Ver�nderung, sind unter den folgenden Bedingungen zul�ssig:
20 //1) Weiterverbreitete nichtkompilierte Exemplare m�ssen das obige Copyright, diese Liste der Bedingungen und den folgenden Haftungsausschluss im Quelltext enthalten.
21 //2) Weiterverbreitete kompilierte Exemplare m�ssen das obige Copyright, diese Liste der Bedingungen und den folgenden Haftungsausschluss in der Dokumentation und/oder anderen Materialien, die mit dem Exemplar verbreitet werden, enthalten.
22 //
23 //DIESE SOFTWARE WIRD VON REC ROBOTICS EQUIPMENT CORPORATION GMBH OHNE JEGLICHE SPEZIELLE ODER IMPLIZIERTE GARANTIEN ZUR VERF�GUNG GESTELLT, DIE UNTER
24 //ANDEREM EINSCHLIESSEN: DIE IMPLIZIERTE GARANTIE DER VERWENDBARKEIT DER SOFTWARE F�R EINEN BESTIMMTEN ZWECK. AUF KEINEN FALL IST REC ROBOTICS EQUIPMENT CORPORATION GMBH
25 //F�R IRGENDWELCHE DIREKTEN, INDIREKTEN, ZUF�LLIGEN, SPEZIELLEN, BEISPIELHAFTEN ODER FOLGESCH�DEN (UNTER ANDEREM VERSCHAFFEN VON ERSATZG�TERN ODER -DIENSTLEISTUNGEN;
26 //EINSCHR�NKUNG DER NUTZUNGSF�HIGKEIT; VERLUST VON NUTZUNGSF�HIGKEIT; DATEN; PROFIT ODER GESCH�FTSUNTERBRECHUNG), WIE AUCH IMMER VERURSACHT UND UNTER WELCHER VERPFLICHTUNG
27 //AUCH IMMER, OB IN VERTRAG, STRIKTER VERPFLICHTUNG ODER UNERLAUBTER HANDLUNG (INKLUSIVE FAHRL�SSIGKEIT) VERANTWORTLICH, AUF WELCHEM WEG SIE AUCH IMMER DURCH DIE BENUTZUNG
28 //DIESER SOFTWARE ENTSTANDEN SIND, SOGAR, WENN SIE AUF DIE M�GLICHKEIT EINES SOLCHEN SCHADENS HINGEWIESEN WORDEN SIND.
29 
30 #ifndef _REC_ROBOTINO_API2_COMPACTBHASIMPLE_H_
31 #define _REC_ROBOTINO_API2_COMPACTBHASIMPLE_H_
32 
33 #include <cmath>
34 #include <algorithm>
35 
36 namespace rec
37 {
38  namespace robotino
39  {
40  namespace api2
41  {
48  {
49  private:
53  class Pole
54  {
55 
56  public:
57  Pole(float x, float y, float weight1, float weight2, float weight3)
58  : _x(x)
59  , _y(y)
60  {
61  _weight[0] = weight1;
62  _weight[1] = weight2;
63  _weight[2] = weight3;
64  }
65 
66  float x() const
67  {
68  return _x;
69  }
70 
71  float y() const
72  {
73  return _y;
74  }
75 
76  float weight1() const
77  {
78  return _weight[0];
79  }
80 
81  float weight2() const
82  {
83  return _weight[1];
84  }
85 
86  float weight3() const
87  {
88  return _weight[2];
89  }
90 
91  float getWeight(float x, float y, int weightIdx) const
92  {
93  float dX = _x - x;
94  float dY = _y - y;
95  float dist = sqrt( dX * dX + dY * dY );
96  return std::max( 0.f, 1 - (_weight[weightIdx-1] * dist) );
97  }
98 
99  private:
100  float _x;
101  float _y;
102 
103  float _weight[3];
104  };
105 
106  static const Pole _pole1;
107  static const Pole _pole2;
108  static const Pole _pole3;
109  static const Pole _pole4;
110  static const Pole _pole5;
111  static const Pole _pole6;
112 
113  public:
121  static void xy2pressure( float x, float y, float* b1, float* b2, float* b3 )
122  {
123  /* Transform exterior coordinates to simplify the later
124  * weight calculation. NOTE: Here the transformation is
125  * temporarily implemented in a very simple way, by just
126  * moving outer points to the hexagon circumcircle. */
127  float dist = sqrt( x * x + y * y );
128  if (dist > 1.0)
129  {
130  x /= dist;
131  y /= dist;
132  }
133 
134  /* Calculate pressure value for bellows #1 with
135  * weights calculated for poles 3, 4, 5. */
136  *b1 = _pole3.getWeight(x, y, 3);
137  *b1 += _pole4.getWeight(x, y, 3);
138  *b1 += _pole5.getWeight(x, y, 3);
139 
140  /* Calculate pressure value for bellows #2 with
141  * weights calculated for poles 5, 6, 1. */
142  *b2 = _pole5.getWeight(x, y, 1);
143  *b2 += _pole6.getWeight(x, y, 1);
144  *b2 += _pole1.getWeight(x, y, 1);
145 
146  /* Calculate pressure value for bellows #3 with
147  * weights calculated for poles 1, 2, 3. */
148  *b3 = _pole1.getWeight(x, y, 2);
149  *b3 += _pole2.getWeight(x, y, 2);
150  *b3 += _pole3.getWeight(x, y, 2);
151  }
152  };
153 
154  const CompactBHASimple::Pole CompactBHASimple::_pole1 = Pole(0.0f, 1.0f, 1.0f, 1.0f, 0.0f);
155  const CompactBHASimple::Pole CompactBHASimple::_pole2 = Pole((sqrt((float)3.0) / 2.0f), 0.5f, 0.0f, 1.0f, 0.0f);
156  const CompactBHASimple::Pole CompactBHASimple::_pole3 = Pole((sqrt((float)3.0) / 2.0f), -0.5f, 0.0f, 1.0f, 1.0f);
157  const CompactBHASimple::Pole CompactBHASimple::_pole4 = Pole(0.0f, -1.0f, 0.0f, 0.0f, 1.0f);
158  const CompactBHASimple::Pole CompactBHASimple::_pole5 = Pole(-(sqrt((float)3.0f) / 2.0f), -0.5f, 1.0f, 0.0f, 1.0f);
159  const CompactBHASimple::Pole CompactBHASimple::_pole6 = Pole(-(sqrt((float)3.0f) / 2.0f), 0.5f, 1.0f, 0.0f, 0.0f);
160  }
161  }
162 }
163 
164 #endif //_REC_ROBOTINO_API2_COMPACTBHASIMPLE_H_
Calculation from xy coordinates to pressures.
Definition: CompactBHASimple.h:47
static void xy2pressure(float x, float y, float *b1, float *b2, float *b3)
Definition: CompactBHASimple.h:121
Definition: AnalogInput.h:36