Main Page · Modules · All Classes · Class Hierarchy
MAGoals.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 "MAGoals.hpp"
23 
24 #include "MAAudio.hpp"
25 #include "MABodyMotion.hpp"
26 #include "MARobotState.hpp"
27 #include "MAComplexIndicators.hpp"
28 #include "MATorso.hpp"
29 
30 MAGoals::MAGoals() : MARobotStateUpdater(MA::UpdateComplexIndicators),
31  DesiredForwardWalkDuration(0, 0, 60000), DesiredBackwardWalkDuration(0, 0, 60000),
32  DesiredLeftTurnDuration(0, 0, 40000), DesiredRightTurnDuration(0, 0, 40000),
33  ArousalFeedbackNeeded(0, 0, 10000), ListenToAudioDesire(0, 0, 10000),
34  DiscoverSoundSource(0, 0, 2000), DesiredAudioCaptureDuration(0, 0, 5000)
35 {
36 }
37 
38 
40 {
43 }
44 
45 
47 {
48  LiePostureDesire = 0;
49  SitPostureDesire = 0;
55 }
56 
57 
59 {
60  ArousalFeedbackNeeded -= state.Torso->CycleTime;
61  // Correct any wrong desires if there is an abyss before the dog while lying
62  if (state.ComplexIndicators->AbyssWhileLying == 1)
63  {
64  SitPostureDesire = 0;
70  }
71  // Stop the motion control if there is no new command received in 60 seconds
72  if (state.BodyMotion->MotionControlAge == 60)
73  {
74  state.BodyMotion->StopMotionControlTimer();
75  MotionControl = 0;
76  }
77  if (state.BodyMotion->MotionControlAge > 0 && MotionControl == 0)
78  {
79  state.BodyMotion->StopMotionControlTimer();
80  }
81  GenerateHeadTurnDesires(state);
82  GenerateDiscoverSoundSource(state);
83 }
84 
85 
86 void MAGoals::GenerateHeadTurnDesires(MARobotState& state)
87 {
88  if (DiscoverSoundSource == 0)
89  {
90  TurnHeadToRight = 0;
91  TurnHeadToLeft = 0;
92  return;
93  }
94 
95  const int HeadLeftRightLimit = 85;
96 
97  if (state.ComplexIndicators->LeftMicrophoneDominance > state.ComplexIndicators->RightMicrophoneDominance &&
98  state.ComplexIndicators->LeftMicrophoneDominance > state.ComplexIndicators->MicrophoneChannelsBalance &&
99  state.Head->LeftRight > -HeadLeftRightLimit)
100  {
101  TurnHeadToLeft = 1;
102  } else {
103  TurnHeadToLeft = 0;
104  }
105  if (state.ComplexIndicators->RightMicrophoneDominance > state.ComplexIndicators->LeftMicrophoneDominance &&
106  state.ComplexIndicators->RightMicrophoneDominance > state.ComplexIndicators->MicrophoneChannelsBalance &&
107  state.Head->LeftRight < HeadLeftRightLimit)
108  {
109  TurnHeadToRight = 1;
110  } else {
111  TurnHeadToRight = 0;
112  }
113 }
114 
115 
116 void MAGoals::GenerateDiscoverSoundSource(MARobotState& state)
117 {
118  DiscoverSoundSource -= state.Torso->CycleTime;
119 }
MANum< int > TurnHeadToLeft
Turn the head to left (goal)
Definition: MAGoals.hpp:90
MANum< int > DiscoverSoundSource
Desire to discover a sound source.
Definition: MAGoals.hpp:84
MANum< int > DesiredRightTurnDuration
The desired duration to turn right (in msec)
Definition: MAGoals.hpp:76
MANum< int > LiePostureDesire
Desire to go into lie posture.
Definition: MAGoals.hpp:68
MANum< int > DesiredForwardWalkDuration
The desired forward walk duration (in msec)
Definition: MAGoals.hpp:70
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
Definition: MAGoals.cpp:58
MANum< int > MotionControl
Control the robot locomotion (goal)
Definition: MAGoals.hpp:94
MANum< int > DesiredBackwardWalkDuration
The desired backward walk duration (in msec)
Definition: MAGoals.hpp:72
MANum< int > ArousalFeedbackNeeded
Arousal feedback needed in the near time (in msec)
Definition: MAGoals.hpp:80
boost::scoped_ptr< MAComplexIndicators > ComplexIndicators
Complex indicators.
MAGoals()
Struct constructor.
Definition: MAGoals.cpp:30
MANum< int > TurnHeadToRight
Turn the head to right (goal)
Definition: MAGoals.hpp:92
MANum< int > SitPostureDesire
Desire to go into sit posture.
Definition: MAGoals.hpp:64
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
Robot state updater base class.
MANum< int > StandPostureDesire
Desire to go into stand posture.
Definition: MAGoals.hpp:66
void ResetLocomotionGoals()
Reset the locomotion goals.
Definition: MAGoals.cpp:46
boost::scoped_ptr< MATorso > Torso
Torso.
MANum< int > DesiredLeftTurnDuration
The desired duration to turn left (in msec)
Definition: MAGoals.hpp:74
Robot state.
bool IsLocomotionDesired() const
Check if the locomotion is desired now.
Definition: MAGoals.cpp:39
boost::scoped_ptr< MAHead > Head
Head.