28#include <VirtualRobot/Grasping/Grasp.h>
29#include <VirtualRobot/Grasping/GraspSet.h>
30#include <VirtualRobot/ManipulationObject.h>
31#include <VirtualRobot/MathTools.h>
32#include <VirtualRobot/Workspace/Manipulability.h>
52#include <IceUtil/UUID.h>
54#include <SimoxUtility/algorithm/string/string_tools.h>
55#include <VirtualRobot/RobotConfig.h>
56#include <VirtualRobot/math/Helpers.h>
58#include <VisionX/interface/components/VoxelGridProviderInterface.h>
60#include <RobotComponents/interface/components/MotionPlanning/MotionPlanningServer.h>
66static const DrawColor COLOR_ROBOT{1.0f, 1.0f, 0.5f, 1.0f};
74 "RobotFilePath",
"RobotAPI/robots/Armar3/ArmarIII.xml",
"File path of the robot to use");
76 "CollisionModel",
"PlatformTorsoHeadColModel",
"Collisionmodel of the robot");
79 "Armar3/reachability/reachability_right_hand_smoothened.bin;Armar3/reachability/"
80 "reachability_left_hand_smoothened.bin",
81 "Paths to manipulability and reachability files (';' delimited)");
87 "Minimum distance to the environment for all robot placements. "
88 "Much faster if set to zero.");
91 "1.0 is a good value for clear visualization, 0 the "
92 "visualization should not slow down the process",
96 "If false no visualization is done.",
100 "Number of robot placement that will be generated for each grasp",
103 "MinManipulabilityDecreaseFactor",
105 "Min initial manipulability in relation to max manipulabity value and factor by which this "
106 "threshold is decreased each trial",
111 "If true, the VoxelGridCSpace is used instead of the SimoxCSpace.",
115 "Name of the Voxel Grid Provider",
119 "EefNamePreferenceFilter",
121 "Prefer grasps where eef name contains this name by setting grasp success probability to "
122 "1. Set to empty string to disable.");
125 "Minimum Distance for a Placement",
129 "Maximum Distance for a Placement",
136 drawRobotId =
"local_robot_";
137 visuLayerName =
"SimpleRobotPlacement";
144 ARMARX_ERROR <<
"Could not find robot file: " << robotFilePath;
150 for (std::string& path : workspaceFilePaths)
152 std::string packageName = std::filesystem::path{path}.begin()->string();
154 <<
"Workspace file path '" << path
155 <<
"' could not be parsed correctly, because package name is empty";
157 path = project.getDataDir() +
"/" + path;
158 if (!std::filesystem::exists(path))
160 throw LocalException(
"File not found at ") << path;
177 srand(IceUtil::Time::now().toSeconds());
182 getProxy(robotStateComponentPrx,
"RobotStateComponent");
184 objectInstances =
wm->getObjectInstancesSegment();
185 agentInstances =
wm->getAgentInstancesSegment();
186 objectClasses = prior->getObjectClassesSegment();
195 wm, prior->getCommonStorage(), robotStateComponentPrx);
214 planningTasks.clear();
215 GraspingPlacementList result;
217 AgentInstancePtr::dynamicCast(agentInstances->getAgentInstanceByName(robotName));
218 std::shared_ptr<RemoteRobot> remoteRobot(
219 new RemoteRobot(robotStateComponentPrx->getSynchronizedRobot()));
220 robot->setGlobalPose(remoteRobot->getGlobalPose());
223 GeneratedGraspList filteredGrasps = filterGrasps(grasps);
224 visualizedGrid.reset();
225 entityDrawerPrx->clearLayer(visuLayerName);
234 prior->getCommonStorage());
238 cspace =
new SimoxCSpace(prior->getCommonStorage(),
false, 30);
240 cspace->addObjectsFromWorkingMemory(
wm);
241 AgentPlanningInformation agentData;
242 agentData.agentProjectNames = robotStateComponentPrx->getArmarXPackages();
243 agentData.agentRelativeFilePath = robotStateComponentPrx->getRobotFilename();
245 agentData.kinemaicChainNames = {};
246 agentData.collisionSetNames = {colModel};
247 agentData.initialJointValues = robot->getConfig()->getRobotNodeJointValueMap();
248 cspace->setAgent(agentData);
249 cspace->setStationaryObjectMargin(
251 cspace->initCollisionTest();
254 ARMARX_VERBOSE <<
"Searching " << placementsPerGrasp <<
" poses for " << filteredGrasps.size()
256 for (
const auto& g : filteredGrasps)
258 Eigen::Matrix4f graspPose = FramedPosePtr::dynamicCast(g.framedPose)->toGlobalEigen(robot);
264 std::map<float, GraspingPlacement> placementCandidates;
265 for (
int i = 0; i < placementsPerGrasp; ++i)
273 VirtualRobot::WorkspaceGridPtr reachGrid = createWorkspaceGrid(g, graspPose);
276 drawWorkspaceGrid(visualizedGrid);
282 float xGoal, yGoal, platformRotation;
284 getSuitablePosition(g, reachGrid, graspPose, xGoal, yGoal, platformRotation, score);
286 newPose->position->x = xGoal;
287 newPose->position->y = yGoal;
288 Eigen::Matrix4f newPoseEigen = newPose->toGlobalEigen(robot);
291 float x = newPoseEigen(0, 3);
292 float y = newPoseEigen(1, 3);
293 float z = newPoseEigen(2, 3);
294 newPoseEigen.block<3, 1>(0, 3) = Eigen::Vector3f::Zero();
296 transform = Eigen::Translation<float, 3>(
x, y, z) *
297 Eigen::AngleAxisf(platformRotation, Eigen::Vector3f(0, 0, 1));
303 ARMARX_INFO <<
"Inserting robot placement: " << resultPose->output();
304 placementCandidates[score] = GraspingPlacement{g, resultPose, 0};
306 if (!placementCandidates.empty())
312 result.push_back(placementCandidates.rbegin()->second);
315 Eigen::Matrix4f inverseRobotPose = robot->getGlobalPose().inverse();
316 std::map<std::pair<float, float>, GraspingPlacement> orderedMap;
318 for (GraspingPlacement& gp : result)
320 Eigen::Matrix4f mat =
321 inverseRobotPose * FramedPosePtr::dynamicCast(gp.robotPose)->toEigen();
322 Eigen::AngleAxisf aa(mat.block<3, 3>(0, 0));
323 float distanceLhs = mat.block<3, 1>(0, 3).
norm() * aa.angle() * 50;
326 float handPreferenceScore =
327 Contains(gp.grasp.eefName, EefNamePreferenceFilter,
true) ? 0.f : 1.f;
328 orderedMap[{handPreferenceScore, distanceLhs}] = gp;
332 entityDrawerPrx->removeLayer(visuLayerName);
340 std::vector<SimpleRobotPlacement::RobotPlacement>
placements;
348 [](
auto& a,
auto& b) { return a.score > b.score; });
360 planningTasks.clear();
361 GraspingPlacementList result;
363 AgentInstancePtr::dynamicCast(agentInstances->getAgentInstanceByName(robotName));
365 robot->setGlobalPose(remoteRobot->getGlobalPose());
368 GeneratedGraspList filteredGrasps = filterGrasps(grasps);
369 visualizedGrid.reset();
370 entityDrawerPrx->clearLayer(visuLayerName);
379 prior->getCommonStorage());
383 cspace =
new SimoxCSpace(prior->getCommonStorage(),
false, 30);
385 cspace->addObjectsFromWorkingMemory(
wm);
386 AgentPlanningInformation agentData;
387 agentData.agentProjectNames = robotStateComponentPrx->getArmarXPackages();
388 agentData.agentRelativeFilePath = robotStateComponentPrx->getRobotFilename();
390 agentData.kinemaicChainNames = {};
391 agentData.collisionSetNames = {colModel};
392 agentData.initialJointValues = robot->getConfig()->getRobotNodeJointValueMap();
393 cspace->setAgent(agentData);
394 cspace->setStationaryObjectMargin(
396 cspace->initCollisionTest();
399 ARMARX_VERBOSE <<
"Searching " << placementsPerGrasp <<
" poses for " << filteredGrasps.size()
402 std::vector<PlacementInfo> pis;
403 for (
const auto& g : filteredGrasps)
407 pi.graspPose = FramedPosePtr::dynamicCast(g.framedPose)->toGlobalEigen(robot);
408 pi.reachGrid = createWorkspaceGrid(g,
pi.graspPose);
409 drawWorkspaceGrid(visualizedGrid);
413 int maxIterations = 1;
414 for (
int n = 0; n < maxIterations; n++)
418 std::vector<SimpleRobotPlacement::RobotPlacement> placements =
419 getSuitablePositions(
pi.grasp,
pi.reachGrid,
pi.graspPose, 0.1, 10, 100);
420 pi.placements.insert(
pi.placements.end(), placements.begin(), placements.end());
429 if (
pi.placements.size() == 0)
439 Eigen::Matrix4f robotpose = ::math::Helpers::CreatePose(
440 Eigen::Vector3f(rp.
x, rp.
y, 0),
441 Eigen::AngleAxisf(rp.
z, Eigen::Vector3f::UnitZ()).toRotationMatrix());
443 pi.sortingInfo.first =
444 Contains(
pi.grasp.eefName, EefNamePreferenceFilter,
true) ? 0.f : 1.f;
445 pi.sortingInfo.second = -rp.
score;
447 entityDrawerPrx->removeLayer(visuLayerName);
449 pis.begin(), pis.end(), [](
auto& a,
auto& b) { return a.sortingInfo < b.sortingInfo; });
452 if (
pi.placements.size() > 0)
454 GraspingPlacement gp;
456 gp.score =
pi.placements.at(0).score;
457 gp.robotPose =
pi.resultPose;
459 result.push_back(gp);
467 const FramedPoseBasePtr& target,
468 const PlanarObstacleList& planarObstacles,
470 const Ice::Current&
c)
472 planningTasks.clear();
473 GraspingPlacementList result;
475 if (!hasWorkspace(endEffectorName))
477 ARMARX_ERROR <<
"No pre-loaded workspace found for EEF '" << endEffectorName <<
"'";
481 FramedPosePtr target_pose = FramedPosePtr::dynamicCast(target);
482 target_pose->changeToGlobal(robotStateComponentPrx->getSynchronizedRobot());
484 std::shared_ptr<RemoteRobot> remoteRobot(
485 new RemoteRobot(robotStateComponentPrx->getSynchronizedRobot()));
486 robot->setGlobalPose(remoteRobot->getGlobalPose());
489 AgentPlanningInformation agentData;
490 agentData.agentProjectNames = robotStateComponentPrx->getArmarXPackages();
491 agentData.agentRelativeFilePath = robotStateComponentPrx->getRobotFilename();
492 agentData.kinemaicChainNames = {};
493 agentData.collisionSetNames = {colModel};
494 agentData.initialJointValues = robot->getConfig()->getRobotNodeJointValueMap();
496 visualizedGrid.reset();
497 entityDrawerPrx->clearLayer(visuLayerName);
505 prior->getCommonStorage());
509 cspace =
new SimoxCSpace(prior->getCommonStorage(),
false, 30);
510 cspace->addObjectsFromWorkingMemory(
wm);
512 cspace->setAgent(agentData);
513 cspace->setStationaryObjectMargin(
517 for (
auto& obstacle : planarObstacles)
519 std::vector<Eigen::Vector3f> plane;
521 for (
auto& p : obstacle)
523 plane.push_back(FramedPositionPtr::dynamicCast(p)->toGlobalEigen(
524 robotStateComponentPrx->getSynchronizedRobot()));
527 cspace->addPlanarObject(plane);
530 cspace->initCollisionTest();
534 g.eefName = endEffectorName;
535 g.framedPose = target_pose;
538 ARMARX_INFO <<
"Searching " << placmentsPerGrasp <<
" poses for EEF pose "
539 << target_pose->toEigen();
542 VirtualRobot::MathTools::ConvexHull2DPtr placementArea_ch;
543 if (placementArea.size() > 2)
545 std::vector<Eigen::Vector2f> area;
546 for (
auto& p : placementArea)
548 area.push_back(FramedPositionPtr::dynamicCast(p)->toGlobalEigen(robot).head(2));
550 placementArea_ch = VirtualRobot::MathTools::createConvexHull2D(area);
553 for (
auto& p : placementArea_ch->vertices)
559 for (
int i = 0; i < placmentsPerGrasp; ++i)
562 VirtualRobot::WorkspaceGridPtr grid = createWorkspaceGrid(g, target_pose->toEigen());
563 drawWorkspaceGrid(visualizedGrid);
565 float xGoal, yGoal, platformRotation;
567 getSuitablePosition(g,
569 target_pose->toEigen(),
576 if (xGoal == 0 && yGoal == 0 && platformRotation == 0)
583 newPose->position->x = xGoal;
584 newPose->position->y = yGoal;
585 Eigen::Matrix4f newPoseEigen = newPose->toGlobalEigen(robot);
588 float x = newPoseEigen(0, 3);
589 float y = newPoseEigen(1, 3);
590 float z = newPoseEigen(2, 3);
591 newPoseEigen.block<3, 1>(0, 3) = Eigen::Vector3f::Zero();
593 transform = Eigen::Translation<float, 3>(
x, y, z) *
594 Eigen::AngleAxisf(platformRotation, Eigen::Vector3f(0, 0, 1));
598 result.push_back(GraspingPlacement{g, resultPose, score});
601 entityDrawerPrx->removeLayer(visuLayerName);
605VirtualRobot::WorkspaceRepresentationPtr
609 for (VirtualRobot::WorkspaceRepresentationPtr workspace : workspaces)
611 if (workspace->getTCP()->getName() == robot->getEndEffector(g.eefName)->getTcp()->getName())
617 return VirtualRobot::WorkspaceRepresentationPtr();
620VirtualRobot::WorkspaceGridPtr
621SimpleRobotPlacement::createWorkspaceGrid(GeneratedGrasp g,
const Eigen::Matrix4f& globalObjectPose)
623 static int counter = 0;
624 std::string graspName =
"some_random_grasp_" +
to_string(counter++);
625 std::string robotType = robotName;
626 std::string eef = g.eefName;
629 VirtualRobot::ManipulationObjectPtr dummyObject(
new ManipulationObject(
"dummyObject"));
630 dummyObject->setGlobalPose(globalObjectPose);
633 Eigen::Matrix4f tcpPoseGlobal = FramedPosePtr::dynamicCast(g.framedPose)->toGlobalEigen(robot);
634 Eigen::Matrix4f tcpPrePoseGlobal =
635 FramedPosePtr::dynamicCast(g.framedPrePose)->toGlobalEigen(robot);
636 Eigen::Matrix4f objectPoseInTcpFrame = tcpPoseGlobal.inverse() * globalObjectPose;
637 VirtualRobot::GraspPtr dummyGrasp(
new Grasp(graspName, robotType, eef, objectPoseInTcpFrame));
638 VirtualRobot::GraspPtr dummyPrepose(
639 new Grasp(graspName, robotType, eef, tcpPrePoseGlobal.inverse() * globalObjectPose));
641 VirtualRobot::WorkspaceRepresentationPtr ws;
646 Eigen::Vector3f minBB, maxBB;
647 ws->getWorkspaceExtends(minBB, maxBB);
648 VirtualRobot::WorkspaceGridPtr reachGridPrepose;
649 reachGridPrepose.reset(
new WorkspaceGrid(
650 minBB(0), maxBB(0), minBB(1), maxBB(1), ws->getDiscretizeParameterTranslation()));
651 reachGridPrepose->setGridPosition(globalObjectPose(0, 3), globalObjectPose(1, 3));
652 reachGridPrepose->fillGridData(ws, dummyObject, dummyPrepose, robot->getRootNode());
655 VirtualRobot::WorkspaceGridPtr reachGridGrasp;
656 reachGridGrasp.reset(
new WorkspaceGrid(
657 minBB(0), maxBB(0), minBB(1), maxBB(1), ws->getDiscretizeParameterTranslation()));
658 reachGridGrasp->setGridPosition(globalObjectPose(0, 3), globalObjectPose(1, 3));
659 ARMARX_INFO <<
" grasp pose: " << dummyGrasp->getTcpPoseGlobal(globalObjectPose);
660 ARMARX_INFO <<
" prepose pose: " << dummyPrepose->getTcpPoseGlobal(globalObjectPose);
661 reachGridGrasp->fillGridData(ws, dummyObject, dummyGrasp, robot->getRootNode());
683 return reachGridGrasp;
688SimpleRobotPlacement::getSuitablePosition(
689 const GeneratedGrasp& g,
690 VirtualRobot::WorkspaceGridPtr reachGrid,
691 const Eigen::Matrix4f& globalObjectPose,
694 float& storeGlobalYaw,
696 const VirtualRobot::MathTools::ConvexHull2DPtr& placementArea)
700 Eigen::Matrix4f originalRobotPoseGlobal = robot->getGlobalPose();
701 Eigen::Matrix4f tmpRobotPoseGlobal = originalRobotPoseGlobal;
704 float minX, maxX, minY, maxY;
705 reachGrid->getExtends(minX, maxX, minY, maxY);
708 reachGrid->getCells(nX, nY);
709 int maxEntry = reachGrid->getMaxEntry();
710 int minRequiredEntry = maxEntry;
712 bool collision =
true;
713 std::vector<GraspPtr> dummyGrasps;
714 float minCollisionDistance =
getProperty<float>(
"MinimumDistanceToEnvironment").getValue();
716 auto collisionCheckVisu =
"collisionCheckRobotVisu";
719 entityDrawerPrx->setRobotVisu(
722 robotStateComponentPrx->getRobotFilename(),
723 simox::alg::join(robotStateComponentPrx->getArmarXPackages(),
","),
725 auto config = robotStateComponentPrx->getSynchronizedRobot()->getConfig();
727 entityDrawerPrx->updateRobotConfig(visuLayerName, collisionCheckVisu, config);
732 float minManipulabilityDecreaseFactor =
734 int maxTrials = 1000;
743 if (counter >= maxTrials)
745 ARMARX_ERROR <<
"Could not find a collision free robot placement.";
752 minRequiredEntry *= minManipulabilityDecreaseFactor;
753 minRequiredEntry = std::max<int>(minRequiredEntry, maxEntry * 0.1f);
755 if (!reachGrid->getRandomPos(
756 minRequiredEntry, storeGlobalX, storeGlobalY, dummyGrasps, 100, &entries))
761 (Eigen::Vector2f(storeGlobalX, storeGlobalY) - globalObjectPose.block<2, 1>(0, 3))
763 if (distance2D > maxDistance2D)
766 ARMARX_INFO <<
"Placement too far away: " << distance2D;
769 if (distance2D < minDistance2D)
771 ARMARX_INFO <<
"Placement too close: " << distance2D;
775 if (placementArea !=
nullptr &&
776 !VirtualRobot::MathTools::isInside(Eigen::Vector2f(storeGlobalX, storeGlobalY),
779 ARMARX_INFO <<
"Generated placement (" << storeGlobalX <<
", " << storeGlobalY
780 <<
") lies outside the permitted area => Retry.";
785 tmpRobotPoseGlobal = originalRobotPoseGlobal;
786 tmpRobotPoseGlobal(0, 3) = storeGlobalX;
787 tmpRobotPoseGlobal(1, 3) = storeGlobalY;
789 storeGlobalYaw = getPlatformRotation(tmpRobotPoseGlobal, globalObjectPose);
790 score = reachGrid->getEntry(storeGlobalX, storeGlobalY);
793 float x = tmpRobotPoseGlobal(0, 3);
794 float y = tmpRobotPoseGlobal(1, 3);
795 float z = tmpRobotPoseGlobal(2, 3);
796 if (std::isnan(x) || std::isnan(y) || std::isnan(z))
801 tmpRobotPoseGlobal.block<3, 1>(0, 3) = Eigen::Vector3f::Zero();
803 transform = Eigen::Translation<float, 3>(x, y, z) *
804 Eigen::AngleAxisf(storeGlobalYaw, Eigen::Vector3f(0, 0, 1));
805 tmpRobotPoseGlobal =
transform * tmpRobotPoseGlobal;
807 robot->setGlobalPose(tmpRobotPoseGlobal);
808 cspace->getAgentSceneObj()->setGlobalPose(tmpRobotPoseGlobal);
809 int max = wsr->getMaxEntry();
811 <<
"Candidate pose: "
812 << 100. * wsr->getEntry(FramedPosePtr::dynamicCast(g.framedPrePose)->toEigen()) /
max
813 <<
"% min. required: " << minRequiredEntry <<
" trial: " << counter * 100 / maxTrials
815 if (!wsr->isCovered(FramedPosePtr::dynamicCast(g.framedPrePose)->toEigen()))
821 collision = cspace->getCD().isInCollision();
822 if (minCollisionDistance > 0)
824 float distance = cspace->getCD().getDistance();
825 if (
distance < minCollisionDistance)
835 updateRobot(collisionCheckVisu,
837 collision ? DrawColor{1.0, 0.0, 0.0, 1} : DrawColor{0.0, 1.0, 0.0, 1});
838 usleep(500000 * visuSlowdownFactor);
874 robot->setGlobalPose(originalRobotPoseGlobal);
878std::vector<SimpleRobotPlacement::RobotPlacement>
879SimpleRobotPlacement::getSuitablePositions(
const GeneratedGrasp& g,
880 WorkspaceGridPtr reachGrid,
881 const Eigen::Matrix4f& globalObjectPose,
882 float requiredReachabilityFraction,
885 const MathTools::ConvexHull2DPtr& placementArea)
888 std::vector<SimpleRobotPlacement::RobotPlacement> placements;
890 Eigen::Matrix4f originalRobotPoseGlobal = robot->getGlobalPose();
891 Eigen::Matrix4f tmpRobotPoseGlobal = originalRobotPoseGlobal;
894 float minX, maxX, minY, maxY;
895 reachGrid->getExtends(minX, maxX, minY, maxY);
898 reachGrid->getCells(nX, nY);
899 int maxEntry = reachGrid->getMaxEntry();
900 int minRequiredEntry = maxEntry * requiredReachabilityFraction;
902 bool collision =
true;
903 std::vector<GraspPtr> dummyGrasps;
904 float minCollisionDistance =
getProperty<float>(
"MinimumDistanceToEnvironment").getValue();
905 auto collisionCheckVisu =
"collisionCheckRobotVisu";
908 entityDrawerPrx->setRobotVisu(
911 robotStateComponentPrx->getRobotFilename(),
912 simox::alg::join(robotStateComponentPrx->getArmarXPackages(),
","),
914 auto config = robotStateComponentPrx->getSynchronizedRobot()->getConfig();
916 entityDrawerPrx->updateRobotConfig(visuLayerName, collisionCheckVisu, config);
922 for (
int n = 0;
n < maxIterations;
n++)
926 float storeGlobalX, storeGlobalY;
927 if (!reachGrid->getRandomPos(
928 minRequiredEntry, storeGlobalX, storeGlobalY, dummyGrasps, 100, &entries))
933 (Eigen::Vector2f(storeGlobalX, storeGlobalY) - globalObjectPose.block<2, 1>(0, 3))
935 if (distance2D > 1000)
938 ARMARX_INFO <<
"Placement too far away: " << distance2D;
941 if (distance2D < 400)
943 ARMARX_INFO <<
"Placement too close: " << distance2D;
947 if (placementArea !=
nullptr &&
948 !VirtualRobot::MathTools::isInside(Eigen::Vector2f(storeGlobalX, storeGlobalY),
951 ARMARX_INFO <<
"Generated placement (" << storeGlobalX <<
", " << storeGlobalY
952 <<
") lies outside the permitted area => Retry.";
957 tmpRobotPoseGlobal = originalRobotPoseGlobal;
958 tmpRobotPoseGlobal(0, 3) = storeGlobalX;
959 tmpRobotPoseGlobal(1, 3) = storeGlobalY;
961 float storeGlobalYaw = getPlatformRotation(tmpRobotPoseGlobal, globalObjectPose);
962 float score = reachGrid->getEntry(storeGlobalX, storeGlobalY);
965 float x = tmpRobotPoseGlobal(0, 3);
966 float y = tmpRobotPoseGlobal(1, 3);
967 float z = tmpRobotPoseGlobal(2, 3);
968 if (std::isnan(x) || std::isnan(y) || std::isnan(z))
973 tmpRobotPoseGlobal.block<3, 1>(0, 3) = Eigen::Vector3f::Zero();
975 transform = Eigen::Translation<float, 3>(x, y, z) *
976 Eigen::AngleAxisf(storeGlobalYaw, Eigen::Vector3f(0, 0, 1));
977 tmpRobotPoseGlobal =
transform * tmpRobotPoseGlobal;
979 robot->setGlobalPose(tmpRobotPoseGlobal);
980 cspace->getAgentSceneObj()->setGlobalPose(tmpRobotPoseGlobal);
981 int max = wsr->getMaxEntry();
983 <<
"Candidate pose: "
984 << 100. * wsr->getEntry(FramedPosePtr::dynamicCast(g.framedPrePose)->toEigen()) /
max
985 <<
"% min. required: " << minRequiredEntry;
986 if (!wsr->isCovered(FramedPosePtr::dynamicCast(g.framedPrePose)->toEigen()))
992 collision = cspace->getCD().isInCollision();
993 if (minCollisionDistance > 0)
995 float distance = cspace->getCD().getDistance();
996 if (
distance < minCollisionDistance)
1006 updateRobot(collisionCheckVisu,
1008 collision ? DrawColor{1.0, 0.0, 0.0, 1} : DrawColor{0.0, 1.0, 0.0, 1});
1009 usleep(500000 * visuSlowdownFactor);
1019 pl.x = storeGlobalX;
1020 pl.y = storeGlobalY;
1021 pl.z = storeGlobalYaw;
1023 placements.push_back(pl);
1029 if ((
int)placements.size() > requiredCount)
1035 ARMARX_INFO <<
"Found " << placements.size() <<
" collision free placements";
1036 robot->setGlobalPose(originalRobotPoseGlobal);
1041SimpleRobotPlacement::getPlatformRotation(
const Eigen::Matrix4f& frameGlobal,
1042 const Eigen::Matrix4f& globalTarget)
1044 Eigen::Matrix4f localTarget = frameGlobal.inverse() * globalTarget;
1045 float x = localTarget(0, 3);
1046 float y = localTarget(1, 3);
1048 float alpha = std::atan2(y, x);
1054SimpleRobotPlacement::loadRobot()
1056 robot = VirtualRobot::RobotIO::loadRobot(robotFilePath);
1059 ARMARX_ERROR <<
"Failed to load robot: " << robotFilePath;
1063 std::shared_ptr<RemoteRobot> remoteRobot(
1064 new RemoteRobot(robotStateComponentPrx->getSynchronizedRobot()));
1065 robot->setGlobalPose(remoteRobot->getGlobalPose());
1069SimpleRobotPlacement::loadWorkspaces()
1071 for (std::string wsFile : workspaceFilePaths)
1073 VirtualRobot::WorkspaceRepresentationPtr newSpace;
1079 newSpace.reset(
new Manipulability(robot));
1080 newSpace->load(wsFile);
1083 ARMARX_INFO <<
"Map '" << wsFile <<
"' loaded as Manipulability map";
1094 newSpace.reset(
new Reachability(robot));
1095 newSpace->load(wsFile);
1098 ARMARX_INFO <<
"Map '" << wsFile <<
"' loaded as Reachability map";
1108 workspaces.push_back(newSpace);
1112 ARMARX_ERROR <<
"Failed to load map '" << wsFile <<
"'";
1118SimpleRobotPlacement::hasWorkspace(std::string tcp)
1120 for (VirtualRobot::WorkspaceRepresentationPtr ws : workspaces)
1122 if (ws->getTCP()->getName() == tcp)
1131SimpleRobotPlacement::filterGrasps(
const GeneratedGraspList grasps)
1133 GeneratedGraspList filteredGrasps = grasps;
1134 GeneratedGraspList::iterator it = filteredGrasps.begin();
1135 while (it != filteredGrasps.end())
1137 GeneratedGrasp g = (*it);
1138 auto tcpName = robot->getEndEffector(g.eefName)->getTcp()->getName();
1139 if (!hasWorkspace(tcpName))
1142 <<
" is not available in workspace";
1143 it = filteredGrasps.erase(it);
1150 return filteredGrasps;
1154SimpleRobotPlacement::drawNewRobot(Eigen::Matrix4f globalPose)
1160 static int suffix = 0;
1161 std::string
id = drawRobotId +
to_string(suffix++);
1162 entityDrawerPrx->setRobotVisu(
1165 robotStateComponentPrx->getRobotFilename(),
1166 simox::alg::join(robotStateComponentPrx->getArmarXPackages(),
","),
1169 auto config = robotStateComponentPrx->getSynchronizedRobot()->getConfig();
1171 entityDrawerPrx->updateRobotConfig(visuLayerName,
id, config);
1172 updateRobot(
id, globalPose, COLOR_ROBOT);
1176SimpleRobotPlacement::updateRobot(std::string
id, Eigen::Matrix4f globalPose, DrawColor color)
1182 entityDrawerPrx->updateRobotColor(visuLayerName,
id, color);
1183 entityDrawerPrx->updateRobotPose(visuLayerName,
id,
new Pose(globalPose));
1187SimpleRobotPlacement::drawWorkspaceGrid(
const GeneratedGrasp& grasp,
1188 const std::string& objectInstanceEntityId)
1195 ObjectInstancePtr::dynamicCast(objectInstances->getEntityById(objectInstanceEntityId));
1196 Eigen::Matrix4f objectPose = instance->getPose()->toGlobalEigen(robot);
1198 drawWorkspaceGrid(createWorkspaceGrid(grasp, objectPose));
1202SimpleRobotPlacement::drawWorkspaceGrid(VirtualRobot::WorkspaceGridPtr reachGrid)
1209 Eigen::Matrix4f pose = Eigen::Matrix4f::Identity();
1210 float minX, maxX, minY, maxY;
1211 reachGrid->getExtends(minX, maxX, minY, maxY);
1217 reachGrid->getCells(nX, nY);
1219 int maxEntry = reachGrid->getMaxEntry();
1221 float sizeX = (maxX - minX) / (
float)nX;
1222 float sizeY = (maxY - minY) / (
float)nY;
1223 auto batch = debugDrawerPrx->ice_batchOneway();
1225 for (
int x = 0; x < nX; x++)
1227 float xPos = minX + (
float)x * sizeX + 0.5f * sizeX;
1229 for (
int y = 0; y < nY; y++)
1231 int cellEntry = reachGrid->getCellEntry(x, y);
1235 float intensity = (
float)cellEntry / (
float)maxEntry;
1237 float yPos = minY + (
float)y * sizeY + 0.5f * sizeY;
1244 VirtualRobot::ColorMap cm = VirtualRobot::ColorMap::eHot;
1245 VirtualRobot::CoinVisualizationFactory::Color color = cm.getColor(intensity);
1247 armarx::DrawColor voxelColor;
1248 voxelColor.r = color.r;
1249 voxelColor.g = color.g;
1250 voxelColor.b = color.b;
1253 batch->setBoxVisu(visuLayerName,
1254 "reachGridVoxel_" +
to_string(counter++),
1261 batch->ice_flushBatchRequests();
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Property< PropertyType > getProperty(const std::string &name)
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.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
The SimoxCSpace contains a set of stationary obstacles and an agent.
static SimoxCSpacePtr PrefetchWorkingMemoryObjects(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx, memoryx::CommonStorageInterfacePrx commonStoragePrx, RobotStateComponentInterfacePrx rsc)
Load objects from WorkingMemory and puts them into the mesh cache.
SimpleRobotPlacementPropertyDefinitions(std::string prefix)
void onInitComponent() override
void onDisconnectComponent() override
GraspingPlacementList generateRobotPlacements(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
Computes a list of candidate robot placements for a list of grasps.
void onConnectComponent() override
GraspingPlacementList generateRobotPlacementsEx(const GeneratedGraspList &grasps, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
VirtualRobot::WorkspaceRepresentationPtr getWorkspaceRepresentation(const GeneratedGrasp &g)
Tries to get a workspace with the same TCP as the EEF of the robot.
GraspingPlacementList generateRobotPlacementsForGraspPose(const std::string &endEffectorName, const FramedPoseBasePtr &target, const PlanarObstacleList &planarObstacles, const ConvexHull &placementArea, const Ice::Current &c=Ice::emptyCurrent) override
Computes a list of candidate robot placements for a grasp pose.
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#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_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
#define TIMING_START(name)
Helper macro to do timing tests.
#define TIMING_END(name)
Prints duration.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< Pose > PosePtr
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
bool Contains(const ContainerType &container, const ElementType &searchElement)
void getMapValues(const MapType &map, OutputIteratorType it)
std::shared_ptr< RemoteRobot > RemoteRobotPtr
const std::string & to_string(const std::string &s)
IceInternal::Handle< FramedPose > FramedPosePtr
constexpr auto n() noexcept
constexpr auto entries(std::index_sequence< I... >) noexcept
IceInternal::Handle< AgentInstance > AgentInstancePtr
Typedef of AgentEntityPtr as IceInternal::Handle<AgentEntity> for convenience.
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
double norm(const Point &a)
double distance(const Point &a, const Point &b)
Eigen::Matrix4f graspPose
armarx::FramedPosePtr resultPose
VirtualRobot::WorkspaceGridPtr reachGrid
std::pair< float, float > sortingInfo
std::vector< SimpleRobotPlacement::RobotPlacement > placements