Main Page · Modules · All Classes · Class Hierarchy
MALegLyingPosition.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 "MALegLyingPosition.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MARobotState.hpp"
26 #include "controllers/MALegController.hpp"
27 #include "MALegMoveAway.hpp"
28 #include "MALegMoved.hpp"
29 #include "MAMotorOverload.hpp"
30 
31 MALegLyingPosition::MALegLyingPosition(MA::Leg::LegTypes leg_type) :
32  MALegBehavior(MCGetClassName(this), leg_type, false)
33 {
34  // 100 ms is needed to have enough time for the LegMoved -> LegMoveAway
35  // activation chain
37 }
38 
39 
41 {
42  if (MA::RobotState->BodyMotion->Lying > 80 && !Controller->IsLyingPosition() &&
43  !MALEGBEHAVIOR_IS_ACTIVATED(MALegMoved, Controller->GetLegType()))
44  {
46  }
48 }
49 
50 
52 {
53  // When the leg is headed back, it is needed to move away from the body before
54  // going to lying position.
55  if (Controller->IsBack())
56  {
57  return true;
58  }
59  // The leg must be moved away if the fore leg is stuck under this leg
60  if ((LegState.Type == MA::Leg::LH && LegState.IsForwardNearBody() &&
61  MA::RobotState->LegLF->IsBackwardNearBody()) ||
62  (LegState.Type == MA::Leg::RH && LegState.IsForwardNearBody() &&
63  MA::RobotState->LegRF->IsBackwardNearBody()))
64  {
65  return true;
66  }
67  return false;
68 }
69 
70 
72 {
73  StartTransition(*Controller, Controller->ToLyingPositionStr);
74 }
75 
76 
78 {
79  MALEGBEHAVIOR_CREATE(MALegMoveAway, LegState.Type, GetMaster());
80 }
81 
82 
84 {
85  // Switch off the joints to let the leg fine-tune its position and avoid
86  // forcing the joints by children
87  Controller->SetPower(false);
88 }
Base class for leg behaviors.
Moves the leg away from the body.
virtual void FailingActions() override
Perform actions when the behavior is being failed.
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual bool IsFailed() override
Whether the behavior is failed.
The leg is being moved on its own.
Definition: MALegMoved.hpp:34