Main Page · Modules · All Classes · Class Hierarchy
MATurnAway.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 "MATurnAway.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MABodyMotion.hpp"
26 #include "types/MAGoals.hpp"
27 #include "types/MARobotState.hpp"
28 #include "MABodyAdjustStandingPosture.hpp"
29 #include "MABodyTurnLeft.hpp"
30 #include "MABodyTurnRight.hpp"
31 #include "MAWalkAway.hpp"
32 #include "MAWalkMaster.hpp"
33 
34 #include <MCLog.hpp>
35 
36 MATurnAway::MATurnAway() : MABehavior(MCGetClassName(this))
37 {
38 }
39 
40 
42 {
44  {
46  }
48 }
49 
50 
52 {
53  return MA::RobotState->BodyMotion->Flying > 60;
54 }
55 
56 
58 {
59  return MA::RobotState->Goals->DesiredLeftTurnDuration == 0 &&
60  MA::RobotState->Goals->DesiredRightTurnDuration == 0;
61 }
62 
63 
65 {
66  MA_RANDOM_POINT_1(Direction, 1, 2);
67  MA_RANDOM_POINT_1(Duration, 12000, 18000);
68 
69  if (Direction == 1)
70  {
71  MA::RobotState->Goals->DesiredLeftTurnDuration = Duration;
73  } else {
74  MA::RobotState->Goals->DesiredRightTurnDuration = Duration;
76  }
77 }
78 
79 
81 {
82  // Don't walk away in the motion control is active
83  if (MA::RobotState->Goals->MotionControl == 0)
85 }
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
Body turns right.
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
Definition: MABehavior.hpp:74
virtual bool IsFailed() override
Whether the behavior is failed.
Definition: MATurnAway.cpp:51
Behavior base class.
Definition: MABehavior.hpp:157
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Definition: MATurnAway.cpp:41
Walk master behavior.
#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
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Definition: MATurnAway.cpp:64
MABehavior * GetMaster()
Get the master behavior.
Definition: MABehavior.cpp:486
Body turns left.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
Definition: MATurnAway.cpp:80
Walk away from an abyss or an object.
Definition: MAWalkAway.hpp:34
virtual bool IsFinished() override
Whether the behavior is finished.
Definition: MATurnAway.cpp:57