24 #include <VirtualRobot/VirtualRobot.h>
34 #include <RobotAPI/libraries/armem_objects/aron/ObjectInstance.aron.generated.h>
35 #include <RobotAPI/libraries/armem_objects/aron/Marker.aron.generated.h>
46 const std::string prefix =
"mem.";
56 defs->topic(debugObserver);
59 defs->topic<objpose::ObjectPoseTopic>();
63 defs->defineOptionalProperty<std::string>(
"cmp.KinematicUnitObserverName",
"KinematicUnitObserver",
64 "Name of the kinematic unit observer.");
65 defs->optional(predictionTimeWindow,
"prediction.TimeWindow",
66 "Duration of time window into the past to use for predictions"
67 " when requested via the PredictingMemoryInterface (in seconds).");
69 defs->optional(p.markerMemoryName, prefix +
".marker.Name",
"Marker Memory Name");
70 defs->optional(p.maxMarkerHistorySize, prefix +
".marker.maxHistorySize",
"Maximum marker memory history size");
77 instance::SegmentAdapter(iceAdapter()),
78 classSegment(iceAdapter()),
79 attachmentSegment(iceAdapter()), virtualRobotReaderPlugin(nullptr)
92 return "ObjectMemory";
98 const auto initSegmentWithCatch = [&](
const std::string & segmentName,
const auto&& fn)
104 catch (
const LocalException& e)
106 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n" << e.what();
108 catch (
const std::exception& e)
110 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment. Reason: \n" << e.what();
114 ARMARX_ERROR <<
"Failed to init `" << segmentName <<
"` segment for unknown reason.";
120 initSegmentWithCatch(
"class", [&]()
127 initSegmentWithCatch(
"attachment", [&]()
129 attachmentSegment.
init();
132 initSegmentWithCatch(p.markerMemoryName, [&]()
135 .addCoreSegment(p.markerMemoryName, arondto::Marker::ToAronType())
136 .setMaxHistorySize(p.maxMarkerHistorySize);
153 &virtualRobotReaderPlugin->get(),
154 kinematicUnitObserver,
178 const armem::actions::GetActionsInputSeq& inputs)
180 using namespace armem::actions;
181 GetActionsOutputSeq outputs;
182 for (
const auto&
input : inputs)
189 Action{
"vis",
"Visualize object"},
192 outputs.push_back({ menu.toIce() });
200 const armem::actions::ExecuteActionInputSeq& inputs)
202 using namespace armem::actions;
203 ExecuteActionOutputSeq outputs;
205 for (
const auto&
input : inputs)
208 if (
input.actionPath == ActionPath{
"vis"})
213 classSegment.visualizeClass(
memoryID);
214 outputs.emplace_back(
true,
"");
218 std::stringstream sstream;
220 <<
" does not refer to a valid object class.";
221 outputs.emplace_back(
false, sstream.str());
226 std::stringstream sstream;
227 sstream <<
"Action path " <<
input.actionPath <<
" is not defined.";
228 outputs.emplace_back(
false, sstream.str());
234 armem::prediction::data::PredictionResultSeq
237 std::vector<armem::prediction::data::PredictionResult> results;
238 for (
const auto& request : requests)
240 auto boRequest = armarx::fromIce<armem::PredictionRequest>(request);
244 and not boRequest.snapshotID.hasGap()
245 and boRequest.snapshotID.hasTimestamp())
247 objpose::ObjectPosePredictionRequest objPoseRequest;
249 objPoseRequest.objectID =
toIce(
ObjectID(request.snapshotID.entityName));
250 objPoseRequest.settings = request.settings;
251 toIce(objPoseRequest.timestamp, boRequest.snapshotID.timestamp);
253 objpose::ObjectPosePredictionResult objPoseResult =
255 result.
success = objPoseResult.success;
258 if (objPoseResult.success)
262 auto queryResult = armarx::fromIce<armem::client::QueryResult>(
264 std::string instanceError =
265 "Could not find instance '" + boRequest.snapshotID.str() +
"' in memory";
266 if (!queryResult.success)
269 result.
errorMessage << instanceError <<
":\n" << queryResult.errorMessage;
273 if (not boRequest.snapshotID.hasInstanceIndex())
275 boRequest.snapshotID.instanceIndex = 0;
277 auto* aronInstance = queryResult.memory.findLatestInstance(
278 boRequest.snapshotID, boRequest.snapshotID.instanceIndex);
279 if (aronInstance ==
nullptr)
282 result.
errorMessage << instanceError <<
": No latest instance found.";
287 armem::arondto::ObjectInstance::FromAron(aronInstance->data());
290 armarx::fromIce<objpose::ObjectPose>(objPoseResult.prediction));
299 result.
errorMessage <<
"No predictions are supported for MemoryID "
300 << boRequest.snapshotID;
302 results.push_back(result.
toIce());
312 tab.reset(
new RemoteGuiTab);
314 tab->instance.setup(*
this);
315 tab->clazz.setup(classSegment);
333 tab->instance.update(*
this);
334 tab->clazz.update(classSegment);
336 if (tab->clazz.data.rebuild)