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>
51 const std::string prefix =
"mem.";
54 classSegment.defineProperties(defs, prefix +
"cls.");
58 attachmentSegment.defineProperties(defs, prefix +
"attachments.");
62 defs->topic(debugObserver);
71 defs->defineOptionalProperty<std::string>(
"cmp.KinematicUnitObserverName",
72 "KinematicUnitObserver",
73 "Name of the kinematic unit observer.");
74 defs->optional(predictionTimeWindow,
75 "prediction.TimeWindow",
76 "Duration of time window into the past to use for predictions"
77 " when requested via the PredictingMemoryInterface (in seconds).");
79 defs->optional(p.markerMemoryName, prefix +
".marker.Name",
"Marker Memory Name");
80 defs->optional(p.maxMarkerHistorySize,
81 prefix +
".marker.maxHistorySize",
82 "Maximum marker memory history size");
92 virtualRobotReaderPlugin(nullptr)
104 return "ObjectMemory";
110 const auto initSegmentWithCatch = [&](
const std::string& segmentName,
const auto&& fn)
116 catch (
const LocalException& e)
118 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n"
121 catch (
const std::exception& e)
123 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n"
129 <<
"` segment for unknown reason.";
135 initSegmentWithCatch(
"class", [&]() { classSegment.init(); });
140 initSegmentWithCatch(
"attachment", [&]() { attachmentSegment.init(); });
142 initSegmentWithCatch(p.markerMemoryName,
146 .addCoreSegment(p.markerMemoryName,
147 arondto::Marker::ToAronType())
148 .setMaxHistorySize(p.maxMarkerHistorySize);
158 kinematicUnitObserver,
"cmp.KinematicUnitObserverName",
false,
"",
false);
164 ARMARX_INFO <<
"Debug observer set for LTM timing measurements";
173 kinematicUnitObserver,
184 attachmentSegment.connect();
204 armem::actions::GetActionsOutputSeq
208 GetActionsOutputSeq outputs;
209 for (
const auto& input : inputs)
216 Action{
"vis",
"Visualize object"},
219 outputs.push_back({menu.toIce()});
226 armem::actions::ExecuteActionOutputSeq
230 ExecuteActionOutputSeq outputs;
232 for (
const auto& input : inputs)
235 if (input.actionPath == ActionPath{
"vis"})
240 classSegment.visualizeClass(memoryID);
241 outputs.emplace_back(
true,
"");
245 std::stringstream sstream;
246 sstream <<
"MemoryID " << memoryID
247 <<
" does not refer to a valid object class.";
248 outputs.emplace_back(
false, sstream.str());
253 std::stringstream sstream;
254 sstream <<
"Action path " << input.actionPath <<
" is not defined.";
255 outputs.emplace_back(
false, sstream.str());
261 armem::prediction::data::PredictionResultSeq
264 std::vector<armem::prediction::data::PredictionResult> results;
265 for (
const auto& request : requests)
271 boRequest.snapshotID) and
272 not boRequest.snapshotID.hasGap() and boRequest.snapshotID.hasTimestamp())
274 objpose::ObjectPosePredictionRequest objPoseRequest;
276 objPoseRequest.objectID =
toIce(
ObjectID(request.snapshotID.entityName));
277 objPoseRequest.settings = request.settings;
278 toIce(objPoseRequest.timestamp, boRequest.snapshotID.timestamp);
280 objpose::ObjectPosePredictionResult objPoseResult =
282 result.
success = objPoseResult.success;
285 if (objPoseResult.success)
291 std::string instanceError =
292 "Could not find instance '" + boRequest.snapshotID.str() +
"' in memory";
293 if (!queryResult.success)
296 result.
errorMessage << instanceError <<
":\n" << queryResult.errorMessage;
300 if (not boRequest.snapshotID.hasInstanceIndex())
302 boRequest.snapshotID.instanceIndex = 0;
304 auto* aronInstance = queryResult.memory.findLatestInstance(
305 boRequest.snapshotID, boRequest.snapshotID.instanceIndex);
306 if (aronInstance ==
nullptr)
309 result.
errorMessage << instanceError <<
": No latest instance found.";
314 armem::arondto::ObjectInstance::FromAron(aronInstance->data());
326 result.
errorMessage <<
"No predictions are supported for MemoryID "
327 << boRequest.snapshotID;
329 results.push_back(result.
toIce());
340 tab.reset(
new RemoteGuiTab);
342 tab->instance.setup(*
this);
343 tab->clazz.setup(classSegment);
345 HBoxLayout segments = {tab->instance.group, tab->clazz.group};
353 tab->instance.update(*
this);
354 tab->clazz.update(classSegment);
356 if (tab->clazz.data.rebuild)
366 classSegment.reloadObjectClassesByObjectFinder();
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.
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