Main Page · Modules · All Classes · Class Hierarchy
MABodySittingBored.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 "MABodySittingBored.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MAGoals.hpp"
27 #include "types/MARobotState.hpp"
28 #include "controllers/MALegController.hpp"
29 #include "MABodyLieDownFromSitting.hpp"
30 #include "MABodySitting.hpp"
31 #include "MABodyStandUpFromSitting.hpp"
32 #include "MABodyStroked.hpp"
33 #include "MAHeadLookAround.hpp"
34 #include "MAHeadTurnAhead.hpp"
35 #include "MAHeavyCalculations.hpp"
36 #include "MANumberGameMaster.hpp"
37 
38 MABodySittingBored::MABodySittingBored() : MABehavior(MCGetClassName(this))
39 {
40  MA_RANDOM_POINT_1(BoredTime, 10000, 90000);
41 
42  SetSelfActivationDuration(BoredTime);
43  MA::RobotState->Goals->SitPostureDesire = 0;
44 }
45 
46 
48 {
49  // Wait until the ongoing heavy calculations are done.
52  // Ignore the number game time
55 
56  if (MA::RobotState->ComplexIndicators->IsSittingPosture &&
57  !MA::LegLF->IsAnyActiveTransition() && !MA::LegLH->IsAnyActiveTransition() &&
58  !MA::LegRF->IsAnyActiveTransition() && !MA::LegRH->IsAnyActiveTransition() &&
60  {
61  // Leave the lying pose immediately if any other pose or locomotion is desired
62  if (MA::RobotState->Goals->LiePostureDesire != 0 ||
63  MA::RobotState->Goals->StandPostureDesire != 0 ||
64  MA::RobotState->Goals->DesiredLeftTurnDuration != 0 ||
65  MA::RobotState->Goals->DesiredRightTurnDuration != 0 ||
66  MA::RobotState->Goals->DesiredBackwardWalkDuration != 0 ||
67  MA::RobotState->Goals->DesiredForwardWalkDuration != 0)
68  {
70  }
72  }
74 }
75 
76 
78 {
82  // Keep the sit posture if we need to listen to the audio.
83  if (MA::RobotState->Goals->ListenToAudioDesire > 0)
84  {
85  MA::RobotState->Goals->SitPostureDesire = 1;
86  return;
87  }
88  // Go to desired posture if needs be...
89  if (MA::RobotState->Goals->LiePostureDesire != 0)
90  {
92  return;
93  }
94  if (MA::RobotState->Goals->StandPostureDesire != 0 ||
95  MA::RobotState->Goals->DesiredLeftTurnDuration != 0 ||
96  MA::RobotState->Goals->DesiredRightTurnDuration != 0 ||
97  MA::RobotState->Goals->DesiredBackwardWalkDuration != 0 ||
98  MA::RobotState->Goals->DesiredForwardWalkDuration != 0)
99  {
101  return;
102  }
103  // ...otherwise go to random posture.
104  MA_RANDOM_POINT_1(NewAction, 1, 6);
105 
106  if (NewAction == 1)
107  {
109  return;
110  }
111  if (NewAction >= 2 && NewAction <= 4)
112  {
114  return;
115  }
116  if (NewAction >= 5)
117  {
118  MA_RANDOM_POINT_1(ForwardWalkDuration, 11000, 60000);
119 
120  MA::RobotState->Goals->DesiredForwardWalkDuration = ForwardWalkDuration;
122  return;
123  }
124 }
#define MABEHAVIOR_IS_NORMAL(_behavior)
Check if a behavior exists and it is in normal state.
Definition: MABehavior.hpp:95
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.
Body stroked behavior.
Body sitting behavior.
Behavior base class.
Definition: MABehavior.hpp:157
Body lies down from sitting behavior.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Body stands up from sitting behavior.
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
Turn the head ahead.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.