Main Page · Modules · All Classes · Class Hierarchy
MALookForAbyss.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 "MALookForAbyss.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MARobotState.hpp"
27 #include "types/MATorso.hpp"
28 #include "controllers/MAHeadController.hpp"
29 #include "controllers/MALegController.hpp"
30 #include "MAAbyssHeadShake.hpp"
31 #include "MABodyStroked.hpp"
32 #include "MAHeadLookAround.hpp"
33 #include "MAHeadTurnAhead.hpp"
34 #include "MAHeadTurnAround.hpp"
35 #include "MAHeadTurnMaster.hpp"
36 #include "MAMotorOverload.hpp"
37 
38 #include <MCLog.hpp>
39 
40 MALookForAbyss::MALookForAbyss() : MABehavior(MCGetClassName(this))
41 {
43  DesiredConnections[MCGetClassName<MAHeadLookAround>()] = -1;
44  DesiredConnections[MCGetClassName<MAHeadTurnAround>()] = -1;
45  DesiredConnections[MCGetClassName<MAHeadTurnMaster>()] = -1;
46  DesiredConnections[MCGetClassName<MABodyStroked>()] = -1;
47 }
48 
49 
51 {
52  if (!MA::LegLF->IsAnyActiveTransition() && !MA::LegLH->IsAnyActiveTransition() &&
53  !MA::LegRF->IsAnyActiveTransition() && !MA::LegRH->IsAnyActiveTransition())
54  {
56  }
58 }
59 
60 
62 {
63  // We need to wait ~1500-1700 msec to get into the starting head position...
64  return GetElapsedActivatedStateTime() > 1700 && MA::RobotState->Torso->FarIR >= 55;
65 }
66 
67 
69 {
70  StartTransition(*MA::Head, "SKIT:look_for_abyss:1.0:1500");
71  // Create the motor overload behaviors
72  MAMotorOverload::CreateBehaviorForMotors(MA::Head->GetMotors(), nullptr);
73 }
74 
75 
77 {
78  if (MA::RobotState->BodyMotion->Lying > 80 && MA::RobotState->BodyMotion->Flying < 20)
79  {
80  MA::RobotState->ComplexIndicators->AbyssWhileLying = 1;
81  MC_LOG("Abyss detected before the dog");
82  // Delete the motor overload behaviors
83  MAMotorOverload::DeleteBehaviorForMotors(MA::Head->GetMotors());
85  }
86 }
87 
88 
90 {
91  if (MA::RobotState->BodyMotion->Lying > 80 && MA::RobotState->BodyMotion->Flying < 20)
92  {
93  MA::RobotState->ComplexIndicators->AbyssWhileLying = 0;
94  MC_LOG("There is no abyss before the dog");
95  // Delete the motor overload behaviors
96  MAMotorOverload::DeleteBehaviorForMotors(MA::Head->GetMotors());
98  }
99 }
Shaking the head when an abyss is detected before the dog.
int GetElapsedActivatedStateTime() const
Get the elapsed activated state time.
Definition: MABehavior.cpp:561
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
Behavior base class.
Definition: MABehavior.hpp:157
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual bool IsFailed() override
Whether the behavior is failed.
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
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
virtual void FailingActions() override
Perform actions when the behavior is being failed.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
Turn the head ahead.
#define MC_LOG(...)
Debug macro.
Definition: MCLog.hpp:41