box_to_grasp_candidates.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
5#include <VirtualRobot/Robot.h>
6
9
10namespace armarx
11{
12 void
14 {
15 auto& l = side("Left");
16 auto& r = side("Right");
17
18 l.hand_transverse = Eigen::Vector3f{0, 1, 0};
19 r.hand_transverse = Eigen::Vector3f{0, 1, 0};
20 l.hand_up = Eigen::Vector3f{-1, 0, -1};
21 r.hand_up = Eigen::Vector3f{+1, 0, -1};
22 l.tcp_shift = Eigen::Vector3f{0, -30, 0};
23 r.tcp_shift = Eigen::Vector3f{0, -30, 0};
24 }
25
26 Eigen::Vector3f
28 {
29 // *INDENT-OFF*
30 switch (align)
31 {
33 [[fallthrough]];
35 [[fallthrough]];
37 [[fallthrough]];
39 return box.axis_x();
40
42 [[fallthrough]];
44 [[fallthrough]];
46 [[fallthrough]];
48 return -box.axis_x();
49
51 [[fallthrough]];
53 [[fallthrough]];
55 [[fallthrough]];
57 return box.axis_y();
58
60 [[fallthrough]];
62 [[fallthrough]];
64 [[fallthrough]];
66 return -box.axis_y();
67
69 [[fallthrough]];
71 [[fallthrough]];
73 [[fallthrough]];
75 return box.axis_z();
76
78 [[fallthrough]];
80 [[fallthrough]];
82 [[fallthrough]];
84 return -box.axis_z();
85 }
86 // *INDENT-ON*
88 throw std::logic_error{"reached unreachable code"};
89 }
90
91 float
93 {
94 // *INDENT-OFF*
95 switch (align)
96 {
98 [[fallthrough]];
100 [[fallthrough]];
102 [[fallthrough]];
104 [[fallthrough]];
105
107 [[fallthrough]];
109 [[fallthrough]];
111 [[fallthrough]];
113 return box.dimension_x();
114
116 [[fallthrough]];
118 [[fallthrough]];
120 [[fallthrough]];
122 [[fallthrough]];
123
125 [[fallthrough]];
127 [[fallthrough]];
129 [[fallthrough]];
131 return box.dimension_y();
132
134 [[fallthrough]];
136 [[fallthrough]];
138 [[fallthrough]];
140 [[fallthrough]];
141
143 [[fallthrough]];
145 [[fallthrough]];
147 [[fallthrough]];
149 return box.dimension_z();
150 }
151 // *INDENT-ON*
153 throw std::logic_error{"reached unreachable code"};
154 }
155
156 Eigen::Vector3f
158 {
159 // *INDENT-OFF*
160 switch (align)
161 {
163 [[fallthrough]];
165 [[fallthrough]];
167 [[fallthrough]];
169 return box.axis_x();
170
172 [[fallthrough]];
174 [[fallthrough]];
176 [[fallthrough]];
178 return -box.axis_x();
179
181 [[fallthrough]];
183 [[fallthrough]];
185 [[fallthrough]];
187 return box.axis_y();
188
190 [[fallthrough]];
192 [[fallthrough]];
194 [[fallthrough]];
196 return -box.axis_y();
197
199 [[fallthrough]];
201 [[fallthrough]];
203 [[fallthrough]];
205 return box.axis_z();
206
208 [[fallthrough]];
210 [[fallthrough]];
212 [[fallthrough]];
214 return -box.axis_z();
215 }
216 // *INDENT-ON*
218 throw std::logic_error{"reached unreachable code"};
219 }
220
221 float
223 {
224 // *INDENT-OFF*
225 switch (align)
226 {
228 [[fallthrough]];
230 [[fallthrough]];
232 [[fallthrough]];
234 [[fallthrough]];
235
237 [[fallthrough]];
239 [[fallthrough]];
241 [[fallthrough]];
243 return box.dimension_x();
244
246 [[fallthrough]];
248 [[fallthrough]];
250 [[fallthrough]];
252 [[fallthrough]];
253
255 [[fallthrough]];
257 [[fallthrough]];
259 [[fallthrough]];
261 return box.dimension_y();
262
264 [[fallthrough]];
266 [[fallthrough]];
268 [[fallthrough]];
270 [[fallthrough]];
271
273 [[fallthrough]];
275 [[fallthrough]];
277 [[fallthrough]];
279 return box.dimension_z();
280 }
281 // *INDENT-ON*
283 throw std::logic_error{"reached unreachable code"};
284 }
285
286 float
288 {
289 // *INDENT-OFF*
290 switch (align)
291 {
293 [[fallthrough]];
295 [[fallthrough]];
297 [[fallthrough]];
299 [[fallthrough]];
300
302 [[fallthrough]];
304 [[fallthrough]];
306 [[fallthrough]];
308 return box.dimension_x();
309
311 [[fallthrough]];
313 [[fallthrough]];
315 [[fallthrough]];
317 [[fallthrough]];
318
320 [[fallthrough]];
322 [[fallthrough]];
324 [[fallthrough]];
326 return box.dimension_y();
327
329 [[fallthrough]];
331 [[fallthrough]];
333 [[fallthrough]];
335 [[fallthrough]];
336
338 [[fallthrough]];
340 [[fallthrough]];
342 [[fallthrough]];
344 return box.dimension_z();
345 }
346 // *INDENT-ON*
348 throw std::logic_error{"reached unreachable code"};
349 }
350
351 bool
355 {
356 const auto t_len = box_transverse_len(box, align);
357 const auto u_len = box_up_len(box, align);
358 const auto f_len = box_forward_len(box, align);
359 return t_len < transverse_length_max && t_len > transverse_length_min &&
360 u_len < upward_length_max && u_len > upward_length_min &&
361 f_len < forward_length_max && f_len > forward_length_min;
362 }
363
364 std::string
366 box_alignment align) const
367 {
368 const auto t_len = box_transverse_len(box, align);
369 const auto u_len = box_up_len(box, align);
370 const auto f_len = box_forward_len(box, align);
371 std::stringstream s;
372 if (!(t_len < transverse_length_max && t_len > transverse_length_min))
373 {
374 s << "tr: " << t_len << " [" << transverse_length_min << ", " << transverse_length_max
375 << "] ";
376 }
377 if (!(u_len < upward_length_max && u_len > upward_length_min))
378 {
379 s << "up: " << u_len << " [" << upward_length_min << ", " << upward_length_max << "] ";
380 }
381 if (!(f_len < forward_length_max && f_len > forward_length_min))
382 {
383 s << "fw: " << f_len << " [" << forward_length_min << ", " << forward_length_max << "]";
384 }
385 return s.str();
386 }
387
388 armarx::grasping::GraspCandidatePtr
389 box_to_grasp_candidates::grasp::make_candidate(const std::string& provider_name) const
390 {
391 ARMARX_CHECK_EXPRESSION(side && side->nh_arm_w_rob.getRobot());
392 return make_candidate(
393 provider_name, side->name, side->nh_arm_w_rob.getRobot()->getGlobalPose());
394 }
395
396 armarx::grasping::GraspCandidatePtr
397 box_to_grasp_candidates::grasp::make_candidate(const std::string& provider_name,
398 const std::string& side_name,
399 const VirtualRobot::RobotPtr& robot) const
400 {
402 return make_candidate(provider_name, side_name, robot->getGlobalPose());
403 }
404
405 armarx::grasping::GraspCandidatePtr
406 box_to_grasp_candidates::grasp::make_candidate(const std::string& provider_name,
407 const std::string& side_name,
408 const Eigen::Matrix4f& global_pose) const
409 {
410 armarx::grasping::GraspCandidatePtr gc = new armarx::grasping::GraspCandidate;
411 gc->robotPose = new armarx::Pose(global_pose);
412 gc->graspPose = new armarx::Pose(pose);
413 gc->providerName = provider_name;
414 gc->side = side_name;
415 gc->approachVector = new armarx::Vector3(approach);
416 gc->objectType = armarx::objpose::UnknownObject;
417 gc->sourceFrame = "root";
418 gc->targetFrame = "root";
419 return gc;
420 }
421
422} // namespace armarx
423
424namespace armarx
425{
427 const VirtualRobot::RobotPtr& robot) :
428 _rnh{std::move(rnh)}, _robot{robot}
429 {
430 ARMARX_CHECK_NOT_NULL(_robot);
431 }
432
434 box_to_grasp_candidates::side(const std::string& side) const
435 {
436 return _sides.at(side);
437 }
438
441 {
443 ARMARX_CHECK_NOT_NULL(_robot);
444 if (_sides.count(side))
445 {
446 return _sides.at(side);
447 }
448 auto& data = _sides[side];
449 data.name = side;
450 data.nh_arm = _rnh->getArm(side);
451 data.nh_arm_w_rob = data.nh_arm.addRobot(_robot);
452 return data;
453 }
454
455 const std::map<std::string, box_to_grasp_candidates::side_data>&
457 {
458 return _sides;
459 }
460
463 const side_data& side,
464 box_alignment align)
465 {
467 const auto g = center_grasp(box.center(),
468
469 box_up_axis(box, align),
470 box_up_len(box, align),
472
475
477 return {g.pose, g.approach, &side};
478 }
479} // namespace armarx
The Pose class.
Definition Pose.h:243
The Vector3 class.
Definition Pose.h:113
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
void * align(size_t alignment, size_t bytes, void *&bufferPlace, size_t &bufferSpace) noexcept
armarx::grasping::GraspCandidatePtr make_candidate(const std::string &provider_name) const
bool in_limits(const box_t &box, box_alignment align) const
std::string limit_violation_string(const box_t &box, box_alignment align) const
static float box_transverse_len(const box_t &box, box_alignment align)
static float box_up_len(const box_t &box, box_alignment align)
static Eigen::Vector3f box_transverse_axis(const box_t &box, box_alignment align)
const side_data & side(const std::string &side) const
static Eigen::Vector3f box_up_axis(const box_t &box, box_alignment align)
static float box_forward_len(const box_t &box, box_alignment align)
grasp center_grasp(const box_t &box, const side_data &side, box_alignment align)
const std::map< std::string, side_data > & sides() const
simox::OrientedBox< float > box_t
box_to_grasp_candidates(armarx::RobotNameHelperPtr rnh, const VirtualRobot::RobotPtr &robot)
#define ARMARX_TRACE
Definition trace.h:77