Segment.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <map>
5#include <memory>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include <SimoxUtility/caching/CacheMap.h>
11#include <SimoxUtility/shapes/OrientedBox.h>
12#include <VirtualRobot/VirtualRobot.h>
13
19
21
28#include <RobotAPI/interface/core/RobotState.h>
29#include <RobotAPI/interface/objectpose/ObjectPoseProvider.h>
30#include <RobotAPI/interface/objectpose/ObjectPoseStorageInterface.h>
31#include <RobotAPI/interface/objectpose/object_pose_types.h>
39
41#include "Decay.h"
42
44{
45 class ObjectInstance;
46}
47
49{
50
52 {
53 public:
55 {
56 int numUpdated = 0;
57 };
58
61 using ObjectPoseMap = std::map<ObjectID, ObjectPose>;
62
64 {
65 std::string robotName = "";
66 std::string robotNode = "Neck_2_Pitch";
67 float offset = 0.0f;
68
70 const std::string& prefix = "calibration.");
71 };
72
73
74 public:
76 virtual ~Segment() override;
77
78
80 const std::string& prefix = "") override;
81 void init() override;
82 void connect(viz::Client arviz);
83
84
85 CommitStats commitObjectPoses(const std::string& providerName,
86 const objpose::data::ProvidedObjectPoseSeq& providedPoses,
87 const Calibration& calibration,
88 std::optional<Time> discardUpdatesUntil = std::nullopt);
89 void commitObjectPoses(const ObjectPoseSeq& objectPoses,
90 const std::string& providerName = "");
91
92
94 objpose::ObjectPoseMap getObjectPosesByProvider(const std::string& providerName,
95 const DateTime& now);
96
97 wm::Entity* findObjectEntity(const ObjectID& objectID,
98 const std::string& providerName = "");
99 std::optional<simox::OrientedBoxf> getObjectOOBB(const ObjectID& id);
100
101 objpose::ProviderInfo getProviderInfo(const std::string& providerName);
102
103 objpose::AttachObjectToRobotNodeOutput
104 attachObjectToRobotNode(const objpose::AttachObjectToRobotNodeInput& input);
105 objpose::DetachObjectFromRobotNodeOutput
106 detachObjectFromRobotNode(const objpose::DetachObjectFromRobotNodeInput& input);
107 objpose::DetachAllObjectsFromRobotNodesOutput
108 detachAllObjectsFromRobotNodes(const objpose::DetachAllObjectsFromRobotNodesInput& input);
109
111
112 /**
113 * @brief If the object is attached to a robot node, update it according to the current robot state.
114 *
115 * If there is no attachement info in `objectPose` itself, the internal data
116 * structure `attachments` is queried. If an attachment is found there,
117 * it is written into the given `objectPose` (thus, it is "cached" in the
118 * info `objectPose`).
119 *
120 * @param synchronized Indicates whether the agent is already synchronized to the current time.
121 */
122 void updateAttachement(ObjectPose& objectPose,
124 bool& synchronized) const;
125
126
129 static ObjectPose getLatestObjectPose(const wm::Entity& entity);
130
131 static std::map<std::string, ObjectPoseMap>
133 static std::map<std::string, ObjectPoseMap>
135 static void getLatestObjectPosesByProviders(const wm::CoreSegment& coreSeg,
136 std::map<std::string, ObjectPoseMap>& out);
137
138 static void getLatestObjectPoses(const wm::CoreSegment& coreSeg, ObjectPoseMap& out);
139 static void getLatestObjectPoses(const wm::ProviderSegment& provSeg, ObjectPoseMap& out);
140 static void getLatestObjectPose(const wm::Entity& entity, ObjectPose& out);
141
142
143 static arondto::ObjectInstance getLatestInstanceData(const wm::Entity& entity);
144
146
147 static std::map<DateTime, ObjectPose>
148 getObjectPosesInRange(const wm::Entity& entity, const DateTime& start, const DateTime& end);
149
150 std::map<std::string, ObjectPoseMap> getLatestObjectPosesByProviders();
151
152 private:
154
155
156 void updateObjectPoses(ObjectPoseMap& objectPoses, const DateTime& now);
157 void updateObjectPoses(ObjectPoseMap& objectPoses,
158 const DateTime& now,
160 bool& agentSynchronized) const;
161 void updateObjectPose(ObjectPose& objectPose,
162 const DateTime& now,
164 bool& agentSynchronized) const;
165
166
167 ObjectPoseMap filterObjectPoses(const ObjectPoseMap& objectPoses) const;
168
169
170 void storeDetachedSnapshot(wm::Entity& entity,
171 const arondto::ObjectInstance& data,
172 Time now,
173 bool commitAttachedPose,
174 bool forgetObject);
175
176
177 std::optional<wm::EntityInstance> findClassInstance(const ObjectID& objectID) const;
178
179 friend struct DetachVisitor;
180
181
182 private:
183 void storeScene(const std::string& filename, const armarx::objects::Scene& scene);
184 std::optional<armarx::objects::Scene> loadScene(const std::string& filename);
185 std::optional<armarx::objects::Scene> loadScene(const std::filesystem::path& path);
186 std::optional<std::filesystem::path> resolveSceneFilepath(const std::string& filename);
187
188 armarx::objects::Scene getSceneSnapshot() const;
189 void commitSceneSnapshot(const armarx::objects::Scene& scene, const std::string& sceneName);
190 void commitSceneSnapshotFromFilename(const std::string& filename, bool lockMemory);
191
192
193 public:
194 /// Loaded robot models identified by the robot name.
196 {
198 std::string fallbackName;
199
200 std::map<std::string, VirtualRobot::RobotPtr> loaded;
201
202 VirtualRobot::RobotPtr get(const std::string& robotName,
203 const std::string& providerName = "");
204 };
205
207
208
209 objpose::ProviderInfoMap providers;
210
211
213
214 /// Decay model.
216
217
218 private:
219 struct Properties
220 {
221 bool discardSnapshotsWhileAttached = true;
222
223 bool separateProviderForAttachedObjects = false;
224
225 bool automaticallyDetachObjectsOnHandOpening = false;
226 float automaticallyDetachPositionThreshold = 0.2;
227
228 /// Package containing the scene snapshots
229 std::string sceneSnapshotsPackage = armarx::ObjectFinder::DefaultObjectsPackageName;
230 std::string sceneSnapshotsDirectory = "scenes";
231 std::string sceneSnapshotsToLoad = "";
232
233 bool autoReloadSceneSnapshotsOnFileChange = false;
234
235 std::vector<std::string> getSceneSnapshotsToLoad() const;
236
237 std::string attachedProviderName = "attached";
238 };
239
240 Properties p;
241
242
243 /// Caches results of attempts to retrieve the OOBB from ArmarXObjects.
244 simox::caching::CacheMap<ObjectID, std::optional<simox::OrientedBoxf>> oobbCache;
245
246 /// Class name -> dataset name.
247 simox::caching::CacheMap<std::string, std::string> classNameToDatasetCache;
248
249 std::unique_ptr<CMakePackageFinder> finder;
250
251 static const std::string timestampPlaceholder;
252
253 public:
272
273
274 private:
275 std::unique_ptr<ArticulatedObjectVisu> visu;
276
277 SimpleRunningTask<>::pointer_type fileWatcherTask;
278 };
279
280} // namespace armarx::armem::server::obj::instance
Base Class for all Logging classes.
Definition Logging.h:240
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
static const std::string DefaultObjectsPackageName
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
Helps connecting a Memory server to the Ice interface.
Models decay of object localizations by decreasing the confidence the longer the object was not local...
Definition Decay.h:19
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition Segment.cpp:147
static std::map< std::string, ObjectPoseMap > getLatestObjectPosesByProviders(const wm::ProviderSegment &provSeg)
static ObjectPose getLatestObjectPose(const wm::Entity &entity)
Definition Segment.cpp:1005
std::map< ObjectID, ObjectPose > ObjectPoseMap
Definition Segment.h:61
objpose::AttachObjectToRobotNodeOutput attachObjectToRobotNode(const objpose::AttachObjectToRobotNodeInput &input)
Definition Segment.cpp:1191
::armarx::armem::articulated_object::ArticulatedObjects getArticulatedObjects()
Definition Segment.cpp:1083
objpose::ProviderInfo getProviderInfo(const std::string &providerName)
Definition Segment.cpp:1171
CommitStats commitObjectPoses(const std::string &providerName, const objpose::data::ProvidedObjectPoseSeq &providedPoses, const Calibration &calibration, std::optional< Time > discardUpdatesUntil=std::nullopt)
objpose::DetachObjectFromRobotNodeOutput detachObjectFromRobotNode(const objpose::DetachObjectFromRobotNodeInput &input)
Definition Segment.cpp:1305
std::optional< simox::OrientedBoxf > getObjectOOBB(const ObjectID &id)
Definition Segment.cpp:1165
objpose::ObjectPoseMap getObjectPosesByProvider(const std::string &providerName, const DateTime &now)
Definition Segment.cpp:659
static ObjectPoseMap getLatestObjectPoses(const wm::CoreSegment &coreSeg)
Definition Segment.cpp:981
objpose::DetachAllObjectsFromRobotNodesOutput detachAllObjectsFromRobotNodes(const objpose::DetachAllObjectsFromRobotNodesInput &input)
Definition Segment.cpp:1359
objpose::ObjectPoseMap getObjectPoses(const DateTime &now)
Definition Segment.cpp:651
static arondto::ObjectInstance getLatestInstanceData(const wm::Entity &entity)
Definition Segment.cpp:1068
static std::map< DateTime, ObjectPose > getObjectPosesInRange(const wm::Entity &entity, const DateTime &start, const DateTime &end)
Definition Segment.cpp:1137
void updateAttachement(ObjectPose &objectPose, VirtualRobot::RobotPtr agent, bool &synchronized) const
If the object is attached to a robot node, update it according to the current robot state.
Definition Segment.cpp:776
std::map< std::string, ObjectPoseMap > getLatestObjectPosesByProviders()
Definition Segment.cpp:974
Segment(server::MemoryToIceAdapter &iceMemory)
Definition Segment.cpp:103
wm::Entity * findObjectEntity(const ObjectID &objectID, const std::string &providerName="")
Definition Segment.cpp:669
Represents a point in time.
Definition DateTime.h:25
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
armarx::armem::robot_state::Robots ArticulatedObjects
Definition types.h:141
armarx::core::time::DateTime Time
std::map< ObjectID, ObjectPose > ObjectPoseMap
std::vector< ObjectPose > ObjectPoseSeq
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="calibration.")
Definition Segment.cpp:93
armarx::RemoteGui::Client::CheckBox detachAllObjectsCommitAttachedPoseCheckBox
Definition Segment.h:267
armarx::RemoteGui::Client::CheckBox infiniteHistory
Definition Segment.h:263
armarx::RemoteGui::Client::GroupBox group
Definition Segment.h:256
armarx::RemoteGui::Client::Button detachAllObjectsButton
Definition Segment.h:266
armarx::RemoteGui::Client::IntSpinBox maxHistorySize
Definition Segment.h:262
armarx::RemoteGui::Client::LineEdit storeLoadLine
Definition Segment.h:258
armarx::RemoteGui::Client::CheckBox discardSnapshotsWhileAttached
Definition Segment.h:264
armarx::RemoteGui::Client::Button storeButton
Definition Segment.h:259
armarx::RemoteGui::Client::Button loadButton
Definition Segment.h:260
Loaded robot models identified by the robot name.
Definition Segment.h:196
std::map< std::string, VirtualRobot::RobotPtr > loaded
Definition Segment.h:200
VirtualRobot::RobotPtr get(const std::string &robotName, const std::string &providerName="")
Definition Segment.cpp:1866
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34