Main Page · Modules · All Classes · Class Hierarchy
MABodySitting.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 "MABodySitting.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MABodyMotion.hpp"
26 #include "types/MAComplexIndicators.hpp"
27 #include "types/MAGoals.hpp"
28 #include "types/MARobotState.hpp"
29 #include "controllers/MALegController.hpp"
30 #include "MABodySittingBored.hpp"
31 #include "MALegSittingPosition.hpp"
32 #include "MALegMoveAway.hpp"
33 #include "MALegMoved.hpp"
34 #include "MASittingFreefall.hpp"
35 #include "MATailToBack.hpp"
36 #include "MATypeRanges.hpp"
37 
38 MABodySitting::MABodySitting() : MABehavior(MCGetClassName(this))
39 {
41 }
42 
43 
45 {
46  if (MA::RobotState->BodyMotion->Sitting > 80)
47  {
49  }
51 }
52 
53 
55 {
56  return MA::RobotState->ComplexIndicators->OverloadDangerWhileSitting > 50;
57 }
58 
59 
61 {
62  if (!MA::RobotState->ComplexIndicators->IsSittingPosture)
63  {
64  // Since the posture is not sitting, just move away the legs to go into lying position and
65  // trigger MABodyLying
66  MALEGBEHAVIOR_CREATE(MALegMoveAway, MA::Leg::LF, this);
67  MALEGBEHAVIOR_CREATE(MALegMoveAway, MA::Leg::LH, this);
68  MALEGBEHAVIOR_CREATE(MALegMoveAway, MA::Leg::RF, this);
69  MALEGBEHAVIOR_CREATE(MALegMoveAway, MA::Leg::RH, this);
70  return;
71  }
72  // Switch off these joints to spare energy
73  // TODO: Enable power savings
74 // if (!MA::RobotState->LegLF->Moving)
75 // MA::LegLF->SetPower(MA::LegJoint1, false);
76 // if (!MA::RobotState->LegRF->Moving)
77 // MA::LegRF->SetPower(MA::LegJoint1, false);
78  // Switch off the joints to let the leg fine-tune its position and avoid
79  // forcing the joints by children
80  if (!MA::RobotState->LegLH->Moving)
81  MA::LegLH->SetPower(false);
82  if (!MA::RobotState->LegRH->Moving)
83  MA::LegRH->SetPower(false);
84 
85  MALEGBEHAVIOR_CREATE(MALegSittingPosition, MA::Leg::LH, this);
86  MALEGBEHAVIOR_CREATE(MALegSittingPosition, MA::Leg::RH, this);
87  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::LH, this);
88  MALEGBEHAVIOR_CREATE(MALegMoved, MA::Leg::RH, this);
90 }
91 
92 
94 {
95  MC_LOG("Overload danger in the front legs while sitting.");
96  if (MA::RobotState->ComplexIndicators->IsSittingPosture &&
97  !MA::RobotState->LegLF->Moving && !MA::RobotState->LegRF->Moving &&
98  !MA::RobotState->LegLH->Moving && !MA::RobotState->LegRH->Moving)
99  {
100  // When motor overload danger happens, the posture is changed to lying.
101  MA::RobotState->Goals->LiePostureDesire = 1;
102  } else {
104  }
105 }
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Move the tail to the back behavior.
Moves the leg to sitting position.
Behavior base class.
Definition: MABehavior.hpp:157
Body sitting bored behavior.
Moves the leg away from the body.
#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
Freefall in sitting posture.
virtual void FailingActions() override
Perform actions when the behavior is being failed.
The leg is being moved on its own.
Definition: MALegMoved.hpp:34
virtual bool IsFailed() override
Whether the behavior is failed.
#define MC_LOG(...)
Debug macro.
Definition: MCLog.hpp:41