Main Page · Modules · All Classes · Class Hierarchy
MAWalkSwingForward.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 "MAWalkSwingForward.hpp"
23 
24 #include "types/MAComplexIndicators.hpp"
25 #include "types/MARobotState.hpp"
26 #include "controllers/MALegController.hpp"
27 #include "MAWalkBalanceToLeft.hpp"
28 #include "MAWalkBalanceToRight.hpp"
29 #include "MAWalkPushBackward.hpp"
30 
31 MAWalkSwingForward::MAWalkSwingForward(MA::Leg::LegTypes leg_type) :
32  MAWalkLegBehaviorBase(MCGetClassName(this), leg_type)
33 {
35  if (!AnyLegSwingForward())
36  {
37  float WalkPeriodQuarter = (float)MA::RobotState->ComplexIndicators->WalkPeriod / 11.0;
38 
39  if (leg_type == MA::Leg::RF)
41  if (leg_type == MA::Leg::RH)
42  SetSelfActivationDuration((int)(WalkPeriodQuarter*8.25));
43  if (leg_type == MA::Leg::LF)
44  SetSelfActivationDuration((int)(WalkPeriodQuarter*5.5));
45  if (leg_type == MA::Leg::LH)
46  SetSelfActivationDuration((int)(WalkPeriodQuarter*2.75));
47  }
48  // Don't let the swing forward behavior activated until this behavior is finished
49  DesiredConnections[MAGetLegBehaviorName<MAWalkPushBackward>(leg_type)] = -1.0;
50 }
51 
52 
54 {
56 }
57 
58 
60 {
61  StartTransition(*Controller, Controller->WalkSwingForwardStr);
62  if (Controller->GetLegType() == MA::Leg::RF)
63  {
64  // The delay duration is determinated with the dumped a_walk#walk_sox_fwd.mtn from MoNet sample //krazy:exclude=spelling
65  // The balance is started to move from the 2th keyframe (2/11) of that MoNet motion sequence.
66  // When the MALegController starts to move the RF leg forward to "Point 1", we need to wait
67  // 1/11 of the walk period and start to move the balance after that.
68  MABEHAVIOR_CREATE(MAWalkBalanceToRight, GetMaster(), (int)MA::RobotState->ComplexIndicators->WalkPeriod / 11);
69  }
70  if (Controller->GetLegType() == MA::Leg::LF)
71  {
72  // The LF leg is swung forward after 5.5/11 of the walk period which is at 6.5/11 in the MoNet
73  // sequence. The balance is started to move after 1/11 period hence waiting that time.
74  MABEHAVIOR_CREATE(MAWalkBalanceToLeft, GetMaster(), (int)MA::RobotState->ComplexIndicators->WalkPeriod / 11);
75  }
76  // The following walk sequence is created here, but not activated until this behavior is finished
77  MALEGBEHAVIOR_CREATE(MAWalkPushBackward, LegState.Type, GetMaster());
78 }
79 
80 
81 bool MAWalkSwingForward::AnyLegSwingForward()
82 {
83  MABehavior* SwingForwardLF = MABehavior::GetBehavior(MAGetLegBehaviorName<MAWalkSwingForward>(MA::Leg::LF));
84  MABehavior* SwingForwardLH = MABehavior::GetBehavior(MAGetLegBehaviorName<MAWalkSwingForward>(MA::Leg::LH));
85  MABehavior* SwingForwardRF = MABehavior::GetBehavior(MAGetLegBehaviorName<MAWalkSwingForward>(MA::Leg::RF));
86  MABehavior* SwingForwardRH = MABehavior::GetBehavior(MAGetLegBehaviorName<MAWalkSwingForward>(MA::Leg::RH));
87 
88  if ((!SwingForwardLF || SwingForwardLF->GetState() == MABehavior::Normal) &&
89  (!SwingForwardLH || SwingForwardLH->GetState() == MABehavior::Normal) &&
90  (!SwingForwardRF || SwingForwardRF->GetState() == MABehavior::Normal) &&
91  (!SwingForwardRH || SwingForwardRH->GetState() == MABehavior::Normal))
92  {
93  return false;
94  }
95  return true;
96 }
Balances the body to left.
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
MALegController * Controller
Leg controller.
Behavior base class.
Definition: MABehavior.hpp:157
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Base behavior for leg movement primitives during walk.
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
MA::Leg::LegTypes Type
The leg type.
Definition: MALeg.hpp:90
StateType GetState() const
Get the behavior state.
Definition: MABehavior.hpp:393
#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
const MALeg & LegState
Leg state.
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
static MABehavior * GetBehavior(const std::string &type_name)
Get an existing behavior by type name.
Definition: MABehavior.cpp:146
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
Balances the body to Right.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Push the leg backward.