@@ -113,8 +113,13 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
113
113
return ;
114
114
}
115
115
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
118
123
return ;
119
124
}
120
125
@@ -136,6 +141,12 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
136
141
137
142
// add earth frame sensor offset and glitch to position
138
143
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
+ );
139
150
140
151
// calculate a velocity offset due to the antenna position offset and body rotation rate
141
152
// note: % operator is overloaded for cross product
@@ -159,6 +170,13 @@ void Vicon::update_vicon_position_estimate(const Location &loc,
159
170
vel_corrected = vicon_yaw_rot.tofloat () * vel_corrected;
160
171
}
161
172
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
+
162
180
// add yaw error reported to vehicle
163
181
yaw = wrap_PI (yaw + radians (_sitl->vicon_yaw_error .get ()));
164
182
0 commit comments