Main Page · Modules · All Classes · Class Hierarchy
MABodyLyingBored.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 "MABodyLyingBored.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 "MABodyLying.hpp"
31 #include "MABodySitFromLying.hpp"
32 #include "MABodyStandUpFromLying.hpp"
33 #include "MABodyStroked.hpp"
34 #include "MAHeadLookAround.hpp"
35 #include "MAHeadTurnAhead.hpp"
36 #include "MAHeavyCalculations.hpp"
37 #include "MALyingExerciseMaster.hpp"
38 #include "MALookForAbyss.hpp"
39 #include "MANumberGameMaster.hpp"
40 
41 MABodyLyingBored::MABodyLyingBored() : MABehavior(MCGetClassName(this))
42 {
43  MA_RANDOM_POINT_1(BoredTime, 10000, 60000);
44 
45  SetSelfActivationDuration(BoredTime);
46  MA::RobotState->Goals->LiePostureDesire = 0;
47 }
48 
49 
51 {
52  // Wait until the ongoing heavy calculations are done.
55  // Ignore the number game time
58 
59  if (!MA::RobotState->BodyMotion->OnStation &&
60  // Make sure that the abyss detection has been done.
61  MA::RobotState->ComplexIndicators->AbyssWhileLying > -1 && !MABEHAVIOR_EXISTS(MALookForAbyss) &&
62  MA::RobotState->ComplexIndicators->IsLyingPosture &&
63  !MA::LegLF->IsAnyActiveTransition() && !MA::LegLH->IsAnyActiveTransition() &&
64  !MA::LegRF->IsAnyActiveTransition() && !MA::LegRH->IsAnyActiveTransition() &&
66  {
67  // Leave the lying pose immediately if any other pose or locomotion is desired
68  if (MA::RobotState->Goals->SitPostureDesire != 0 ||
69  MA::RobotState->Goals->StandPostureDesire != 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  {
76  }
78  }
80 }
81 
82 
84 {
87  // Don't do anything if there is an abyss before the dog
88  if (MA::RobotState->ComplexIndicators->AbyssWhileLying == 1)
89  return;
90 
91  MA_RANDOM_POINT_1(DoExercise, 0, 5);
92 
93  // Do an exercise if the self activation was so long and the activation is not indicated by a desire.
95  DoExercise == 0)
96  {
98  return;
99  }
101  // Go to desired posture if needs be...
102  if (MA::RobotState->Goals->SitPostureDesire != 0)
103  {
105  return;
106  }
107  if (MA::RobotState->Goals->StandPostureDesire != 0 ||
108  MA::RobotState->Goals->DesiredLeftTurnDuration != 0 ||
109  MA::RobotState->Goals->DesiredRightTurnDuration != 0 ||
110  MA::RobotState->Goals->DesiredBackwardWalkDuration != 0 ||
111  MA::RobotState->Goals->DesiredForwardWalkDuration != 0)
112  {
114  return;
115  }
116  // ...otherwise go to random posture.
117  MA_RANDOM_POINT_1(NewAction, 1, 2);
118 
119  if (NewAction == 1)
120  {
122  return;
123  }
124  if (NewAction == 2)
125  {
126  MA_RANDOM_POINT_1(ForwardWalkDuration, 8000, 60000);
127 
128  MA::RobotState->Goals->DesiredForwardWalkDuration = ForwardWalkDuration;
130  return;
131  }
132 }
#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.
Number game master behavior.
#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
The head looks around behavior.
Run heavy calculations during inactivity.
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
Definition: MABehavior.hpp:74
Body stroked behavior.
int GetSelfActivationDuration() const
Get the self-activation duration.
Definition: MABehavior.cpp:536
Behavior base class.
Definition: MABehavior.hpp:157
Body lying behavior.
Definition: MABodyLying.hpp:34
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Definition: MABodyLying.cpp:42
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
#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 stands up from lying behavior.
The robot stands up from lying behavior.
Do some exercises while lying.
Turn the head ahead.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Look for abyss before the dog.