box_to_grasp_candidates.cpp
Go to the documentation of this file.
2 
3 #include <sstream>
4 
5 #include <VirtualRobot/Robot.h>
6 
9 
10 namespace 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*
152  ARMARX_TRACE;
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*
217  ARMARX_TRACE;
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*
282  ARMARX_TRACE;
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*
347  ARMARX_TRACE;
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  {
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  {
401  ARMARX_CHECK_NOT_NULL(robot);
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 
424 namespace armarx
425 {
427  const VirtualRobot::RobotPtr& robot) :
428  _rnh{std::move(rnh)}, _robot{robot}
429  {
430  ARMARX_CHECK_NOT_NULL(_robot);
431  }
432 
433  const box_to_grasp_candidates::side_data&
434  box_to_grasp_candidates::side(const std::string& side) const
435  {
436  return _sides.at(side);
437  }
438 
440  box_to_grasp_candidates::side(const std::string& side)
441  {
442  ARMARX_TRACE;
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,
465  {
466  ARMARX_TRACE;
467  const auto g = center_grasp(box.center(),
468 
469  box_up_axis(box, align),
470  box_up_len(box, align),
471  side.hand_up,
472 
475 
476  side.tcp_shift);
477  return {g.pose, g.approach, &side};
478  }
479 } // namespace armarx
armarx::box_to_grasp_candidates::box_alignment::neg_x_pos_z
@ neg_x_pos_z
armarx::box_to_grasp_candidates::box_alignment::pos_x_neg_y
@ pos_x_neg_y
armarx::box_to_grasp_candidates::box_alignment::pos_y_pos_x
@ pos_y_pos_x
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::box_to_grasp_candidates::box_alignment::neg_z_pos_x
@ neg_z_pos_x
armarx::box_to_grasp_candidates::box_alignment::neg_x_pos_y
@ neg_x_pos_y
armarx::box_to_grasp_candidates::box_alignment::neg_z_pos_y
@ neg_z_pos_y
armarx::box_to_grasp_candidates::box_to_grasp_candidates
box_to_grasp_candidates(armarx::RobotNameHelperPtr rnh, const VirtualRobot::RobotPtr &robot)
Definition: box_to_grasp_candidates.cpp:426
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::box_to_grasp_candidates::box_forward_len
static float box_forward_len(const box_t &box, box_alignment align)
Definition: box_to_grasp_candidates.cpp:287
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::box_to_grasp_candidates::side_data::tcp_shift
Eigen::Vector3f tcp_shift
Definition: box_to_grasp_candidates.h:98
armarx::box_to_grasp_candidates::box_transverse_len
static float box_transverse_len(const box_t &box, box_alignment align)
Definition: box_to_grasp_candidates.cpp:92
armarx::box_to_grasp_candidates::grasp::make_candidate
armarx::grasping::GraspCandidatePtr make_candidate(const std::string &provider_name) const
Definition: box_to_grasp_candidates.cpp:389
trace.h
armarx::box_to_grasp_candidates::box_alignment::pos_z_neg_x
@ pos_z_neg_x
armarx::box_to_grasp_candidates::side_data::nh_arm_w_rob
armarx::RobotNameHelper::RobotArm nh_arm_w_rob
Definition: box_to_grasp_candidates.h:97
std::align
void * align(size_t alignment, size_t bytes, void *&bufferPlace, size_t &bufferSpace) noexcept
Definition: HeterogenousContinuousContainer.h:37
armarx::box_to_grasp_candidates::box_alignment::neg_y_neg_z
@ neg_y_neg_z
armarx::box_to_grasp_candidates::length_limit::upward_length_min
float upward_length_min
Definition: box_to_grasp_candidates.h:84
armarx::box_to_grasp_candidates::side_data
Definition: box_to_grasp_candidates.h:93
armarx::box_to_grasp_candidates::length_limit::transverse_length_min
float transverse_length_min
Definition: box_to_grasp_candidates.h:82
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::box_to_grasp_candidates::box_alignment::neg_y_pos_x
@ neg_y_pos_x
armarx::box_to_grasp_candidates::side_data::name
std::string name
Definition: box_to_grasp_candidates.h:95
armarx::box_to_grasp_candidates::box_alignment
box_alignment
Definition: box_to_grasp_candidates.h:17
armarx::RobotNameHelperPtr
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
Definition: RobotNameHelper.h:32
armarx::box_to_grasp_candidates::length_limit::limit_violation_string
std::string limit_violation_string(const box_t &box, box_alignment align) const
Definition: box_to_grasp_candidates.cpp:365
armarx::box_to_grasp_candidates::box_alignment::neg_y_pos_z
@ neg_y_pos_z
armarx::box_to_grasp_candidates::box_alignment::pos_x_pos_y
@ pos_x_pos_y
armarx::box_to_grasp_candidates::side_data::hand_up
Eigen::Vector3f hand_up
Definition: box_to_grasp_candidates.h:99
armarx::box_to_grasp_candidates::box_alignment::neg_x_neg_z
@ neg_x_neg_z
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::box_to_grasp_candidates::add_armar6_defaults
void add_armar6_defaults()
Definition: box_to_grasp_candidates.cpp:13
armarx::box_to_grasp_candidates::box_alignment::pos_x_neg_z
@ pos_x_neg_z
armarx::box_to_grasp_candidates::box_alignment::pos_y_neg_z
@ pos_y_neg_z
armarx::box_to_grasp_candidates::box_alignment::pos_z_pos_y
@ pos_z_pos_y
armarx::box_to_grasp_candidates::box_alignment::pos_z_neg_y
@ pos_z_neg_y
armarx::box_to_grasp_candidates::grasp
Definition: box_to_grasp_candidates.h:103
armarx::box_to_grasp_candidates::side
const side_data & side(const std::string &side) const
Definition: box_to_grasp_candidates.cpp:434
armarx::box_to_grasp_candidates::center_grasp
grasp center_grasp(const box_t &box, const side_data &side, box_alignment align)
Definition: box_to_grasp_candidates.cpp:462
armarx::RobotArm::getRobot
const VirtualRobot::RobotPtr & getRobot() const
Definition: RobotNameHelper.cpp:416
armarx::box_to_grasp_candidates::box_up_axis
static Eigen::Vector3f box_up_axis(const box_t &box, box_alignment align)
Definition: box_to_grasp_candidates.cpp:157
armarx::box_to_grasp_candidates::box_alignment::pos_z_pos_x
@ pos_z_pos_x
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::box_to_grasp_candidates::box_alignment::neg_y_neg_x
@ neg_y_neg_x
armarx::box_to_grasp_candidates::box_alignment::pos_x_pos_z
@ pos_x_pos_z
armarx::box_to_grasp_candidates::box_alignment::pos_y_pos_z
@ pos_y_pos_z
armarx::box_to_grasp_candidates::box_alignment::neg_z_neg_y
@ neg_z_neg_y
armarx::box_to_grasp_candidates::box_transverse_axis
static Eigen::Vector3f box_transverse_axis(const box_t &box, box_alignment align)
Definition: box_to_grasp_candidates.cpp:27
simox::OrientedBox
Definition: ice_conversions.h:17
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::box_to_grasp_candidates::box_alignment::pos_y_neg_x
@ pos_y_neg_x
armarx::box_to_grasp_candidates::box_up_len
static float box_up_len(const box_t &box, box_alignment align)
Definition: box_to_grasp_candidates.cpp:222
armarx::box_to_grasp_candidates::sides
const std::map< std::string, side_data > & sides() const
Definition: box_to_grasp_candidates.cpp:456
box_to_grasp_candidates.h
armarx::box_to_grasp_candidates::length_limit::in_limits
bool in_limits(const box_t &box, box_alignment align) const
Definition: box_to_grasp_candidates.cpp:352
armarx::box_to_grasp_candidates::side_data::hand_transverse
Eigen::Vector3f hand_transverse
Definition: box_to_grasp_candidates.h:100
armarx::box_to_grasp_candidates::length_limit::forward_length_min
float forward_length_min
Definition: box_to_grasp_candidates.h:86
armarx::box_to_grasp_candidates::box_alignment::neg_x_neg_y
@ neg_x_neg_y
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::box_to_grasp_candidates::box_alignment::neg_z_neg_x
@ neg_z_neg_x
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19