GraspProviderExample.cpp
Go to the documentation of this file.
2
3#include <SimoxUtility/color/cmaps.h>
4
7
8#include <RobotAPI/libraries/GraspingUtility/aron/GraspCandidate.aron.generated.h>
14
16
18
19namespace armarx
20{
26
29 {
30 ARMARX_IMPORTANT << "Prperty defs";
33
34 defs->topic(debugObserver);
35
36 defs->optional(memoryName, "mem.MemoryName", "Name of the memory to use.");
37
38 return defs;
39 }
40
41 std::string
43 {
44 return "GraspProviderExample";
45 }
46
50
51 void
56
57 void
59 {
60 writer.connect(memoryNameSystem());
61 reader.connect(memoryNameSystem());
63 task->start();
64 }
65
66 void
68 {
69 task->stop();
70 }
71
72 void
76
77 void
79 {
80 ARMARX_IMPORTANT << "Running example.";
81
83 int i = 0;
84
85
86 while (!task->isStopped() && i++ < 100)
87 {
88 // initialize all necessary fields of a grasp candidate and use writer to commit it to memory
89 grasping::GraspCandidate candidate = makeDummyGraspCandidate();
90 candidate.groupNr = i; //non-necessary field, but used to commit different candidates
91
92 writer.commitGraspCandidate(candidate, armem::Time::Now(), "candidateProvider");
93
94 // initialize all necessary fields of a bimanual grasp candidate and use writer to commit it to memory
95 grasping::BimanualGraspCandidate bimanualCandidate = makeDummyBimanualGraspCandidate();
96 bimanualCandidate.groupNr =
97 i; //non-necessary field, but used to commit different candidates
98
99 writer.commitBimanualGraspCandidate(
100 bimanualCandidate, armem::Time::Now(), "bimanualProvider");
101
102
103 //test for writing Seqs, candidates from the same object appear as instances of the same snapshot
104 grasping::GraspCandidateSeq candidatesToWrite;
105 candidatesToWrite.push_back(new grasping::GraspCandidate(candidate));
106 candidate.side = "Left";
107 candidatesToWrite.push_back(new grasping::GraspCandidate(candidate));
108
109
110 writer.commitGraspCandidateSeq(
111 candidatesToWrite, armem::Time::Now(), "candidateProvider");
112
113 // test reader and debug by logging the group number of the candidate
114
115 std::map<std::string, grasping::GraspCandidatePtr> candidates;
116
117 try
118 {
119 candidates = reader.queryLatestGraspCandidates();
120 }
122 {
123 ARMARX_ERROR << e.makeMsg(memoryName);
124 }
125
126
127 for (auto& [id, ca] : candidates)
128 {
129 ARMARX_INFO << "candidate with ID " << id << " has group number " << ca->groupNr;
130 }
131
132 std::map<std::string, grasping::BimanualGraspCandidatePtr> bimanualCandidates;
133
134 try
135 {
136 bimanualCandidates = reader.queryLatestBimanualGraspCandidates();
137 }
139 {
140 ARMARX_ERROR << e.makeMsg(memoryName);
141 }
142
143 for (auto& [id, ca] : bimanualCandidates)
144 {
145 ARMARX_INFO << "bimanual candidate with ID " << id << " has group number "
146 << ca->groupNr;
147 }
148
149 m.waitForNextTick();
150 }
151 }
152
153 grasping::GraspCandidate
155 {
156 armarx::grasping::GraspCandidate candidate = armarx::grasping::GraspCandidate();
157
158 candidate.approachVector = Vector3BasePtr(toIce(zeroVector));
159 candidate.graspPose = PoseBasePtr(toIce(identityMatrix));
160 candidate.providerName = "Example";
161 candidate.side = "Right";
162 candidate.robotPose = PoseBasePtr(toIce(identityMatrix));
163 // tcpPose is optional, however it is needed to visualize with arviz
164 candidate.tcpPoseInHandRoot = PoseBasePtr(toIce(identityMatrix));
165 // source Info is also not necessary, but reference object name is used as entity name
166 // "UnknownObject" if none is provided
167 candidate.sourceInfo = new grasping::GraspCandidateSourceInfo();
168 candidate.sourceInfo->referenceObjectName = "Box";
169 candidate.sourceInfo->bbox = new grasping::BoundingBox();
170 candidate.sourceInfo->bbox->center = Vector3BasePtr(toIce(zeroVector));
171 candidate.sourceInfo->bbox->ha1 = Vector3BasePtr(toIce(zeroVector));
172 candidate.sourceInfo->bbox->ha2 = Vector3BasePtr(toIce(zeroVector));
173 candidate.sourceInfo->bbox->ha3 = Vector3BasePtr(toIce(zeroVector));
174 candidate.sourceInfo->referenceObjectPose = PoseBasePtr(toIce(identityMatrix));
175
176 return candidate;
177 }
178
179 grasping::BimanualGraspCandidate
181 {
182 armarx::grasping::BimanualGraspCandidate bimanualCandidate =
183 armarx::grasping::BimanualGraspCandidate();
184
185 bimanualCandidate.approachVectorLeft = Vector3BasePtr(toIce(zeroVector));
186 bimanualCandidate.approachVectorRight = Vector3BasePtr(toIce(zeroVector));
187 bimanualCandidate.graspPoseLeft = PoseBasePtr(toIce(Eigen::Matrix4f()));
188 bimanualCandidate.graspPoseRight = PoseBasePtr(toIce(Eigen::Matrix4f()));
189 bimanualCandidate.providerName = "BimanualExample";
190 bimanualCandidate.robotPose = PoseBasePtr(toIce(identityMatrix));
191 bimanualCandidate.tcpPoseInHandRootRight = PoseBasePtr(toIce(identityMatrix));
192 bimanualCandidate.tcpPoseInHandRootLeft = PoseBasePtr(toIce(identityMatrix));
193 bimanualCandidate.inwardsVectorLeft = Vector3BasePtr(toIce(zeroVector));
194 bimanualCandidate.inwardsVectorRight = Vector3BasePtr(toIce(zeroVector));
195 return bimanualCandidate;
196 }
197
198} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
grasping::BimanualGraspCandidate makeDummyBimanualGraspCandidate()
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
grasping::GraspCandidate makeDummyGraspCandidate()
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Indicates that a query resulted in an Error.
Definition ArMemError.h:191
static std::string makeMsg(const std::string &memory, const std::string &message="")
static DateTime Now()
Definition DateTime.cpp:51
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition Metronome.h:57
Duration waitForNextTick() const
Wait and block until the target period is met.
Definition Metronome.cpp:27
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)