Main Page · Modules · All Classes · Class Hierarchy
MABodyTurnLeft.cpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyleft (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 "MABodyTurnLeft.hpp"
23 
24 #include <MCLog.hpp>
25 
26 #include "types/MAComplexIndicators.hpp"
27 #include "types/MAGoals.hpp"
28 #include "types/MARobotState.hpp"
29 #include "controllers/MALegController.hpp"
30 
31 #include "MABodyAdjustStandingPosture.hpp"
32 #include "MABodyStateMaster.hpp"
33 
34 MABodyTurnLeft::MABodyTurnLeft() : MABehavior(MCGetClassName(this))
35 {
36  DesiredConnections[MCGetClassName<MABodyStateMaster>()] = -1.0;
37 }
38 
39 
41 {
43 }
44 
45 
47 {
48  return MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime+GetElapsedActivatedStateTime() >=
49  MA::RobotState->Goals->DesiredLeftTurnDuration;
50 }
51 
52 
54 {
55  std::string Suffix = ":1.8";
56 
57  if (MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime == 0)
58  Suffix += ":1000";
59 
60  StartTransition(*MA::LegLF, "SKIT:turn_left"+Suffix);
61  StartTransition(*MA::LegLH, "SKIT:turn_left"+Suffix);
62  StartTransition(*MA::LegRF, "SKIT:turn_left"+Suffix);
63  StartTransition(*MA::LegRH, "SKIT:turn_left"+Suffix);
64  if (MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime == 0)
65  MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime = 1;
66 }
67 
68 
70 {
71  MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime += GetElapsedActivatedStateTime();
73 }
74 
75 
77 {
78  MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime += GetElapsedActivatedStateTime();
79  if (MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime >=
80  MA::RobotState->Goals->DesiredLeftTurnDuration)
81  {
82  MC_LOG("Left turn duration: %d msec (desired: %d msec)",
83  (int)MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime,
84  (int)MA::RobotState->Goals->DesiredLeftTurnDuration);
85  } else {
86  MC_LOG("The left turn duration is less than the desired (%d < %d)",
87  (int)MA::RobotState->ComplexIndicators->ElapsedLeftTurnTime,
88  (int)MA::RobotState->Goals->DesiredLeftTurnDuration);
89  }
91 }
virtual bool IsFailed() override
Whether the behavior is failed.
virtual void FailingActions() override
Perform actions when the behavior is being failed.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
int GetElapsedActivatedStateTime() const
Get the elapsed activated state time.
Definition: MABehavior.cpp:561
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
Behavior base class.
Definition: MABehavior.hpp:157
#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
Body turns left.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
#define MC_LOG(...)
Debug macro.
Definition: MCLog.hpp:41
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.