22 #include "MAComplexIndicators.hpp" 24 #include "MAAudio.hpp" 25 #include "MABodyMotion.hpp" 26 #include "MAGoals.hpp" 29 #include "MARobotState.hpp" 30 #include "MATorso.hpp" 31 #include "MATypeRanges.hpp" 34 WalkPeriod(2400, 1400, 3200),
35 ElapsedForwardWalkTime(0, 0, 100000),
36 ElapsedBackwardWalkTime(0, 0, 100000),
37 ElapsedLeftTurnTime(0, 0, 20700),
38 ElapsedRightTurnTime(0, 0, 20700),
39 AbyssWhileLying(-1, -1, 1),
40 LeftMicrophoneDominance(0, 0, 255), RightMicrophoneDominance(0, 0, 255),
41 MicrophoneChannelsBalance(0, 0, 255),
42 NearObjectForwardFactor(0, 0, 2000),
43 AbyssWhileWalkingFactor(0, 0, 3000),
44 BodyOutOfWalkingRangeFactor(0, 0, 500),
45 OverloadDangerWhileSittingFactor(0, 0, 3000),
46 WalkSpeedAccelerationStart(-1)
49 NearObjectForward.
SetMinMax(MA::StandardRangeMin, MA::StandardRangeMax);
64 IsLyingPosture = state.
LegLF->IsLyingPosition &&
65 state.
LegLH->IsLyingPosition &&
66 state.
LegRF->IsLyingPosition &&
67 state.
LegRH->IsLyingPosition;
68 IsStandingPosture = state.
LegLF->IsStandingPosition &&
69 state.
LegLH->IsStandingPosition &&
70 state.
LegRF->IsStandingPosition &&
71 state.
LegRH->IsStandingPosition;
72 IsSittingPosture = state.
LegLF->IsSittingPosition &&
73 state.
LegLH->IsSittingPosition &&
74 state.
LegRF->IsSittingPosition &&
75 state.
LegRH->IsSittingPosition;
76 GenerateWalkPeriod(state);
77 GenerateNearObjectForward(state);
78 GenerateAbyssWhileWalking(state);
79 GenerateAbyssWhileLying(state);
80 GenerateBodyOutOfWalkingRange(state);
81 GenerateOverloadDangerWhileSitting(state);
82 GenerateListenWithEars(state);
83 GenerateMicrophoneChannelDominances(state);
87 void MAComplexIndicators::GenerateWalkPeriod(
MARobotState& state)
92 WalkSpeedAccelerationStart = -1;
101 if (WalkSpeedAccelerationStart == -1)
113 WalkSpeedAccelerationStart = -1;
123 WalkSpeedAccelerationStart = -1;
128 WalkSpeedAccelerationStart = -1;
133 void MAComplexIndicators::GenerateNearObjectForward(
MARobotState& state)
135 if (state.
Torso->NearIR <= 15 && state.
BodyMotion->IsBodyRollInWalkRange())
138 NearObjectForwardFactor += state.
Torso->CycleTime*4;
140 NearObjectForwardFactor -= state.
Torso->CycleTime;
142 NearObjectForward = NearObjectForwardFactor.GetScaledValue();
146 void MAComplexIndicators::GenerateAbyssWhileWalking(
MARobotState& state)
148 if (state.
Torso->ChestIR > 65 && state.
BodyMotion->IsBodyRollInWalkRange() &&
153 AbyssWhileWalkingFactor += state.
Torso->CycleTime*6;
155 AbyssWhileWalkingFactor -= state.
Torso->CycleTime;
161 void MAComplexIndicators::GenerateAbyssWhileLying(
MARobotState& state)
167 AbyssWhileLying = -1;
173 void MAComplexIndicators::GenerateBodyOutOfWalkingRange(
MARobotState& state)
175 if (!state.
BodyMotion->IsBodyRollInWalkRange())
178 BodyOutOfWalkingRangeFactor += state.
Torso->CycleTime;
180 BodyOutOfWalkingRangeFactor -= state.
Torso->CycleTime;
186 void MAComplexIndicators::GenerateOverloadDangerWhileSitting(
MARobotState& state)
190 Hits += state.
LegLF->Force1 <= MA::ForeLegForce1SittingLimit;
191 Hits += (state.
LegLF->Force1 <= MA::ForeLegForce1SittingEmergencyLimit)*3;
192 Hits += state.
LegLF->Force3 <= MA::ForeLegForce3SittingLimit;
193 Hits += state.
LegRF->Force1 <= MA::ForeLegForce1SittingLimit;
194 Hits += (state.
LegRF->Force1 <= MA::ForeLegForce1SittingEmergencyLimit)*3;
195 Hits += state.
LegRF->Force3 <= MA::ForeLegForce3SittingLimit;
199 OverloadDangerWhileSittingFactor += state.
Torso->CycleTime;
201 OverloadDangerWhileSittingFactor -= state.
Torso->CycleTime;
207 void MAComplexIndicators::GenerateListenWithEars(
MARobotState& state)
209 bool SelfNoises =
false;
211 SelfNoises = SelfNoises || (state.
Audio->RemainingPlaybackTime > 0 && state.
Audio->SpeakerVolume > 0);
212 SelfNoises = SelfNoises || state.
LegLF->InMotion > 0 || state.
LegLH->InMotion > 0;
213 SelfNoises = SelfNoises || state.
LegRF->InMotion > 0 || state.
LegRH->InMotion > 0;
214 SelfNoises = SelfNoises || (state.
Head->InMotion > 0 && !state.
Goals->TurnHeadToLeft && !state.
Goals->TurnHeadToRight);
216 bool GoodPose =
false;
218 GoodPose = GoodPose || state.
BodyMotion->Lying > 90;
219 GoodPose = GoodPose || state.
BodyMotion->Sitting > 90;
220 GoodPose = GoodPose || IsStandingPosture > 0;
222 if (!SelfNoises && GoodPose)
229 void MAComplexIndicators::GenerateMicrophoneChannelDominances(
MARobotState& state)
231 const int MinPower = 2000;
232 const int LeftPower = state.
Audio->LeftMicrophonePower;
233 const int RightPower = state.
Audio->RightMicrophonePower;
234 const int BackgroundPower = state.
Audio->BackgroundSoundPower;
236 if (((LeftPower > MinPower && LeftPower > BackgroundPower*5) ||
237 (RightPower > MinPower && RightPower > BackgroundPower*5)) &&
238 MA::RobotState->ComplexIndicators->ListenWithEars == 1)
240 if ((
float)LeftPower > (
float)RightPower*1.05)
243 if ((
float)LeftPower*1.05 < (
float)RightPower)
MANum< int > BodyOutOfWalkingRange
The robot body is out of the walking range.
MAComplexIndicators()
Struct constructor.
MANum< int > ElapsedRightTurnTime
The current right turning time (in msec)
MANum< int > WalkPeriod
The walk period of the robot.
MANum< int > ListenWithEars
Whenever listening with ears.
virtual void SetMinMax(T min_value, T max_value)
Set the minimal and maximal values.
MANum< int > MicrophoneChannelsBalance
Counter for the balance of the microphone channels.
MANum< int > ElapsedBackwardWalkTime
The current backward walk time (in msec)
bool IsLocomotionActive() const
Check if the locomotion is active now.
MANum< int > OverloadDangerWhileSitting
Overload danger in the first legs while sitting.
MANum< int > AbyssWhileWalking
Abyss is before the dog while walking.
boost::scoped_ptr< MALeg > LegRH
LegRH.
MANum< int > ElapsedLeftTurnTime
The current left turning time (in msec)
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
boost::scoped_ptr< MAGoals > Goals
Goals.
MANum< int > RightMicrophoneDominance
Counter for the dominance of the right microphone channel.
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
boost::scoped_ptr< MALeg > LegLF
LegLF.
Robot state updater base class.
MANum< int > LeftMicrophoneDominance
Counter for the dominance of the left microphone channel.
boost::scoped_ptr< MALeg > LegRF
LegRF.
MANum< int > ElapsedForwardWalkTime
The current forward walk time (in msec)
boost::scoped_ptr< MAAudio > Audio
Audio input/output.
boost::scoped_ptr< MATorso > Torso
Torso.
boost::scoped_ptr< MALeg > LegLH
LegLH.
T GetValueChange() const
The last value change difference.
boost::scoped_ptr< MAHead > Head
Head.