SITL: add parameter for Vicon observation delay

This commit is contained in:
Peter Barker 2018-03-26 13:54:05 +11:00 committed by Randy Mackay
parent dfcf4788d3
commit 08189e0754
4 changed files with 39 additions and 6 deletions

View File

@ -77,17 +77,17 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
vicon.last_observation_ms = now; vicon.last_observation_ms = now;
obs_elements observation; obs_elements observation;
if (vicon.observation_history_length == 0) { if (_sitl->vicon_observation_history_length == 0) {
// no delay // no delay
observation = new_obs; observation = new_obs;
} else { } else {
vicon.observation_history.push(new_obs); vicon.observation_history->push(new_obs);
if (vicon.observation_history.space() != 0) { if (vicon.observation_history->space() != 0) {
::fprintf(stderr, "Insufficient delay\n"); ::fprintf(stderr, "Insufficient delay\n");
return; return;
} }
if (!vicon.observation_history.pop(observation)) { if (!vicon.observation_history->pop(observation)) {
abort(); abort();
} }
} }
@ -117,11 +117,38 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
} }
} }
bool Vicon::init_sitl_pointer()
{
if (_sitl == nullptr) {
_sitl = (SITL *)AP_Param::find_object("SIM_");
if (_sitl == nullptr) {
return false;
}
}
if (_sitl->vicon_observation_history_length > 0 &&
vicon.observation_history == nullptr) {
const uint8_t maxlen = 100;
if (_sitl->vicon_observation_history_length > maxlen) {
::fprintf(stderr, "Clamping history length to %u", maxlen);
_sitl->vicon_observation_history_length = maxlen;
}
vicon.observation_history = new ObjectArray<obs_elements>(_sitl->vicon_observation_history_length);
if (vicon.observation_history == nullptr) {
AP_HAL::panic("Failed to allocate history");
}
}
return true;
}
/* /*
update vicon sensor state update vicon sensor state
*/ */
void Vicon::update(const Location &loc, const Vector3f &position, const Quaternion &attitude) void Vicon::update(const Location &loc, const Vector3f &position, const Quaternion &attitude)
{ {
if (!init_sitl_pointer()) {
return;
}
maybe_send_heartbeat(); maybe_send_heartbeat();
update_vicon_position_estimate(loc, position, attitude); update_vicon_position_estimate(loc, position, attitude);
} }

View File

@ -20,6 +20,8 @@
#include "SIM_Aircraft.h" #include "SIM_Aircraft.h"
#include <SITL/SITL.h>
#include <AP_HAL/utility/RingBuffer.h> #include <AP_HAL/utility/RingBuffer.h>
namespace SITL { namespace SITL {
@ -38,6 +40,8 @@ public:
private: private:
SITL *_sitl;
// TODO: make these parameters: // TODO: make these parameters:
const uint8_t system_id = 17; const uint8_t system_id = 17;
const uint8_t component_id = 18; const uint8_t component_id = 18;
@ -57,8 +61,7 @@ private:
struct { struct {
const uint16_t observation_interval_ms = 20; const uint16_t observation_interval_ms = 20;
// delay results by some multiplier of the observation_interval: // delay results by some multiplier of the observation_interval:
const uint8_t observation_history_length = 0; ObjectArray<obs_elements> *observation_history;
ObjectArray<obs_elements> observation_history{observation_history_length};
uint32_t last_observation_ms; uint32_t last_observation_ms;
} vicon; } vicon;
@ -69,6 +72,7 @@ private:
void maybe_send_heartbeat(); void maybe_send_heartbeat();
uint32_t last_heartbeat_ms; uint32_t last_heartbeat_ms;
bool init_sitl_pointer();
}; };
} }

View File

@ -112,6 +112,7 @@ const AP_Param::GroupInfo SITL::var_info2[] = {
AP_GROUPINFO("ARSPD2_FAIL", 11, SITL, arspd2_fail, 0), AP_GROUPINFO("ARSPD2_FAIL", 11, SITL, arspd2_fail, 0),
AP_GROUPINFO("ARSPD2_FAILP",12, SITL, arspd2_fail_pressure, 0), AP_GROUPINFO("ARSPD2_FAILP",12, SITL, arspd2_fail_pressure, 0),
AP_GROUPINFO("ARSPD2_PITOT",13, SITL, arspd2_fail_pitot_pressure, 0), AP_GROUPINFO("ARSPD2_PITOT",13, SITL, arspd2_fail_pitot_pressure, 0),
AP_GROUPINFO("VICON_HSTLEN",14, SITL, vicon_observation_history_length, 0),
AP_GROUPEND AP_GROUPEND
}; };

View File

@ -90,6 +90,7 @@ public:
AP_Float gps_noise; // amplitude of the gps altitude error AP_Float gps_noise; // amplitude of the gps altitude error
AP_Int16 gps_lock_time; // delay in seconds before GPS gets lock AP_Int16 gps_lock_time; // delay in seconds before GPS gets lock
AP_Int16 gps_alt_offset; // gps alt error AP_Int16 gps_alt_offset; // gps alt error
AP_Int8 vicon_observation_history_length; // frame delay for vicon messages
AP_Float mag_noise; // in mag units (earth field is 818) AP_Float mag_noise; // in mag units (earth field is 818)
AP_Float mag_error; // in degrees AP_Float mag_error; // in degrees