00001
00009 #ifndef _POSTPROC_H
00010 #define _POSTPROC_H
00011
00012
00013
00014
00015
00016
00017 #include <gsl/gsl_matrix.h>
00018 #include <gsl/gsl_vector.h>
00019 #include <gsl/gsl_blas.h>
00020 #include <gsl/gsl_linalg.h>
00021
00022 #include <gsl/gsl_rng.h>
00023 #include <gsl/gsl_randist.h>
00024 #include <gsl/gsl_multifit_nlin.h>
00025 #include <gsl/gsl_deriv.h>
00026 #include <gsl/gsl_fft_real.h>
00027 #include <gsl/gsl_fft_halfcomplex.h>
00028
00029 #define PI 3.14159
00030
00031 #include "lowerleg_struct.h"
00032 #include "ekf.h"
00033 #include "matrix_tools.h"
00034 using namespace std;
00035
00036
00037
00038 int load_collar_calibs(char *foldername, vector< vector<double> > &Hprev, vector< vector<double> >&Pvals,
00039 vector< vector<double> > &qvals, vector<double> &firstlink, vector<vector< double> > &Plate);
00040 int load_opti_data(char *filename,vector< vector<double> > &datapoints,vector<string> &point_labels);
00041 int load_collar_opti_data(vector<vector<double> > &datapoints,vector<string> &point_labels,vector<vector<int> > point_flag, tibia &tib);
00042 int load_accl_data(char *filename, int num_accls, int num_accl_entries, vector< vector<double> > &datapoints);
00043 int load_collar_accl_data(char *filename, tibia &tib, femur &fem);
00044
00045 int load_collar_active_data(vector<vector<double> > datapoints, tibia &tib, femur &fem);
00046 int load_active_data(char *filename, int num_act, vector< vector<double> > &datapoints);
00047 int load_passive_data(char *filename, int num_act, vector< vector<double> > &datapoints);
00048 int load_collar_passive_data(vector<vector<double> > all_pass_data, tibia &tib, femur &fem);
00049
00050 int load_all_measures(tibia &tib, femur &fem,vector<vector<double> > &frame_refs);
00051
00052
00053
00057 struct angle_data
00058 {
00065 double DH_mat[16];
00071 double Mat_loc[16];
00074 double Ptloc[3];
00078 double Ptglob[3];
00079 };
00080
00081
00082
00083 int solve_gsl_lm(gsl_multifit_function_fdf *f, gsl_vector_view xv, double precision, int nbre_iter, gsl_multifit_fdfsolver *s, gsl_matrix *covar);
00084 void print_results_lm(gsl_multifit_fdfsolver *s, size_t n, size_t p, int status, gsl_matrix *covar);
00085
00086
00087
00088
00089 void gsl_rot_to_rodrigues(gsl_matrix *Rot, gsl_vector *rodrig);
00090 void gsl_rodrigues_to_rot(gsl_vector *rodrig, gsl_matrix *Rot);
00091 void encaps_vector2rot(double *vrot, double *Rot);
00092 void gramSchmidt(gsl_vector *v1, gsl_vector *v2, gsl_vector *v3, gsl_matrix *T);
00093 void rotX(double alpha_rad, gsl_matrix *Rot);
00094 void rotY(double alpha_rad, gsl_matrix *Rot);
00095 void rotZ(double alpha_rad, gsl_matrix *Rot);
00096 void rotEuler(double X, double Y, double Z, gsl_matrix *Rot);
00097 void gsl_vector2Rot_matrix(gsl_matrix *Rot, gsl_vector *v);
00098 void gsl_Rot_matrix2vector(gsl_matrix *Rot, gsl_vector *v);
00099 void mat_passage_3pts(gsl_vector *v1, gsl_vector *v2, gsl_vector *v3, gsl_matrix *T);
00100 int gsl_hom_matrix(gsl_vector *origin,gsl_matrix *Rot,gsl_matrix *H);
00101
00102
00103 void free_acc(double *accl, double *quat);
00104 void quat_multiply(gsl_vector *M1,gsl_vector *M2,gsl_vector *ans0);
00105 void quat_rotate(gsl_vector *quat1, gsl_vector *vect, gsl_vector *ans1);
00106 void quat_invert(gsl_vector *quat);
00107 void get_quaternion_avg(vector<vector<double> > quat_datas, gsl_vector *quat_avg);
00108 void rodrigues_to_quat(gsl_vector *quat_rod, gsl_vector *quat);
00109
00110
00111 int calc_joint_angle_err(double angle_rad, double &DH_mat, double &Mat_loc,double &Ptloc,double &Ptglob, double &err);
00112 int calc_j_angle_wrap(const gsl_vector *angle_rad, struct angle_data *angleD, gsl_vector *err);
00113
00114 int jnt_angle_jacobian(double theta, double DH_mat[], double Mat_loc[],double Ptloc[3],double J[]);
00115 int jnt_angle_jacob_wrap(const gsl_vector *angle_rad, struct angle_data *angle_d, gsl_matrix *J);
00116
00117 int calc_jnt_angle_jacob_wrap(const gsl_vector *angle_rad, struct angle_data *angle_d, gsl_vector *err, gsl_matrix *J);
00118 int calc_joint_ang(struct angle_data *angle_d, double theta_init,double precision, int nb_iter, double &theta_sol);
00119
00120
00121 int calc_link_frame_opti(tibia &tib, string linkname, int fr_num, gsl_matrix *M);
00122 int calc_trans_mat(double Ploc[], double Pglob[], gsl_matrix *H);
00123
00124 int DHtoFix(vector<double> &firstlink, gsl_matrix *DHF);
00125 int DH_hayati(double beta, double alpha, double a, double theta, gsl_matrix *DHayati);
00126 int gsl_pt_quat_matrix(vector<double> &Pvals, vector<double> &qvals,gsl_matrix *MatOP);
00127
00128 int get_link_number(collar &col,string linkname);
00129 int calc_transf_matrix(gsl_matrix *Matlink,
00130 int linknumber,
00131 vector< vector<double> > &Hprev,
00132 vector< vector<double> > &Pvals,
00133 vector< vector<double> > &qvals,
00134 vector<double> &firstlink);
00135
00136
00137
00138 int clean_opti_data(vector< vector<double> > &datapoints,vector<vector<int> > &point_flag,vector<string> &point_labels);
00139 double getdist(vector<double> &basepoint,vector<double> &newpoint);
00140 int getmaxmin(vector<double> &currpt,vector<double> &max_pt,vector<double> &min_pt);
00141 int checkinbox(vector<double> &currpt,vector<double> &max_pt,vector<double> &min_pt);
00142 double getcang(vector<double> &oldpoint, vector<double> &basepoint,vector<double> &newpoint);
00143
00144
00145 void extract_data_point(vector< vector<double> > &datapoints, int variable_id, double data[]);
00146 int gsl_get_fourier_coeffs(double data[], gsl_vector *f_data,int num_frames,gsl_fft_real_wavetable * real, gsl_fft_real_workspace * work);
00147 int get_fourier_dominant_estimate(double data[], gsl_vector * f_data, int num_dominant_freq);
00148 void gsl_filter_data(double data[],int num_frames, int num_dominant_freq);
00149 void gsl_low_pass_fourier(double data[], gsl_vector * f_data, int num_freq);
00150 void gsl_low_pass_filter_data(double data[],int num_frames, int num_freq);
00151
00152
00153 int generate_jacobian_femur(gsl_matrix *J, gsl_vector *state_vec, vector<vector<double> > wire_a_points,
00154 vector<double> thetas,vector<double> q);
00155 int generate_mes_vec_femur(gsl_vector *mes_vector,femur &fem, int frame_count, int &wire_frame_count, gsl_vector *tot_wire_len,vector<double> &q);
00156 int h_femur_encaps(gsl_vector *h, gsl_vector *state_vec, vector<vector<double> > wire_a_points,
00157 vector<double> thetas,vector<double> q);
00158 int h_measurement_femur(gsl_vector *h,double *sa, double *sddot,double *qa, double theta1, double theta2,
00159 double theta3, double theta4, double theta5, double *a1, double *a2, double *a3,
00160 double *a4,double *a5,double *a6);
00161 int jacob_set_tot(gsl_matrix *H, double sa[3], double sddot[3],double qa[4], double theta1, double theta2,
00162 double theta3, double theta4, double theta5, double *a1, double *a2, double *a3,
00163 double *a4,double *a5,double *a6);
00164
00165
00166 int load_mario_frame_opti_data(vector<vector<double> > &datapoints,vector<string> &point_labels, vector<vector<double> > &frame);
00167 int calc_mario_frame_opti(gsl_matrix *H, vector<vector<double> > &frame_mario, vector<vector<double> > &frame);
00168
00169
00170 int convert_opti_to_mario(tibia &tib, gsl_matrix *H);
00171
00172
00173
00174 int run_kalman_femur(femur &fem, vector<vector<double> > wire_A_points, gsl_vector *tot_wire_len,
00175 vector<vector<double> > &state, vector<double> thetas);
00176 int first_local_extrema(double *data, int num_iter,int frame_start);
00177 int opti_first_extrema(vector<vector<double> > &datapoints, int num_markers);
00178 int first_local_extrema_vec(vector<vector<double> > data, int index, int index_step);
00179
00180
00181 double adj_labview_tmstamp(double tmstamp);
00182 int sync_opti_active(vector<vector<double> > &active_wire_data, vector<vector<double> >&optical_data,int num_opti_markers);
00183
00184 int filter_sync_passive_active(vector<vector<double> > active_wire_data, vector<vector<double> > &passive_wire_data);
00185
00186
00187 int read_all_wire_bases(vector<vector<double> > &wire_bases);
00188
00189
00190 int set_theta_err_cov(gsl_matrix * Q, int num_theta);
00191 int set_initial_estimate(gsl_vector * state_estimate);
00192 int set_process_mat(gsl_matrix *A, double deltaT);
00193 int set_proc_cov_mat(gsl_matrix *Q);
00194
00195
00196 int generate_jacobian_femur_theta(gsl_matrix *J, gsl_vector *state_vec);
00197 int generate_mes_vec_femur(gsl_vector *mes_vector, femur &fem, int frame_count);
00198 int h_measurement_femur_theta(gsl_vector *h, double theta1, double theta2,double theta3, double theta4, double theta5);
00199 int h_femur_theta_encaps(gsl_vector *h, gsl_vector *state_vec);
00200
00201 int run_kalman_femur_theta(femur &fem, vector<vector<double> > &state);
00202
00203
00204 int filter_accl(vector<vector<double> > &accl_data);
00205
00206
00207 int accl_mario_orient(double *quat_mario, double *quat);
00208
00209
00210
00211 int generate_jacobian_tib_low_theta(gsl_matrix *J, gsl_vector *state_vec);
00212 int generate_mes_vec_tib_low(gsl_vector *mes_vector, tibia &tib, int frame_count);
00213 int h_measurement_tib_low_theta(gsl_vector *h, double theta1, double theta2,double theta3, double theta4);
00214 int h_tib_low_theta_encaps(gsl_vector *h, gsl_vector *state_vec);
00215
00216 int run_kalman_tib_low_theta(tibia &tib, vector<vector<double> > &state);
00217
00218
00219
00220
00221
00222
00223
00224 #endif