30 #include <Eigen/Geometry>
32 #include <VirtualRobot/EndEffector/EndEffector.h>
33 #include <VirtualRobot/RobotConfig.h>
35 #include <RobotAPI/interface/objectpose/ObjectPoseStorageInterface.h>
52 simulatorPrxName = getProperty<std::string>(
"SimulatorProxyName").getValue();
61 if (getProperty<bool>(
"UseLegacyWorkingMemory").getValue())
75 workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(
"WorkingMemory",
false,
"",
false);
111 "Name of the object pose storage (only used if necessary).");
163 ARMARX_WARNING <<
"Could not get joint angles fvrom simulator...";
171 std::string myShapeName = shapeName;
181 if (!eef->hasPreshape(myShapeName))
183 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " << eef->getName() <<
". Looking for partial match";
185 bool foundMatch =
false;
187 for (
const std::string& name : eef->getPreshapes())
189 if (name.find(myShapeName) != std::string::npos)
200 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " << eef->getName() <<
" available shapes: " << eef->getPreshapes();
205 VirtualRobot::RobotConfigPtr config = eef->getPreshape(myShapeName);
206 std::map < std::string, float >
jointAngles = config->getRobotNodeJointValueMap();
208 NameControlModeMap controlModes;
210 for (std::pair<std::string, float> pair :
jointAngles)
212 controlModes.insert(std::make_pair(pair.first, ePositionControl));
215 kinematicUnitPrx->switchControlMode(controlModes);
221 const std::string& shapeName,
const std::string& objectInstanceName,
const Ice::Current&
c)
223 std::string myShapeName = shapeName;
224 ARMARX_INFO <<
"Setting shape " << myShapeName <<
" while checking for collision with " << objectInstanceName;
232 if (!eef->hasPreshape(myShapeName))
234 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " << eef->getName() <<
". Looking for partial match";
236 bool foundMatch =
false;
237 for (
const std::string& name : eef->getPreshapes())
239 if (name.find(myShapeName) != std::string::npos)
250 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " << eef->getName() <<
" available shapes: " << eef->getPreshapes();
255 VirtualRobot::EndEffectorPtr endeffector = robot->getEndEffector(eef->getName());
258 auto loadFromObjectPoseStorage = [
this, &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
263 auto fetchObjectPose = [
this, &objectID, &client]() -> std::optional<Eigen::Matrix4f>
269 if (
auto it = objectPoses.find(objectID); it != objectPoses.end())
271 return it->second.objectPoseGlobal;
276 if (
auto objectPose = fetchObjectPose())
281 object->setGlobalPose(objectPose.value());
288 auto loadFromWorkingMemory = [
this, &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
291 memoryx::ObjectInstancePtr::dynamicCast(workingMemoryPrx->getObjectInstancesSegment()->getObjectInstanceByName(objectInstanceName));
296 const std::string objectClassName = objInstance->getMostProbableClass();
298 auto classes = workingMemoryPrx->getObjectClassesSegment()->addPriorClassWithSubclasses(objectClassName);
306 workingMemoryPrx->getObjectClassesSegment()->getEntityByName(objectClassName)->ice_clone());
313 objInstance->setPose(objInstance->getPose()->toGlobal(robot));
314 simoxObject->updateFromEntity(objInstance);
316 return simoxObject->getManipulationObject();
319 VirtualRobot::ManipulationObjectPtr manipulationObject =
nullptr;
320 if (not manipulationObject)
322 manipulationObject = loadFromObjectPoseStorage();
324 if (not manipulationObject and workingMemoryPrx)
326 manipulationObject = loadFromWorkingMemory();
329 if (manipulationObject)
331 endeffector->closeActors(manipulationObject);
333 const std::map<std::string, float>
jointAngles = endeffector->getConfiguration()->getRobotNodeJointValueMap();
335 NameControlModeMap controlModes;
338 controlModes.emplace(name, ePositionControl);
341 kinematicUnitPrx->switchControlMode(controlModes);
346 ARMARX_WARNING <<
"Could not load object '" << objectInstanceName <<
"'. "
347 <<
"Cannot set shape '" << shapeName <<
"' with collision check. "
348 <<
"Setting shape '" << shapeName <<
"' without collision check instead.";
349 setShape(shapeName,
c);
357 NameControlModeMap controlModes;
359 for (std::pair<std::string, float> pair :
jointAngles)
361 controlModes.insert(std::make_pair(pair.first, ePositionControl));
364 kinematicUnitPrx->switchControlMode(controlModes);
366 simulatorPrx->actuateRobotJointsPos(getRobotNameFromHandUnitName(), handUnitJointsToRobotJoints(
jointAngles));
374 std::map<std::string, std::vector<std::string>> conversion_dict;
375 conversion_dict[
"Fingers"] = {
"Index",
"Middle",
"Ring",
"Pinky"};
376 conversion_dict[
"Thumb"] = {
"Thumb"};
379 for (
const auto& joint : joints)
381 if (conversion_dict.find(joint.first) != conversion_dict.end())
383 auto correspondences = conversion_dict.at(joint.first);
384 for (
const auto& correspondence : correspondences)
386 for (
int i = 1; i < 4; i++)
388 std::stringstream joint_id;
389 joint_id << correspondence <<
" " << side <<
" " << i <<
" Joint";
390 robot_joints[joint_id.str()] = joint.second * M_PI_2;
395 ARMARX_WARNING <<
"No corresponding finger joint found for " << joint.first;
409 std::stringstream stream;
410 stream << side.front();