Main Page · Modules · All Classes · Class Hierarchy
MAGoodFloorSkit.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 "MAGoodFloorSkit.hpp"
23 
24 #include "core/MARandomness.hpp"
25 #include "controllers/MAHeadController.hpp"
26 #include "controllers/MALedsController.hpp"
27 #include "controllers/MALegController.hpp"
28 #include "controllers/MATailController.hpp"
29 #include "MABodyStateMaster.hpp"
30 #include "MATailToBack.hpp"
31 
32 MAGoodFloorSkit::MAGoodFloorSkit() : MABehavior(MCGetClassName(this)), LedAnimCount(0)
33 {
34  DesiredConnections[MCGetClassName<MABodyStateMaster>()] = -1.0;
35 }
36 
37 
39 {
41 }
42 
43 
45 {
46  MA_RANDOM_POINT_1(HappySkit, 1, 3);
47  MA_RANDOM_POINT_1(SkitDurationScale, 100, 150);
48  std::string ScaleStr(':'+MCToStr((float)SkitDurationScale / 100));
49 
50  if (HappySkit == 1)
51  SkitName = "stand_happyfeet1";
52  if (HappySkit == 2)
53  SkitName = "stand_happyfeet4";
54  if (HappySkit == 3)
55  SkitName = "stand_happyfeet_joy";
56 
57  StartTransition(*MA::LegLF, "SKIT:"+SkitName+ScaleStr);
58  StartTransition(*MA::LegLH, "SKIT:"+SkitName+ScaleStr);
59  StartTransition(*MA::LegRF, "SKIT:"+SkitName+ScaleStr);
60  StartTransition(*MA::LegRH, "SKIT:"+SkitName+ScaleStr);
61  StartTransition(*MA::Head, "SKIT:"+SkitName+ScaleStr);
62  StartTransition(*MA::Tail, "SKIT:"+SkitName+ScaleStr);
63 }
64 
65 
67 {
68  // All skits will have a face LED animation after 1 second
69  if (GetState() == MABehavior::Activated && LedAnimCount == 0 && GetElapsedActivatedStateTime() >= 1200)
70  {
71  StartTransition(*MA::Leds, MA::Leds->ShowHappyAnimStr);
72  LedAnimCount++;
73  } else
74  // Only the stand_happyfeet1 skit is more than 4 seconds long to have more than one face LED animation
75  if (GetState() == MABehavior::Activated && LedAnimCount == 1 && SkitName == "stand_happyfeet1" &&
77  {
78  StartTransition(*MA::Leds, MA::Leds->ShowHappyAnimStr);
79  LedAnimCount++;
80  }
81 }
82 
83 
85 {
87 }
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
virtual void ActivatedStateUpdate() override
Perform actions when the behavior is in activated state.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
Move the tail to the back 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
std::string MCToStr(const T value, bool hex_manipulator=false)
Convert an other type to string with std::stringstream.
Definition: MCDefs.hpp:360
StateType GetState() const
Get the behavior state.
Definition: MABehavior.hpp:393
#define MABEHAVIOR_CREATE(_behavior, _master,...)
Create behaviors with custom constructor safely.
Definition: MABehavior.hpp:43
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.
void StartTransition(MAController &controller, const std::string &transition_name)
Start a transition.
Definition: MABehavior.cpp:793
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.