Main Page · Modules · All Classes · Class Hierarchy
MAHeadLookAround.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 "MAHeadLookAround.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MAEmotions.hpp"
27 #include "types/MAGoals.hpp"
28 #include "types/MAHead.hpp"
29 #include "types/MARobotState.hpp"
30 #include "controllers/MAHeadController.hpp"
31 #include "MABodyStroked.hpp"
32 #include "MAHeadTurnAhead.hpp"
33 #include "MAMotorOverload.hpp"
34 #include "MASkitterPlaybackExecute.hpp"
35 
36 MAHeadLookAround::MAHeadLookAround() : MABehavior(MCGetClassName(this))
37 {
38  // Destroy the behavior if it is not activated immediately
40  // Register the desired connections
41  DesiredConnections[MCGetClassName<MAHeadTurnAhead>()] = -1.0;
42 }
43 
44 
46 {
47  if (MA::RobotState->Head->SleptAwaken > 80 &&
48  (MA::RobotState->BodyMotion->Lying > 80 || MA::RobotState->BodyMotion->Sitting > 80 ||
49  MA::RobotState->BodyMotion->OnStation || MA::RobotState->ComplexIndicators->IsStandingPosture))
50  {
52  }
54 }
55 
56 
58 {
59  bool Ret = true;
60 
61  Ret = Ret && (MA::RobotState->BodyMotion->Lying < 60 && MA::RobotState->BodyMotion->Sitting < 60);
62  Ret = Ret && !MA::RobotState->BodyMotion->OnStation;
63  Ret = Ret && !MA::RobotState->ComplexIndicators->IsStandingPosture;
64  Ret = Ret || MA::RobotState->Head->SleptAwaken == 0;
65  Ret = Ret || MA::RobotState->Goals->TurnHeadToLeft != 0;
66  Ret = Ret || MA::RobotState->Goals->TurnHeadToRight != 0;
67  return Ret;
68 }
69 
70 
72 {
73  if (MA::RobotState->BodyMotion->Lying > 80 || MA::RobotState->ComplexIndicators->IsStandingPosture ||
74  MA::RobotState->BodyMotion->OnStation)
75  {
76  StartTransition(*MA::Head, MA::Head->LookAroundLyingStr);
77  }
78  if (MA::RobotState->BodyMotion->Sitting > 80)
79  StartTransition(*MA::Head, MA::Head->LookAroundSittingStr);
80  // Create the motor overload behaviors
81  MAMotorOverload::CreateBehaviorForMotors(MA::Head->GetMotors(), nullptr);
82 }
83 
84 
86 {
87  // Corner case: Orphan behavior
88  if (!GetMaster())
89  return;
90 
92  MACreateBehavior<MAHeadLookAround>(GetMaster());
93  // Delete the motor overload behaviors
94  MAMotorOverload::DeleteBehaviorForMotors(MA::Head->GetMotors());
95 }
#define MABEHAVIOR_IS_NORMAL(_behavior)
Check if a behavior exists and it is in normal state.
Definition: MABehavior.hpp:95
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
Definition: MABehavior.hpp:74
Body stroked behavior.
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
Behavior base class.
Definition: MABehavior.hpp:157
Skitter playback execution behavior.
void SetLifetimeExpirationTime(const unsigned int expiration_time)
Set the lifetime expiration time.
Definition: MABehavior.cpp:542
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
virtual bool IsFailed() override
Whether the behavior is failed.
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
virtual void FinishingActions() override
Perform actions when the behavior is being finished.