Skip to content

Commit 266c20f

Browse files
SITL: Add gausian noise and rate to VICON sim
1 parent efe6e85 commit 266c20f

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

libraries/SITL/SIM_Vicon.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
113113
return;
114114
}
115115

116-
if (now_us - last_observation_usec < 20000) {
117-
// create observations at 20ms intervals (matches EKF max rate)
116+
if (_sitl->vicon_rate_hz == 0) {
117+
return;
118+
}
119+
const uint64_t vicon_interval_us = 1000000UL / _sitl->vicon_rate_hz; // Interval in microseconds based on rate
120+
if (now_us - last_observation_usec < vicon_interval_us) {
121+
// create observations at rate specified by vicon_rate_hz
122+
// by default runs at 50Hz
118123
return;
119124
}
120125

@@ -136,6 +141,12 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
136141

137142
// add earth frame sensor offset and glitch to position
138143
Vector3d pos_corrected = position + (pos_offset_ef + _sitl->vicon_glitch.get()).todouble();
144+
// add some gaussian noise to the position
145+
pos_corrected += Vector3d(
146+
Aircraft::rand_normal(0, _sitl->vicon_pos_stddev),
147+
Aircraft::rand_normal(0, _sitl->vicon_pos_stddev),
148+
Aircraft::rand_normal(0, _sitl->vicon_pos_stddev)
149+
);
139150

140151
// calculate a velocity offset due to the antenna position offset and body rotation rate
141152
// note: % operator is overloaded for cross product
@@ -159,6 +170,13 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
159170
vel_corrected = vicon_yaw_rot.tofloat() * vel_corrected;
160171
}
161172

173+
// add some gaussian noise to the velocity
174+
vel_corrected += Vector3f(
175+
Aircraft::rand_normal(0, _sitl->vicon_vel_stddev),
176+
Aircraft::rand_normal(0, _sitl->vicon_vel_stddev),
177+
Aircraft::rand_normal(0, _sitl->vicon_vel_stddev)
178+
);
179+
162180
// add yaw error reported to vehicle
163181
yaw = wrap_PI(yaw + radians(_sitl->vicon_yaw_error.get()));
164182

libraries/SITL/SITL.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,27 @@ const AP_Param::GroupInfo SIM::var_info3[] = {
724724
AP_SUBGROUPINFO(volz_sim, "VOLZ_", 55, SIM, Volz),
725725
#endif
726726

727+
// @Param: VICON_P_SD
728+
// @DisplayName: SITL vicon position standard deviation for gaussian noise
729+
// @Description: SITL vicon position standard deviation for gaussian noise
730+
// @Units: m
731+
// @User: Advanced
732+
AP_GROUPINFO("VICON_P_SD", 56, SIM, vicon_pos_stddev, 0.0f),
733+
734+
// @Param: VICON_V_SD
735+
// @DisplayName: SITL vicon velocity standard deviation for gaussian noise
736+
// @Description: SITL vicon velocity standard deviation for gaussian noise
737+
// @Units: m/s
738+
// @User: Advanced
739+
AP_GROUPINFO("VICON_V_SD", 57, SIM, vicon_vel_stddev, 0.0f),
740+
741+
// @Param: VICON_RATE
742+
// @DisplayName: SITL vicon rate
743+
// @Description: SITL vicon rate
744+
// @Units: Hz
745+
// @User: Advanced
746+
AP_GROUPINFO("VICON_RATE", 58, SIM, vicon_rate_hz, 50),
747+
727748
#ifdef SFML_JOYSTICK
728749
AP_SUBGROUPEXTENSION("", 63, SIM, var_sfml_joystick),
729750
#endif // SFML_JOYSTICK

libraries/SITL/SITL.h

+3
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,14 @@ class SIM {
538538

539539
// vicon parameters
540540
AP_Vector3f vicon_glitch; // glitch in meters in vicon's local NED frame
541+
AP_Float vicon_pos_stddev; // noise in meters in vicon's local NED frame
542+
AP_Float vicon_vel_stddev; // noise in m/s in vicon's local NED frame
541543
AP_Int8 vicon_fail; // trigger vicon failure
542544
AP_Int16 vicon_yaw; // vicon local yaw in degrees
543545
AP_Int16 vicon_yaw_error; // vicon yaw error in degrees (added to reported yaw sent to vehicle)
544546
AP_Int8 vicon_type_mask; // vicon message type mask (bit0:vision position estimate, bit1:vision speed estimate, bit2:vicon position estimate)
545547
AP_Vector3f vicon_vel_glitch; // velocity glitch in m/s in vicon's local frame
548+
AP_Int16 vicon_rate_hz; // vicon data rate in Hz
546549

547550
// get the rangefinder reading for the desired instance, returns -1 for no data
548551
float get_rangefinder(uint8_t instance);

0 commit comments

Comments
 (0)