Skip to content

Commit f0d933b

Browse files
Sensor orientation find tuning fixed.
Some "nick" references removed.
1 parent 7557892 commit f0d933b

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

NAV_Algorithms/AHRS.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class AHRS_type
7272
bool GNSS_heading_valid
7373
);
7474

75-
inline void set_from_euler( float r, float n, float y)
75+
inline void set_from_euler( float roll, float pitch, float yaw)
7676
{
77-
attitude.from_euler( r, n, y);
77+
attitude.from_euler( roll, pitch, yaw);
7878
attitude.get_rotation_matrix( body2nav);
7979
euler = attitude;
8080
}

NAV_Algorithms/navigator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ class navigator_t
191191
// return flight_observer;
192192
// }
193193

194-
void set_attitude( float roll, float nick, float yaw)
194+
void set_attitude( float roll, float pitch, float yaw)
195195
{
196-
ahrs.set_from_euler(roll, nick, yaw);
196+
ahrs.set_from_euler(roll, pitch, yaw);
197197
#if DEVELOPMENT_ADDITIONS
198-
ahrs_magnetic.set_from_euler(roll, nick, yaw);
198+
ahrs_magnetic.set_from_euler(roll, pitch, yaw);
199199
#endif
200200
}
201201

NAV_Algorithms/organizer.h

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,57 @@ class organizer_t
8989

9090
void fine_tune_sensor_orientation( const vector_average_collection_t & values)
9191
{
92-
float3vector observed_body_acc = sensor_mapping * values.acc_observed_level;
93-
float pitch_correction = - ATAN2( - observed_body_acc[FRONT], - observed_body_acc[DOWN]);
94-
float roll_correction = + ATAN2( - observed_body_acc[RIGHT], - observed_body_acc[DOWN]);
92+
float3vector gravity_measurement_body = sensor_mapping * values.acc_observed_level;
9593

96-
quaternion<float> q_correction;
97-
q_correction.from_euler( roll_correction, pitch_correction, ZERO);
94+
// correct for "gravity pointing to minus "down" "
95+
gravity_measurement_body.negate();
96+
97+
// evaluate observed "down" direction in the body frame
98+
float3vector unity_vector_down_body;
99+
unity_vector_down_body = gravity_measurement_body;
100+
unity_vector_down_body.normalize();
101+
102+
// find two more unity vectors defining the corrected coordinate system
103+
float3vector unity_vector_front_body;
104+
unity_vector_front_body[FRONT] = unity_vector_down_body[DOWN];
105+
unity_vector_front_body[DOWN] = unity_vector_down_body[FRONT];
106+
unity_vector_front_body.normalize();
107+
108+
float3vector unity_vector_right_body;
109+
unity_vector_right_body = unity_vector_down_body.vector_multiply( unity_vector_front_body);
110+
unity_vector_right_body.normalize();
111+
112+
// fine tune the front vector using the other ones
113+
unity_vector_front_body = unity_vector_right_body.vector_multiply( unity_vector_down_body);
114+
115+
// calculate the rotation matrix using our calibration data
116+
float3matrix observed_correction_matrix;
117+
observed_correction_matrix.e[FRONT][0]=unity_vector_front_body[0];
118+
observed_correction_matrix.e[FRONT][1]=unity_vector_front_body[1];
119+
observed_correction_matrix.e[FRONT][2]=unity_vector_front_body[2];
120+
121+
observed_correction_matrix.e[RIGHT][0]=unity_vector_right_body[0];
122+
observed_correction_matrix.e[RIGHT][1]=unity_vector_right_body[1];
123+
observed_correction_matrix.e[RIGHT][2]=unity_vector_right_body[2];
124+
125+
observed_correction_matrix.e[DOWN][0]=unity_vector_down_body[0];
126+
observed_correction_matrix.e[DOWN][1]=unity_vector_down_body[1];
127+
observed_correction_matrix.e[DOWN][2]=unity_vector_down_body[2];
128+
129+
quaternion<float> q_observed_correction;
130+
q_observed_correction.from_rotation_matrix(observed_correction_matrix);
98131

99132
quaternion<float> q_present_setting;
100133
q_present_setting.from_euler (
101134
configuration (SENS_TILT_ROLL),
102135
configuration (SENS_TILT_PITCH),
103136
configuration (SENS_TILT_YAW));
104137

138+
quaternion <float> q_sensor_orientation_corrected;
139+
q_sensor_orientation_corrected = q_observed_correction * q_present_setting;
140+
105141
quaternion<float> q_new_setting;
106-
q_new_setting = q_correction * q_present_setting;
142+
q_new_setting = q_observed_correction * q_present_setting;
107143

108144
eulerangle<float> new_euler = q_new_setting;
109145

0 commit comments

Comments
 (0)