box_to_grasp_candidates.cpp
Go to the documentation of this file.
1 #include <sstream>
2 
4 
6 
8 
9 namespace armarx
10 {
12  {
13  auto& l = side("Left");
14  auto& r = side("Right");
15 
16  l.hand_transverse = Eigen::Vector3f{0, 1, 0};
17  r.hand_transverse = Eigen::Vector3f{0, 1, 0};
18  l.hand_up = Eigen::Vector3f{-1, 0, -1};
19  r.hand_up = Eigen::Vector3f{+1, 0, -1};
20  l.tcp_shift = Eigen::Vector3f{0, -30, 0};
21  r.tcp_shift = Eigen::Vector3f{0, -30, 0};
22  }
23 
24  Eigen::Vector3f
26  {
27  // *INDENT-OFF*
28  switch (align)
29  {
30  case box_alignment::pos_y_pos_x: [[fallthrough]];
31  case box_alignment::neg_y_pos_x: [[fallthrough]];
32  case box_alignment::pos_z_pos_x: [[fallthrough]];
33  case box_alignment::neg_z_pos_x: return box.axis_x();
34 
35  case box_alignment::pos_y_neg_x: [[fallthrough]];
36  case box_alignment::neg_y_neg_x: [[fallthrough]];
37  case box_alignment::pos_z_neg_x: [[fallthrough]];
38  case box_alignment::neg_z_neg_x: return -box.axis_x();
39 
40  case box_alignment::pos_x_pos_y: [[fallthrough]];
41  case box_alignment::neg_x_pos_y: [[fallthrough]];
42  case box_alignment::pos_z_pos_y: [[fallthrough]];
43  case box_alignment::neg_z_pos_y: return box.axis_y();
44 
45  case box_alignment::pos_x_neg_y: [[fallthrough]];
46  case box_alignment::neg_x_neg_y: [[fallthrough]];
47  case box_alignment::pos_z_neg_y: [[fallthrough]];
48  case box_alignment::neg_z_neg_y: return -box.axis_y();
49 
50  case box_alignment::pos_x_pos_z: [[fallthrough]];
51  case box_alignment::neg_x_pos_z: [[fallthrough]];
52  case box_alignment::pos_y_pos_z: [[fallthrough]];
53  case box_alignment::neg_y_pos_z: return box.axis_z();
54 
55  case box_alignment::pos_x_neg_z: [[fallthrough]];
56  case box_alignment::neg_x_neg_z: [[fallthrough]];
57  case box_alignment::pos_y_neg_z: [[fallthrough]];
58  case box_alignment::neg_y_neg_z: return -box.axis_z();
59  }
60  // *INDENT-ON*
62  throw std::logic_error{"reached unreachable code"};
63  }
64 
65  float
67  {
68  // *INDENT-OFF*
69  switch (align)
70  {
71  case box_alignment::pos_y_pos_x: [[fallthrough]];
72  case box_alignment::neg_y_pos_x: [[fallthrough]];
73  case box_alignment::pos_z_pos_x: [[fallthrough]];
74  case box_alignment::neg_z_pos_x: [[fallthrough]];
75 
76  case box_alignment::pos_y_neg_x: [[fallthrough]];
77  case box_alignment::neg_y_neg_x: [[fallthrough]];
78  case box_alignment::pos_z_neg_x: [[fallthrough]];
79  case box_alignment::neg_z_neg_x: return box.dimension_x();
80 
81  case box_alignment::pos_x_pos_y: [[fallthrough]];
82  case box_alignment::neg_x_pos_y: [[fallthrough]];
83  case box_alignment::pos_z_pos_y: [[fallthrough]];
84  case box_alignment::neg_z_pos_y: [[fallthrough]];
85 
86  case box_alignment::pos_x_neg_y: [[fallthrough]];
87  case box_alignment::neg_x_neg_y: [[fallthrough]];
88  case box_alignment::pos_z_neg_y: [[fallthrough]];
89  case box_alignment::neg_z_neg_y: return box.dimension_y();
90 
91  case box_alignment::pos_x_pos_z: [[fallthrough]];
92  case box_alignment::neg_x_pos_z: [[fallthrough]];
93  case box_alignment::pos_y_pos_z: [[fallthrough]];
94  case box_alignment::neg_y_pos_z: [[fallthrough]];
95 
96  case box_alignment::pos_x_neg_z: [[fallthrough]];
97  case box_alignment::neg_x_neg_z: [[fallthrough]];
98  case box_alignment::pos_y_neg_z: [[fallthrough]];
99  case box_alignment::neg_y_neg_z: return box.dimension_z();
100  }
101  // *INDENT-ON*
102  ARMARX_TRACE;
103  throw std::logic_error{"reached unreachable code"};
104  }
105 
106  Eigen::Vector3f
108  {
109  // *INDENT-OFF*
110  switch (align)
111  {
112  case box_alignment::pos_x_pos_y: [[fallthrough]];
113  case box_alignment::pos_x_pos_z: [[fallthrough]];
114  case box_alignment::pos_x_neg_y: [[fallthrough]];
115  case box_alignment::pos_x_neg_z: return box.axis_x();
116 
117  case box_alignment::neg_x_pos_y: [[fallthrough]];
118  case box_alignment::neg_x_pos_z: [[fallthrough]];
119  case box_alignment::neg_x_neg_y: [[fallthrough]];
120  case box_alignment::neg_x_neg_z: return -box.axis_x();
121 
122  case box_alignment::pos_y_pos_x: [[fallthrough]];
123  case box_alignment::pos_y_pos_z: [[fallthrough]];
124  case box_alignment::pos_y_neg_x: [[fallthrough]];
125  case box_alignment::pos_y_neg_z: return box.axis_y();
126 
127  case box_alignment::neg_y_pos_x: [[fallthrough]];
128  case box_alignment::neg_y_pos_z: [[fallthrough]];
129  case box_alignment::neg_y_neg_x: [[fallthrough]];
130  case box_alignment::neg_y_neg_z: return -box.axis_y();
131 
132  case box_alignment::pos_z_pos_x: [[fallthrough]];
133  case box_alignment::pos_z_pos_y: [[fallthrough]];
134  case box_alignment::pos_z_neg_x: [[fallthrough]];
135  case box_alignment::pos_z_neg_y: return box.axis_z();
136 
137  case box_alignment::neg_z_pos_x: [[fallthrough]];
138  case box_alignment::neg_z_pos_y: [[fallthrough]];
139  case box_alignment::neg_z_neg_x: [[fallthrough]];
140  case box_alignment::neg_z_neg_y: return -box.axis_z();
141  }
142  // *INDENT-ON*
143  ARMARX_TRACE;
144  throw std::logic_error{"reached unreachable code"};
145  }
146 
147  float
149  {
150  // *INDENT-OFF*
151  switch (align)
152  {
153  case box_alignment::pos_x_pos_y: [[fallthrough]];
154  case box_alignment::pos_x_pos_z: [[fallthrough]];
155  case box_alignment::pos_x_neg_y: [[fallthrough]];
156  case box_alignment::pos_x_neg_z: [[fallthrough]];
157 
158  case box_alignment::neg_x_pos_y: [[fallthrough]];
159  case box_alignment::neg_x_pos_z: [[fallthrough]];
160  case box_alignment::neg_x_neg_y: [[fallthrough]];
161  case box_alignment::neg_x_neg_z: return box.dimension_x();
162 
163  case box_alignment::pos_y_pos_x: [[fallthrough]];
164  case box_alignment::pos_y_pos_z: [[fallthrough]];
165  case box_alignment::pos_y_neg_x: [[fallthrough]];
166  case box_alignment::pos_y_neg_z: [[fallthrough]];
167 
168  case box_alignment::neg_y_pos_x: [[fallthrough]];
169  case box_alignment::neg_y_pos_z: [[fallthrough]];
170  case box_alignment::neg_y_neg_x: [[fallthrough]];
171  case box_alignment::neg_y_neg_z: return box.dimension_y();
172 
173  case box_alignment::pos_z_pos_x: [[fallthrough]];
174  case box_alignment::pos_z_pos_y: [[fallthrough]];
175  case box_alignment::pos_z_neg_x: [[fallthrough]];
176  case box_alignment::pos_z_neg_y: [[fallthrough]];
177 
178  case box_alignment::neg_z_pos_x: [[fallthrough]];
179  case box_alignment::neg_z_pos_y: [[fallthrough]];
180  case box_alignment::neg_z_neg_x: [[fallthrough]];
181  case box_alignment::neg_z_neg_y: return box.dimension_z();
182  }
183  // *INDENT-ON*
184  ARMARX_TRACE;
185  throw std::logic_error{"reached unreachable code"};
186  }
187 
188  float
190  {
191  // *INDENT-OFF*
192  switch (align)
193  {
194  case box_alignment::pos_y_pos_z: [[fallthrough]];
195  case box_alignment::pos_y_neg_z: [[fallthrough]];
196  case box_alignment::neg_y_pos_z: [[fallthrough]];
197  case box_alignment::neg_y_neg_z: [[fallthrough]];
198 
199  case box_alignment::pos_z_pos_y: [[fallthrough]];
200  case box_alignment::pos_z_neg_y: [[fallthrough]];
201  case box_alignment::neg_z_pos_y: [[fallthrough]];
202  case box_alignment::neg_z_neg_y: return box.dimension_x();
203 
204  case box_alignment::pos_x_pos_z: [[fallthrough]];
205  case box_alignment::pos_x_neg_z: [[fallthrough]];
206  case box_alignment::neg_x_pos_z: [[fallthrough]];
207  case box_alignment::neg_x_neg_z: [[fallthrough]];
208 
209  case box_alignment::pos_z_pos_x: [[fallthrough]];
210  case box_alignment::pos_z_neg_x: [[fallthrough]];
211  case box_alignment::neg_z_pos_x: [[fallthrough]];
212  case box_alignment::neg_z_neg_x: return box.dimension_y();
213 
214  case box_alignment::pos_x_pos_y: [[fallthrough]];
215  case box_alignment::pos_x_neg_y: [[fallthrough]];
216  case box_alignment::neg_x_pos_y: [[fallthrough]];
217  case box_alignment::neg_x_neg_y: [[fallthrough]];
218 
219  case box_alignment::pos_y_pos_x: [[fallthrough]];
220  case box_alignment::pos_y_neg_x: [[fallthrough]];
221  case box_alignment::neg_y_pos_x: [[fallthrough]];
222  case box_alignment::neg_y_neg_x: return box.dimension_z();
223  }
224  // *INDENT-ON*
225  ARMARX_TRACE;
226  throw std::logic_error{"reached unreachable code"};
227  }
228 
230  {
231  const auto t_len = box_transverse_len(box, align);
232  const auto u_len = box_up_len(box, align);
233  const auto f_len = box_forward_len(box, align);
234  return t_len < transverse_length_max &&
235  t_len > transverse_length_min &&
236  u_len < upward_length_max &&
237  u_len > upward_length_min &&
238  f_len < forward_length_max &&
239  f_len > forward_length_min;
240  }
241 
243  {
244  const auto t_len = box_transverse_len(box, align);
245  const auto u_len = box_up_len(box, align);
246  const auto f_len = box_forward_len(box, align);
247  std::stringstream s;
248  if (!(t_len < transverse_length_max && t_len > transverse_length_min))
249  {
250  s << "tr: " << t_len << " [" << transverse_length_min << ", " << transverse_length_max << "] ";
251  }
252  if (!(u_len < upward_length_max && u_len > upward_length_min))
253  {
254  s << "up: " << u_len << " [" << upward_length_min << ", " << upward_length_max << "] ";
255  }
256  if (!(f_len < forward_length_max && f_len > forward_length_min))
257  {
258  s << "fw: " << f_len << " [" << forward_length_min << ", " << forward_length_max << "]";
259  }
260  return s.str();
261  }
262 
263  armarx::grasping::GraspCandidatePtr
265  const std::string& provider_name
266  ) const
267  {
269  return make_candidate(provider_name, side->name,
270  side->nh_arm_w_rob.getRobot()->getGlobalPose());
271  }
272  armarx::grasping::GraspCandidatePtr
274  const std::string& provider_name,
275  const std::string& side_name,
276  const VirtualRobot::RobotPtr& robot
277  ) const
278  {
279  ARMARX_CHECK_NOT_NULL(robot);
280  return make_candidate(provider_name, side_name, robot->getGlobalPose());
281  }
282  armarx::grasping::GraspCandidatePtr
284  const std::string& provider_name,
285  const std::string& side_name,
286  const Eigen::Matrix4f& global_pose
287  ) const
288  {
289  armarx::grasping::GraspCandidatePtr gc = new armarx::grasping::GraspCandidate;
290  gc->robotPose = new armarx::Pose(global_pose);
291  gc->graspPose = new armarx::Pose(pose);
292  gc->providerName = provider_name;
293  gc->side = side_name;
294  gc->approachVector = new armarx::Vector3(approach);
295  gc->objectType = armarx::objpose::UnknownObject;
296  gc->sourceFrame = "root";
297  gc->targetFrame = "root";
298  return gc;
299  }
300 
301 }
302 
303 namespace armarx
304 {
306  : _rnh{std::move(rnh)}, _robot{robot}
307  {
308  ARMARX_CHECK_NOT_NULL(_robot);
309  }
310 
312  {
313  return _sides.at(side);
314  }
315 
317  {
318  ARMARX_TRACE;
319  ARMARX_CHECK_NOT_NULL(_robot);
320  if (_sides.count(side))
321  {
322  return _sides.at(side);
323  }
324  auto& data = _sides[side];
325  data.name = side;
326  data.nh_arm = _rnh->getArm(side);
327  data.nh_arm_w_rob = data.nh_arm.addRobot(_robot);
328  return data;
329  }
330 
331  const std::map<std::string, box_to_grasp_candidates::side_data>& box_to_grasp_candidates::sides() const
332  {
333  return _sides;
334  }
335 
337  const simox::OrientedBox<float>& box,
338  const side_data& side,
340  {
341  ARMARX_TRACE;
342  const auto g = center_grasp(
343  box.center(),
344 
345  box_up_axis(box, align),
346  box_up_len(box, align),
347  side.hand_up,
348 
351 
352  side.tcp_shift);
353  return {g.pose, g.approach, &side};
354  }
355 }
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::length_limit::upward_length_max
float upward_length_max
Definition: box_to_grasp_candidates.h:68
armarx::box_to_grasp_candidates::length_limit::transverse_length_max
float transverse_length_max
Definition: box_to_grasp_candidates.h:66
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:305
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:189
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:80
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:66
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:264
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:79
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:67
armarx::box_to_grasp_candidates::side_data
Definition: box_to_grasp_candidates.h:75
armarx::box_to_grasp_candidates::length_limit::transverse_length_min
float transverse_length_min
Definition: box_to_grasp_candidates.h:65
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
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:77
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:34
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:242
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:81
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::length_limit::forward_length_max
float forward_length_max
Definition: box_to_grasp_candidates.h:70
armarx::box_to_grasp_candidates::add_armar6_defaults
void add_armar6_defaults()
Definition: box_to_grasp_candidates.cpp:11
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:84
armarx::box_to_grasp_candidates::side
const side_data & side(const std::string &side) const
Definition: box_to_grasp_candidates.cpp:311
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:336
armarx::RobotArm::getRobot
const VirtualRobot::RobotPtr & getRobot() const
Definition: RobotNameHelper.cpp:375
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:107
armarx::box_to_grasp_candidates::box_alignment::pos_z_pos_x
@ pos_z_pos_x
ExpressionException.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
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:25
simox::OrientedBox
Definition: ice_conversions.h:18
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
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:148
armarx::box_to_grasp_candidates::sides
const std::map< std::string, side_data > & sides() const
Definition: box_to_grasp_candidates.cpp:331
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:229
armarx::box_to_grasp_candidates::side_data::hand_transverse
Eigen::Vector3f hand_transverse
Definition: box_to_grasp_candidates.h:82
armarx::box_to_grasp_candidates::length_limit::forward_length_min
float forward_length_min
Definition: box_to_grasp_candidates.h:69
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:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18