diff --git a/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld index a9c8350dd9e..1b51bb7043e 100644 --- a/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/agam/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld @@ -53,7 +53,7 @@ *(.text.param_get) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text._ZN4EKF220PublishLocalPositionERKy) +*(.text._ZN4EKF220PublishLocalPositionERKyRKN6matrix7Vector3IfEE) *(.text._mav_finalize_message_chan_send) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) *(.text._ZN6events12SendProtocol6updateERKy) @@ -176,7 +176,7 @@ *(.text._ZN3Ekf24controlOpticalFlowFusionERKN9estimator9imuSampleE) *(.text._ZN19MavlinkStreamRawRpm4sendEv) *(.text._ZN13MavlinkStream10const_rateEv) -*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleE) +*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleERKN6matrix7Vector3IfEE) *(.text._ZN15FailureDetector20updateAttitudeStatusERK16vehicle_status_s) *(.text._ZN7Mavlink19configure_sik_radioEv) *(.text._ZN13BatteryStatus8adc_pollEv) @@ -582,7 +582,7 @@ *(.text._ZN4uORB10DeviceNode15poll_notify_oneEP6pollfdm) *(.text._ZN3GPS21handleInjectDataTopicEv.part.0) *(.text._ZN9Commander17systemPowerUpdateEv) -*(.text._ZN4EKF221PublishGlobalPositionERKy) +*(.text._ZN4EKF221PublishGlobalPositionERKyRK9LatLonAlt) *(.text._ZNK12FailsafeBase17getSelectedActionERKNS_5StateERK16failsafe_flags_sbbRNS_19SelectedActionStateE) *(.text.imxrt_padctl_address) *(.text._ZNK6matrix6VectorIfLj2EE4unitEv) diff --git a/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld index 348b5308651..6468bdc8c8e 100644 --- a/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/ark/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld @@ -49,7 +49,7 @@ *(.text.param_get) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text._ZN4EKF220PublishLocalPositionERKy) +*(.text._ZN4EKF220PublishLocalPositionERKyRKN6matrix7Vector3IfEE) *(.text._mav_finalize_message_chan_send) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) *(.text._ZN6events12SendProtocol6updateERKy) @@ -171,7 +171,7 @@ *(.text._ZN3Ekf24controlOpticalFlowFusionERKN9estimator9imuSampleE) *(.text._ZN19MavlinkStreamRawRpm4sendEv) *(.text._ZN13MavlinkStream10const_rateEv) -*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleE) +*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleERKN6matrix7Vector3IfEE) *(.text._ZN15FailureDetector20updateAttitudeStatusERK16vehicle_status_s) *(.text._ZN7Mavlink19configure_sik_radioEv) *(.text.getpid) @@ -568,7 +568,7 @@ *(.text._ZN4uORB10DeviceNode15poll_notify_oneEP6pollfdm) *(.text._ZN3GPS21handleInjectDataTopicEv.part.0) *(.text._ZN9Commander17systemPowerUpdateEv) -*(.text._ZN4EKF221PublishGlobalPositionERKy) +*(.text._ZN4EKF221PublishGlobalPositionERKyRK9LatLonAlt) *(.text._ZNK12FailsafeBase17getSelectedActionERKNS_5StateERK16failsafe_flags_sbbRNS_19SelectedActionStateE) *(.text.imxrt_padctl_address) *(.text._ZNK6matrix6VectorIfLj2EE4unitEv) diff --git a/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld index 6da98ea8561..e6dc1e6a3a0 100644 --- a/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/nxp/mr-tropic/nuttx-config/scripts/itcm_functions_includes.ld @@ -53,7 +53,7 @@ *(.text.param_get) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text._ZN4EKF220PublishLocalPositionERKy) +*(.text._ZN4EKF220PublishLocalPositionERKyRKN6matrix7Vector3IfEE) *(.text._mav_finalize_message_chan_send) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) *(.text._ZN6events12SendProtocol6updateERKy) @@ -174,7 +174,7 @@ *(.text._ZN3Ekf24controlOpticalFlowFusionERKN9estimator9imuSampleE) *(.text._ZN19MavlinkStreamRawRpm4sendEv) *(.text._ZN13MavlinkStream10const_rateEv) -*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleE) +*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleERKN6matrix7Vector3IfEE) *(.text._ZN15FailureDetector20updateAttitudeStatusERK16vehicle_status_s) *(.text._ZN7Mavlink19configure_sik_radioEv) *(.text._ZN13BatteryStatus8adc_pollEv) @@ -570,7 +570,7 @@ *(.text._ZN4uORB10DeviceNode15poll_notify_oneEP6pollfdm) *(.text._ZN3GPS21handleInjectDataTopicEv.part.0) *(.text._ZN9Commander17systemPowerUpdateEv) -*(.text._ZN4EKF221PublishGlobalPositionERKy) +*(.text._ZN4EKF221PublishGlobalPositionERKyRK9LatLonAlt) *(.text._ZNK12FailsafeBase17getSelectedActionERKNS_5StateERK16failsafe_flags_sbbRNS_19SelectedActionStateE) *(.text.imxrt_padctl_address) *(.text._ZNK6matrix6VectorIfLj2EE4unitEv) diff --git a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld index 70f21285b77..491065eafa3 100644 --- a/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/nxp/tropic-community/nuttx-config/scripts/itcm_functions_includes.ld @@ -53,7 +53,7 @@ *(.text.param_get) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text._ZN4EKF220PublishLocalPositionERKy) +*(.text._ZN4EKF220PublishLocalPositionERKyRKN6matrix7Vector3IfEE) *(.text._mav_finalize_message_chan_send) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) *(.text._ZN6events12SendProtocol6updateERKy) @@ -174,7 +174,7 @@ *(.text._ZN3Ekf24controlOpticalFlowFusionERKN9estimator9imuSampleE) *(.text._ZN19MavlinkStreamRawRpm4sendEv) *(.text._ZN13MavlinkStream10const_rateEv) -*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleE) +*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleERKN6matrix7Vector3IfEE) *(.text._ZN15FailureDetector20updateAttitudeStatusERK16vehicle_status_s) *(.text._ZN7Mavlink19configure_sik_radioEv) *(.text._ZN13BatteryStatus8adc_pollEv) @@ -569,7 +569,7 @@ *(.text._ZN4uORB10DeviceNode15poll_notify_oneEP6pollfdm) *(.text._ZN3GPS21handleInjectDataTopicEv.part.0) *(.text._ZN9Commander17systemPowerUpdateEv) -*(.text._ZN4EKF221PublishGlobalPositionERKy) +*(.text._ZN4EKF221PublishGlobalPositionERKyRK9LatLonAlt) *(.text._ZNK12FailsafeBase17getSelectedActionERKNS_5StateERK16failsafe_flags_sbbRNS_19SelectedActionStateE) *(.text.imxrt_padctl_address) *(.text._ZNK6matrix6VectorIfLj2EE4unitEv) diff --git a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld index a9c8350dd9e..1b51bb7043e 100644 --- a/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/px4/fmu-v6xrt/nuttx-config/scripts/itcm_functions_includes.ld @@ -53,7 +53,7 @@ *(.text.param_get) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text._ZN4EKF220PublishLocalPositionERKy) +*(.text._ZN4EKF220PublishLocalPositionERKyRKN6matrix7Vector3IfEE) *(.text._mav_finalize_message_chan_send) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) *(.text._ZN6events12SendProtocol6updateERKy) @@ -176,7 +176,7 @@ *(.text._ZN3Ekf24controlOpticalFlowFusionERKN9estimator9imuSampleE) *(.text._ZN19MavlinkStreamRawRpm4sendEv) *(.text._ZN13MavlinkStream10const_rateEv) -*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleE) +*(.text._ZN4EKF215PublishOdometryERKyRKN9estimator9imuSampleERKN6matrix7Vector3IfEE) *(.text._ZN15FailureDetector20updateAttitudeStatusERK16vehicle_status_s) *(.text._ZN7Mavlink19configure_sik_radioEv) *(.text._ZN13BatteryStatus8adc_pollEv) @@ -582,7 +582,7 @@ *(.text._ZN4uORB10DeviceNode15poll_notify_oneEP6pollfdm) *(.text._ZN3GPS21handleInjectDataTopicEv.part.0) *(.text._ZN9Commander17systemPowerUpdateEv) -*(.text._ZN4EKF221PublishGlobalPositionERKy) +*(.text._ZN4EKF221PublishGlobalPositionERKyRK9LatLonAlt) *(.text._ZNK12FailsafeBase17getSelectedActionERKNS_5StateERK16failsafe_flags_sbbRNS_19SelectedActionStateE) *(.text.imxrt_padctl_address) *(.text._ZNK6matrix6VectorIfLj2EE4unitEv) diff --git a/src/modules/ekf2/EKF/estimator_interface.cpp b/src/modules/ekf2/EKF/estimator_interface.cpp index 744a383e9e6..56dcaa528a4 100644 --- a/src/modules/ekf2/EKF/estimator_interface.cpp +++ b/src/modules/ekf2/EKF/estimator_interface.cpp @@ -641,9 +641,8 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp) return true; } -Vector3f EstimatorInterface::getPosition() const +Vector3f EstimatorInterface::globalToLocalPosition(const LatLonAlt &lla) const { - LatLonAlt lla = _output_predictor.getLatLonAlt(); float x; float y; diff --git a/src/modules/ekf2/EKF/estimator_interface.h b/src/modules/ekf2/EKF/estimator_interface.h index 3e82bbaac7b..1abd6349c44 100644 --- a/src/modules/ekf2/EKF/estimator_interface.h +++ b/src/modules/ekf2/EKF/estimator_interface.h @@ -261,7 +261,8 @@ public: Vector3f getVelocityDerivative() const { return _output_predictor.getVelocityDerivative(); } void resetVelocityDerivativeAccumulation() { return _output_predictor.resetVelocityDerivativeAccumulation(); } float getVerticalPositionDerivative() const { return _output_predictor.getVerticalPositionDerivative(); } - Vector3f getPosition() const; + Vector3f getPosition() const { return globalToLocalPosition(getLatLonAlt()); } + Vector3f globalToLocalPosition(const LatLonAlt &lla) const; LatLonAlt getLatLonAlt() const { return _output_predictor.getLatLonAlt(); } const Vector3f &getOutputTrackingError() const { return _output_predictor.getOutputTrackingError(); } diff --git a/src/modules/ekf2/EKF2.cpp b/src/modules/ekf2/EKF2.cpp index ac8ae5e6767..26b1170df13 100644 --- a/src/modules/ekf2/EKF2.cpp +++ b/src/modules/ekf2/EKF2.cpp @@ -857,9 +857,13 @@ void EKF2::Run() if (_ekf.update()) { perf_set_elapsed(_ekf_update_perf, hrt_elapsed_time(&ekf_update_start)); - PublishLocalPosition(now); - PublishOdometry(now, imu_sample_new); - PublishGlobalPosition(now); + // the output position, reconstructed once for all position publications + const LatLonAlt lla = _ekf.getLatLonAlt(); + const Vector3f position = _ekf.globalToLocalPosition(lla); + + PublishLocalPosition(now, position); + PublishOdometry(now, imu_sample_new, position); + PublishGlobalPosition(now, lla); PublishSensorBias(now); #if defined(CONFIG_EKF2_WIND) @@ -1364,7 +1368,7 @@ void EKF2::PublishEventFlags(const hrt_abstime ×tamp) } } -void EKF2::PublishGlobalPosition(const hrt_abstime ×tamp) +void EKF2::PublishGlobalPosition(const hrt_abstime ×tamp, const LatLonAlt &lla) { if (_ekf.global_origin_valid() && _ekf.control_status().flags.yaw_align) { // generate and publish global position data @@ -1372,7 +1376,6 @@ void EKF2::PublishGlobalPosition(const hrt_abstime ×tamp) global_pos.timestamp_sample = timestamp; // Position GPS / WGS84 frame - const LatLonAlt lla = _ekf.getLatLonAlt(); global_pos.lat = lla.latitude_deg(); global_pos.lon = lla.longitude_deg(); global_pos.lat_lon_valid = _ekf.isGlobalHorizontalPositionValid(); @@ -1696,14 +1699,13 @@ void EKF2::PublishInnovationVariances(const hrt_abstime ×tamp) _estimator_innovation_variances_pub.publish(variances); } -void EKF2::PublishLocalPosition(const hrt_abstime ×tamp) +void EKF2::PublishLocalPosition(const hrt_abstime ×tamp, const Vector3f &position) { vehicle_local_position_s lpos{}; // generate vehicle local position data lpos.timestamp_sample = timestamp; // Position of body origin in local NED frame - const Vector3f position{_ekf.getPosition()}; lpos.x = position(0); lpos.y = position(1); lpos.z = position(2); @@ -1819,7 +1821,7 @@ void EKF2::PublishLocalPosition(const hrt_abstime ×tamp) _local_position_pub.publish(lpos); } -void EKF2::PublishOdometry(const hrt_abstime ×tamp, const imuSample &imu_sample) +void EKF2::PublishOdometry(const hrt_abstime ×tamp, const imuSample &imu_sample, const Vector3f &position) { // generate vehicle odometry data vehicle_odometry_s odom; @@ -1827,7 +1829,7 @@ void EKF2::PublishOdometry(const hrt_abstime ×tamp, const imuSample &imu_sa // position odom.pose_frame = vehicle_odometry_s::POSE_FRAME_NED; - _ekf.getPosition().copyTo(odom.position); + position.copyTo(odom.position); // orientation quaternion _ekf.getQuaternion().copyTo(odom.q); diff --git a/src/modules/ekf2/EKF2.hpp b/src/modules/ekf2/EKF2.hpp index 7f963ab61da..f8c276ead6c 100644 --- a/src/modules/ekf2/EKF2.hpp +++ b/src/modules/ekf2/EKF2.hpp @@ -192,12 +192,12 @@ private: estimator_bias_s fillEstimatorBiasMsg(const BiasEstimator::status &status, uint64_t timestamp_sample_us, uint64_t timestamp, uint32_t device_id = 0); void PublishEventFlags(const hrt_abstime ×tamp); - void PublishGlobalPosition(const hrt_abstime ×tamp); + void PublishGlobalPosition(const hrt_abstime ×tamp, const LatLonAlt &lla); void PublishInnovations(const hrt_abstime ×tamp); void PublishInnovationTestRatios(const hrt_abstime ×tamp); void PublishInnovationVariances(const hrt_abstime ×tamp); - void PublishLocalPosition(const hrt_abstime ×tamp); - void PublishOdometry(const hrt_abstime ×tamp, const imuSample &imu_sample); + void PublishLocalPosition(const hrt_abstime ×tamp, const Vector3f &position); + void PublishOdometry(const hrt_abstime ×tamp, const imuSample &imu_sample, const Vector3f &position); void PublishSensorBias(const hrt_abstime ×tamp); void PublishStates(const hrt_abstime ×tamp); void PublishStatus(const hrt_abstime ×tamp);