box_to_grasp_candidates.ipp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <SimoxUtility/math/distance/angle_between.h>
4 #include <SimoxUtility/math/project_to_plane.h>
5 #include <SimoxUtility/math/convert/pos_mat3f_to_mat4f.h>
6 #include <SimoxUtility/meta/enum/adapt_enum.h>
7 
10 
11 
12 namespace simox::meta
13 {
14  template<>
15  const simox::meta::EnumNames<armarx::box_to_grasp_candidates::box_alignment>
16  enum_names<armarx::box_to_grasp_candidates::box_alignment>
17  {
22 
27 
32 
37 
42 
47  };
48 }
49 
50 namespace armarx
51 {
52  template<class D1, class D2, class D3>
53  inline
54  std::enable_if_t <
55  simox::meta::is_vec3_v<D1>&&
56  simox::meta::is_vec3_v<D2>&&
57  simox::meta::is_vec3_v<D3>, box_to_grasp_candidates::grasp >
59  const Eigen::MatrixBase<D1>& center_pos,
60  const Eigen::MatrixBase<D2>& up, float up_len, const Eigen::Vector3f& hand_up,
61  const Eigen::MatrixBase<D3>& transverse, const Eigen::Vector3f& hand_transv,
62  const Eigen::Vector3f& tcp_shift)
63  {
64  const Eigen::Vector3f up_normalized = up.normalized();
66  const Eigen::Vector3f ax = hand_up.cross(up).normalized();
67  const float ang_u = simox::math::angle_between_vec3f_vec3f(hand_up, up_normalized, ax);
68  const Eigen::Matrix3f upward_ori = Eigen::AngleAxisf(ang_u, ax).toRotationMatrix();
69 
70 
72  const Eigen::Vector3f hand_transv_glob = upward_ori * hand_transv;
73  const Eigen::Vector3f hand_transv_glob_flat = simox::math::project_to_plane(hand_transv_glob, up_normalized);
74  const Eigen::Vector3f transverse_flat = simox::math::project_to_plane(transverse, up_normalized);
75  const float ang = simox::math::angle_between_vec3f_vec3f(
76  hand_transv_glob_flat,
77  transverse_flat,
78  up_normalized
79  );
80  const Eigen::Matrix3f transv_align = Eigen::AngleAxisf{ang, up_normalized.normalized()}.toRotationMatrix();
81 
82  const Eigen::Matrix3f gc_ori = transv_align * upward_ori;
83  const Eigen::Vector3f gc_pos = center_pos + up_normalized * up_len / 2;
84  return
85  {
86  simox::math::pos_mat3f_to_mat4f(
87  gc_pos + gc_ori * tcp_shift,
88  gc_ori
89  ),
90  -up_normalized,
91  nullptr
92  };
93  }
94 
95  inline
97  const box_t& box,
98  const side_data& side,
99  const length_limit& limit,
100  auto consume_grasp)
101  {
102  for (std::uint_fast8_t i = 0; i < 24; ++i)
103  {
104  const auto align = static_cast<box_alignment>(i);
105  if (limit.in_limits(box, align))
106  {
107  ARMARX_VERBOSE << "align ok " << std::to_string(align);
108  consume_grasp(center_grasp(box, side, align));
109  }
110  else
111  {
112  ARMARX_VERBOSE << "align out of bounds " << std::to_string(align)
113  << limit.limit_violation_string(box, align);
114  }
115  }
116  }
117  inline
119  const box_t& box,
120  const side_data& side,
121  const length_limit& limit,
122  auto consume_grasp,
123  const side_enabled_map& enabled)
124  {
125  for (std::uint_fast8_t i = 0; i < 24; ++i)
126  {
127  const auto align = static_cast<box_alignment>(i);
128  if (limit.in_limits(box, align) && enabled[align])
129  {
130  ARMARX_VERBOSE << "align ok " << std::to_string(align);
131  consume_grasp(center_grasp(box, side, align));
132  }
133  else if (!enabled[align])
134  {
135  ARMARX_VERBOSE << "align disabled " << std::to_string(align);
136  }
137  else
138  {
139  ARMARX_VERBOSE << "align out of bounds " << std::to_string(align)
140  << limit.limit_violation_string(box, align);
141  }
142  }
143  }
144  inline
146  const box_t& box,
147  const std::string& s,
148  const length_limit& limit,
149  auto consume_grasp)
150  {
151  center_grasps(box, side(s), limit, std::move(consume_grasp));
152  }
153  inline
155  const box_t& box,
156  const std::string& s,
157  const length_limit& limit,
158  auto consume_grasp,
159  const side_enabled_map& enabled)
160  {
161  center_grasps(box, side(s), limit, std::move(consume_grasp), enabled);
162  }
163 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::box_to_grasp_candidates::center_grasps
void center_grasps(const box_t &box, const side_data &side, const length_limit &limit, auto consume_grasp)
Definition: box_to_grasp_candidates.ipp:96
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::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
simox::meta
Definition: box_to_grasp_candidates.ipp:12
trace.h
armarx::box_to_grasp_candidates::box_alignment::pos_z_neg_x
@ pos_z_neg_x
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::side_data
Definition: box_to_grasp_candidates.h:75
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::length_limit
Definition: box_to_grasp_candidates.h:63
armarx::box_to_grasp_candidates::box_alignment
box_alignment
Definition: box_to_grasp_candidates.h:17
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::box_alignment::neg_x_neg_z
@ neg_x_neg_z
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
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::side
const side_data & side(const std::string &side) const
Definition: box_to_grasp_candidates.cpp:311
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
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::box_to_grasp_candidates::box_alignment::pos_z_pos_x
@ pos_z_pos_x
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
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
simox::OrientedBox
Definition: ice_conversions.h:18
armarx::box_to_grasp_candidates::box_alignment::pos_y_neg_x
@ pos_y_neg_x
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
Logging.h
armarx::box_to_grasp_candidates::side_enabled_map
Definition: box_to_grasp_candidates.h:37
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