Remove unsafe access to .data() and _data in Matrix

This commit is contained in:
Julian Kent
2019-09-16 11:12:23 +02:00
committed by Daniel Agar
parent 78bf12f0db
commit 2d4ecab3b0
8 changed files with 29 additions and 21 deletions
@@ -495,9 +495,9 @@ bool AttitudeEstimatorQ::init()
// Fill rotation matrix
Dcmf R;
R.setRow(0, i);
R.setRow(1, j);
R.setRow(2, k);
R.row(0) = i;
R.row(1) = j;
R.row(2) = k;
// Convert to quaternion
_q = R;
@@ -716,7 +716,10 @@ calibrate_return read_accelerometer_avg(int sensor_correction_sub, int (&subs)[m
for (unsigned i = 0; i < max_accel_sens; i++) {
matrix::Vector3f accel_sum_vec(&accel_sum[i][0]);
accel_sum_vec = board_rotation * accel_sum_vec;
memcpy(&accel_sum[i][0], accel_sum_vec.data(), sizeof(accel_sum[i]));
for (size_t j = 0; j < 3; j++) {
accel_sum[i][j] = accel_sum_vec(j);
}
}
for (unsigned s = 0; s < max_accel_sens; s++) {
+2 -4
View File
@@ -1323,8 +1323,7 @@ void Ekf2::run()
}
// The rotation of the tangent plane vs. geographical north
matrix::Quatf q;
_ekf.copy_quaternion(q.data());
matrix::Quatf q = _ekf.get_quaternion();
lpos.yaw = matrix::Eulerf(q).psi();
@@ -1787,8 +1786,7 @@ const Vector3f Ekf2::get_vel_body_wind()
{
// Used to correct baro data for positional errors
matrix::Quatf q;
_ekf.copy_quaternion(q.data());
matrix::Quatf q = _ekf.get_quaternion();
matrix::Dcmf R_to_body(q.inversed());
// Calculate wind-compensated velocity in body frame
+4 -1
View File
@@ -3431,7 +3431,10 @@ protected:
} else {
matrix::Quatf q = matrix::Eulerf(att_sp.roll_body, att_sp.pitch_body, att_sp.yaw_body);
memcpy(&msg.q[0], q.data(), sizeof(msg.q));
for (size_t i = 0; i < 4; i++) {
msg.q[i] = q(i);
}
}
msg.body_roll_rate = att_rates_sp.roll;
+5 -3
View File
@@ -778,7 +778,8 @@ void VotedSensorsUpdate::magPoll(vehicle_magnetometer_s &magnetometer)
_last_magnetometer[uorb_index].magnetometer_ga[1] = vect(1);
_last_magnetometer[uorb_index].magnetometer_ga[2] = vect(2);
_mag.voter.put(uorb_index, mag_report.timestamp, vect.data(), mag_report.error_count, _mag.priority[uorb_index]);
_mag.voter.put(uorb_index, mag_report.timestamp, _last_magnetometer[uorb_index].magnetometer_ga, mag_report.error_count,
_mag.priority[uorb_index]);
}
}
@@ -834,13 +835,14 @@ void VotedSensorsUpdate::baroPoll(vehicle_air_data_s &airdata)
_baro_device_id[uorb_index] = baro_report.device_id;
got_update = true;
Vector3f vect(baro_report.pressure, baro_report.temperature, 0.f);
float vect[3] = {baro_report.pressure, baro_report.temperature, 0.f};
_last_airdata[uorb_index].timestamp = baro_report.timestamp;
_last_airdata[uorb_index].baro_temp_celcius = baro_report.temperature;
_last_airdata[uorb_index].baro_pressure_pa = corrected_pressure;
_baro.voter.put(uorb_index, baro_report.timestamp, vect.data(), baro_report.error_count, _baro.priority[uorb_index]);
_baro.voter.put(uorb_index, baro_report.timestamp, vect, baro_report.error_count, _baro.priority[uorb_index]);
}
}