25#include <VirtualRobot/VirtualRobot.h>
38#include <RobotAPI/libraries/armem_objects/aron/Marker.aron.generated.h>
39#include <RobotAPI/libraries/armem_objects/aron/ObjectInstance.aron.generated.h>
55 const std::string prefix =
"mem.";
58 classSegment.defineProperties(defs, prefix +
"cls.");
62 attachmentSegment.defineProperties(defs, prefix +
"attachments.");
66 defs->topic(debugObserver);
75 defs->defineOptionalProperty<std::string>(
"cmp.KinematicUnitObserverName",
76 "KinematicUnitObserver",
77 "Name of the kinematic unit observer.");
78 defs->optional(predictionTimeWindow,
79 "prediction.TimeWindow",
80 "Duration of time window into the past to use for predictions"
81 " when requested via the PredictingMemoryInterface (in seconds).");
83 defs->optional(p.markerMemoryName, prefix +
".marker.Name",
"Marker Memory Name");
84 defs->optional(p.maxMarkerHistorySize,
85 prefix +
".marker.maxHistorySize",
86 "Maximum marker memory history size");
96 virtualRobotReaderPlugin(nullptr)
108 return "ObjectMemory";
114 const auto initSegmentWithCatch = [&](
const std::string& segmentName,
const auto&& fn)
120 catch (
const LocalException& e)
122 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n"
125 catch (
const std::exception& e)
127 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n"
133 <<
"` segment for unknown reason.";
139 initSegmentWithCatch(
"class", [&]() { classSegment.init(); });
144 initSegmentWithCatch(
"attachment", [&]() { attachmentSegment.init(); });
146 initSegmentWithCatch(p.markerMemoryName,
150 .addCoreSegment(p.markerMemoryName,
151 arondto::Marker::ToAronType())
152 .setMaxHistorySize(p.maxMarkerHistorySize);
162 kinematicUnitObserver,
"cmp.KinematicUnitObserverName",
false,
"",
false);
168 ARMARX_INFO <<
"Debug observer set for LTM timing measurements";
177 kinematicUnitObserver,
188 attachmentSegment.connect();
208 armem::actions::GetActionsOutputSeq
212 GetActionsOutputSeq outputs;
213 for (
const auto& input : inputs)
220 Action{
"vis",
"Visualize object"},
223 outputs.push_back({menu.toIce()});
230 armem::actions::ExecuteActionOutputSeq
234 ExecuteActionOutputSeq outputs;
236 for (
const auto& input : inputs)
239 if (input.actionPath == ActionPath{
"vis"})
244 classSegment.visualizeClass(memoryID);
245 outputs.emplace_back(
true,
"");
249 std::stringstream sstream;
250 sstream <<
"MemoryID " << memoryID
251 <<
" does not refer to a valid object class.";
252 outputs.emplace_back(
false, sstream.str());
257 std::stringstream sstream;
258 sstream <<
"Action path " << input.actionPath <<
" is not defined.";
259 outputs.emplace_back(
false, sstream.str());
265 armem::prediction::data::PredictionResultSeq
268 std::vector<armem::prediction::data::PredictionResult> results;
269 for (
const auto& request : requests)
275 boRequest.snapshotID) and
276 not boRequest.snapshotID.hasGap() and boRequest.snapshotID.hasTimestamp())
278 objpose::ObjectPosePredictionRequest objPoseRequest;
280 objPoseRequest.objectID =
toIce(
ObjectID(request.snapshotID.entityName));
281 objPoseRequest.settings = request.settings;
282 toIce(objPoseRequest.timestamp, boRequest.snapshotID.timestamp);
284 objpose::ObjectPosePredictionResult objPoseResult =
286 result.
success = objPoseResult.success;
289 if (objPoseResult.success)
295 std::string instanceError =
296 "Could not find instance '" + boRequest.snapshotID.str() +
"' in memory";
297 if (!queryResult.success)
300 result.
errorMessage << instanceError <<
":\n" << queryResult.errorMessage;
304 if (not boRequest.snapshotID.hasInstanceIndex())
306 boRequest.snapshotID.instanceIndex = 0;
308 auto* aronInstance = queryResult.memory.findLatestInstance(
309 boRequest.snapshotID, boRequest.snapshotID.instanceIndex);
310 if (aronInstance ==
nullptr)
313 result.
errorMessage << instanceError <<
": No latest instance found.";
318 armem::arondto::ObjectInstance::FromAron(aronInstance->data());
330 result.
errorMessage <<
"No predictions are supported for MemoryID "
331 << boRequest.snapshotID;
333 results.push_back(result.
toIce());
344 tab.reset(
new RemoteGuiTab);
346 tab->instance.setup(*
this);
347 tab->clazz.setup(classSegment);
349 HBoxLayout segments = {tab->instance.group, tab->clazz.group};
357 tab->instance.update(*
this);
358 tab->clazz.update(classSegment);
360 if (tab->clazz.data.rebuild)
370 classSegment.reloadObjectClassesByObjectFinder();
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
armarx::viz::Client & getArvizClient()
Default component property definition container.
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
std::string getName() const
Retrieve name of object.
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
bool hasGap() const
Indicate whether this ID has a gap such as in 'Memory//MyProvider' (no core segment name).
bool hasEntityName() const
void latestEntitySnapshot(const MemoryID &entityID)
armem::query::data::Input buildQueryInputIce() const
void setDebugObserver(DebugObserverInterfacePrx observer)
Set an optional debug observer for timing measurements.
Brief description of class ObjectMemory.
armem::actions::ExecuteActionOutputSeq executeActions(const armem::actions::ExecuteActionInputSeq &inputs) override
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
virtual ~ObjectMemory() override
void RemoteGui_update() override
armem::actions::GetActionsOutputSeq getActions(const armem::actions::GetActionsInputSeq &inputs) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
void onConnectComponent() override
Pure virtual hook for the subclass.
void reloadKnownObjectClasses(const Ice::Current ¤t) override
void onExitComponent() override
Hook for subclass.
armem::prediction::data::PredictionResultSeq predict(const armem::prediction::data::PredictionRequestSeq &requests) override
void createRemoteGuiTab()
std::string getDefaultName() const override
void connect(std::experimental::observer_ptr< robot_state::VirtualRobotReader > virtualRobotReader, viz::Client arviz, DebugObserverInterfacePrx debugObserver)
SegmentAdapter(MemoryToIceAdapter &iceMemory)
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="")
void connect(robot_state::VirtualRobotReader *virtualRobotReader, KinematicUnitObserverInterfacePrx kinematicUnitObserver, viz::Client arviz, DebugObserverInterfacePrx debugObserver)
virtual objpose::ObjectPosePredictionResultSeq predictObjectPoses(const objpose::ObjectPosePredictionRequestSeq &requests, ICE_CURRENT_ARG) override
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="")
server::ltm::Memory & longtermMemory()
virtual armem::query::data::Result query(const armem::query::data::Input &input, const Ice::Current &=Ice::emptyCurrent) override
server::wm::Memory & workingMemory()
MemoryToIceAdapter & iceAdapter()
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
#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_ERROR
The logging level for unexpected behaviour, that must be fixed.
query::Builder QueryBuilder
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
void toIce(data::MemoryID &ice, const MemoryID &id)
void toAron(arondto::ObjectAttachmentInfo &dto, const ObjectAttachmentInfo &bo)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
void RemoteGui_startRunningTask()
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
aron::data::DictPtr prediction
armem::MemoryID snapshotID
armem::prediction::data::PredictionResult toIce() const