Main Page · Modules · All Classes · Class Hierarchy
MALegMoved.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 "MALegMoved.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "types/MARobotState.hpp"
26 #include "controllers/MALedsController.hpp"
27 #include "controllers/MALegController.hpp"
28 #include "controllers/MASpeakerController.hpp"
29 #include "MALegLyingPosition.hpp"
30 #include "MALegSittingPosition.hpp"
31 #include "MALegMoveAway.hpp"
32 #include "MALegPull.hpp"
33 
34 MALegMoved::MALegMoved(MA::Leg::LegTypes leg_type) :
35  // There are no lifetime and active state duration set -> The behavior is dynamic,
36  // but it is not destroyed until the leg is not stopped and the behavior finished.
37  MALegBehavior(MCGetClassName(this), leg_type, false)
38 {
40  // Register the desired connections
41  DesiredConnections[MAGetLegBehaviorName<MALegLyingPosition>(leg_type)] = -1.0;
42  DesiredConnections[MAGetLegBehaviorName<MALegSittingPosition>(leg_type)] = -1.0;
43  DesiredConnections[MAGetLegBehaviorName<MALegPull>(leg_type)] = -1.0;
44 }
45 
46 
48 {
49  // The leg is being moved, but there are no generators, thus it is moved by "somebody".
50  if (!Controller->IsMoving() && LegState.Stopped < 20)
51  {
53  }
55 }
56 
57 
59 {
60  // The leg is being moved with generators -> Failed.
61  // It is a safety check since the behavior does not have lifetime, so
62  // it becomes "failed" when an other behavior start to move the joints.
63  if (Controller->IsMoving())
64  return true;
65  else
66  return false;
67 }
68 
69 
71 {
72  if (LegState.Stopped > 80)
73  {
74  return true;
75  }
76  return false;
77 }
78 
79 
81 {
82  MALEGBEHAVIOR_CREATE(MALegMoveAway, LegState.Type, GetMaster());
83 }
84 
85 
87 {
89 }
90 
91 
93 {
94  StartTransition(*MA::Leds, MA::Leds->ShowAngryFaceStr);
95  // Avoid concurrent barking
96  if (!MALEGBEHAVIOR_IS_ACTIVATED(MALegMoved, MA::Leg::LF) &&
97  !MALEGBEHAVIOR_IS_ACTIVATED(MALegMoved, MA::Leg::LH) &&
98  !MALEGBEHAVIOR_IS_ACTIVATED(MALegMoved, MA::Leg::RF) &&
99  !MALEGBEHAVIOR_IS_ACTIVATED(MALegMoved, MA::Leg::RH))
100  {
101  MA_RANDOM_POINT_1(Sound, 1, 2);
102 
103  if (Sound == 1)
104  PlaySound("legsangry1");
105  if (Sound == 2)
106  PlaySound("legsangry2");
107  }
108 }
virtual void FailingActions() override
Perform actions when the behavior is being failed.
Definition: MALegMoved.cpp:80
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
Definition: MALegMoved.cpp:47
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
Definition: MABehavior.hpp:766
MALegController * Controller
Leg controller.
virtual bool IsFinished() override
Whether the behavior is finished.
Definition: MALegMoved.cpp:70
int PlaySound(const std::string &name)
Play a sound and register the playback.
Definition: MABehavior.cpp:823
Base class for leg behaviors.
Moves the leg away from the body.
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
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
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
Definition: MALegMoved.cpp:86
virtual bool IsFailed() override
Whether the behavior is failed.
Definition: MALegMoved.cpp:58
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
The leg is being moved on its own.
Definition: MALegMoved.hpp:34
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Definition: MALegMoved.cpp:92