30#include <Eigen/Geometry>
32#include <VirtualRobot/EndEffector/EndEffector.h>
33#include <VirtualRobot/RobotConfig.h>
37#include <RobotAPI/interface/objectpose/ObjectPoseStorageInterface.h>
115 "cmp.ObjectPoseStorageName",
116 "Name of the object pose storage (only used if necessary).");
131 << objectName <<
flush;
171 ARMARX_WARNING <<
"Could not get joint angles fvrom simulator...";
180 std::string myShapeName = shapeName;
190 if (!
eef->hasPreshape(myShapeName))
192 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " <<
eef->getName()
193 <<
". Looking for partial match";
195 bool foundMatch =
false;
197 for (
const std::string& name :
eef->getPreshapes())
199 if (name.find(myShapeName) != std::string::npos)
210 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " <<
eef->getName()
211 <<
" available shapes: " <<
eef->getPreshapes();
216 VirtualRobot::RobotConfigPtr config =
eef->getPreshape(myShapeName);
217 std::map<std::string, float> jointAngles = config->getRobotNodeJointValueMap();
219 NameControlModeMap controlModes;
221 for (std::pair<std::string, float> pair : jointAngles)
223 controlModes.insert(std::make_pair(pair.first, ePositionControl));
232 const std::string& objectInstanceName,
233 const Ice::Current&
c)
235 std::string myShapeName = shapeName;
236 ARMARX_INFO <<
"Setting shape " << myShapeName <<
" while checking for collision with "
237 << objectInstanceName;
245 if (!
eef->hasPreshape(myShapeName))
247 ARMARX_INFO <<
"Shape with name " << myShapeName <<
" not known in eef " <<
eef->getName()
248 <<
". Looking for partial match";
250 bool foundMatch =
false;
251 for (
const std::string& name :
eef->getPreshapes())
253 if (name.find(myShapeName) != std::string::npos)
264 ARMARX_WARNING <<
"No match found for " << myShapeName <<
" in eef " <<
eef->getName()
265 <<
" available shapes: " <<
eef->getPreshapes();
270 VirtualRobot::EndEffectorPtr endeffector =
robot->getEndEffector(
eef->getName());
273 auto loadFromObjectPoseStorage = [
this,
274 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
279 auto fetchObjectPose = [
this, &objectID, &client]() -> std::optional<Eigen::Matrix4f>
285 if (
auto it = objectPoses.find(objectID); it != objectPoses.end())
287 return it->second.objectPoseGlobal;
292 if (
auto objectPose = fetchObjectPose())
294 if (std::optional<armarx::ObjectInfo> info =
297 VirtualRobot::ManipulationObjectPtr
object =
299 object->setGlobalPose(objectPose.value());
306 auto loadFromWorkingMemory = [
this,
307 &objectInstanceName]() -> VirtualRobot::ManipulationObjectPtr
311 objectInstanceName));
317 const std::string objectClassName = objInstance->getMostProbableClass();
319 auto classes =
workingMemoryPrx->getObjectClassesSegment()->addPriorClassWithSubclasses(
328 memoryx::ObjectClassPtr::dynamicCast(
workingMemoryPrx->getObjectClassesSegment()
329 ->getEntityByName(objectClassName)
338 objInstance->setPose(objInstance->getPose()->toGlobal(
robot));
339 simoxObject->updateFromEntity(objInstance);
341 return simoxObject->getManipulationObject();
344 VirtualRobot::ManipulationObjectPtr manipulationObject =
nullptr;
345 if (not manipulationObject)
347 manipulationObject = loadFromObjectPoseStorage();
351 manipulationObject = loadFromWorkingMemory();
354 if (manipulationObject)
356 endeffector->closeActors(manipulationObject);
358 const std::map<std::string, float> jointAngles =
359 endeffector->getConfiguration()->getRobotNodeJointValueMap();
361 NameControlModeMap controlModes;
362 for (
const auto& [name, value] : jointAngles)
364 controlModes.emplace(name, ePositionControl);
372 ARMARX_WARNING <<
"Could not load object '" << objectInstanceName <<
"'. "
373 <<
"Cannot set shape '" << shapeName <<
"' with collision check. "
374 <<
"Setting shape '" << shapeName <<
"' without collision check instead.";
384 NameControlModeMap controlModes;
386 for (std::pair<std::string, float> pair : jointAngles)
388 controlModes.insert(std::make_pair(pair.first, ePositionControl));
403 std::map<std::string, std::vector<std::string>> conversion_dict;
404 conversion_dict[
"Fingers"] = {
"Index",
"Middle",
"Ring",
"Pinky"};
405 conversion_dict[
"Thumb"] = {
"Thumb"};
406 auto robot_joints = armarx::NameValueMap();
408 for (
const auto& joint : joints)
410 if (conversion_dict.find(joint.first) != conversion_dict.end())
412 auto correspondences = conversion_dict.at(joint.first);
413 for (
const auto& correspondence : correspondences)
415 for (
int i = 1; i < 4; i++)
417 std::stringstream joint_id;
418 joint_id << correspondence <<
" " << side <<
" " << i <<
" Joint";
419 robot_joints[joint_id.str()] = joint.second * M_PI_2;
425 ARMARX_WARNING <<
"No corresponding finger joint found for " << joint.first;
441 std::stringstream stream;
442 stream << side.front();
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
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.
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