Main Page · Modules · All Classes · Class Hierarchy
MAHeavyCalculations.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 "MAHeavyCalculations.hpp"
23 
24 #include "types/MARobotState.hpp"
25 #include "types/MAGoals.hpp"
26 #include "types/MAHead.hpp"
27 #include "types/MALeg.hpp"
28 #include "controllers/MAHeadController.hpp"
29 #include "controllers/MALedsController.hpp"
30 #include "controllers/MALegController.hpp"
31 #include "ml/MADataCollector.hpp"
32 #include "MABehaviorManager.hpp"
33 #include "MABodyLyingBored.hpp"
34 #include "MABodySittingBored.hpp"
35 #include "MABodyStandingBored.hpp"
36 #include "MAMouthSpeaking.hpp"
37 #include "MAMouthSpeakingMaster.hpp"
38 
39 #include <MCLog.hpp>
40 #include <MCTimer.hpp>
41 
42 MAHeavyCalculations::MAHeavyCalculations() : MABehavior(MCGetClassName(this), false)
43 {
45  // Suppress these behaviors to avoid any concurrent activations until
46  // the ongoing calculations are finished
47  DesiredConnections[MCGetClassName<MABodyStandingBored>()] = -1.0;
48  DesiredConnections[MCGetClassName<MABodySittingBored>()] = -1.0;
49  DesiredConnections[MCGetClassName<MABodyLyingBored>()] = -1.0;
50 }
51 
52 
54 {
55  bool CalculationNeeded = true;
56 
57  CalculationNeeded = CalculationNeeded && MA::DataCollector->IsAnyJobFinished();
58  CalculationNeeded = CalculationNeeded && !MA::DataCollector->AreAllFinishedJobsCompressed();
59 
60  if (!CalculationNeeded)
62 
63  // Be sure that the body is in rest and there are no ongoing movements
64  int ReadyBody = 0;
65 
69  ReadyBody += !MA::Head->IsAnyActiveTransition() && !MA::LegLF->IsAnyActiveTransition() &&
70  !MA::LegLH->IsAnyActiveTransition() && !MA::LegRF->IsAnyActiveTransition() &&
71  !MA::LegRH->IsAnyActiveTransition();
74  if (ReadyBody == 3 && MA::RobotState->Goals->ArousalFeedbackNeeded == 0)
75  {
77  }
79 }
80 
81 
83 {
84  return MA::DataCollector->AreAllFinishedJobsCompressed();
85 }
86 
87 
89 {
90  StartTransition(*MA::Leds, MA::Leds->HeavyCalculationStr);
91 }
92 
93 
95 {
96  MA::Leds->StartTransition(MA::Leds->FadeOutCrownWhiteStr);
97 }
98 
99 
101 {
102  if (GetElapsedActivatedStateTime() > 50 && !MA::DataCollector->AreAllFinishedJobsCompressed())
103  {
104  MA::BehaviorManager->HibernateSystem();
105  MA::DataCollector->CompressAllFinishedJobs();
106  MA::BehaviorManager->ResumeSystem();
107  }
108 }
#define MABEHAVIOR_IS_NORMAL(_behavior)
Check if a behavior exists and it is in normal state.
Definition: MABehavior.hpp:95
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
Definition: MABehavior.hpp:74
Body standing bored behavior.
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
Mouth speaking behavior.
Body sitting bored behavior.
void SetSelfActivationDuration(const int new_duration)
Set the self-activation duration.
Definition: MABehavior.cpp:530
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
#define MABEHAVIOR_IS_ACTIVATED(_behavior)
Check if a behavior exists and it is in activated state.
Definition: MABehavior.hpp:104
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Mouth speaking master behavior.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
virtual bool IsFinished() override
Whether the behavior is finished.
Body lying bored behavior.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
virtual void ActivatedStateUpdate() override
Perform actions when the behavior is in activated state.