Main Page · Modules · All Classes · Class Hierarchy
MALegSittingPosition.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 "MALegSittingPosition.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 MALegSittingPosition::MALegSittingPosition(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->Sitting > 80 && !Controller->IsSittingPosition() &&
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 sitting position. -> So the behavior fails to trigger the "move-leg-away"
55  // behavior.
56  if (Controller->IsBack())
57  {
58  MALEGBEHAVIOR_CREATE(MALegMoveAway, LegState.Type, GetMaster());
59  return true;
60  }
61  return false;
62 }
63 
64 
66 {
67  StartTransition(*Controller, Controller->ToSittingPositionStr);
68 }
69 
70 
72 {
73  // Switch off the joints to let the leg fine-tune its position and avoid
74  // forcing the joints by children
75  Controller->SetPower(false);
76 }
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual bool IsFailed() override
Whether the behavior is failed.
Base class for leg behaviors.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
Moves the leg away from the body.
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
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.
The leg is being moved on its own.
Definition: MALegMoved.hpp:34