Skip to content

Commit d39a4e2

Browse files
author
jonas
committed
include timestamp_sample into target gnss message
1 parent 79dce59 commit d39a4e2

File tree

9 files changed

+44
-12
lines changed

9 files changed

+44
-12
lines changed

msg/TargetGnss.msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# landing target GNSS position in WGS84 coordinates.
22

33
uint64 timestamp # [us] time since system start
4+
uint64 timestamp_sample # [us] timestamp of the raw observation
45

56
float64 latitude_deg # [deg] Latitude, allows centimeter level RTK precision
67
float64 longitude_deg # [deg] Longitude, allows centimeter level RTK precision

src/modules/mavlink/mavlink_receiver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,9 @@ MavlinkReceiver::handle_message_target_absolute(mavlink_message_t *msg)
28572857
mavlink_msg_target_absolute_decode(msg, &target_absolute);
28582858

28592859
target_gnss_s target_GNSS_report{};
2860-
target_GNSS_report.timestamp = _mavlink_timesync.sync_stamp(target_absolute.timestamp);
2860+
2861+
target_GNSS_report.timestamp = hrt_absolute_time();
2862+
target_GNSS_report.timestamp_sample = _mavlink_timesync.sync_stamp(target_absolute.timestamp);
28612863

28622864
bool updated = false;
28632865

src/modules/simulation/simulator_mavlink/SimulatorMavlink.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ SimulatorMavlink::handle_message_target_absolute(const mavlink_message_t *msg)
694694

695695
target_gnss_s target_GNSS_report{};
696696
target_GNSS_report.timestamp = hrt_absolute_time();
697+
target_GNSS_report.timestamp_sample = target_GNSS_report.timestamp;
697698

698699
bool updated = false;
699700

src/modules/vision_target_estimator/Orientation/KF_orientation.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ namespace vision_target_estimator
4848

4949
void KF_orientation::predict(float dt)
5050
{
51+
if (!PX4_ISFINITE(dt) || (dt < 0.f)) {
52+
return;
53+
}
54+
5155
matrix::Vector<float, State::size> state_next;
5256
matrix::SquareMatrix<float, State::size> cov_next;
5357

@@ -104,8 +108,16 @@ void KF_orientation::computeInnovation(const matrix::Vector<float, State::size>
104108
const ScalarMeas &meas,
105109
float &innov, float &innov_var) const
106110
{
107-
innov = matrix::wrap_pi(meas.val - (meas.H.transpose() * state)(0, 0));
111+
112+
innov = meas.val - (meas.H.transpose() * state)(0, 0);
108113
innov_var = (meas.H.transpose() * cov * meas.H)(0, 0) + meas.unc;
114+
115+
// Wrap innovations for yaw measurements
116+
const bool is_yaw_meas = (fabsf(meas.H(State::yaw)) > 0.f) && (fabsf(meas.H(State::yaw_rate)) < FLT_EPSILON);
117+
118+
if (is_yaw_meas) {
119+
innov = matrix::wrap_pi(innov);
120+
}
109121
}
110122

111123
void KF_orientation::pushHistory(const uint64_t time_us)

src/modules/vision_target_estimator/Orientation/KF_orientation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class KF_orientation
9696
};
9797

9898
const matrix::Vector<float, State::size> &getState() const { return _state; }
99+
const matrix::SquareMatrix<float, State::size> &getStateCovariance() const { return _state_covariance; }
99100
matrix::Vector<float, State::size> getStateCovarianceDiag() const { return _state_covariance.diag(); }
100101

101102
void setYawAccVar(float var) { _yaw_acc_var = var; }

src/modules/vision_target_estimator/Orientation/VTEOrientation.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,21 @@ void VTEOrientation::updateParams()
299299

300300
ModuleParams::updateParams();
301301

302-
_yaw_unc = _param_vte_yaw_unc_in.get();
302+
const float new_yaw_unc = _param_vte_yaw_unc_in.get();
303303
const float new_yaw_acc_var = _param_vte_yaw_acc_unc.get();
304304
const float new_ev_angle_noise = _param_vte_ev_angle_noise.get();
305305
_ev_noise_md = _param_vte_ev_noise_md.get();
306306
const float new_nis_threshold = _param_vte_yaw_nis_thre.get();
307307

308+
if (PX4_ISFINITE(new_yaw_unc) && new_yaw_unc > 0.f) {
309+
const bool yaw_unc_changed = PX4_ISFINITE(_yaw_unc) && (fabsf(new_yaw_unc - _yaw_unc) > 1e-3f);
310+
_yaw_unc = new_yaw_unc;
311+
312+
if (_estimator_initialized && yaw_unc_changed) {
313+
resetFilter();
314+
}
315+
}
316+
308317
if (PX4_ISFINITE(new_yaw_acc_var) && (new_yaw_acc_var >= 0.f)) {
309318
_yaw_acc_var = new_yaw_acc_var;
310319
_target_est_yaw.setYawAccVar(_yaw_acc_var);

src/modules/vision_target_estimator/Position/KF_position.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ namespace vision_target_estimator
5252

5353
void KF_position::predict(float dt, float acc_uav)
5454
{
55+
56+
if (!PX4_ISFINITE(dt) || (dt < 0.f) || !PX4_ISFINITE(acc_uav)) {
57+
return;
58+
}
59+
5560
_last_acc = acc_uav;
5661

5762
matrix::Vector<float, vtest::State::size> state_next;

src/modules/vision_target_estimator/Position/KF_position.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class KF_position
9191
};
9292

9393
const matrix::Vector<float, vtest::State::size> &getState() const { return _state; }
94+
const matrix::SquareMatrix<float, vtest::State::size> &getStateCovariance() const { return _state_covariance; }
9495
matrix::Vector<float, vtest::State::size> getStateCovarianceDiag() const { return _state_covariance.diag(); }
9596

9697
void setInputVar(float var) { _input_var = var; }

src/modules/vision_target_estimator/Position/VTEPosition.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ bool VTEPosition::updateUavGpsData()
449449
_uav_gps_position.lat_deg = vehicle_gps_position.latitude_deg;
450450
_uav_gps_position.lon_deg = vehicle_gps_position.longitude_deg;
451451
_uav_gps_position.alt_m = (float)vehicle_gps_position.altitude_msl_m;
452-
_uav_gps_position.timestamp = vehicle_gps_position.timestamp;
452+
_uav_gps_position.timestamp = vehicle_gps_position.timestamp_sample;
453453
_uav_gps_position.eph = vehicle_gps_position.eph;
454454
_uav_gps_position.epv = vehicle_gps_position.epv;
455455
_uav_gps_position.valid = isUavGpsPositionValid();
456456

457457
// Velocity
458-
_uav_gps_vel.timestamp = vehicle_gps_position.timestamp;
458+
_uav_gps_vel.timestamp = vehicle_gps_position.timestamp_sample;
459459
_uav_gps_vel.xyz(vtest::Axis::x) = vehicle_gps_position.vel_n_m_s;
460460
_uav_gps_vel.xyz(vtest::Axis::y) = vehicle_gps_position.vel_e_m_s;
461461
_uav_gps_vel.xyz(vtest::Axis::z) = vehicle_gps_position.vel_d_m_s;
@@ -474,8 +474,8 @@ bool VTEPosition::updateUavGpsData()
474474
#if defined(CONFIG_VTEST_MOVING)
475475
void VTEPosition::updateTargetGpsVelocity(const target_gnss_s &target_gnss)
476476
{
477-
_target_gps_vel.timestamp = target_gnss.timestamp;
478-
_target_gps_vel.valid = isMeasRecent(target_gnss.timestamp);
477+
_target_gps_vel.timestamp = target_gnss.timestamp_sample;
478+
_target_gps_vel.valid = isMeasRecent(target_gnss.timestamp_sample);
479479

480480
_target_gps_vel.xyz(vtest::Axis::x) = target_gnss.vel_n_m_s;
481481
_target_gps_vel.xyz(vtest::Axis::y) = target_gnss.vel_e_m_s;
@@ -485,7 +485,7 @@ void VTEPosition::updateTargetGpsVelocity(const target_gnss_s &target_gnss)
485485

486486
bool VTEPosition::isTargetGpsPositionValid(const target_gnss_s &target_gnss)
487487
{
488-
if (!isMeasRecent(target_gnss.timestamp)) {
488+
if (!isMeasRecent(target_gnss.timestamp_sample)) {
489489
return false;
490490
}
491491

@@ -499,7 +499,7 @@ bool VTEPosition::isTargetGpsPositionValid(const target_gnss_s &target_gnss)
499499

500500
bool VTEPosition::isTargetGpsVelocityValid(const target_gnss_s &target_gnss)
501501
{
502-
if (!isMeasRecent(target_gnss.timestamp)) {
502+
if (!isMeasRecent(target_gnss.timestamp_sample)) {
503503
return false;
504504
}
505505

@@ -874,7 +874,7 @@ bool VTEPosition::ProcessObsGNSSVelTarget(const target_gnss_s &target_gnss, Targ
874874
obs.meas_h_xyz(vtest::Axis::y, vtest::State::vel_target) = 1;
875875
obs.meas_h_xyz(vtest::Axis::z, vtest::State::vel_target) = 1;
876876

877-
obs.timestamp = target_gnss.timestamp;
877+
obs.timestamp = target_gnss.timestamp_sample;
878878

879879
obs.type = ObsType::Target_gps_vel;
880880

@@ -953,7 +953,7 @@ bool VTEPosition::processObsGNSSPosMission(TargetObs &obs)
953953
/*Target GNSS observation: [rx + bx, ry + by, rz + bz]*/
954954
bool VTEPosition::processObsGNSSPosTarget(const target_gnss_s &target_gnss, TargetObs &obs)
955955
{
956-
const int64_t time_diff_us = signedTimeDiffUs(target_gnss.timestamp, _uav_gps_position.timestamp);
956+
const int64_t time_diff_us = signedTimeDiffUs(target_gnss.timestamp_sample, _uav_gps_position.timestamp);
957957
const float dt_sync_us = fabsf(static_cast<float>(time_diff_us));
958958

959959
if (dt_sync_us > _meas_recent_timeout_us) {
@@ -1030,7 +1030,7 @@ bool VTEPosition::processObsGNSSPosTarget(const target_gnss_s &target_gnss, Targ
10301030
obs.meas_h_xyz(vtest::Axis::z, vtest::State::bias) = 1;
10311031
}
10321032

1033-
obs.timestamp = target_gnss.timestamp;
1033+
obs.timestamp = target_gnss.timestamp_sample;
10341034

10351035
obs.meas_xyz = gps_relative_pos;
10361036

0 commit comments

Comments
 (0)