Main Page · Modules · All Classes · Class Hierarchy
MABodyStandingBored.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 "MABodyStandingBored.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MABodyMotion.hpp"
26 #include "types/MAComplexIndicators.hpp"
27 #include "types/MAGoals.hpp"
28 #include "types/MARobotState.hpp"
29 #include "controllers/MALegController.hpp"
30 #include "MABodyLieDownFromStanding.hpp"
31 #include "MABodySitDownFromStanding.hpp"
32 #include "MABodyStroked.hpp"
33 #include "MABodyTurnLeft.hpp"
34 #include "MABodyTurnRight.hpp"
35 #include "MAGoodFloorTalk.hpp"
36 #include "MAHeadLookAround.hpp"
37 #include "MAHeadTurnAhead.hpp"
38 #include "MAHeavyCalculations.hpp"
39 #include "MASoftCarpetReaction.hpp"
40 #include "MAStandFunnySkitMaster.hpp"
41 #include "MAWalkMaster.hpp"
42 #include "MAWrongFloorSkit.hpp"
43 
44 #include <MCLog.hpp>
45 
46 MABodyStandingBored::MABodyStandingBored() : MABehavior(MCGetClassName(this)),
47  MARobotStateUpdater(MA::UpdateComplexIndicators), ResetFloorOwnerFeedback(false)
48 {
49  RegisterUpdater(*this);
50  MA_RANDOM_POINT_1(BoredTime, 10000, 30000);
51 
52  SetSelfActivationDuration(BoredTime);
53  MA::RobotState->Goals->StandPostureDesire = 0;
54 }
55 
56 
58 {
59  // Wait until the ongoing heavy calculations are done.
62 
63  if (MA::RobotState->ComplexIndicators->IsStandingPosture &&
64  !MA::LegLF->IsAnyActiveTransition() && !MA::LegLH->IsAnyActiveTransition() &&
65  !MA::LegRF->IsAnyActiveTransition() && !MA::LegRH->IsAnyActiveTransition() &&
67  {
68  if (MA::RobotState->Goals->LiePostureDesire != 0 ||
69  MA::RobotState->Goals->SitPostureDesire != 0 ||
70  MA::RobotState->Goals->DesiredLeftTurnDuration != 0 ||
71  MA::RobotState->Goals->DesiredRightTurnDuration != 0 ||
72  MA::RobotState->Goals->DesiredBackwardWalkDuration != 0 ||
73  MA::RobotState->Goals->DesiredForwardWalkDuration != 0 ||
74  MA::RobotState->BodyMotion->Floor.OwnerFeedback >= 0 ||
75  MA::RobotState->Goals->HappyOnCarpetFeedback != 0)
76  {
78  }
80  }
82 }
83 
84 
86 {
88  // Give responses for owner feedback of floor surface recognition
89  if (MA::RobotState->BodyMotion->Floor.OwnerFeedback >= 0)
90  {
91  if ((int)MA::RobotState->BodyMotion->Floor.OwnerFeedback == (int)MA::RobotState->BodyMotion->Floor.Surface)
92  {
94  } else {
96  }
97  ResetFloorOwnerFeedback = true;
98  return;
99  }
100  if (MA::RobotState->Goals->HappyOnCarpetFeedback == 1)
101  {
102  MA_RANDOM_POINT_1(HappyReaction, 1, 5);
103 
104  MA::RobotState->Goals->HappyOnCarpetFeedback = 0;
105  if (HappyReaction == 1)
106  {
108  return;
109  }
110  }
111  // Start the desired locomotion if needs be...
112  if (MA::RobotState->Goals->DesiredLeftTurnDuration-
113  MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime > 1000)
114  {
117  return;
118  }
119  if (MA::RobotState->Goals->DesiredRightTurnDuration-
120  MA::RobotState->ComplexIndicators->ElapsedRightTurnTime > 1000)
121  {
124  return;
125  }
126  if (MA::RobotState->Goals->DesiredForwardWalkDuration != 0 ||
127  MA::RobotState->Goals->DesiredBackwardWalkDuration != 0)
128  {
130  return;
131  }
132  // If the locomotion is controlled, the standing posture is not left to sit or lie postures.
133  if (MA::RobotState->Goals->MotionControl == 1)
134  return;
135  // Go to desired posture if needs be...
136  if (MA::RobotState->Goals->LiePostureDesire != 0)
137  {
139  return;
140  }
141  if (MA::RobotState->Goals->SitPostureDesire != 0)
142  {
144  return;
145  }
146  // Do a random funny skit.
147  MA_RANDOM_POINT_1(RandomFunnyAction, 1, 20);
148 
149  if (RandomFunnyAction == 1)
150  {
152  return;
153  }
154  // ...otherwise go to random posture.
155  MA_RANDOM_POINT_1(NewAction, 1, 8);
156 
157  if (NewAction == 1)
158  {
159  // Set a random turn duration
160  MA_RANDOM_POINT_1(NewDuration, 2000, 20000);
161 
162  MA::RobotState->Goals->DesiredLeftTurnDuration = NewDuration;
165  return;
166  }
167  if (NewAction == 2)
168  {
169  // Set a random turn duration
170  MA_RANDOM_POINT_1(NewDuration, 6000, 20000);
171 
172  MA::RobotState->Goals->DesiredRightTurnDuration = NewDuration;
175  return;
176  }
177  if (NewAction == 3)
178  {
180  return;
181  }
182  if (NewAction >= 4 && NewAction <= 6)
183  {
185  return;
186  }
187  if (NewAction >= 7)
188  {
190  return;
191  }
192  // The lowest priority thing to turn the head ahead
194 }
195 
196 
198 {
199  if (unlikely(ResetFloorOwnerFeedback))
200  {
201  ResetFloorOwnerFeedback = false;
202  state.BodyMotion->Floor.OwnerFeedback = -1;
203  }
204 }
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
#define MABEHAVIOR_IS_NORMAL(_behavior)
Check if a behavior exists and it is in normal state.
Definition: MABehavior.hpp:95
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
#define MABEHAVIOR_DELETE(_behavior)
Delete a behavior safely (mark it dirty if exists)
Definition: MABehavior.hpp:81
Body turns right.
The head looks around behavior.
Run heavy calculations during inactivity.
Body stroked behavior.
Behavior base class.
Definition: MABehavior.hpp:157
Indicate the floor surface recognition period.
Sad skit when the floor surface was recognized incorrectly.
Body sits down from standing behavior.
Walk master behavior.
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
static void RegisterUpdater(MARobotStateUpdater &updater)
Register a robot state updater.
#define MABEHAVIOR_CREATE(_behavior, _master,...)
Create behaviors with custom constructor safely.
Definition: MABehavior.hpp:43
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
#define MABEHAVIOR_IS_ACTIVATED(_behavior)
Check if a behavior exists and it is in activated state.
Definition: MABehavior.hpp:104
Body turns left.
Master behavior for a funny skit while standing.
Happy talk when the floor surface was recognized correctly.
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
Robot state updater base class.
Body lie down from standing behavior.
Turn the head ahead.
Robot state.
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.