Main Page · Modules · All Classes · Class Hierarchy
MAHeadTurnAhead.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 "MAHeadTurnAhead.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MARobotState.hpp"
27 #include "controllers/MAHeadController.hpp"
28 #include "MAHeadLookAround.hpp"
29 #include "MAMotorOverload.hpp"
30 
31 MAHeadTurnAhead::MAHeadTurnAhead() : MABehavior(MCGetClassName(this))
32 {
33  // Set a lifetime duration to avoid dangling behaviors
35 }
36 
37 
39 {
40  if ((MA::RobotState->BodyMotion->Lying > 80 || MA::RobotState->BodyMotion->Sitting > 80 ||
41  MA::RobotState->BodyMotion->OnStation || MA::RobotState->ComplexIndicators->IsStandingPosture) &&
42  !MABEHAVIOR_EXISTS(MAHeadLookAround) && !MA::Head->IsNormalAhead())
43  {
45  }
47 }
48 
49 
51 {
52  return MA::Head->IsUp() && !MA::Head->IsTransitionActive(MA::Head->ToNormalAheadStr);
53 }
54 
55 
57 {
58  StartTransition(*MA::Head, MA::Head->ToNormalAheadStr);
59  // Create the motor overload behaviors
60  MAMotorOverload::CreateBehaviorForMotors(MA::Head->GetMotors(), nullptr);
61 }
62 
63 
65 {
66  // Delete the motor overload behaviors
67  MAMotorOverload::DeleteBehaviorForMotors(MA::Head->GetMotors());
68 }
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
The head looks around behavior.
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
Definition: MABehavior.hpp:74
Behavior base class.
Definition: MABehavior.hpp:157
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
void SetLifetimeExpirationTime(const unsigned int expiration_time)
Set the lifetime expiration time.
Definition: MABehavior.cpp:542
virtual bool IsFinished() override
Whether the behavior is finished.
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793