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
12namespace simox::meta
13{
14 template<>
15 const simox::meta::EnumNames<armarx::box_to_grasp_candidates::box_alignment>
17 {
22
27
32
37
42
47 };
48}
49
50namespace 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}
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
const simox::meta::EnumNames< armarx::box_to_grasp_candidates::box_alignment > enum_names< armarx::box_to_grasp_candidates::box_alignment >
void * align(size_t alignment, size_t bytes, void *&bufferPlace, size_t &bufferSpace) noexcept
bool in_limits(const box_t &box, box_alignment align) const
std::string limit_violation_string(const box_t &box, box_alignment align) const
const side_data & side(const std::string &side) const
grasp center_grasp(const box_t &box, const side_data &side, box_alignment align)
void center_grasps(const box_t &box, const side_data &side, const length_limit &limit, auto consume_grasp)
simox::OrientedBox< float > box_t
#define ARMARX_TRACE
Definition trace.h:77