25 #include <SimoxUtility/math/convert.h>
33 #define STATE_POSITION 0
34 #define STATE_VELOCITY 1
35 #define STATE_ACCELERATION 2
51 armarx::CollisionModel);
52 debugDrawer->updateRobotColor(
"Preview",
"previewRobot", DrawColor{0, 1, 0, 0.5});
67 return task->isRunning();
79 std::unique_lock lock(motionMutex);
99 std::unique_lock lock(motionMutex);
114 if (
task->isRunning())
123 return !(
task->isRunning());
140 std::unique_lock lock(motionMutex);
144 int maxDerivative = 1;
148 for (
size_t i = 0; i <
jointNames.size(); ++i)
159 targetPosValue += it->second;
162 debugTargetValues[jointName] =
new Variant(targetPosValue);
177 auto pid =
PIDs.find(jointName);
179 if (pid !=
PIDs.end())
182 auto cv = pid->second->getControlValue();
187 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
188 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
189 debugVelocityValues[jointName] =
new Variant(targetVel);
202 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
208 localModel->setGlobalPoseForRobotNode(customRootNode, p);
218 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
219 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
225 std::unique_lock lock(motionMutex);
228 if (moveToFrameZeroPose)
247 std::unique_lock lock(motionMutex);
253 for (std::string& p : proj)
260 ARMARX_WARNING <<
"ArmarX Package " << p <<
" has not been found!";
271 localModel = VirtualRobot::RobotIO::loadRobot(
272 modelFileName, VirtualRobot::RobotIO::RobotDescription::eStructure);
273 if (getProperty<std::string>(
"CustomRootNode").isSet() &&
274 !getProperty<std::string>(
"CustomRootNode").getValue().
empty())
277 localModel->getRobotNode(getProperty<std::string>(
"CustomRootNode").getValue());
281 customRootNode.reset();
286 jointTraj = TrajectoryPtr::dynamicCast(trajs);
291 ARMARX_ERROR <<
"Error when loading TrajectoryPlayer: cannot load jointTraj !!!";
304 ARMARX_ERROR <<
"Not all trajectory dimensions are named !!! (would cause problems when "
305 "using kinematicUnit)";
309 NameControlModeMap modes;
310 LimitlessStateSeq limitlessStates;
312 for (
size_t i = 0; i <
jointNames.size(); ++i)
318 modes[jointName] = eVelocityControl;
322 modes[jointName] = ePositionControl;
332 VirtualRobot::RobotNodePtr rn =
localModel->getRobotNode(jointName);
335 ls.enabled = rn->isLimitless();
336 ls.limitLo = rn->getJointLimitLo();
337 ls.limitHi = rn->getJointLimitHi();
340 ARMARX_INFO <<
"limitless status - " << jointName <<
": " << rn->isLimitless();
341 limitlessStates.push_back(ls);
346 if (limitlessStates.size() ==
jointNames.size())
349 jointTraj->setLimitless(limitlessStates);
379 NameControlModeMap modes;
381 for (
size_t i = 0; i <
jointNames.size(); ++i)
387 modes[jointName] = eVelocityControl;
391 modes[jointName] = ePositionControl;
410 std::unique_lock lock(jointAnglesMutex);
411 latestJointAngles = angles;
418 usingProxy(getProperty<std::string>(
"KinematicUnitName").getValue());
423 loopPlayback = getProperty<bool>(
"LoopPlayback").getValue();
424 maxVel = getProperty<float>(
"absMaximumVelocity").getValue();
426 usingTopic(getProperty<std::string>(
"KinematicTopicName").getValue());
435 getProperty<std::string>(
"KinematicUnitName").getValue());
436 debugObserver = getTopic<DebugObserverInterfacePrx>(
"DebugObserver");
437 debugDrawer = getTopic<armarx::DebugDrawerInterfacePrx>(
"DebugDrawerUpdates");
438 armarxProject = getProperty<std::string>(
"ArmarXProjects").getValue();
441 Eigen::Vector3f position(getProperty<float>(
"Offset.x").getValue(),
442 getProperty<float>(
"Offset.y").getValue(),
443 getProperty<float>(
"Offset.z").getValue());
444 Eigen::Vector3f orientation(getProperty<float>(
"Offset.roll").getValue(),
445 getProperty<float>(
"Offset.pitch").getValue(),
446 getProperty<float>(
"Offset.yaw").getValue());
447 offset = simox::math::pos_rpy_to_mat4f(position, orientation);
547 std::unique_lock lock(motionMutex);
553 int maxDerivative = 1;
555 std::vector<Ice::DoubleSeq> states =
559 for (
size_t i = 0; i <
jointNames.size(); ++i)
571 targetPosValue += it->second;
574 debugTargetValues[jointName] =
new Variant(targetPosValue);
591 auto pid =
PIDs.find(jointName);
593 if (pid !=
PIDs.end())
595 auto cv = pid->second->getControlValue();
611 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
612 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
614 debugVelocityValues[jointName] =
new Variant(targetVel);
627 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
633 localModel->setGlobalPoseForRobotNode(customRootNode, p);
661 RobotPoseUnitInterfacePrx robotPoseUnitPrx = getProxy<RobotPoseUnitInterfacePrx>(
662 getProperty<std::string>(
"RobotPoseUnitName").getValue());
664 robotPoseUnitPrx->moveTo(PoseBasePtr::dynamicCast(
targetRobotPose), 0.001f, 0.001f);
691 std::unique_lock lock(jointAnglesMutex);
692 updatePIDController(latestJointAngles);
695 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
696 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
701 TrajectoryPlayer::updatePIDController(
const NameValueMap& angles)
709 for (
const auto& joint : angles)
711 const std::string& name = joint.first;
718 auto it =
PIDs.find(name);
720 if (it ==
PIDs.end())
723 getProperty<float>(
"Ki").
getValue(),
724 getProperty<float>(
"Kd").
getValue(),
729 it =
PIDs.find(name);
744 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
748 std::unique_lock lock(jointAnglesMutex);
751 for (NameValueMap::iterator it = latestJointAngles.begin(); it != latestJointAngles.end(); it++)
753 std::string jointName = it->first;
754 float jointValue = it->second;
756 float lowLimit =
localModel->getRobotNode(jointName)->getJointLimitLow();
757 float highLimit =
localModel->getRobotNode(jointName)->getJointLimitHigh();
758 DrawColor errColor = {1, 0, 0, 1};
759 DrawColor warnColor = {1, 1, 0, 1};
760 DrawColor normColor = {0, 1, 0, 1};
761 if (jointValue < lowLimit || jointValue > highLimit)
763 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, errColor);
767 float dist = highLimit - lowLimit;
769 bool isWarning = ((jointValue < (lowLimit + 0.1 * dist)) && (jointValue >= lowLimit)) ||
770 ((jointValue > (highLimit - 0.1 * dist)) && (jointValue <= highLimit));
774 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, warnColor);
778 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, normColor);
790 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
794 std::unique_lock lock(jointAnglesMutex);
796 localModel->setJointValues(latestJointAngles);