@@ -75,17 +75,20 @@ QuaternionMEKF::QuaternionMEKF()
7575 state = AngularKalmanData ();
7676}
7777
78- void QuaternionMEKF::tick (float dt, Magnetometer &magnetometer, Velocity &angular_velocity, Acceleration &acceleration, FSMState FSM_state)
78+ void QuaternionMEKF::tick (float dt, Magnetometer &magnetometer, Velocity &angular_velocity, Acceleration &acceleration, FSMState FSM_state, Velocity &gyro_bias_sflp )
7979{
8080 if (FSM_state >= FSMState::STATE_IDLE) //
8181 {
8282
8383 // setQ(dt, sd);
8484 // priori(dt, orientation, FSM_state, acceleration);
8585 // update(barometer, acceleration, orientation, FSM_state, gps);
86-
86+ x (3 ) = gyro_bias_sflp.vx * pi/180 ;
87+ x (4 ) = gyro_bias_sflp.vy * pi/180 ;
88+ x (5 ) = gyro_bias_sflp.vz * pi/180 ;
8789 time_update (angular_velocity, dt);
8890 measurement_update (acceleration, magnetometer);
91+
8992 calculate_tilt ();
9093 Eigen::Matrix<float , 4 , 1 > curr_quat = quaternion (); // w,x,y,z
9194
@@ -355,11 +358,6 @@ AngularKalmanData QuaternionMEKF::getState()
355358void QuaternionMEKF::calculate_tilt ()
356359{
357360
358- const float alpha = 0.98 ; // Higher values dampen out current measurements --> reduce peaks
359-
360- // The guess & check method!
361- // Quat --> euler --> rotation matrix --> reference&cur vector --> dot product for angle!
362-
363361 Eigen::Quaternion<float >
364362 ref = Eigen::Quaternionf (0 , 0 , 0 , 1 );
365363
@@ -379,12 +377,33 @@ void QuaternionMEKF::calculate_tilt()
379377 }
380378
381379 // const float gain = 0.2;
382- // // Arthur's Comp Filter
380+ // Arthur's Comp Filter
383381 // float filtered_tilt = gain * tilt + (1 - gain) * prev_tilt;
384382 // prev_tilt = filtered_tilt;
385383 state.mq_tilt = tilt;
384+ }
385+
386+
387+ void QuaternionMEKF::calculate_tilt (IMU_SFLP imu_sflp)
388+ {
389+
390+ Eigen::Vector3f ref (1 ,0 ,0 );
391+
392+ Eigen::Quaternion<float > sflp_quat = Eigen::Quaternionf (imu_sflp.quaternion .w ,imu_sflp.quaternion .x ,imu_sflp.quaternion .y ,imu_sflp.quaternion .z );
393+ sflp_quat.normalize ();
394+
395+ Eigen::Vector3f rotated_vector = sflp_quat * ref;
396+
397+ Eigen::Vector3f world_vertical (0 , 0 , 1 );
398+ float dot = rotated_vector.dot (world_vertical);
399+ float cur_mag = rotated_vector.norm ();
400+ float tilt = 0 ;
401+ if (cur_mag != 0 )
402+ {
403+ tilt = acos (dot / (cur_mag));
404+ }
386405
387- // Serial.print("TILT: ") ;
406+ state. sflp_tilt = tilt ;
388407}
389408
390409QuaternionMEKF mqekf;
0 commit comments