25#include <SimoxUtility/algorithm/string.h>
26#include <SimoxUtility/json.h>
27#include <VirtualRobot/CollisionDetection/CollisionModel.h>
28#include <VirtualRobot/ManipulationObject.h>
65 defs->component(workingMemory);
66 defs->component(robotStateComponent);
67 defs->component(priorKnowledge);
69 defs->optional(updateFrequency,
"UpdateFrequency",
"Target number of updates per second.");
70 defs->optional(configFile,
"ConfigFile",
"Path to the config file.");
71 defs->optional(loadObjectDatasetsStr,
73 "Only load the files for the following datasets, separated by ;. Load all "
74 "if input is empty.");
82 return "WorkingMemoryObjectPoseProvider";
88 return "WorkingMemoryObjectPoseProvider";
95 ARMARX_INFO <<
"Loading config file '" << configFile <<
"' ...";
96 if (std::filesystem::is_regular_file(configFile))
98 const nlohmann::json j = nlohmann::read_json(configFile);
103 ARMARX_INFO <<
"No config file at '" << configFile <<
"'";
114 ARMARX_IMPORTANT <<
"Loading workingmemory and priorknowledge entites and files. This may "
116 attachments.initFromProxies(workingMemory, robotStateComponent);
118 std::vector<std::string> loadDatasets = simox::alg::split(loadObjectDatasetsStr,
";");
120 objectClassSegment.initFromProxy(priorKnowledge, loadDatasets);
130 while (task && !task->isStopped())
132 provideObjectInstancesPoses();
155 WorkingMemoryObjectPoseProvider::provideObjectInstancesPoses()
157 std::scoped_lock lock(mutex);
158 std::vector<ObjectInstancePtr> instances = attachments.
queryObjects();
159 provideObjectInstancesPoses(instances);
163 WorkingMemoryObjectPoseProvider::provideObjectInstancesPoses(
164 const std::vector<ObjectInstancePtr>& objectInstances)
166 armarx::objpose::data::ProvidedObjectPoseSeq objectPoses;
168 for (
const auto& instance : objectInstances)
170 objectPoses.push_back(toProvidedObjectPose(instance).toIce());
176 armarx::objpose::ProvidedObjectPose
177 WorkingMemoryObjectPoseProvider::toProvidedObjectPose(
const ObjectInstancePtr& instance)
179 armarx::objpose::ProvidedObjectPose pose;
181 pose.
objectType = armarx::objpose::KnownObject;
182 std::string className = instance->getMostProbableClass();
183 if (
auto it = config.objectNames.find(className); it != config.objectNames.end())
186 << it->second <<
"'";
187 className = it->second;
189 pose.
objectID = armarx::ObjectID(className);
192 pose.
objectPose = instance->getPose()->toEigen();
199 pose.
confidence = instance->getExistenceCertainty();
200 if (instance->hasLocalizationTimestamp())
209 std::optional<ObjectClassWrapper> objectClass = objectClassSegment.getClass(className);
213 VirtualRobot::CollisionModelPtr collisionModel =
214 objectClass->manipulationObject->getCollisionModel();
215 VirtualRobot::BoundingBox bb = collisionModel->getBoundingBox(
false);
216 Eigen::Vector3f bbMin = bb.getMin();
217 Eigen::Vector3f bbMax = bb.getMax();
218 Eigen::Vector3f extents = bbMax - bbMin;
222 (0.5 * (bbMin + bbMax)).eval(), Eigen::Quaternionf::Identity(), extents);
230 armarx::objpose::ProviderInfo
233 armarx::objpose::ProviderInfo info;
240 const AttachObjectToRobotNodeInput& attachment,
243 std::scoped_lock lock(mutex);
244 attachments.attachObjectToRobotNode(attachment);
249 const DetachObjectFromRobotNodeInput& detachment,
252 std::scoped_lock lock(mutex);
253 attachments.detachObjectFromRobotNode(detachment);
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
static std::string resolvePath(const std::string &path, bool verbose=true)
Resolves environment variables and home paths and tries to make path absolute.
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
This util class helps with keeping a cycle time during a control cycle.
IceUtil::Time waitForCycleDuration()
This function will wait (virtual or system time) until the cycle time is reached.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
std::string getName() const
Retrieve name of object.
void setInstanceName(const std::string &instanceName)
objpose::ObjectPoseStorageInterfacePrx objectPoseTopic
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
std::string providerName
Name of the providing component.
Eigen::Matrix4f objectPose
DateTime timestamp
Source timestamp.
ObjectType objectType
Known or unknown object.
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
std::string objectPoseFrame
std::vector< ObjectInstancePtr > queryObjects()
Get all entities from objectInstanceSegment and cast them to ObjectInstance.
Brief description of class WorkingMemoryObjectPoseProvider.
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void attachObjectToRobotNode(const AttachObjectToRobotNodeInput &attachment, const Ice::Current &) override
void detachObjectFromRobotNode(const DetachObjectFromRobotNodeInput &detachment, const Ice::Current &) override
void onConnectComponent() override
static std::string GetDefaultName()
void onExitComponent() override
armarx::objpose::ProviderInfo getProviderInfo(const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
#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_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_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
void fromIce(Eigen::Vector2f &e, const Ice::FloatSeq &ice)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)> >
void from_json(const nlohmann::json &j, Config &config)
IceInternal::Handle< ObjectInstance > ObjectInstancePtr
void to_json(nlohmann::json &j, const Config &config)
std::map< std::string, std::string > objectNames