Main Page · Modules · All Classes · Class Hierarchy
MAWalkInitialPosition.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 "MAWalkInitialPosition.hpp"
23 
24 #include "types/MAGoals.hpp"
25 #include "types/MARobotState.hpp"
26 #include "controllers/MALegController.hpp"
27 #include "MAHeadTurnAhead.hpp"
28 #include "MAWalkMaster.hpp"
29 #include "MAWalkSwingBackward.hpp"
30 #include "MAWalkSwingForward.hpp"
31 
32 MAWalkInitialPosition::MAWalkInitialPosition() : MABehavior(MCGetClassName(this))
33 {
34 }
35 
36 
38 {
40 }
41 
42 
44 {
46 
47  if (WalkMaster)
48  {
49  WalkMaster->StartWalk();
50  } else {
51  MC_WARNING("Walk master behavior does not exist!");
52  }
53  // The head is turned ahead with a separate behavior to avoid stopping the walk sequence
54  // if the head motion fails.
56  StartTransition(*MA::LegLF, MA::LegLF->BalanceToLeftStr);
57  StartTransition(*MA::LegLH, MA::LegLH->BalanceToLeftStr);
58  StartTransition(*MA::LegRF, MA::LegRF->BalanceToLeftStr);
59  StartTransition(*MA::LegRH, MA::LegRH->BalanceToLeftStr);
60  StartTransition(*MA::LegLF, MA::LegLF->ToInitialWalkPositionStr);
61  StartTransition(*MA::LegLH, MA::LegLH->ToInitialWalkPositionStr);
62  StartTransition(*MA::LegRF, MA::LegRF->ToInitialWalkPositionStr);
63  StartTransition(*MA::LegRH, MA::LegRH->ToInitialWalkPositionStr);
64 }
65 
66 
68 {
69  // Start walking
70  if (MA::RobotState->Goals->DesiredForwardWalkDuration > 0)
71  {
72  MALEGBEHAVIOR_CREATE(MAWalkSwingForward, MA::Leg::LF, GetMaster());
73  MALEGBEHAVIOR_CREATE(MAWalkSwingForward, MA::Leg::LH, GetMaster());
74  MALEGBEHAVIOR_CREATE(MAWalkSwingForward, MA::Leg::RF, GetMaster());
75  MALEGBEHAVIOR_CREATE(MAWalkSwingForward, MA::Leg::RH, GetMaster());
76  } else {
77  MALEGBEHAVIOR_CREATE(MAWalkSwingBackward, MA::Leg::LF, GetMaster());
78  MALEGBEHAVIOR_CREATE(MAWalkSwingBackward, MA::Leg::LH, GetMaster());
79  MALEGBEHAVIOR_CREATE(MAWalkSwingBackward, MA::Leg::RF, GetMaster());
80  MALEGBEHAVIOR_CREATE(MAWalkSwingBackward, MA::Leg::RH, GetMaster());
81  }
82 }
Behavior base class.
Definition: MABehavior.hpp:157
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
#define MC_WARNING(...)
Warning macro.
Definition: MCLog.hpp:43
Walk master behavior.
Swing the leg forward.
#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
Swing the leg backward.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
#define MABEHAVIOR_GET(_behavior)
Get a behavior safely with dynamic cast.
Definition: MABehavior.hpp:67
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
Turn the head ahead.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.