25#include <SimoxUtility/algorithm/string.h>
26#include <SimoxUtility/json.h>
27#include <VirtualRobot/CollisionDetection/CollisionModel.h>
28#include <VirtualRobot/ManipulationObject.h>
64 defs->component(workingMemory);
65 defs->component(robotStateComponent);
66 defs->component(priorKnowledge);
68 defs->optional(updateFrequency,
"UpdateFrequency",
"Target number of updates per second.");
69 defs->optional(configFile,
"ConfigFile",
"Path to the config file.");
70 defs->optional(loadObjectDatasetsStr,
72 "Only load the files for the following datasets, separated by ;. Load all "
73 "if input is empty.");
81 return "WorkingMemoryObjectPoseProvider";
88 ARMARX_INFO <<
"Loading config file '" << configFile <<
"' ...";
89 if (std::filesystem::is_regular_file(configFile))
91 const nlohmann::json j = nlohmann::read_json(configFile);
96 ARMARX_INFO <<
"No config file at '" << configFile <<
"'";
107 ARMARX_IMPORTANT <<
"Loading workingmemory and priorknowledge entites and files. This may "
109 attachments.initFromProxies(workingMemory, robotStateComponent);
111 std::vector<std::string> loadDatasets = simox::alg::split(loadObjectDatasetsStr,
";");
113 objectClassSegment.initFromProxy(priorKnowledge, loadDatasets);
123 while (task && !task->isStopped())
125 provideObjectInstancesPoses();
148 WorkingMemoryObjectPoseProvider::provideObjectInstancesPoses()
150 std::scoped_lock lock(mutex);
151 std::vector<ObjectInstancePtr> instances = attachments.
queryObjects();
152 provideObjectInstancesPoses(instances);
156 WorkingMemoryObjectPoseProvider::provideObjectInstancesPoses(
157 const std::vector<ObjectInstancePtr>& objectInstances)
159 armarx::objpose::data::ProvidedObjectPoseSeq objectPoses;
161 for (
const auto& instance : objectInstances)
163 objectPoses.push_back(toProvidedObjectPose(instance).toIce());
169 armarx::objpose::ProvidedObjectPose
170 WorkingMemoryObjectPoseProvider::toProvidedObjectPose(
const ObjectInstancePtr& instance)
172 armarx::objpose::ProvidedObjectPose pose;
174 pose.
objectType = armarx::objpose::KnownObject;
175 std::string className = instance->getMostProbableClass();
176 if (
auto it = config.objectNames.find(className); it != config.objectNames.end())
179 << it->second <<
"'";
180 className = it->second;
182 pose.
objectID = armarx::ObjectID(className);
185 pose.
objectPose = instance->getPose()->toEigen();
192 pose.
confidence = instance->getExistenceCertainty();
193 if (instance->hasLocalizationTimestamp())
202 std::optional<ObjectClassWrapper> objectClass = objectClassSegment.getClass(className);
206 VirtualRobot::CollisionModelPtr collisionModel =
207 objectClass->manipulationObject->getCollisionModel();
208 VirtualRobot::BoundingBox bb = collisionModel->getBoundingBox(
false);
209 Eigen::Vector3f bbMin = bb.getMin();
210 Eigen::Vector3f bbMax = bb.getMax();
211 Eigen::Vector3f extents = bbMax - bbMin;
215 (0.5 * (bbMin + bbMax)).eval(), Eigen::Quaternionf::Identity(), extents);
223 armarx::objpose::ProviderInfo
226 armarx::objpose::ProviderInfo info;
233 const AttachObjectToRobotNodeInput& attachment,
236 std::scoped_lock lock(mutex);
237 attachments.attachObjectToRobotNode(attachment);
242 const DetachObjectFromRobotNodeInput& detachment,
245 std::scoped_lock lock(mutex);
246 attachments.detachObjectFromRobotNode(detachment);
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.
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
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