Main Page · Modules · All Classes · Class Hierarchy
MAWaitFloorFeedback.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 "MAWaitFloorFeedback.hpp"
23 
24 #include "types/MABodyMotion.hpp"
25 #include "types/MAComplexIndicators.hpp"
26 #include "types/MAGoals.hpp"
27 #include "types/MARobotState.hpp"
28 #include "ml/MAClassifierModels.hpp"
29 #include "ml/MADataCollector.hpp"
30 #include "MABehaviorManager.hpp"
31 #include "MABodyStandingBored.hpp"
32 #include "MAWalkInitialPosition.hpp"
33 
34 MAWaitFloorFeedback::MAWaitFloorFeedback() : MABehavior(MCGetClassName(this)),
35  MARobotStateUpdater(MA::UpdateComplexIndicators), DataCollectionStopped(false),
36  Initialized(false)
37 {
38  RegisterUpdater(*this);
39  // Set the maximal wait time for the owner feedback
40  SetActivatedStateExpirationTime(MA::MaxFeedbackWaitTime);
41 }
42 
43 
45 {
47 }
48 
49 
51 {
52  // We can't wait more after the dog start to walk forward again
54  MA::RobotState->Goals->DesiredForwardWalkDuration > 2000;
55 }
56 
57 
59 {
60  return (int)MA::RobotState->BodyMotion->Floor.OwnerFeedback >= 0;
61 }
62 
63 
65 {
66  if (!DataCollectionStopped && GetElapsedActivatedStateTime() > 2000)
67  {
68  DataCollectionStopped = true;
69  MA::DataCollector->StopActiveJobToCollectAType(MA::FloorSurfaceModelID, "RobotState");
70  MA::DataCollector->StopActiveJobToCollectAType(MA::FloorSurfaceModelID, "LogMessage");
71  }
72 }
73 
74 
76 {
77  MAFloorSurface& Floor = MA::RobotState->BodyMotion->Floor;
78 
79  if ((int)Floor.OwnerFeedback == (int)MA::WoodFlooring)
80  MC_LOG("Owner feedback arrived: wood flooring");
81  if ((int)Floor.OwnerFeedback == (int)MA::Field)
82  MC_LOG("Owner feedback arrived: field");
83  if ((int)Floor.OwnerFeedback == (int)MA::Carpet)
84  MC_LOG("Owner feedback arrived: carpet");
85  if ((int)Floor.OwnerFeedback == (int)MA::FoamMat)
86  MC_LOG("Owner feedback arrived: foam mat");
87  if ((int)Floor.OwnerFeedback == (int)MA::Vinyl)
88  MC_LOG("Owner feedback arrived: vinyl");
89  if ((int)Floor.OwnerFeedback == (int)MA::Tiles)
90  MC_LOG("Owner feedback arrived: tiles");
91  if ((int)Floor.OwnerFeedback == (int)MA::CarpetedFloor)
92  MC_LOG("Owner feedback arrived: carpeted floor");
93  if ((int)Floor.OwnerFeedback == (int)MA::UserDefinedFloor)
94  MC_LOG("Owner feedback arrived: user defined");
95 
96  // The standing posture is needed to execute the body responses for the good/wrong results when
97  // the robot is standing or walking.
98  if ((MA::RobotState->ComplexIndicators->IsStandingPosture > 0 ||
99  MA::RobotState->ComplexIndicators->IsLocomotionActive()) && !MABEHAVIOR_EXISTS(MABodyStandingBored))
100  {
101  MA::RobotState->Goals->StandPostureDesire = 1;
102  MA::RobotState->Goals->ArousalFeedbackNeeded = MA::RobotState->Goals->ArousalFeedbackNeeded.GetMax();
103  }
104 }
105 
106 
108 {
109  if (unlikely(!Initialized))
110  {
111  Initialized = true;
112  state.BodyMotion->Floor.OwnerFeedback = -1;
113  }
114 }
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.
virtual bool IsFailed() override
Whether the behavior is failed.
#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
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
Behavior base class.
Definition: MABehavior.hpp:157
Floor surface struct.
void SetActivatedStateExpirationTime(const unsigned int expiration_time)
Set the activated state expiration time.
Definition: MABehavior.cpp:552
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Definition: MCDefs.hpp:627
Initial balance of the body before walk.
virtual bool IsFinished() override
Whether the behavior is finished.
#define MABEHAVIOR_IS_ACTIVATED(_behavior)
Check if a behavior exists and it is in activated state.
Definition: MABehavior.hpp:104
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
Robot state updater base class.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
#define MC_LOG(...)
Debug macro.
Definition: MCLog.hpp:41
Robot state.