EKF: allocate and unallocate buffer more robustly

This commit is contained in:
bugobliterator
2016-01-30 23:48:41 -08:00
parent c6249a2825
commit 8200ef4d17
3 changed files with 36 additions and 10 deletions
+26 -8
View File
@@ -203,14 +203,19 @@ void EstimatorInterface::setOpticalFlowData(uint64_t time_usec, float *data)
bool EstimatorInterface::initialise_interface(uint64_t timestamp)
{
_imu_buffer.allocate(IMU_BUFFER_LENGTH);
_gps_buffer.allocate(OBS_BUFFER_LENGTH);
_mag_buffer.allocate(OBS_BUFFER_LENGTH);
_baro_buffer.allocate(OBS_BUFFER_LENGTH);
_range_buffer.allocate(OBS_BUFFER_LENGTH);
_airspeed_buffer.allocate(OBS_BUFFER_LENGTH);
_flow_buffer.allocate(OBS_BUFFER_LENGTH);
_output_buffer.allocate(IMU_BUFFER_LENGTH);
if(!(_imu_buffer.allocate(IMU_BUFFER_LENGTH) &&
_gps_buffer.allocate(OBS_BUFFER_LENGTH) &&
_mag_buffer.allocate(OBS_BUFFER_LENGTH) &&
_baro_buffer.allocate(OBS_BUFFER_LENGTH) &&
_range_buffer.allocate(OBS_BUFFER_LENGTH) &&
_airspeed_buffer.allocate(OBS_BUFFER_LENGTH) &&
_flow_buffer.allocate(OBS_BUFFER_LENGTH) &&
_output_buffer.allocate(IMU_BUFFER_LENGTH))) {
PX4_WARN("Estimator Buffer Allocation failed!");
unallocate_buffers();
return false;
}
_dt_imu_avg = 0.0f;
@@ -237,6 +242,19 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp)
return true;
}
void EstimatorInterface::unallocate_buffers()
{
_imu_buffer.unallocate();
_gps_buffer.unallocate();
_mag_buffer.unallocate();
_baro_buffer.unallocate();
_range_buffer.unallocate();
_airspeed_buffer.unallocate();
_flow_buffer.unallocate();
_output_buffer.unallocate();
}
bool EstimatorInterface::position_is_valid()
{
// return true if the position estimate is valid