Main Page · Modules · All Classes · Class Hierarchy
MABodyTypes.cpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #include "MABodyTypes.hpp"
23 
24 #include "MARobotState.hpp"
25 #include "MABodyMotion.hpp"
26 #include "MATypeRanges.hpp"
27 
28 #include <boost/bind.hpp>
29 
30 #include <math.h>
31 
32 MABodyPartFeature::MABodyPartFeature(int value, int minimum, int maximum) :
33  Value(value, minimum, maximum)
34 {
35 }
36 
37 
38 MALegPosition::MALegPosition() : MABodyPartFeature(), ForeBackValue(0, -100, 100),
39  UpDownValue(0, -100, 100)
40 {
41  MA_SIGNAL_CONNECT(ForeBackValue.GetValueChangeSignal(), MALegPosition::NotifyNumUpdate);
42  MA_SIGNAL_CONNECT(UpDownValue.GetValueChangeSignal(), MALegPosition::NotifyNumUpdate);
43 }
44 
45 
48 {
49  MA_SIGNAL_CONNECT(ForeBackValue.GetValueChangeSignal(), MALegPosition::NotifyNumUpdate);
50  MA_SIGNAL_CONNECT(UpDownValue.GetValueChangeSignal(), MALegPosition::NotifyNumUpdate);
51 }
52 
53 
55 {
57  ForeBackValue = DegreeToForeBack(degree);
60  UpDownValue = DegreeToUpDown(degree);
62 }
63 
64 
66 {
67  float ForeBack = (float)ForeBackValue;
68  float UpDown = (float)UpDownValue;
69  int Ret = 0;
70 
71  if (UpDown < 0)
72  {
73  Ret = 90+(int)round(UpDown*90 / 100);
74  if (ForeBack < 0)
75  Ret = -Ret;
76  return Ret;
77  }
78  if (ForeBack < 0)
79  Ret = (int)-(round(UpDown*(-MA::Joint1Min-90) / 100)+90);
80  else
81  Ret = (int)(round(UpDown*(MA::Joint1Max-90) / 100)+90);
82  return Ret;
83 }
84 
85 
86 void MALegPosition::NotifyNumUpdate(MANum<float>& number)
87 {
88  if (&number == &UpDownValue)
89  {
90  int Degree = ToJointDegree();
91 
93  ForeBackValue = DegreeToForeBack(Degree);
95  }
96  if (&number == &ForeBackValue)
97  {
98  int Degree = (int)round((float)ForeBackValue*90 / 100);;
99 
101  UpDownValue = DegreeToUpDown(Degree);
103  }
104 }
105 
106 
107 float MALegPosition::DegreeToForeBack(int degree) const
108 {
109  float Ret = 0.0;
110 
111  if (unlikely(degree >= 90))
112  Ret = 100.0;
113  else
114  if (unlikely(degree <= -90))
115  Ret = -100.0;
116  else
117  Ret = (float)(degree*100) / 90;
118  return Ret;
119 }
120 
121 
122 float MALegPosition::DegreeToUpDown(int degree) const
123 {
124  float Ret = 0.0;
125 
126  if (likely(MCAbs(degree) <= 90))
127  {
128  Ret = -(float)((90-MCAbs(degree))*100) / 90;
129  }
130  else
131  if (unlikely(degree < -90))
132  Ret = -(float)((degree+90)*100) / (-MA::Joint1Min-90);
133  else
134  if (unlikely(degree > 90))
135  Ret = (float)((degree-90)*100) / (MA::Joint1Max-90);
136  return Ret;
137 }
138 
139 
140 MASidelong::MASidelong(int value) : MABodyPartFeature(value, 0, 100)
141 {
142 }
143 
144 
146 {
147  Value = (float)((degree-MA::Joint2Min)*100) / (-MA::Joint2Min+MA::Joint2Max);
148 }
149 
150 
152 {
153  return (int)round((float)Value*(-MA::Joint2Min+MA::Joint2Max) / 100)+MA::Joint2Min;
154 }
155 
156 
158 {
159 }
160 
161 
163 {
164  Value = degree <= 0 ? 0 : (float)(degree*100) / MA::Joint3Max;
165 }
166 
167 
169 {
170  return (int)round((float)Value*MA::Joint3Max / 100);
171 }
172 
173 
175 {
176 }
177 
178 
180 {
181  Value = -(float)(degree*100) / MA::NeckPanMax;
182 }
183 
184 
186 {
187  return -(int)round((float)Value*MA::NeckPanMax / 100);
188 }
189 
190 
191 MAHeadPosition::MAHeadPosition() : ForeBackValue(0, -100, 100), UpDownValue(0, -100, 100)
192 {
193 }
194 
195 
197 {
198  MC_UNUSED(degree)
199  // Nothing to do
200 }
201 
202 
204 {
205  // Nothing to do
206  return 0;
207 }
208 
209 
210 void MAHeadPosition::FromJointDegrees(int neck_tilt1, int neck_tilt2)
211 {
212  MANum<int> NeckTilt1(neck_tilt1, MA::NeckT1Min, MA::NeckT1Max);
213  MANum<int> NeckTilt2(neck_tilt2, MA::NeckT2Min, MA::NeckT2Max);
214  int ZeroDegreeCorrection = (MA::RobotState.get() && MA::RobotState->BodyMotion->Sitting > 80) ? 35 : 0;
215  int ZeroDegree = -NeckTilt1-ZeroDegreeCorrection;
216 
217  ForeBackValue = -(float)((int)NeckTilt1+ZeroDegreeCorrection);
218  UpDownValue = (float)((int)NeckTilt2-ZeroDegree);
219 }
220 
221 
222 int MAHeadPosition::ToNeckTilt1Degree() const
223 {
224  int ZeroDegreeCorrection = (MA::RobotState.get() && MA::RobotState->BodyMotion->Sitting > 80) ? 35 : 0;
225  MANum<int> Degree(-((int)ForeBackValue+ZeroDegreeCorrection), MA::NeckT1Min, MA::NeckT1Max);
226 
227  return (int)Degree;
228 }
229 
230 
231 int MAHeadPosition::ToNeckTilt2Degree() const
232 {
233  int ZeroDegreeCorrection = (MA::RobotState.get() && MA::RobotState->BodyMotion->Sitting > 80) ? 35 : 0;
234  MANum<int> Degree((int)UpDownValue-ToNeckTilt1Degree()-ZeroDegreeCorrection, MA::NeckT2Min, MA::NeckT2Max);
235 
236  return (int)Degree;
237 }
238 
239 
241 {
242 }
243 
244 
246 {
247  Value = degree <= -60.0 ? 100.0 : 100.0-(float)((degree-MA::MouthMin)*100) / (MA::MouthMax-MA::MouthMin);
248 }
249 
250 
252 {
253  return MA::MouthMin+(int)round((float)(100.0-Value)*(MA::MouthMax-MA::MouthMin) / 100);
254 }
MANum< float > Value
Current value.
Definition: MABodyTypes.hpp:86
virtual int ToJointDegree() const override
Transform to a joint degree value.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
MABodyPartFeature(int value=0, int minimum=-100, int maximum=100)
Struct constructor.
Definition: MABodyTypes.cpp:32
MAMouthOpened(int value=0)
Struct constructor.
MANum< float > UpDownValue
Current up-down direction value.
boost::shared_ptr< ValueChangeSignalType > & GetValueChangeSignal()
Get the value change signal.
Definition: MANum.hpp:84
void SetBlockedNotifications(bool new_state)
Set the notifications to be blocked.
Definition: MANum.hpp:120
The forward-backward/upward-downward feature of a leg joint.
Definition: MABodyTypes.hpp:92
MANum< float > UpDownValue
Current up-down direction value.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
Definition: MABodyTypes.cpp:54
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
virtual int ToJointDegree() const override
Transform to a joint degree value.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
MANum< float > ForeBackValue
Current fore-back direction value.
T MCAbs(const T &value)
Calculate absolute value.
Definition: MCDefs.hpp:399
MAHeadPosition()
Struct constructor.
MASidelong(int value=0)
Struct constructor.
A base class for the limb features.
Definition: MABodyTypes.hpp:56
virtual int ToJointDegree() const override
Transform to a joint degree value.
virtual int ToJointDegree() const override
Transform to a joint degree value.
virtual int ToJointDegree() const override
Transform to a joint degree value.
Definition: MABodyTypes.cpp:65
#define MC_UNUSED(a)
Helper macro to avoid compiler warning about unused function parameters.
Definition: MCDefs.hpp:601
virtual int ToJointDegree() const override
Transform to a joint degree value.
MABentStretched(int value=0)
Struct constructor.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
MALeftRightTurned(int value=0)
Struct constructor.
MA_SLOT_CLASS MALegPosition()
Struct constructor.
Definition: MABodyTypes.cpp:38
MANum< float > ForeBackValue
Current fore-back direction value.