22 #include "MAWalkMaster.hpp" 24 #include "core/MARandomness.hpp" 25 #include "types/MABodyMotion.hpp" 26 #include "types/MAComplexIndicators.hpp" 27 #include "types/MAGoals.hpp" 28 #include "types/MARobotState.hpp" 29 #include "types/MATorso.hpp" 30 #include "types/MATypeRanges.hpp" 31 #include "controllers/MAHeadController.hpp" 32 #include "controllers/MALegController.hpp" 33 #include "ml/MAClassifierModels.hpp" 34 #include "ml/MADataCollector.hpp" 35 #include "ml/MASurfaceAnalyzer.hpp" 36 #include "MAAvoidObstacleMaster.hpp" 37 #include "MABehaviorManager.hpp" 38 #include "MABodyAdjustStandingPosture.hpp" 39 #include "MABodyStateMaster.hpp" 40 #include "MABodyStroked.hpp" 41 #include "MAHeadLookAround.hpp" 42 #include "MAHeadLookAroundMaster.hpp" 43 #include "MARecognizeFloorSurface.hpp" 44 #include "MAWalkFreefall.hpp" 45 #include "MAWalkInitialPosition.hpp" 46 #include "MAWaitFloorFeedback.hpp" 48 #include <MCDataContainer.hpp> 52 RecognizedSurface((int)
MA::UnknownFloor), RecognizedCurrentSurface((int)
MA::UnknownFloor),
56 SurfaceRecognitionTimer->SetDuration(2410);
57 RegisterUpdater(*
this);
65 void MAWalkMaster::StartWalk()
71 if (MA::RobotState->Goals->DesiredForwardWalkDuration < 2000 &&
72 MA::RobotState->Goals->DesiredBackwardWalkDuration < 2000)
79 MA::RobotState->Goals->DesiredForwardWalkDuration = NewDuration;
80 MA::RobotState->Goals->DesiredBackwardWalkDuration = 0;
103 if ((
int)MA::RobotState->ComplexIndicators->ElapsedForwardWalkTime == 0)
107 if ((MA::RobotState->ComplexIndicators->ElapsedForwardWalkTime >= 150*32) &&
108 !SurfaceAnalyzer.get())
114 if (SurfaceAnalyzer.get())
116 SurfaceAnalyzer->AddSamples(*MA::RobotState);
118 if (SurfaceAnalyzer.get() && SurfaceAnalyzer->IsValid() &&
119 RecognizedSurface == (int)MA::UnknownFloor)
122 MC::FloatList SurfaceFeatureVector = SurfaceAnalyzer->GetFeatureVector();
127 MC::FloatList Confidence;
129 MA::DataCollector->AddCustomDataToActiveJob(MA::FloorSurfaceModelID, MA::FloorSurfaceVectorID,
132 RecognizedSurface = (int)MA::ClassifierModels->Recognize(MA::FloorSurfacesID, SurfaceFeatureVector,
134 RecognizedCurrentSurface = RecognizedSurface;
135 if (RecognizedSurface == (
int)MA::WoodFlooring)
136 MC_LOG(
"Recognized: wood flooring");
138 if (RecognizedSurface == (
int)MA::Field)
139 MC_LOG(
"Recognized: field");
141 if (RecognizedSurface == (
int)MA::CarpetedFloor)
142 MC_LOG(
"Recognized: carpeted floor");
144 if (RecognizedSurface == (
int)MA::Carpet)
148 MC_LOG(
"Recognized: carpet");
153 int Duration = MA::RobotState->Goals->DesiredForwardWalkDuration-
154 MA::RobotState->ComplexIndicators->ElapsedForwardWalkTime;
156 Duration = (int)((
float)Duration / Divider)+MA::RobotState->ComplexIndicators->ElapsedForwardWalkTime;
157 MA::RobotState->Goals->DesiredForwardWalkDuration = Duration;
158 MA::RobotState->Goals->HappyOnCarpetFeedback = 1;
161 if (RecognizedSurface == (
int)MA::Vinyl)
162 MC_LOG(
"Recognized: vinyl");
164 if (RecognizedSurface == (
int)MA::Tiles)
166 MC_LOG(
"Recognized: tiles");
168 MC_LOG(
"Recognized: unknown");
172 MA::DataCollector->AddCustomDataToActiveJob(MA::FloorSurfaceModelID, MA::RecognizedFloorSurfaceID,
176 SurfaceRecognitionTimer->Start();
179 if (SurfaceAnalyzer.get() && SurfaceAnalyzer->IsValid() &&
180 SurfaceRecognitionTimer->Timeout())
182 SurfaceRecognitionTimer->Start();
184 MC::FloatList SurfaceFeatureVector = SurfaceAnalyzer->GetFeatureVector();
185 MC::FloatList Confidence;
188 RecognizedCurrentSurface = (int)MA::ClassifierModels->Recognize(MA::FloorSurfacesID,
189 SurfaceFeatureVector, Confidence);
190 if (RecognizedCurrentSurface == (
int)MA::WoodFlooring)
191 MC_LOG(
"Recognized: wood flooring");
193 if (RecognizedCurrentSurface == (
int)MA::Field)
194 MC_LOG(
"Recognized: field");
196 if (RecognizedCurrentSurface == (
int)MA::Carpet)
197 MC_LOG(
"Recognized: carpet");
199 if (RecognizedCurrentSurface == (
int)MA::Vinyl)
200 MC_LOG(
"Recognized: vinyl");
202 if (RecognizedCurrentSurface == (
int)MA::Tiles)
204 MC_LOG(
"Recognized: tiles");
206 MC_LOG(
"Recognized: unknown");
214 bool Failed = MA::RobotState->ComplexIndicators->BodyOutOfWalkingRange > 90;
216 Failed = Failed || MA::RobotState->Torso->CycleTime > MA::WalkCycleTimeMax;
217 if (MA::RobotState->Torso->CycleTime > MA::WalkCycleTimeWarning)
219 MC_WARNING(
"Cycle time is over the safe level (%d > %d)",
220 (
int)MA::RobotState->Torso->CycleTime, MA::WalkCycleTimeWarning);
222 if (MA::RobotState->Torso->CycleTime > MA::WalkCycleTimeMax)
227 MC_WARNING(
"Cycle time is over the emergency level (%d > %d)",
228 (
int)MA::RobotState->Torso->CycleTime, MA::WalkCycleTimeMax);
230 if (!MA::RobotState->BodyMotion->IsBodyRollInWalkRange())
257 if (state.
Goals->DesiredForwardWalkDuration > 0)
264 if (state.
Goals->DesiredForwardWalkDuration > 0)
271 state.
BodyMotion->Floor.Surface = RecognizedSurface;
272 state.
BodyMotion->Floor.CurrentSurface = RecognizedCurrentSurface;
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
#define MABEHAVIOR_DELETE(_behavior)
Delete a behavior safely (mark it dirty if exists)
The head looks around behavior.
#define MABEHAVIOR_EXISTS(_behavior)
Check if a behavior exists.
int GetElapsedActivatedStateTime() const
Get the elapsed activated state time.
MA::DesiredConnectionMap DesiredConnections
Desired connection map to other behaviors.
#define MC_WARNING(...)
Warning macro.
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
virtual void FinishingActions() override
Perform actions when the behavior is being finished.
boost::scoped_ptr< MAComplexIndicators > ComplexIndicators
Complex indicators.
StateType GetState() const
Get the behavior state.
#define MABEHAVIOR_CREATE(_behavior, _master,...)
Create behaviors with custom constructor safely.
std::string MCGetClassName(T *instance=nullptr, const std::string &name_suffix="")
Get a class name.
Initial balance of the body before walk.
Avoid an abyss or an object while walking.
Freefall when the robot falls down while walking or caused by safety reasons.
boost::scoped_ptr< MAGoals > Goals
Goals.
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
Robot state updater base class.
virtual void ActivatedStateUpdate() override
Perform actions when the behavior is in activated state.
virtual void ActivatingActions() override
Perform actions when the behavior is being activated.
Simple timer class with microsecond precision.
Indicate the floor surface recognition period.
MCBinaryData * MCEncodeToBinaryData(const T &data, bool portable=true)
Encode a data into binary form.
const T MCMax(const U &container)
Get the maximal value of a container.
Wait for owner feedback about the real flooring surface.
virtual bool IsFailed() override
Whether the behavior is failed.
virtual MABehavior::StimulusLevelType GetCurrentStimulus() override
Get the current behavior stimulus.
#define MC_LOG(...)
Debug macro.
void MCPrintContainerAsFloats(U &container, const std::string &message="", unsigned int digits=2)
Print a container to the output as float numbers.