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);
116 double tsim =
input->tsim;
123 for (
int i = 1; i <= n_LB_joints; i++)
125 mbs_data_virt_q[i] =
input->q_LB[i - 1];
126 mbs_data_virt_qd[i] =
input->qd_LB[i - 1];
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];
166 vel_xFP = Jac_FK.block(0, 0, 6, n_LB_joints) *
input->qd_LB_des;
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];
179 pos_err =
input->pos_target - pos_xFP;
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;
218 else if (
options->pseudo_inverse)
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++)
259 output->qd_UB_des[i] = qd_gaze_des(i);
278 printf(
"hello from GazeSatb finish \n");
289void 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];
298void GazeStabilization::predict_optFlow_xy()
303 optFlow_pred[1] = -1 * atan2(sens_virt.V[3], q_virt[0]);
306void 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.;
int get_n_gaze_joints(void)
int get_n_real_joints(void)
GazeStabilization(GazeStabOptions *options)
int get_n_all_joints(void)
GazeStabOptions * options
#define ARMARX_IMPORTANT_S
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
void free_sensor(MbsSensor *psens)
Free the memory of MbsSensor structure.
void allocate_sensor(MbsSensor *psens, int njoint)
Allocate the Jacobian matrix of the MbsSensor according to the number of joints in the multibody syst...
void init_sensor(MbsSensor *psens, int njoint)
Initialize all fields of MbsSensor structure to 0.
void mbs_sensor_ArmarIII_simplified_virt(MbsSensor *sens, double *q_dof, double *qd_dof, int isens)
void mbs_sensor_ArmarIV_GazeStab_virt(MbsSensor *sens, double *q, double *qd, double *qdd, int isens)
void mbs_sensor_ArmarIV_W_Torso_virt(MbsSensor *sens, double *q, double *qd, double *qdd, int isens)
Eigen::MatrixXd pseudoInverse(const Eigen::MatrixXd &a, double epsilon=std::numeric_limits< double >::epsilon())
Eigen::MatrixXd weightedPseudoInverse(const Eigen::MatrixXd &a, const Eigen::VectorXd w)
double OM[4]
Angular velocity vector of the sensor expressed in the inertial frame: .
double R[4][4]
Rotation matrix from the inertial frame to the sensor frame: .