26 #include <SimoxUtility/math/convert.h>
31 #define STATE_POSITION 0
32 #define STATE_VELOCITY 1
33 #define STATE_ACCELERATION 2
45 debugDrawer->updateRobotColor(
"Preview",
"previewRobot", DrawColor {0, 1, 0, 0.5});
59 return task->isRunning();
72 std::unique_lock lock(motionMutex);
91 std::unique_lock lock(motionMutex);
106 if (
task->isRunning())
115 return !(
task->isRunning());
131 std::unique_lock lock(motionMutex);
135 int maxDerivative = 1;
139 for (
size_t i = 0; i <
jointNames.size(); ++i)
150 targetPosValue += it->second;
153 debugTargetValues[jointName] =
new Variant(targetPosValue);
168 auto pid =
PIDs.find(jointName);
170 if (pid !=
PIDs.end())
173 auto cv = pid->second->getControlValue();
179 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
180 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
181 debugVelocityValues[jointName] =
new Variant(targetVel);
194 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
200 localModel->setGlobalPoseForRobotNode(customRootNode, p);
210 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
211 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
221 std::unique_lock lock(motionMutex);
224 if (moveToFrameZeroPose)
243 std::unique_lock lock(motionMutex);
249 for (std::string& p : proj)
256 ARMARX_WARNING <<
"ArmarX Package " << p <<
" has not been found!";
267 localModel = VirtualRobot::RobotIO::loadRobot(
modelFileName, VirtualRobot::RobotIO::RobotDescription::eStructure);
268 if (getProperty<std::string>(
"CustomRootNode").isSet() && !getProperty<std::string>(
"CustomRootNode").getValue().
empty())
270 customRootNode =
localModel->getRobotNode(getProperty<std::string>(
"CustomRootNode").getValue());
274 customRootNode.reset();
279 jointTraj = TrajectoryPtr::dynamicCast(trajs);
284 ARMARX_ERROR <<
"Error when loading TrajectoryPlayer: cannot load jointTraj !!!";
297 ARMARX_ERROR <<
"Not all trajectory dimensions are named !!! (would cause problems when using kinematicUnit)";
301 NameControlModeMap modes;
302 LimitlessStateSeq limitlessStates;
304 for (
size_t i = 0; i <
jointNames.size(); ++i)
310 modes[jointName] = eVelocityControl;
314 modes[jointName] = ePositionControl;
324 VirtualRobot::RobotNodePtr rn =
localModel->getRobotNode(jointName);
327 ls.enabled = rn->isLimitless();
328 ls.limitLo = rn->getJointLimitLo();
329 ls.limitHi = rn->getJointLimitHi();
332 ARMARX_INFO <<
"limitless status - " << jointName <<
": " << rn->isLimitless();
333 limitlessStates.push_back(ls);
338 if (limitlessStates.size() ==
jointNames.size())
341 jointTraj->setLimitless(limitlessStates);
372 NameControlModeMap modes;
374 for (
size_t i = 0; i <
jointNames.size(); ++i)
380 modes[jointName] = eVelocityControl;
384 modes[jointName] = ePositionControl;
401 std::unique_lock lock(jointAnglesMutex);
402 latestJointAngles = angles;
409 usingProxy(getProperty<std::string>(
"KinematicUnitName").getValue());
414 loopPlayback = getProperty<bool>(
"LoopPlayback").getValue();
415 maxVel = getProperty<float>(
"absMaximumVelocity").getValue();
417 usingTopic(getProperty<std::string>(
"KinematicTopicName").getValue());
425 kinematicUnit = getProxy<KinematicUnitInterfacePrx>(getProperty<std::string>(
"KinematicUnitName").getValue());
426 debugObserver = getTopic<DebugObserverInterfacePrx>(
"DebugObserver");
427 debugDrawer = getTopic<armarx::DebugDrawerInterfacePrx>(
"DebugDrawerUpdates");
428 armarxProject = getProperty<std::string>(
"ArmarXProjects").getValue();
431 Eigen::Vector3f position(getProperty<float>(
"Offset.x").getValue(), getProperty<float>(
"Offset.y").getValue(), getProperty<float>(
"Offset.z").getValue());
432 Eigen::Vector3f orientation(getProperty<float>(
"Offset.roll").getValue(), getProperty<float>(
"Offset.pitch").getValue(), getProperty<float>(
"Offset.yaw").getValue());
433 offset = simox::math::pos_rpy_to_mat4f(position, orientation);
534 std::unique_lock lock(motionMutex);
540 int maxDerivative = 1;
546 for (
size_t i = 0; i <
jointNames.size(); ++i)
557 targetPosValue += it->second;
560 debugTargetValues[jointName] =
new Variant(targetPosValue);
577 auto pid =
PIDs.find(jointName);
579 if (pid !=
PIDs.end())
581 auto cv = pid->second->getControlValue();
598 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
599 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
601 debugVelocityValues[jointName] =
new Variant(targetVel);
614 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
620 localModel->setGlobalPoseForRobotNode(customRootNode, p);
649 RobotPoseUnitInterfacePrx robotPoseUnitPrx
650 = getProxy<RobotPoseUnitInterfacePrx>(getProperty<std::string>(
"RobotPoseUnitName").getValue());
652 robotPoseUnitPrx->moveTo(PoseBasePtr::dynamicCast(
targetRobotPose), 0.001f, 0.001f);
681 std::unique_lock lock(jointAnglesMutex);
682 updatePIDController(latestJointAngles);
685 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
686 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
694 void TrajectoryPlayer::updatePIDController(
const NameValueMap& angles)
702 for (
const auto& joint : angles)
704 const std::string& name = joint.first;
711 auto it =
PIDs.find(name);
713 if (it ==
PIDs.end())
716 getProperty<float>(
"Ki").
getValue(),
717 getProperty<float>(
"Kd").
getValue(),
723 it =
PIDs.find(name);
738 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
742 std::unique_lock lock(jointAnglesMutex);
745 for (NameValueMap::iterator it = latestJointAngles.begin(); it != latestJointAngles.end(); it++)
747 std::string jointName = it->first;
748 float jointValue = it->second;
750 float lowLimit =
localModel->getRobotNode(jointName)->getJointLimitLow();
751 float highLimit =
localModel->getRobotNode(jointName)->getJointLimitHigh();
752 DrawColor errColor = {1, 0, 0, 1};
753 DrawColor warnColor = {1, 1, 0, 1};
754 DrawColor normColor = {0, 1, 0, 1};
755 if (jointValue < lowLimit || jointValue > highLimit)
757 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, errColor);
761 float dist = highLimit - lowLimit;
763 bool isWarning = ((jointValue < (lowLimit + 0.1 * dist)) && (jointValue >= lowLimit)) ||
764 ((jointValue > (highLimit - 0.1 * dist)) && (jointValue <= highLimit));
768 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, warnColor);
772 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, normColor);
786 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
790 std::unique_lock lock(jointAnglesMutex);
792 localModel->setJointValues(latestJointAngles);