22 #include "MABodyMotion.hpp" 24 #include "ml/MAClassifierModels.hpp" 25 #include "MAComplexIndicators.hpp" 26 #include "MARobotState.hpp" 27 #include "MATorso.hpp" 28 #include "MATypeRanges.hpp" 30 #include <MCSampleStatistics.hpp> 32 #include <boost/math/constants/constants.hpp> 45 if (surface == MA::WoodFlooring)
46 return "Wood flooring";
47 if (surface == MA::Field)
49 if (surface == MA::Carpet)
51 if (surface == MA::FoamMat)
53 if (surface == MA::Vinyl)
55 if (surface == MA::Tiles)
57 if (surface == MA::CarpetedFloor)
58 return "Carpeted floor";
59 if (surface == MA::UserDefinedFloor)
60 return "User defined";
68 if (surface_softness == MA::HardFlooring)
69 return "Hard floor surface";
70 if (surface_softness == MA::SoftFlooring)
71 return "Soft floor surface";
73 return "Very soft floor surface";
79 if (surface == MA::WoodFlooring)
80 return MA::HardFlooring;
81 if (surface == MA::Field)
82 return MA::SoftFlooring;
83 if (surface == MA::Carpet)
84 return MA::VerySoftFlooring;
85 if (surface == MA::FoamMat)
86 return MA::SoftFlooring;
87 if (surface == MA::Vinyl)
88 return MA::HardFlooring;
89 if (surface == MA::Tiles)
90 return MA::HardFlooring;
91 if (surface == MA::CarpetedFloor)
92 return MA::SoftFlooring;
94 return MA::HardFlooring;
99 OwnerFeedback(-500, -500, 3000)
105 BodyState((int)
MA::UnknownBodyState, (int)
MA::UnknownBodyState, (int)
MA::Poked),
106 MotionControlAge(0, 0, 60),
107 BackStrokedFactor(0, 0, 2000),
108 LyingOnBackFactor(0, 0, 400),
109 LyingOnBackLeftSideFactor(0, 0, 3000),
110 LyingOnBackRightSideFactor(0, 0, 3000),
111 BodyOnLeftSideFactor(0, 0, 3000),
112 BodyOnRightSideFactor(0, 0, 3000),
113 LyingFactor(0, 0, 400),
114 LyingOnLeftSideFactor(0, 0, 3000),
115 LyingOnRightSideFactor(0, 0, 3000),
116 SittingFactor(0, 0, 800),
117 FlyingFactor(0, 0, 3000),
118 PokedFactor(0, 0, 600),
124 UpsideDown.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
125 LateralPosition.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
126 HeadStand.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
127 LyingOnBack.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
128 LyingOnBackLeftSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
129 LyingOnBackRightSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
130 BodyOnLeftSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
131 BodyOnRightSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
132 Lying.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
133 LyingOnLeftSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
134 LyingOnRightSide.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
135 Sitting.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
136 Flying.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
137 Poked.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
162 UpsideDown = (int)(((
float)
AccelZ.
Degree+90) / 180.0*100.0);
163 LateralPosition = (int)(((
float)
AccelY.
Degree+90) / 180.0*100.0);
164 HeadStand = (int)(((
float)
AccelX.
Degree+90) / 180.0*100.0);
166 state.
LegRH->InMotion > 0 || state.
Head->InMotion > 0;
169 GenerateLyingOnBack(state);
170 GenerateLyingOnBackLeftSide(state);
171 GenerateLyingOnBackRightSide(state);
172 GenerateBodyOnLeftSide(state);
173 GenerateBodyOnRightSide(state);
174 GenerateLying(state);
175 GenerateLyingOnLeftSide(state);
176 GenerateLyingOnRightSide(state);
177 GenerateSitting(state);
178 GenerateFlying(state);
179 GeneratePoked(state);
181 GenerateBodyPitchAndRoll();
185 void MABodyMotion::GenerateBodyPitchAndRoll()
190 BodyRoll = (int)(atan(Alpha)*180.0 / boost::math::constants::pi<float>());
191 BodyPitch = (int)(atan(Beta)*180.0 / boost::math::constants::pi<float>());
195 void MABodyMotion::GenerateLyingOnBack(
MARobotState& state)
197 if (UpsideDown >= 75 &&
199 state.
Torso->BackGrabbed == 0)
210 void MABodyMotion::GenerateLyingOnBackLeftSide(
MARobotState& state)
212 if (UpsideDown >= 65 && LateralPosition < 25 &&
214 state.
Torso->BackGrabbed == 0)
225 void MABodyMotion::GenerateLyingOnBackRightSide(
MARobotState& state)
227 if (UpsideDown >= 65 && LateralPosition > 75 &&
229 state.
Torso->BackGrabbed == 0)
240 void MABodyMotion::GenerateBodyOnLeftSide(
MARobotState& state)
242 bool PawsFree =
true;
244 PawsFree = PawsFree && state.
LegLF->Paw == 0;
245 PawsFree = PawsFree && state.
LegLH->Paw == 0;
246 PawsFree = PawsFree && state.
LegRF->Paw == 0;
247 PawsFree = PawsFree && state.
LegRH->Paw == 0;
249 if (UpsideDown > 20 && UpsideDown < 95 && LateralPosition < 10 &&
251 PawsFree && state.
Torso->BackGrabbed == 0)
262 void MABodyMotion::GenerateBodyOnRightSide(
MARobotState& state)
264 bool PawsFree =
true;
266 PawsFree = PawsFree && state.
LegLF->Paw == 0;
267 PawsFree = PawsFree && state.
LegLH->Paw == 0;
268 PawsFree = PawsFree && state.
LegRF->Paw == 0;
269 PawsFree = PawsFree && state.
LegRH->Paw == 0;
271 if (UpsideDown > 20 && UpsideDown < 95 && LateralPosition > 90 &&
273 PawsFree && state.
Torso->BackGrabbed == 0)
287 int LegsMovedToStand = 0;
289 LegsMovedToStand += (state.
LegLF->Moving && state.
LegLF->UpDown < -80);
290 LegsMovedToStand += (state.
LegLH->Moving && state.
LegLH->UpDown < -80);
291 LegsMovedToStand += (state.
LegRF->Moving && state.
LegRF->UpDown < -80);
292 LegsMovedToStand += (state.
LegRH->Moving && state.
LegRH->UpDown < -80);
294 Result = Result && !state.
BodyMotion->SkitPlayback;
295 Result = Result && UpsideDown < 15 && HeadStand >= 8;
296 Result = Result && Sitting <= 10;
298 Result = Result && !state.
ComplexIndicators->IsStandingPosture && LegsMovedToStand < 4;
312 void MABodyMotion::GenerateLyingOnLeftSide(
MARobotState& state)
314 if (UpsideDown > 0 && UpsideDown < 15 && LateralPosition > 0 && LateralPosition < 15 &&
316 state.
Torso->BackGrabbed == 0)
327 void MABodyMotion::GenerateLyingOnRightSide(
MARobotState& state)
329 if (UpsideDown > 0 && UpsideDown < 15 && LateralPosition > 80 && LateralPosition < 95 &&
331 state.
Torso->BackGrabbed == 0)
344 if (UpsideDown < 15 && HeadStand >= 0 && HeadStand <= 12 &&
346 (state.
LegLF->Paw == 1 || state.
LegRF->Paw == 1))
359 int Multiplier = state.
Torso->BackGrabbed > 80 ? 3 : 1;
360 bool PawsFree =
true;
362 PawsFree = PawsFree && state.
LegLF->Paw == 0;
363 PawsFree = PawsFree && state.
LegLH->Paw == 0;
364 PawsFree = PawsFree && state.
LegRF->Paw == 0;
365 PawsFree = PawsFree && state.
LegRH->Paw == 0;
367 if ((
int)
BodyState == MA::PickupMode && PawsFree)
384 !(
bool)state.
LegLF->Moving && !(
bool)state.
LegLH->Moving &&
385 !(
bool)state.
LegRF->Moving && !(
bool)state.
LegRH->Moving &&
void Start(int time_shift=0)
Start the timer.
bool IsBodyRollInWalkRange() const
Check if the body roll is in the acceptable walking range.
MAIntervalNum< int > LyingOnBackFactor
Indicator variable when the robot body is lying upside down.
MANum< int > Degree
Degree (-90°..90°)
MAIntervalNum< int > LyingOnBackRightSideFactor
Indicator variable when the robot body is lying upside down/right side.
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
virtual void SetMinMax(T min_value, T max_value)
Set the minimal and maximal values.
MAIntervalNum< int > LyingOnBackLeftSideFactor
Indicator variable when the robot body is lying upside down/left side.
MANum< int > MotionControlAge
Elapsed time since the last motion control command (in seconds)
MANum< int > BodyRoll
Body roll.
MAIntervalNum< int > SittingFactor
Indicator variable for sitting position.
bool IsStarted() const
Check if the timer has been started.
void StopMotionControlTimer()
Stop the motion control timer.
boost::scoped_ptr< MAComplexIndicators > ComplexIndicators
Complex indicators.
MANum< int > InMotion
Any body part is in motion.
void Stop()
Stop the timer.
MAIntervalNum< int > LyingFactor
Indicator variable when the robot body is lying.
boost::scoped_ptr< MALeg > LegRH
LegRH.
MABodyMotion()
Struct constructor.
MANum< int > Raw
Raw data (-19613300..19613300)
MCTimer MotionControlTimer
Motion control command timer.
MAIntervalNum< int > LyingOnRightSideFactor
Indicator variable when the robot body is lying on its right side.
MAIntervalNum< int > FlyingFactor
Indicator variable to detect the flying (pick-up) mode.
MAFloorSurface()
Struct constructor.
MAIntervalNum< int > BodyOnRightSideFactor
Indicator variable when the robot body is on its right side.
MANum< int > BodyPitch
Body pitch.
MAAccelData AccelZ
Accelerometer (Z dimension, up-down)
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
boost::scoped_ptr< MALeg > LegLF
LegLF.
std::string MAFloorSurfacesTypeStr(const MA::FloorSurfacesType surface)
Get floor surface string.
int GetElapsedTime()
Get the elapsed time since the timer has been started or since the last timeout.
MAIntervalNum< int > BodyOnLeftSideFactor
Indicator variable when the robot body is on its left side.
Robot state updater base class.
boost::scoped_ptr< MALeg > LegRF
LegRF.
void SetMagnitude(float value)
Set the magnitude.
void StartMotionControlTimer()
Start the motion control timer.
MAIntervalNum< int > LyingOnLeftSideFactor
Indicator variable when the robot body is lying on its left side.
MA::FloorSurfaceSoftnessType MAMapFloorSurfaceToSoftness(const MA::FloorSurfacesType surface)
Map a floor surface to softness.
MAIntervalNum< int > PokedFactor
Indicator variable to detect the poked state.
std::string MAFloorSurfaceSoftnessTypeStr(const MA::FloorSurfaceSoftnessType surface_softness)
Get floor surface softness string.
boost::scoped_ptr< MATorso > Torso
Torso.
MAAccelData AccelY
Accelerometer (Y dimension, left-right)
boost::scoped_ptr< MALeg > LegLH
LegLH.
MAAccelData()
Struct constructor.
MANum< int > BodyState
Body state.
T GetValueChange() const
The last value change difference.
MAAccelData AccelX
Accelerometer (X dimension, front-back)
boost::scoped_ptr< MAHead > Head
Head.