55 eye_pitch_left =
"EyeL_1_joint";
56 eye_pitch_right =
"EyeR_1_joint";
57 eye_yaw_left =
"EyeL_2_joint";
58 eye_yaw_right =
"EyeR_2_joint";
59 neck_roll =
"Neck_2_joint";
63 eye_pitch_left =
"Cameras";
64 eye_yaw_left =
"Eye_Left";
65 eye_yaw_right =
"Eye_Right";
66 neck_roll =
"Neck_2_Roll";
69 "Neck_1_Pitch", neck_roll,
"Neck_3_Yaw", eye_pitch_left, eye_yaw_right, eye_yaw_left};
84 ARMARX_LOG <<
"Velocity based: " << velocityBased;
96 vor->setJointNames(eye_pitch_left, eye_pitch_right, eye_yaw_left, eye_yaw_right, neck_roll);
97 vor->setBools(armar4, velocityBased);
98 vor->setPIDValues(kp, ki, kd);
101 jointIK->setBools(armar4, velocityBased);
104 okr->setJointNames(eye_pitch_left, eye_pitch_right, eye_yaw_left, eye_yaw_right, neck_roll);
105 okr->setBools(armar4, velocityBased);
106 okr->setPIDValues(kp, ki, kd);
110 this, &ReflexCombination::combineReflexes, 5,
false,
"ReflexCombinationTask");
111 execCombineReflexesTask->setDelayWarningTolerance(2);
116 int sampling_size = 20;
118 IMU_GyroFilters[
"X"]->update(0,
new Variant((
float)0.0));
120 IMU_GyroFilters[
"Y"]->update(0,
new Variant((
float)0.0));
122 IMU_GyroFilters[
"Z"]->update(0,
new Variant((
float)0.0));
124 double frequency = 10.;
125 int sampleRate = 100;
126 double resonance = 1.0;
128 std::map<std::string, float> filterProperties{{
"minSampleTimeDelta", 100 * 1000.0}};
130 for (
auto& joint_name : headJointNames)
134 VelocityFilters[joint_name]->setProperties(filterProperties);
135 VelocityFilters[joint_name]->update(0,
new Variant((
double)0.0));
137 PreVelocityFilters[joint_name] =
139 PreVelocityFilters[joint_name]->setInitialValue(0.);
140 PreVelocityFilters[joint_name]->update(0,
new Variant((
double)0.0));
148 FlowFilters[
"X"]->setInitialValue(0.);
149 FlowFilters[
"X"]->update(0,
new Variant((
float)0.0));
152 FlowFilters[
"Y"]->setInitialValue(0.);
153 FlowFilters[
"Y"]->update(0,
new Variant((
float)0.0));
177 jointIK->setRobot(nodeSetName, headIKName, robotStateComponent);
186 if ((combinationMethod ==
Reafference) && !jointIKEnabled)
188 ARMARX_WARNING <<
"Reafference combination cannot work without IK method enabled. Setting "
189 "to weighted sum imnstead";
193 execCombineReflexesTask->start();
199 execCombineReflexesTask->stop();
221 const Ice::Current&
c)
225 ARMARX_LOG <<
"new reflex weights vor:" << vorWeight <<
" okr:" << okrWeight
226 <<
" jointik:" << jointIKWeight;
230 debugValues[
"reflexes_vor"] =
new Variant(vorWeight);
231 debugValues[
"reflexes_okr"] =
new Variant(okrWeight);
232 debugValues[
"reflexes_ik"] =
new Variant(jointIKWeight);
234 debugObserver->setDebugChannel(
"ReflexCombination", debugValues);
237 std::scoped_lock lock(mutex);
239 this->vorWeight = vorWeight;
240 this->okrWeight = okrWeight;
241 this->jointIKWeight = jointIKWeight;
243 vorEnabled = (vorWeight > 0);
244 jointIKEnabled = (jointIKWeight > 0);
245 okrEnabled = (okrWeight > 0);
247 ARMARX_LOG <<
"enabled reflexes vor:" << vorEnabled <<
" okr:" << okrEnabled
248 <<
" jointik:" << jointIKEnabled;
250 vor->setEnabled(vorEnabled);
251 okr->setEnabled(okrEnabled);
252 jointIK->setEnabled(jointIKEnabled);
271ReflexCombination::combineReflexes()
273 std::scoped_lock lock(mutex);
275 if (!(vorEnabled || jointIKEnabled || okrEnabled))
278 <<
"at least one reflex must be enabled to stabilize the gaze!";
291 NameControlModeMap controlModes;
293 std::map<std::string, float> weights;
294 std::map<std::string, float> jointValuesIK = jointIK->getJoints();
295 std::map<std::string, float> jointValuesVOR = vor->getJoints();
296 std::map<std::string, float> jointValuesOKR = okr->getJoints();
301 mapValues[
"optFlow_predX"] =
new Variant(jointIK->optFlow_pred[0]);
302 mapValues[
"optFlow_predY"] =
new Variant(jointIK->optFlow_pred[1]);
303 mapValues[
"meanOptFlow_pred"] =
new Variant((
float)jointIK->mean_optFl_pred);
304 mapValues[
"imu_gyro_predX"] =
new Variant(jointIK->gyroscopeRotation_pred[0]);
305 mapValues[
"imu_gyro_predY"] =
new Variant(jointIK->gyroscopeRotation_pred[1]);
306 mapValues[
"imu_gyro_predZ"] =
new Variant(jointIK->gyroscopeRotation_pred[2]);
307 mapValues[
"vel_filtered"] =
new Variant(VelocityFilters[eye_yaw_left]->
getValue()->getDouble());
308 mapValues[
"flow_filteredX"] =
new Variant(FlowFilters[
"X"]->
getValue()->getDouble());
309 mapValues[
"flow_filteredY"] =
new Variant(FlowFilters[
"Y"]->
getValue()->getDouble());
310 mapValues[
"imu_filteredX"] =
new Variant(IMU_GyroFilters[
"X"]->
getValue()->getFloat());
311 mapValues[
"imu_filteredY"] =
new Variant(IMU_GyroFilters[
"Y"]->
getValue()->getFloat());
312 mapValues[
"imu_filteredZ"] =
new Variant(IMU_GyroFilters[
"Z"]->
getValue()->getFloat());
313 debugObserver->setDebugChannel(
"ForwardPredictor", mapValues);
338 for (
auto& kv : jointValuesIK)
340 if (!resultJointValues.count(kv.first))
342 resultJointValues[kv.first] = 0;
343 weights[kv.first] = 0;
345 resultJointValues[kv.first] += jointIKWeight * kv.second;
346 weights[kv.first] += jointIKWeight;
349 for (
auto& kv : jointValuesVOR)
351 if (!resultJointValues.count(kv.first))
353 resultJointValues[kv.first] = 0;
354 weights[kv.first] = 0;
356 resultJointValues[kv.first] += vorWeight * kv.second;
357 weights[kv.first] += vorWeight;
360 for (
auto& kv : jointValuesOKR)
362 if (!resultJointValues.count(kv.first))
364 resultJointValues[kv.first] = 0;
365 weights[kv.first] = 0;
367 resultJointValues[kv.first] += okrWeight * kv.second;
368 weights[kv.first] += okrWeight;
376 for (
auto& kv : weights)
378 resultJointValues[kv.first] = resultJointValues[kv.first] / kv.second;
383 if (resultJointValues.empty())
392 for (
auto const& headJoint : headJointNames)
394 if (resultJointValues.find(headJoint) == resultJointValues.end())
396 resultJointValues[headJoint] = 0.;
407 resultJointValues[
"Eye_Left"] =
408 resultJointValues[
"Eye_Right"] +
409 kp * (PreVelocityFilters[
"Eye_Right"]->getValue()->getDouble() -
410 PreVelocityFilters[
"Eye_Left"]->
getValue()->getDouble());
417 for (
auto& kv : resultJointValues)
421 controlModes[kv.first] = eVelocityControl;
425 controlModes[kv.first] = ePositionControl;
429 if (neckPerturbation && velocityBased)
431 controlModes[
"Neck_3_Yaw"] = eVelocityControl;
432 resultJointValues[
"Neck_3_Yaw"] =
443 for (
auto& kv : resultJointValues)
445 debugValues[kv.first] =
new Variant(kv.second);
448 debugObserver->setDebugChannel(
"ReflexCombination", debugValues);
452 for (
auto& kv : jointValuesIK)
454 debugValuesIK[kv.first] =
new Variant(kv.second);
456 debugObserver->setDebugChannel(
"ReflexCombinationIK", debugValuesIK);
459 for (
auto& kv : jointValuesOKR)
461 debugValuesOKR[kv.first] =
new Variant(kv.second);
463 debugObserver->setDebugChannel(
"ReflexCombinationOKR", debugValuesOKR);
466 for (
auto& kv : jointValuesVOR)
468 debugValuesVOR[kv.first] =
new Variant(kv.second);
470 debugObserver->setDebugChannel(
"ReflexCombinationVOR", debugValuesVOR);
472 kinUnitPrx->switchControlMode(controlModes);
475 kinUnitPrx->setJointVelocities(resultJointValues);
479 kinUnitPrx->setJointAngles(resultJointValues);
490 Ice::Float currentPlatformVelocityY,
491 Ice::Float currentPlatformVelocityRotation,
492 const Ice::Current&
c)
512 const Ice::Current&
c)
514 std::scoped_lock lock(mutex);
516 NameValueMap tmp = values;
521 bool jointAnglesReached =
true;
522 for (std::pair<std::string, Ice::Float> joint : targetJointAngles)
524 jointAnglesReached &= (tmp[joint.first] >= (joint.second - offset));
525 jointAnglesReached &= (tmp[joint.first] <= (joint.second + offset));
528 if (jointAnglesReached)
530 newHeadTarget =
false;
557 vor->reportJointAngles(values, valueChanged,
c);
561 jointIK->reportJointAngles(values, valueChanged,
c);
565 okr->reportJointAngles(values, valueChanged,
c);
569 for (
auto& joint_name : headJointNames)
571 PreVelocityFilters[joint_name]->update(
timestamp,
new Variant(tmp[joint_name]));
572 VelocityFilters[joint_name]->update(
573 timestamp,
new Variant(PreVelocityFilters[joint_name]->getValue()->getDouble()));
581 const Ice::Current&
c)
584 std::scoped_lock lock(mutex);
585 NameValueMap velocities_filtered(velocities);
586 for (
auto& joint_name : headJointNames)
588 if (velocities_filtered.count(joint_name))
590 velocities_filtered[joint_name] = VelocityFilters[joint_name]->getValue()->getDouble();
597 vor->reportJointVelocities(velocities_filtered, valueChanged,
c);
601 jointIK->reportJointVelocities(velocities_filtered, valueChanged,
c);
605 if (combinationMethod ==
Reafference && jointIKEnabled)
607 velocities_filtered[eye_yaw_left] =
609 velocities_filtered[eye_yaw_right] = 0.;
610 velocities_filtered[eye_pitch_left] = 0.;
612 okr->reportJointVelocities(velocities_filtered, valueChanged,
timestamp,
c);
661 const Ice::Current&
c)
664 std::scoped_lock lock(mutex);
669 double x_flow, y_flow;
671 x_flow = FlowFilters[
"X"]->getValue()->getDouble();
672 y_flow = FlowFilters[
"Y"]->getValue()->getDouble();
678 if (combinationMethod ==
Reafference && jointIKEnabled)
680 x_flow -= jointIK->optFlow_pred[0];
681 y_flow -= jointIK->optFlow_pred[1];
683 if (fabs(x_flow) < 0.04)
691 okr->reportNewOpticalFlow(x_flow, y_flow, deltaT,
timestamp);
697 const FramedPositionBasePtr& targetPosition,
701 std::scoped_lock lock(mutex);
703 newHeadTarget =
true;
704 this->targetJointAngles = targetJointAngles;
706 ARMARX_INFO <<
" new head target " << targetPosition->output();
712 jointIK->reportHeadTargetChanged(targetJointAngles, targetPosition);
726 const std::string& name,
727 const IMUData& values,
729 const Ice::Current&
c)
733 std::scoped_lock lock(mutex);
741 if (IMU_GyroFilters[
"X"] && IMU_GyroFilters[
"Y"] && IMU_GyroFilters[
"Z"])
743 IMU_GyroFilters[
"X"]->update(
timestamp->timestamp,
744 new Variant((
float)values.gyroscopeRotation[0]));
745 IMU_GyroFilters[
"Y"]->update(
timestamp->timestamp,
746 new Variant((
float)values.gyroscopeRotation[1]));
747 IMU_GyroFilters[
"Z"]->update(
timestamp->timestamp,
748 new Variant((
float)values.gyroscopeRotation[2]));
751 IMUData values2 = values;
753 if (IMU_GyroFilters[
"X"] && IMU_GyroFilters[
"Y"] && IMU_GyroFilters[
"Z"])
755 values2.gyroscopeRotation[0] = IMU_GyroFilters[
"X"]->getValue()->getFloat();
756 values2.gyroscopeRotation[1] = IMU_GyroFilters[
"Y"]->getValue()->getFloat();
757 values2.gyroscopeRotation[2] = IMU_GyroFilters[
"Z"]->getValue()->getFloat();
760 if (combinationMethod ==
Reafference && jointIKEnabled)
762 values2.gyroscopeRotation[0] -= jointIK->gyroscopeRotation_pred[0];
763 values2.gyroscopeRotation[1] -= jointIK->gyroscopeRotation_pred[1];
764 values2.gyroscopeRotation[2] -= jointIK->gyroscopeRotation_pred[2];
766 if (fabs(values2.gyroscopeRotation[2]) < 0.04)
768 values2.gyroscopeRotation[2] = 0.;
774 vor->reportSensorValues(values2);
779armarx::ReflexCombination::setImageQuality(
float quality)
781 Ice::StringSeq imageSources = getProperty<Ice::StringSeq>(
"ImageProviders");
785 imageSourceSelection->setImageSource(imageSources[1], 100000000);
789 imageSourceSelection->setImageSource(imageSources[0], 100000000);
800 okr->reportNewTrackingError(pixelX, pixelY, angleX, angleY);
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void onInitComponent() override
void reportHeadTargetChanged(const NameValueMap &targetJointAngles, const FramedPositionBasePtr &targetPosition, const Ice::Current &c=Ice::emptyCurrent) override
void setReafferenceMethod(bool isReafference, const Ice::Current &c=Ice::emptyCurrent) override
void onDisconnectComponent() override
void reportSensorValues(const std::string &device, const std::string &name, const IMUData &values, const TimestampBasePtr ×tamp, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void updateWeights(float vor, float okr, float jointIK, const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportControlModeChanged(const NameControlModeMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointAccelerations(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointVelocities(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointTorques(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void onConnectComponent() override
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
void reportNewTrackingError(Ice::Float pixelX, Ice::Float pixelY, Ice::Float angleX, Ice::Float angleY, const Ice::Current &) override
void reportNewOpticalFlow(Ice::Float, Ice::Float, Ice::Float, Ice::Long, const Ice::Current &) override
void onExitComponent() override
void reportJointCurrents(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointAngles(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointStatuses(const NameStatusMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
The Variant class is described here: Variants.
The DerivationFilter calculates the derivate of a datafield.
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< FramedPose > FramedPosePtr