Main Page · Modules · All Classes · Class Hierarchy
MABodyStroked.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 "MABodyStroked.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MABodyMotion.hpp"
26 #include "types/MAComplexIndicators.hpp"
27 #include "types/MAHead.hpp"
28 #include "types/MARobotState.hpp"
29 #include "types/MATorso.hpp"
30 #include "MABackStroked.hpp"
31 #include "MAChinStroked.hpp"
32 #include "MACrownStroked.hpp"
33 #include "MANumberGameMaster.hpp"
34 
35 #include "MABodyLieDownFromStanding.hpp"
36 #include "MABodyLieDownFromSitting.hpp"
37 #include "MABodySitDownFromStanding.hpp"
38 #include "MABodySitFromLying.hpp"
39 #include "MABodyStandUpFromLying.hpp"
40 #include "MABodyStandUpFromSitting.hpp"
41 #include "MAWalkMaster.hpp"
42 
43 MABodyStroked::MABodyStroked() : MABehavior(MCGetClassName(this), false)
44 {
45  DesiredConnections[MCGetClassName<MABodyLieDownFromSitting>()] = -1.0;
46  DesiredConnections[MCGetClassName<MABodyLieDownFromStanding>()] = -1.0;
47  DesiredConnections[MCGetClassName<MABodySitDownFromStanding>()] = -1.0;
48  DesiredConnections[MCGetClassName<MABodySitFromLying>()] = -1.0;
49  DesiredConnections[MCGetClassName<MABodyStandUpFromLying>()] = -1.0;
50  DesiredConnections[MCGetClassName<MABodyStandUpFromSitting>()] = -1.0;
51  DesiredConnections[MCGetClassName<MAWalkMaster>()] = -1.0;
52 }
53 
54 
56 {
57  // Don't let the body responses until the abyss detection is finished
58  if (MA::RobotState->ComplexIndicators->AbyssWhileLying == -1 &&
59  // Note: Abyss detection is not performed on the station yet, review this condition if
60  // this behavior changes in the future.
61  !MA::RobotState->BodyMotion->OnStation)
62  {
64  }
65  if (MA::RobotState->Head->SleptAwaken < 80 || MABEHAVIOR_IS_ACTIVATED(MANumberGameMaster))
67  // Chin stroking is ignored in standing posture
68  if (MA::RobotState->Head->CrownStroked < 90 && MA::RobotState->Torso->BackStroked < 90 &&
69  MA::RobotState->Head->ChinStroked > 90 && MA::RobotState->ComplexIndicators->IsStandingPosture)
70  {
72  }
73  // Stroked if some sensors are stroked AND
74  // none of the sensors are pressed AND
75  // the body is in an appropriate pose.
76  if ((MA::RobotState->Head->CrownStroked > 90 || MA::RobotState->Torso->BackStroked > 90 ||
77  MA::RobotState->Head->ChinStroked > 90) &&
78  (MA::RobotState->Head->CrownPressed < 50 && MA::RobotState->Torso->BackFButtonPressed < 50 &&
79  MA::RobotState->Torso->BackMButtonPressed < 50 && MA::RobotState->Torso->BackRButtonPressed < 50) &&
80  (MA::RobotState->BodyMotion->Lying > 80 || MA::RobotState->BodyMotion->OnStation ||
81  MA::RobotState->BodyMotion->Sitting > 80 || MA::RobotState->ComplexIndicators->IsStandingPosture))
82  {
84  }
86 }
87 
88 
90 {
91  // We do not want to have immediate reactivation when stroking
92  return HasActivatedStateExpired();
93 }
94 
95 
97 {
98  // Creating behaviors for body responses
99  if (MA::RobotState->Head->ChinStroked > 90 && !MA::RobotState->ComplexIndicators->IsStandingPosture)
100  MACreateBehavior<MAChinStroked>(nullptr);
101  if (MA::RobotState->Head->CrownStroked > 90)
102  MACreateBehavior<MACrownStroked>(nullptr);
103  if (MA::RobotState->Torso->BackStroked > 90)
104  MACreateBehavior<MABackStroked>(nullptr);
105 
106  // Adding some uncertainty to the duration of the activation
107  MA_RANDOM_POINT_1(TempInt, 1, 30);
108 
109  SetActivatedStateExpirationTime(2000+TempInt*100);
110 }
Number game master behavior.
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
Behavior base class.
Definition: MABehavior.hpp:157
void SetActivatedStateExpirationTime(const unsigned int expiration_time)
Set the activated state expiration time.
Definition: MABehavior.cpp:552
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
#define MABEHAVIOR_IS_ACTIVATED(_behavior)
Check if a behavior exists and it is in activated state.
Definition: MABehavior.hpp:104
virtual bool IsFinished() override
Whether the behavior is finished.
bool HasActivatedStateExpired() const
Check if the activated state is expired.
Definition: MABehavior.cpp:577
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.