Main Page · Modules · All Classes · Class Hierarchy
MALegMoveAway.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 "MALegMoveAway.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MARobotState.hpp"
26 #include "controllers/MALegController.hpp"
27 #include "MALegLyingPosition.hpp"
28 #include "MALegSittingPosition.hpp"
29 
30 MALegMoveAway::MALegMoveAway(MA::Leg::LegTypes leg_type) :
31  MALegBehavior(MCGetClassName(this), leg_type)
32 {
33  // Register the desired connections
34  DesiredConnections[MCGetClassName<MALegLyingPosition>()] = -1.0;
35  DesiredConnections[MCGetClassName<MALegSittingPosition>()] = -1.0;
36 }
37 
38 
40 {
41  // It is over-stimulated all the time
43 }
44 
45 
47 {
48  // Enable these cases only for lying position
49  if (MA::RobotState->BodyMotion->Lying > 60)
50  {
51  // Special case for a fore leg: A fore leg is backward
52  if ((LegState.Type == MA::Leg::LF || LegState.Type == MA::Leg::RF) &&
53  LegState.IsBackwardNearBody())
54  {
55  StartTransition(*Controller, Controller->MoveAwayBackwardStr);
56  } else
57  // Special case for a hind leg: A fore leg is backward and the hind leg is forward above it
58  if ((LegState.Type == MA::Leg::LH && LegState.IsForwardNearBody() &&
59  MA::RobotState->LegLF->IsBackwardNearBody()) ||
60  (LegState.Type == MA::Leg::RH && LegState.IsForwardNearBody() &&
61  MA::RobotState->LegRF->IsBackwardNearBody()))
62  {
63  StartTransition(*Controller, Controller->MoveAwayFirstUpStr);
64  } else {
65  StartTransition(*Controller, Controller->MoveAwayStr);
66  }
67  return;
68  }
69  StartTransition(*Controller, Controller->MoveAwayStr);
70 }
71 
72 
74 {
75  if (MA::RobotState->BodyMotion->Lying > 80)
76  {
77  MALEGBEHAVIOR_CREATE(MALegLyingPosition, LegState.Type, GetMaster());
78  }
79  if (MA::RobotState->BodyMotion->Sitting > 80)
80  {
81  // Switch the joints of the first legs back before moving the hind legs
82  // TODO: Enable power savings
83 // MA::LegLF->SetPower(MA::LegJoint1, true);
84 // MA::LegRF->SetPower(MA::LegJoint1, true);
85  MALEGBEHAVIOR_CREATE(MALegSittingPosition, LegState.Type, GetMaster());
86  }
87 }
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
MALegController * Controller
Leg controller.
Moves the leg to sitting position.
Base class for leg behaviors.
Move a leg to lying position.
MA::Leg::LegTypes Type
The leg type.
Definition: MALeg.hpp:90
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.
const MALeg & LegState
Leg state.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793