22 #include "MABehaviorManager.hpp" 24 #include "core/MAMicrophoneDevice.hpp" 25 #include "types/skits/MASkitDatabase.hpp" 26 #include "sound/MASoundDatabase.hpp" 27 #include "controllers/MAController.hpp" 28 #include "ml/MAClassifierModels.hpp" 29 #include "ml/MADataCollector.hpp" 30 #include "MABatteryStatus.hpp" 31 #include "MABodyAngry.hpp" 32 #include "MABodyAwaking.hpp" 33 #include "MABodyHappy.hpp" 34 #include "MABodyPoked.hpp" 35 #include "MABodyStateMaster.hpp" 36 #include "MABodySleeping.hpp" 37 #include "MABodyStroked.hpp" 38 #include "MAChangeEyePupil.hpp" 39 #include "MAClientConnected.hpp" 40 #include "MADataUploadStatus.hpp" 41 #include "MAEyePupil.hpp" 42 #include "MAHeadLookAroundMaster.hpp" 43 #include "MAHeavyCalculations.hpp" 44 #include "MASkitterPlaybackMaster.hpp" 45 #include "MAMouthSpeakingMaster.hpp" 46 #include "MANoWritableStorage.hpp" 47 #include "MANumberGameMaster.hpp" 48 #include "MAHeadTurnMaster.hpp" 49 #include "MASoundEventMaster.hpp" 50 #include "MASpeakerVolume.hpp" 51 #include "MAStartUp.hpp" 52 #include "MASwitchSoundProfile.hpp" 53 #include "MASwitchVolumeControl.hpp" 54 #include "numbergame/MANumberGameMaster.hpp" 57 #include <MCTimer.hpp> 65 MABehaviorManager::MABehaviorManager() : Verbose(false)
67 if (MA::BehaviorManager.
get())
69 MC_WARNING(
"The global behavior manager is overridden.");
71 MA::BehaviorManager.reset(
this);
72 if (!MA::DataCollector.
get())
76 if (!MA::ClassifierModels.
get())
83 MABehaviorManager::~MABehaviorManager()
85 if (MA::BehaviorManager.
get() ==
this)
87 MA::BehaviorManager.release();
90 if (MA::SkitDatabase.
get())
92 MA::SkitDatabase.reset(
nullptr);
94 if (MA::SoundDatabase.
get())
96 MA::SoundDatabase.reset(
nullptr);
98 if (MA::DataCollector.
get())
100 MA::DataCollector.reset(
nullptr);
102 if (MA::ClassifierModels.
get())
104 MA::ClassifierModels.reset(
nullptr);
125 MA::BehaviorList ProposedBehaviors;
130 MC_LOG(
"Merge the new behaviors to the global list");
137 MC_LOG(
"Calculate and circulate the activations");
144 MC_LOG(
"Create the list of the proposed behavior list");
148 for (
auto& behavior : Behaviors)
153 behavior->GetActivationLevel() == 100)
155 ProposedBehaviors.push_back(behavior);
162 MC_LOG(
"Execute the final behaviors");
164 for (
auto& behavior : ProposedBehaviors)
180 MC_LOG(
"Remove the finished/failed behaviors (self-destroy)");
187 MC_LOG(
"Remove the finished or deleted behaviors");
219 MA::DataCollector->UpdateJobs();
238 if (MA::Microphone.
get())
239 MA::Microphone->ResetListening();
245 #if !defined(__AIBO_BUILD__) 255 #if !defined(__AIBO_BUILD__) 271 if (!MA::SkitDatabase.
get())
274 MA::SkitDatabase->CreateMirroredSkits();
276 if (!MA::SoundDatabase.
get())
281 MACreateBehavior<MABatteryStatus>(
nullptr);
282 MACreateBehavior<MADataUploadStatus>(
nullptr);
285 MACreateBehavior<MAStartUp>(
nullptr);
286 MACreateBehavior<MABodyAngry>(
nullptr);
287 MACreateBehavior<MABodyHappy>(
nullptr);
288 MACreateBehavior<MABodyPoked>(
nullptr);
289 MACreateBehavior<MABodyAwaking>(
nullptr);
290 MACreateBehavior<MABodySleeping>(
nullptr);
291 MACreateBehavior<MABodyStroked>(
nullptr);
292 MACreateBehavior<MAEyePupil>(
nullptr);
293 MACreateBehavior<MAHeadLookAroundMaster>(
nullptr);
294 MACreateBehavior<MAHeadTurnMaster>(
nullptr);
295 MACreateBehavior<MASpeakerVolume>(
nullptr);
296 MACreateBehavior<MASwitchSoundProfile>(
nullptr);
297 MACreateBehavior<MASwitchVolumeControl>(
nullptr);
298 MACreateBehavior<MAMouthSpeakingMaster>(
nullptr);
299 MACreateBehavior<MABodyStateMaster>(
nullptr);
300 MACreateBehavior<MASkitterPlaybackMaster>(
nullptr);
301 MACreateBehavior<MAHeavyCalculations>(
nullptr);
302 MACreateBehavior<MAClientConnected>(
nullptr);
303 MACreateBehavior<MANumberGameMaster>(
nullptr);
304 MACreateBehavior<MASoundEventMaster>(
nullptr);
305 MACreateBehavior<MAChangeEyePupil>(
nullptr);
void SetVerbose(bool new_state)
Set the verbosity level.
static void GarbageCollection()
Destroy the dirty behaviors.
static void ResumeSystem()
Resume the behavior system.
static bool Exists(const std::string &type_name, bool can_be_dying=false)
Check if a behavior exists.
bool Verbose
Whether the behavior manager is verbose.
virtual std::string GetSkitDatabaseFileName()
Get the skit database file name.
static void MergeNewBehaviors()
Merge all new behaviors to the existing behaviors.
static MASoundDatabase * LoadFromFile(const std::string &file_name)
Load sound database from file.
static const MA::BehaviorList & GetBehaviors()
Get all existing behaviors.
#define MC_WARNING(...)
Warning macro.
static void HibernateSystem()
Hibernate the behavior system.
static void CalculateActivations()
Calculate the current self-activation levels and send them out to the connected behaviors.
static void ResumeSystemTime()
Hibernate the system time.
QString MCGetDataFile(const QString &file_name)
Search a data file.
static void Cleanup()
Destroy all behaviors.
static void ClearBehaviorStateEvents()
Get the current behavior state events.
virtual std::string GetSoundDatabaseFileName()
Get the sound database file name.
virtual void SetRandomSeed()
Set random seed in a platform specific way.
static void SetNewSeed(int seed=(int) time(nullptr))
Set a new global random seed based on the system time.
static MASkitDatabase * LoadFromFile(const std::string &file_name)
Load skit database from file.
MA::BehaviorList ActiveBehaviors
Active behavior list.
static bool IsMergeNeeded()
Check if new behavior merge is needed.
static void HibernateSystemTime()
Hibernate the system time.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
virtual void UpdateBehaviors()
Update the behavior states in a cycle.
#define MC_LOG(...)
Debug macro.
virtual void CreateDefaultBehaviors()
Create the default behaviors.