11 #include <Eigen/Dense>
47 optFlow_pred.resize(2);
48 gyroscopeRotation_pred.resize(3);
63 printf(
"hello from GazeSatb init\n");
76 q_UB_des = Eigen::VectorXd::Zero(n_UB_joints);
90 q_virt[2] = -
M_PI / 2.;
97 vel_xFP = Eigen::VectorXd::Zero(6);
98 pos_xFP = Eigen::Vector3d::Zero();
99 desired_vel_xFP = Eigen::VectorXd::Zero(6);
123 for (
int i = 1; i <= n_LB_joints; i++)
132 mbs_data_virt_q[i] =
input->
q_UB[i - (n_LB_joints + 1)];
133 mbs_data_virt_qd[i] =
input->
qd_UB[i - (n_LB_joints + 1)];
140 mbs_data_virt_qd[i] = qd_gaze_des(i - (n_LB_joints + 1));
156 predict_optFlow_xy();
157 predict_optFlow_index();
160 for (
int row = 0; row < 6; row++)
163 Jac_FK(row, col) = sens_virt.
J[row + 1][col + 1];
168 for (
int i = 0; i < 3; i++)
170 pos_xFP(i) = sens_virt.
P[i + 1];
173 for (
int row = 0; row < 3; row++)
174 for (
int col = 0; col < 3; col++)
176 R_xFP[row][col] = sens_virt.
R[row + 1][col + 1];
190 Eigen::VectorXd drift_corr(6);
191 drift_corr << K1* pos_err, 0, K2*
get_or_err(), 0;
193 desired_vel_xFP = -1 * vel_xFP + drift_corr;
226 Eigen::Map<Eigen::VectorXd> tmp(&
input->
q_UB[0], n_UB_joints);
228 null_space_err << K3*(q_UB_des - tmp), 0., 0., 0.;
230 qd_gaze_des = inv_Jac * desired_vel_xFP + null_space * null_space_err;
239 double dt = tsim - last_t_ctrl;
246 for (
int i = 0; i < n_virt_joints; i++)
248 q_virt[i] +=
dt * qd_gaze_des(i + n_UB_joints);
257 for (
int i = 0; i < n_UB_joints; i++)
278 printf(
"hello from GazeSatb finish \n");
289 void GazeStabilization::predict_IMU()
293 gyroscopeRotation_pred[0] = -1 * (sens_head_imu.
R[1][1] * sens_head_imu.
OM[1] + sens_head_imu.
R[2][1] * sens_head_imu.
OM[2] + sens_head_imu.
R[3][1] * sens_head_imu.
OM[3]);
294 gyroscopeRotation_pred[2] = sens_head_imu.
R[1][2] * sens_head_imu.
OM[1] + sens_head_imu.
R[2][2] * sens_head_imu.
OM[2] + sens_head_imu.
R[3][2] * sens_head_imu.
OM[3];
295 gyroscopeRotation_pred[1] = sens_head_imu.
R[1][3] * sens_head_imu.
OM[1] + sens_head_imu.
R[2][3] * sens_head_imu.
OM[2] + sens_head_imu.
R[3][3] * sens_head_imu.
OM[3];
298 void GazeStabilization::predict_optFlow_xy()
303 optFlow_pred[1] = -1 * atan2(sens_virt.
V[3], q_virt[0]);
306 void GazeStabilization::predict_optFlow_index()
315 const double f = 529.9 * (59.7 / 640.);
321 v_yaw = sens_eye.
R[1][3] * sens_virt.
OM[1] + sens_eye.
R[2][3] * sens_virt.
OM[2] + sens_eye.
R[3][3] * sens_virt.
OM[3];
323 v_hor = sens_eye.
R[1][2] * sens_eye.
V[1] + sens_eye.
R[2][2] * sens_eye.
V[2] + sens_eye.
R[3][2] * sens_eye.
V[3];
324 v_ver = sens_eye.
R[1][3] * sens_eye.
V[1] + sens_eye.
R[2][3] * sens_eye.
V[2] + sens_eye.
R[3][3] * sens_eye.
V[3];
325 v_roll = sens_eye.
R[1][1] * sens_eye.
OM[1] + sens_eye.
R[2][1] * sens_eye.
OM[2] + sens_eye.
R[3][1] * sens_eye.
OM[3];
329 double surf = 30.*22.;
332 double int_zoom = 6612.53 / surf;
335 double int_tilt = 40359.9 / (f * surf);
338 double int_yaw = 58943.5 / (f * surf);
347 double int_roll = 6612.53 / surf;
351 mean_optFl_pred = 0.;
352 mean_optFl_pred += int_zoom * fabs(v_zoom / q_virt[0]);
353 mean_optFl_pred += int_tilt * fabs(v_tilt);
354 mean_optFl_pred += int_yaw * fabs(v_yaw);
355 mean_optFl_pred += int_hor * fabs(v_hor / q_virt[0]);
356 mean_optFl_pred += int_ver * fabs(v_ver / q_virt[0]);
357 mean_optFl_pred += int_roll * fabs(v_roll);
359 double f_rad = f *
M_PI / 180.0;
360 optFlow_pred[0] = (f_rad / q_virt[0]) * v_hor + f_rad * v_yaw;
361 optFlow_pred[0] = optFlow_pred[0] / 3.;