Main Page · Modules · All Classes · Class Hierarchy
MAWalkFreefall.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 "MAWalkFreefall.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAGoals.hpp"
26 #include "types/MARobotState.hpp"
27 #include "controllers/MAHeadController.hpp"
28 #include "controllers/MALegController.hpp"
29 #include "MAAvoidObstacleMaster.hpp"
30 #include "MABodyPoked.hpp"
31 #include "MABodyStateMaster.hpp"
32 
33 MAWalkFreefall::MAWalkFreefall(bool force_fall) : MABehavior(MCGetClassName(this)), ForceFall(force_fall)
34 {
37  DesiredConnections[MCGetClassName<MABodyPoked>()] = -1.0;
38  DesiredConnections[MCGetClassName<MABodyStateMaster>()] = -1.0;
39 }
40 
41 
43 {
44  if (ForceFall)
45  {
47  }
48  if (!MA::RobotState->BodyMotion->IsBodyRollInWalkRange() &&
49  MA::RobotState->BodyMotion->BodyState == MA::FallingOver)
50  {
52  }
54 }
55 
56 
58 {
59  return GetElapsedActivatedStateTime() > 6000;
60 }
61 
62 
64 {
65  // Don't give carpet feedback after falling over
66  MA::RobotState->Goals->HappyOnCarpetFeedback = 0;
67  // Leave motion control
68  MA::RobotState->Goals->MotionControl = 0;
69  MA::Head->SetPower(false);
70  MA::LegLF->SetPower(false);
71  MA::LegRF->SetPower(false);
72  MA::LegLH->SetPower(false);
73  MA::LegRH->SetPower(false);
74  // The detected abyss or obstacle is not real. The robot falls down...
76 }
#define MABEHAVIOR_DELETE(_behavior)
Delete a behavior safely (mark it dirty if exists)
Definition: MABehavior.hpp:81
virtual bool IsFinished() override
Whether the behavior is finished.
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
void SetLifetimeExpirationTime(const unsigned int expiration_time)
Set the lifetime expiration time.
Definition: MABehavior.cpp:542
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
MAWalkFreefall(bool force_fall)
Class constructor.
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.
Avoid an abyss or an object while walking.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.