20namespace xrt::tracking::hand::mercury::lm {
26LMToModel(T lm, minmax mm)
28 return mm.min + ((sin(lm) + T(1)) * ((mm.max - mm.min) * T(.5)));
33ModelToLM(T model, minmax mm)
35 return asin((2 * (model - mm.min) / (mm.max - mm.min)) - 1);
41OptimizerHandUnpackFromVector(
const T *in,
const KinematicHandLM &state, OptimizerHand<T> &out)
44 const Quat<T> pre_wrist_orientation(state.this_frame_pre_rotation);
45 const Vec3<T> pre_wrist_position(state.this_frame_pre_position);
48#ifdef USE_HAND_TRANSLATION
49 out.wrist_post_location.x = in[acc_idx++];
50 out.wrist_post_location.y = in[acc_idx++];
51 out.wrist_post_location.z = in[acc_idx++];
53 out.wrist_final_location.x = out.wrist_post_location.x + T(pre_wrist_position.x);
54 out.wrist_final_location.y = out.wrist_post_location.y + T(pre_wrist_position.y);
55 out.wrist_final_location.z = out.wrist_post_location.z + T(pre_wrist_position.z);
59#ifdef USE_HAND_ORIENTATION
60 out.wrist_post_orientation_aax.x = in[acc_idx++];
61 out.wrist_post_orientation_aax.y = in[acc_idx++];
62 out.wrist_post_orientation_aax.z = in[acc_idx++];
64 Quat<T> post_wrist_orientation = {};
66 AngleAxisToQuaternion<T>(out.wrist_post_orientation_aax, post_wrist_orientation);
68 Quat<T> pre_wrist_orientation_t(pre_wrist_orientation);
70 QuaternionProduct<T>(pre_wrist_orientation_t, post_wrist_orientation, out.wrist_final_orientation);
73#ifdef USE_EVERYTHING_ELSE
75 out.thumb.metacarpal.swing.x = LMToModel(in[acc_idx++], the_limit.thumb_mcp_swing_x);
76 out.thumb.metacarpal.swing.y = LMToModel(in[acc_idx++], the_limit.thumb_mcp_swing_y);
77 out.thumb.metacarpal.twist = LMToModel(in[acc_idx++], the_limit.thumb_mcp_twist);
79 out.thumb.rots[0] = LMToModel(in[acc_idx++], the_limit.thumb_curls[0]);
80 out.thumb.rots[1] = LMToModel(in[acc_idx++], the_limit.thumb_curls[1]);
82 for (
int finger_idx = 0; finger_idx < 4; finger_idx++) {
84 out.finger[finger_idx].proximal_swing.x =
85 LMToModel(in[acc_idx++], the_limit.fingers[finger_idx].pxm_swing_x);
86 out.finger[finger_idx].proximal_swing.y =
87 LMToModel(in[acc_idx++], the_limit.fingers[finger_idx].pxm_swing_y);
89 out.finger[finger_idx].rots[0] = LMToModel(in[acc_idx++], the_limit.fingers[finger_idx].curls[0]);
90 out.finger[finger_idx].rots[1] = LMToModel(in[acc_idx++], the_limit.fingers[finger_idx].curls[1]);
95 if (state.optimize_hand_size) {
96 out.hand_size = LMToModel(in[acc_idx++], the_limit.hand_size);
98 out.hand_size = T(state.target_hand_size);
105OptimizerHandPackIntoVector(OptimizerHand<T> &in,
bool use_hand_size, T *out)
109#ifdef USE_HAND_TRANSLATION
110 out[acc_idx++] = in.wrist_post_location.x;
111 out[acc_idx++] = in.wrist_post_location.y;
112 out[acc_idx++] = in.wrist_post_location.z;
114#ifdef USE_HAND_ORIENTATION
115 out[acc_idx++] = in.wrist_post_orientation_aax.x;
116 out[acc_idx++] = in.wrist_post_orientation_aax.y;
117 out[acc_idx++] = in.wrist_post_orientation_aax.z;
119#ifdef USE_EVERYTHING_ELSE
120 out[acc_idx++] = ModelToLM(in.thumb.metacarpal.swing.x, the_limit.thumb_mcp_swing_x);
121 out[acc_idx++] = ModelToLM(in.thumb.metacarpal.swing.y, the_limit.thumb_mcp_swing_y);
122 out[acc_idx++] = ModelToLM(in.thumb.metacarpal.twist, the_limit.thumb_mcp_twist);
124 out[acc_idx++] = ModelToLM(in.thumb.rots[0], the_limit.thumb_curls[0]);
125 out[acc_idx++] = ModelToLM(in.thumb.rots[1], the_limit.thumb_curls[1]);
127 for (
int finger_idx = 0; finger_idx < 4; finger_idx++) {
130 ModelToLM(in.finger[finger_idx].proximal_swing.x, the_limit.fingers[finger_idx].pxm_swing_x);
132 ModelToLM(in.finger[finger_idx].proximal_swing.y, the_limit.fingers[finger_idx].pxm_swing_y);
134 out[acc_idx++] = ModelToLM(in.finger[finger_idx].rots[0], the_limit.fingers[finger_idx].curls[0]);
135 out[acc_idx++] = ModelToLM(in.finger[finger_idx].rots[1], the_limit.fingers[finger_idx].curls[1]);
141 out[acc_idx++] = ModelToLM(in.hand_size, the_limit.hand_size);
150 opt.hand_size = (T)STANDARD_HAND_SIZE;
152 opt.wrist_post_orientation_aax.x = (T)(0);
153 opt.wrist_post_orientation_aax.y = (T)(0);
154 opt.wrist_post_orientation_aax.z = (T)(0);
159 opt.wrist_post_location.x = (T)(0);
160 opt.wrist_post_location.y = (T)(0);
161 opt.wrist_post_location.z = (T)(0);
164 for (
int i = 0; i < 4; i++) {
166 opt.finger[i].metacarpal.swing.x = T(0);
167 opt.finger[i].metacarpal.twist = T(0);
169 opt.finger[i].proximal_swing.x = T(rad<HandScalar>(15.0f));
170 opt.finger[i].rots[0] = T(rad<HandScalar>(-5));
171 opt.finger[i].rots[1] = T(rad<HandScalar>(-5));
174 opt.thumb.metacarpal.swing.x = (T)(0);
175 opt.thumb.metacarpal.swing.y = (T)(0);
176 opt.thumb.metacarpal.twist = (T)(0);
178 opt.thumb.rots[0] = T(rad<HandScalar>(-5));
179 opt.thumb.rots[1] = T(rad<HandScalar>(-59));
181 opt.finger[0].metacarpal.swing.y = (T)(-0.19);
182 opt.finger[1].metacarpal.swing.y = (T)(0);
183 opt.finger[2].metacarpal.swing.y = (T)(0.19);
184 opt.finger[3].metacarpal.swing.y = (T)(0.38);
186 opt.finger[0].metacarpal.swing.x = (T)(-0.02);
187 opt.finger[1].metacarpal.swing.x = (T)(0);
188 opt.finger[2].metacarpal.swing.x = (T)(0.02);
189 opt.finger[3].metacarpal.swing.x = (T)(0.04);
191 opt.finger[0].proximal_swing.y = (T)(-0.01);
192 opt.finger[1].proximal_swing.y = (T)(0);
193 opt.finger[2].proximal_swing.y = (T)(0.01);
194 opt.finger[3].proximal_swing.y = (T)(0.02);
Defines for Levenberg-Marquardt kinematic optimizer.
Interface for Levenberg-Marquardt kinematic optimizer.
void OptimizerHandInit(OptimizerHand< T > &opt, Quat< T > &pre_rotation)
Definition lm_optimizer_params_packer.inl:148
Autodiff-safe rotations for Levenberg-Marquardt kinematic optimizer.
C interface to math library.
Definition lm_defines.hpp:411
Definition lm_defines.hpp:215
Basic logging functionality.