Main Page · Modules · All Classes · Class Hierarchy
MABodyLying.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 "MABodyLying.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MAGoals.hpp"
27 #include "types/MARobotState.hpp"
28 #include "controllers/MALegController.hpp"
29 #include "MABodyLyingBored.hpp"
30 #include "MABodyLyingHappyTalk.hpp"
31 #include "MALegLyingPosition.hpp"
32 #include "MALegMoved.hpp"
33 #include "MALookForAbyss.hpp"
34 #include "MATailToBack.hpp"
35 
36 MABodyLying::MABodyLying() : MABehavior(MCGetClassName(this))
37 {
39 }
40 
41 
43 {
44  if (MA::RobotState->BodyMotion->OnStation || MA::RobotState->BodyMotion->Lying > 80)
45  {
47  }
49 }
50 
51 
53 {
54  return MA::RobotState->BodyMotion->Lying < 20 && !MA::RobotState->BodyMotion->OnStation;
55 }
56 
57 
59 {
60  // Check first if there is an abyss before the dog
61  if (MA::RobotState->ComplexIndicators->AbyssWhileLying < 0)
62  {
64  }
65  if (MA::RobotState->Goals->DesireLyingOnTheFloor > 0)
66  {
68  }
69  // Switch off all joints to spare energy and let the leg fine-tune its position to avoid
70  // "child-attack" by forcing the joints.
71  if (!MA::RobotState->LegLF->Moving)
72  MA::LegLF->SetPower(false);
73  if (!MA::RobotState->LegRF->Moving)
74  MA::LegRF->SetPower(false);
75  if (!MA::RobotState->LegLH->Moving)
76  MA::LegLH->SetPower(false);
77  if (!MA::RobotState->LegRH->Moving)
78  MA::LegRH->SetPower(false);
79  MALEGBEHAVIOR_CREATE(MALegLyingPosition, MA::Leg::LF, this);
80  MALEGBEHAVIOR_CREATE(MALegLyingPosition, MA::Leg::LH, this);
81  MALEGBEHAVIOR_CREATE(MALegLyingPosition, MA::Leg::RF, this);
82  MALEGBEHAVIOR_CREATE(MALegLyingPosition, MA::Leg::RH, this);
83  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::LF, this);
84  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::LH, this);
85  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::RF, this);
86  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::RH, this);
88 }
Move the tail to the back behavior.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Definition: MABodyLying.cpp:58
Behavior base class.
Definition: MABehavior.hpp:157
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Definition: MABodyLying.cpp:42
Move a leg to lying position.
#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
The leg is being moved on its own.
Definition: MALegMoved.hpp:34
Look for abyss before the dog.
virtual bool IsFailed() override
Whether the behavior is failed.
Definition: MABodyLying.cpp:52
Talking when the dog goes to lying after flying or upside down.
Body lying bored behavior.