32#include <Eigen/Geometry>
34#include <VirtualRobot/EndEffector/EndEffector.h>
35#include <VirtualRobot/ManipulationObject.h>
36#include <VirtualRobot/RobotConfig.h>
40#include <RobotAPI/interface/objectpose/ObjectPoseStorageInterface.h>
118 "cmp.ObjectPoseStorageName",
119 "Name of the object pose storage (only used if necessary).");
134 << objectName <<
flush;
174 ARMARX_WARNING <<
"Could not get joint angles fvrom simulator...";
183 std::string myShapeName = shapeName;
193 if (!
eef->hasPreshape(myShapeName))
195 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " <<
eef->getName()
196 <<
". Looking for partial match";
198 bool foundMatch =
false;
200 for (
const std::string& name :
eef->getPreshapes())
202 if (name.find(myShapeName) != std::string::npos)
213 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " <<
eef->getName()
214 <<
" available shapes: " <<
eef->getPreshapes();
219 VirtualRobot::RobotConfigPtr config =
eef->getPreshape(myShapeName);
220 std::map<std::string, float> jointAngles = config->getRobotNodeJointValueMap();
222 NameControlModeMap controlModes;
224 for (std::pair<std::string, float> pair : jointAngles)
226 controlModes.insert(std::make_pair(pair.first, ePositionControl));
235 const std::string& objectInstanceName,
236 const Ice::Current&
c)
238 std::string myShapeName = shapeName;
239 ARMARX_INFO <<
"Setting shape " << myShapeName <<
" while checking for collision with "
240 << objectInstanceName;
248 if (!
eef->hasPreshape(myShapeName))
250 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " <<
eef->getName()
251 <<
". Looking for partial match";
253 bool foundMatch =
false;
254 for (
const std::string& name :
eef->getPreshapes())
256 if (name.find(myShapeName) != std::string::npos)
267 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " <<
eef->getName()
268 <<
" available shapes: " <<
eef->getPreshapes();
273 VirtualRobot::EndEffectorPtr endeffector =
robot->getEndEffector(
eef->getName());
276 auto loadFromObjectPoseStorage = [
this,
277 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
282 auto fetchObjectPose = [
this, &objectID, &client]() -> std::optional<Eigen::Matrix4f>
288 if (
auto it = objectPoses.find(objectID); it != objectPoses.end())
290 return it->second.objectPoseGlobal;
295 if (
auto objectPose = fetchObjectPose())
297 if (std::optional<armarx::ObjectInfo> info =
300 VirtualRobot::ManipulationObjectPtr
object =
302 object->setGlobalPose(objectPose.value());
309 auto loadFromWorkingMemory = [
this,
310 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
314 objectInstanceName));
320 const std::string objectClassName = objInstance->getMostProbableClass();
322 auto classes =
workingMemoryPrx->getObjectClassesSegment()->addPriorClassWithSubclasses(
331 memoryx::ObjectClassPtr::dynamicCast(
workingMemoryPrx->getObjectClassesSegment()
332 ->getEntityByName(objectClassName)
341 objInstance->setPose(objInstance->getPose()->toGlobal(
robot));
342 simoxObject->updateFromEntity(objInstance);
344 return simoxObject->getManipulationObject();
347 VirtualRobot::ManipulationObjectPtr manipulationObject =
nullptr;
348 if (not manipulationObject)
350 manipulationObject = loadFromObjectPoseStorage();
354 manipulationObject = loadFromWorkingMemory();
357 if (manipulationObject)
359 endeffector->closeActors(manipulationObject);
361 const std::map<std::string, float> jointAngles =
362 endeffector->getConfiguration()->getRobotNodeJointValueMap();
364 NameControlModeMap controlModes;
365 for (
const auto& [name, value] : jointAngles)
367 controlModes.emplace(name, ePositionControl);
375 ARMARX_WARNING <<
"Could not load object '" << objectInstanceName <<
"'. "
376 <<
"Cannot set shape '" << shapeName <<
"' with collision check. "
377 <<
"Setting shape '" << shapeName <<
"' without collision check instead.";
387 NameControlModeMap controlModes;
389 for (std::pair<std::string, float> pair : jointAngles)
391 controlModes.insert(std::make_pair(pair.first, ePositionControl));
406 std::map<std::string, std::vector<std::string>> conversion_dict;
407 conversion_dict[
"Fingers"] = {
"Index",
"Middle",
"Ring",
"Pinky"};
408 conversion_dict[
"Thumb"] = {
"Thumb"};
409 auto robot_joints = armarx::NameValueMap();
411 for (
const auto& joint : joints)
413 if (conversion_dict.find(joint.first) != conversion_dict.end())
415 auto correspondences = conversion_dict.at(joint.first);
416 for (
const auto& correspondence : correspondences)
418 for (
int i = 1; i < 4; i++)
420 std::stringstream joint_id;
421 joint_id << correspondence <<
" " << side <<
" " << i <<
" Joint";
422 robot_joints[joint_id.str()] = joint.second * M_PI_2;
428 ARMARX_WARNING <<
"No corresponding finger joint found for " << joint.first;
444 std::stringstream stream;
445 stream << side.front();
452 return "HandUnitDynamicSimulation";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
This unit connects to the physics simulator topic (default: "Simulator") and implements a HandUnit.
void onInitHandUnit() override
armarx::NameValueMap handUnitJointsToRobotJoints(const armarx::NameValueMap &joints)
void onExitHandUnit() override
memoryx::WorkingMemoryInterfacePrx workingMemoryPrx
void setObjectReleased(const std::string &objectName, const Ice::Current &) override
SimulatorInterfacePrx simulatorPrx
std::string objectPoseStorageName
std::string robotStateComponentName
KinematicUnitInterfacePrx kinematicUnitPrx
void onStartHandUnit() override
void setShape(const std::string &shapeName, const Ice::Current &) override
void setObjectGrasped(const std::string &objectName, const Ice::Current &) override
std::string getRobotNameFromHandUnitName()
NameValueMap getCurrentJointValues(const Ice::Current &c=Ice::emptyCurrent) override
PropertyDefinitionsPtr createPropertyDefinitions() override
Send command to the hand to open all fingers.
static std::string GetDefaultName()
RobotStateComponentInterfacePrx robotStateComponentPrx
std::string simulatorPrxName
void setJointAngles(const NameValueMap &jointAngles, const Ice::Current &) override
std::string getHandSideFromHandUnitName()
void setShapeWithObjectInstance(const std::string &shapeName, const std::string &objectInstanceName, const Ice::Current &c=Ice::emptyCurrent) override
VirtualRobot::RobotPtr robot
VirtualRobot::EndEffectorPtr eef
std::string kinematicUnitName
std::map< std::string, float > handJoints
std::string graspedObject
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)
static VirtualRobot::ManipulationObjectPtr loadManipulationObject(const std::optional< ObjectInfo > &ts, VirtualRobot::ObjectIO::ObjectDescription loadMode=VirtualRobot::ObjectIO::ObjectDescription::eFull)
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Provides access to the armarx::objpose::ObjectPoseStorageInterface (aka the object memory).
const ObjectFinder & getObjectFinder() const
Get the internal object finder.
ObjectPoseMap fetchObjectPosesAsMap() const
Fetch all known object poses.
ObjectPoseStorageInterfacePrx objectPoseStorage
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::shared_ptr< class Robot > RobotPtr
std::map< ObjectID, ObjectPose > ObjectPoseMap
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr