22 #include "MAMouthController.hpp" 24 #include "core/MADevice.hpp" 25 #include "core/MARandomness.hpp" 26 #include "types/skits/MAMotionSkit.hpp" 27 #include "types/MAHead.hpp" 28 #include "types/MARobotState.hpp" 41 MC_WARNING(
"The global mouth controller is overridden.");
44 MA::Mouth.reset(
this);
53 if (MA::Mouth.
get() ==
this)
60 state.
Head->Mouth = (int)
Mouth->GetSensorValue();
61 state.
Head->MouthForce = (int)
Mouth->GetForce();
62 state.
Head->MouthMoving =
Mouth->HasGenerator();
63 state.
Head->MouthClosed = IsMouthClosed();
69 MA::DeviceList Motors;
71 Motors.push_back(
Mouth.get());
76 bool MAMouthController::IsMovingMouth()
const 78 return Mouth->HasGenerator();
83 MA::DeviceGeneratorsMap MAMouthController::CloseMouth()
89 return ApplyGenerators(*Container,
true);
93 bool MAMouthController::IsMouthClosed()
const 95 return (
int)MouthOpened.
Value < 10;
99 MA::DeviceGeneratorsMap MAMouthController::Speaking()
103 if ((
int)MouthOpened.
Value < 25 || (
int)MouthOpened.
Value > 35)
113 for (
int i = 0; i < 5; ++i)
118 Generator = CreateGenerator(
MAMouthOpened(15+MouthOpenedValues[i]), 60+MouthOpenedDurations[i],
126 Generator = CreateGenerator(
MAMouthOpened(15+20-MouthOpenedValues[i]), 60+100-MouthOpenedDurations[i],
130 return ApplyGenerators(*Container,
true);
134 MA::DeviceGeneratorsMap MAMouthController::Burp()
147 return ApplyGenerators(*Container,
true);
152 void MAMouthController::Stop()
154 Mouth->ClearGenerators();
158 bool MAMouthController::IsPowerOn()
const 160 return Mouth->IsPowerOn();
164 void MAMouthController::SetPower(
bool new_state)
167 if (
Mouth->IsPowerOn() != new_state)
169 Mouth->SetPower(new_state);
177 void MAMouthController::RegisterDeviceUpdates()
179 MA_SIGNAL_CONNECT(
Mouth->DeviceValueChangeSignal, MAMouthController::NotifyDeviceUpdate);
183 void MAMouthController::NotifyDeviceUpdate(
MADevice& device)
185 if (!device.HasSensorValue())
198 return MA::DeviceGeneratorsMap();
200 MA::DeviceGeneratorsMap DeviceGenerators;
205 Mouth->ClearGenerators();
206 Mouth->AddGeneratorContainer(*Container);
207 MA_INSERT_DEVICEGENERATOR(DeviceGenerators,
Mouth.get(), Container);
208 return DeviceGenerators;
223 MA::DeviceGeneratorsMap MAMouthController::ApplyGenerators(
MAGeneratorContainer& container,
bool clear)
225 MA::DeviceGeneratorsMap DeviceGenerators;
230 Mouth->ClearGenerators();
232 Mouth->AddGeneratorContainer(container);
233 MA_INSERT_DEVICEGENERATOR(DeviceGenerators,
Mouth.get(), &container);
234 return DeviceGenerators;
MANum< float > Value
Current value.
#define MA_RANDOM_POINT_1(_variable_name, _min, _max)
Set a random point with one value.
void AddGenerator(MAGeneratorBase &generator, bool in_front=false)
Add a new generator after the last internal generator.
void SetTransferFunction(FunctionType function)
Set the transfer function.
MAMouthController()
Class constructor.
boost::shared_ptr< MADevice > Mouth
Mouth.
virtual ~MAMouthController()
Class destructor.
virtual MA::DeviceGeneratorsMap GetSkitTransitionGenerators(MA::SkitBaseSPtr skit) override
Get skit transition generators.
virtual void FromJointDegree(int degree) override
Compute from a joint degree value.
#define MC_WARNING(...)
Warning macro.
Base class for the controllers.
static FunctionType GetRandomFunction()
Get a random generator function type.
virtual int ToJointDegree() const override
Transform to a joint degree value.
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
Generator container class.
MAGeneratorContainer * GetGeneratorContainer(MA::Leg::LegTypes leg, MA::LegJointsType joint) const
Get generator container for a leg joint.
virtual MA::DeviceList GetMotors() const override
Get the list of the motors.
Motion sequence (motion skit) class.
Base class for generators.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
The opened-closed position of the mouth.
#define MA_RANDOM_POINT_N(_variable_name, _count, _min, _max)
Set a random point with a value list.
boost::scoped_ptr< MAHead > Head
Head.