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
15namespace armarx
16{
22
25 {
26 ARMARX_IMPORTANT << "Prperty defs";
29
30 defs->topic(debugObserver);
31
32 defs->optional(memoryName, "mem.MemoryName", "Name of the memory to use.");
33
34 return defs;
35 }
36
37 std::string
39 {
40 return "GraspProviderExample";
41 }
42
46
47 void
52
53 void
55 {
56 writer.connect(memoryNameSystem());
57 reader.connect(memoryNameSystem());
59 task->start();
60 }
61
62 void
64 {
65 task->stop();
66 }
67
68 void
72
73 void
75 {
76 ARMARX_IMPORTANT << "Running example.";
77
79 int i = 0;
80
81
82 while (!task->isStopped() && i++ < 100)
83 {
84 // initialize all necessary fields of a grasp candidate and use writer to commit it to memory
85 grasping::GraspCandidate candidate = makeDummyGraspCandidate();
86 candidate.groupNr = i; //non-necessary field, but used to commit different candidates
87
88 writer.commitGraspCandidate(candidate, armem::Time::Now(), "candidateProvider");
89
90 // initialize all necessary fields of a bimanual grasp candidate and use writer to commit it to memory
91 grasping::BimanualGraspCandidate bimanualCandidate = makeDummyBimanualGraspCandidate();
92 bimanualCandidate.groupNr =
93 i; //non-necessary field, but used to commit different candidates
94
95 writer.commitBimanualGraspCandidate(
96 bimanualCandidate, armem::Time::Now(), "bimanualProvider");
97
98
99 //test for writing Seqs, candidates from the same object appear as instances of the same snapshot
100 grasping::GraspCandidateSeq candidatesToWrite;
101 candidatesToWrite.push_back(new grasping::GraspCandidate(candidate));
102 candidate.side = "Left";
103 candidatesToWrite.push_back(new grasping::GraspCandidate(candidate));
104
105
106 writer.commitGraspCandidateSeq(
107 candidatesToWrite, armem::Time::Now(), "candidateProvider");
108
109 // test reader and debug by logging the group number of the candidate
110
111 std::map<std::string, grasping::GraspCandidatePtr> candidates;
112
113 try
114 {
115 candidates = reader.queryLatestGraspCandidates();
116 }
118 {
119 ARMARX_ERROR << e.makeMsg(memoryName);
120 }
121
122
123 for (auto& [id, ca] : candidates)
124 {
125 ARMARX_INFO << "candidate with ID " << id << " has group number " << ca->groupNr;
126 }
127
128 std::map<std::string, grasping::BimanualGraspCandidatePtr> bimanualCandidates;
129
130 try
131 {
132 bimanualCandidates = reader.queryLatestBimanualGraspCandidates();
133 }
135 {
136 ARMARX_ERROR << e.makeMsg(memoryName);
137 }
138
139 for (auto& [id, ca] : bimanualCandidates)
140 {
141 ARMARX_INFO << "bimanual candidate with ID " << id << " has group number "
142 << ca->groupNr;
143 }
144
145 m.waitForNextTick();
146 }
147 }
148
149 grasping::GraspCandidate
151 {
152 armarx::grasping::GraspCandidate candidate = armarx::grasping::GraspCandidate();
153
154 candidate.approachVector = Vector3BasePtr(toIce(zeroVector));
155 candidate.graspPose = PoseBasePtr(toIce(identityMatrix));
156 candidate.providerName = "Example";
157 candidate.side = "Right";
158 candidate.robotPose = PoseBasePtr(toIce(identityMatrix));
159 // tcpPose is optional, however it is needed to visualize with arviz
160 candidate.tcpPoseInHandRoot = PoseBasePtr(toIce(identityMatrix));
161 // source Info is also not necessary, but reference object name is used as entity name
162 // "UnknownObject" if none is provided
163 candidate.sourceInfo = new grasping::GraspCandidateSourceInfo();
164 candidate.sourceInfo->referenceObjectName = "Box";
165 candidate.sourceInfo->bbox = new grasping::BoundingBox();
166 candidate.sourceInfo->bbox->center = Vector3BasePtr(toIce(zeroVector));
167 candidate.sourceInfo->bbox->ha1 = Vector3BasePtr(toIce(zeroVector));
168 candidate.sourceInfo->bbox->ha2 = Vector3BasePtr(toIce(zeroVector));
169 candidate.sourceInfo->bbox->ha3 = Vector3BasePtr(toIce(zeroVector));
170 candidate.sourceInfo->referenceObjectPose = PoseBasePtr(toIce(identityMatrix));
171
172 return candidate;
173 }
174
175 grasping::BimanualGraspCandidate
177 {
178 armarx::grasping::BimanualGraspCandidate bimanualCandidate =
179 armarx::grasping::BimanualGraspCandidate();
180
181 bimanualCandidate.approachVectorLeft = Vector3BasePtr(toIce(zeroVector));
182 bimanualCandidate.approachVectorRight = Vector3BasePtr(toIce(zeroVector));
183 bimanualCandidate.graspPoseLeft = PoseBasePtr(toIce(Eigen::Matrix4f()));
184 bimanualCandidate.graspPoseRight = PoseBasePtr(toIce(Eigen::Matrix4f()));
185 bimanualCandidate.providerName = "BimanualExample";
186 bimanualCandidate.robotPose = PoseBasePtr(toIce(identityMatrix));
187 bimanualCandidate.tcpPoseInHandRootRight = PoseBasePtr(toIce(identityMatrix));
188 bimanualCandidate.tcpPoseInHandRootLeft = PoseBasePtr(toIce(identityMatrix));
189 bimanualCandidate.inwardsVectorLeft = Vector3BasePtr(toIce(zeroVector));
190 bimanualCandidate.inwardsVectorRight = Vector3BasePtr(toIce(zeroVector));
191 return bimanualCandidate;
192 }
193
194} // namespace armarx
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)