GraspProviderExample.cpp
Go to the documentation of this file.
1 #include "GraspProviderExample.h"
2 
3 #include <SimoxUtility/color/cmaps.h>
4 
7 
8 #include <RobotAPI/libraries/GraspingUtility/aron/GraspCandidate.aron.generated.h>
14 
15 namespace armarx
16 {
18  std::string prefix) :
20  {
21  }
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 
44  {
45  }
46 
47  void
49  {
50  ARMARX_IMPORTANT << "Init";
51  }
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
70  {
71  }
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 
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 
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  }
117  catch (armem::error::QueryFailed& e)
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  }
134  catch (armem::error::QueryFailed& e)
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
armarx::GraspProviderExamplePropertyDefinitions::GraspProviderExamplePropertyDefinitions
GraspProviderExamplePropertyDefinitions(std::string prefix)
Definition: GraspProviderExample.cpp:17
armarx::GraspProviderExample::getDefaultName
std::string getDefaultName() const override
Definition: GraspProviderExample.cpp:38
armarx::armem::GraspCandidateReader::queryLatestBimanualGraspCandidates
std::map< std::string, ::armarx::grasping::BimanualGraspCandidatePtr > queryLatestBimanualGraspCandidates(std::string const &provider="") const
Definition: GraspCandidateReader.cpp:225
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
Pose.h
armarx::GraspProviderExample::makeDummyGraspCandidate
grasping::GraspCandidate makeDummyGraspCandidate()
Definition: GraspProviderExample.cpp:150
query_fns.h
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::GraspProviderExamplePropertyDefinitions
Definition: GraspProviderExample.h:17
armarx::armem::error::QueryFailed::makeMsg
static std::string makeMsg(const std::string &memory, const std::string &message="")
Definition: ArMemError.cpp:208
MemoryRemoteGui.h
GraspProviderExample.h
armarx::GraspProviderExample::run
void run()
Definition: GraspProviderExample.cpp:74
armarx::GraspProviderExample::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: GraspProviderExample.cpp:63
ice_conversions.h
armarx::armem::GraspCandidateWriter::commitBimanualGraspCandidate
bool commitBimanualGraspCandidate(const armarx::grasping::BimanualGraspCandidate &candidate, const armem::Time &timestamp, const std::string &provider)
Definition: GraspCandidateWriter.cpp:68
Metronome.h
armarx::GraspProviderExample::makeDummyBimanualGraspCandidate
grasping::BimanualGraspCandidate makeDummyBimanualGraspCandidate()
Definition: GraspProviderExample.cpp:176
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
ExpressionException.h
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:31
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::GraspProviderExample::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: GraspProviderExample.cpp:69
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::GraspProviderExample::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: GraspProviderExample.cpp:54
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:35
armarx::GraspProviderExample::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: GraspProviderExample.cpp:24
Builder.h
armarx::armem::error::QueryFailed
Indicates that a query resulted in an Error.
Definition: ArMemError.h:190
armarx::armem::GraspCandidateReader::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem, bool use=true)
Definition: GraspCandidateReader.cpp:18
armarx::armem::GraspCandidateReader::queryLatestGraspCandidates
::armarx::grasping::GraspCandidateDict queryLatestGraspCandidates(std::string const &provider="") const
Definition: GraspCandidateReader.cpp:188
armarx::armem::GraspCandidateWriter::commitGraspCandidateSeq
bool commitGraspCandidateSeq(const armarx::grasping::GraspCandidateSeq &candidates, const armem::Time &timestamp, const std::string &provider)
Definition: GraspCandidateWriter.cpp:90
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::armem::GraspCandidateWriter::commitGraspCandidate
bool commitGraspCandidate(const armarx::grasping::GraspCandidate &candidate, const armem::Time &timestamp, const std::string &provider)
Definition: GraspCandidateWriter.cpp:49
armarx::GraspProviderExample::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: GraspProviderExample.cpp:48
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55
armarx::armem::GraspCandidateWriter::connect
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: GraspCandidateWriter.cpp:13
armarx::GraspProviderExample::GraspProviderExample
GraspProviderExample()
Definition: GraspProviderExample.cpp:43