Origin of EKF2 and Local Position

Hi all,
I’m currently developing a project for my Master degree and I wanted a clarification on this topic.
I’m currently spawning multiple models in a Gazebo simulation using this command:

PX4_SYS_AUTOSTART={code} PX4_GZ_MODEL_POSE='{x},{y}' PX4_SIM_MODEL={model} ./build/px4_sitl_default/bin/px4 -i {count+1}

(since it’s in a launch file in Python, all the curly brackets values are substituted at runtime). In particular, as you can see I do set an initial pose to spawn the model at.

I would have expected that the EKF2 origin/init would have been in the spawning position, but instead it seems to be in (0,0,0). I see this both from the ROS2 logs printing the VehicleLocalPosition topic messages and from the relative log I’ve uploaded here:

I understand that the EKF2 origin is set at boot (as stated in this GitHub answer)

The origin of the local frame is set at boot and shouldn't be reset. 

and is not the same as the home position (found this here)

The origin of this “local position” is set where the EKF2 initializes. (This is not the “home” position which is reset on arming.)

but then I wonder how this works. Is the spawn position not taken into consideration? Is the EKF2 always initialized in (0,0,0)?

Hi,
I have kind of the same setup. The output of VehicleLocalPosition has values relative to the spawn location, as it would be expected.
In the Gazebo GUI, the robots are at the spot that you provided in PX4_GZ_MODEL_POSE ?
The only difference I see between our two lines is that I completely define PX4_GZ_MODEL_POSE : PX4_GZ_POSE=x,y,z,0,0,0,0 (last 4 values represent the quaternion of the desired orientation).

Can you confirm you are using the default parameters of the EKF2 ?

yes, the spawning positions are good

As far as the parameters I’m using, I don’t think I’m changing anything related to the EKF2, but here’s one airframe for example:

#!/bin/sh
#
# @name OpenRobotics X3
#
# @type Quadrotor x
#

. ${R}etc/init.d/rc.mc_defaults

PX4_SIMULATOR=${PX4_SIMULATOR:=gz}
PX4_GZ_WORLD=${PX4_GZ_WORLD:=default}
PX4_SIM_MODEL=${PX4_SIM_MODEL:=X3}

param set-default SIM_GZ_EN 1

param set-default COM_OF_LOSS_T 3

param set-default RTL_RETURN_ALT 5

param set-default SENS_EN_GPSSIM 1
param set-default SENS_EN_BAROSIM 1
param set-default SENS_EN_MAGSIM 1 

param set-default CA_AIRFRAME 0
param set-default CA_ROTOR_COUNT 4

# Rotors
# SDF and Airframe have different reference frames!
param set-default CA_ROTOR0_PX  0.13
param set-default CA_ROTOR0_PY  0.22
param set-default CA_ROTOR0_KM  0.05 # CCW

param set-default CA_ROTOR1_PX -0.13
param set-default CA_ROTOR1_PY -0.20
param set-default CA_ROTOR1_KM  0.05 # CCW

param set-default CA_ROTOR2_PX  0.13
param set-default CA_ROTOR2_PY -0.22
param set-default CA_ROTOR2_KM -0.05 # CW

param set-default CA_ROTOR3_PX -0.13
param set-default CA_ROTOR3_PY  0.20
param set-default CA_ROTOR3_KM -0.05 # CW

# Set actuators to some functions
param set-default SIM_GZ_EC_FUNC1 101
param set-default SIM_GZ_EC_FUNC2 102
param set-default SIM_GZ_EC_FUNC3 103
param set-default SIM_GZ_EC_FUNC4 104

# Min-Max throttle values
param set-default SIM_GZ_EC_MIN1 150
param set-default SIM_GZ_EC_MIN2 150
param set-default SIM_GZ_EC_MIN3 150
param set-default SIM_GZ_EC_MIN4 150

param set-default SIM_GZ_EC_MAX1 1000
param set-default SIM_GZ_EC_MAX2 1000
param set-default SIM_GZ_EC_MAX3 1000
param set-default SIM_GZ_EC_MAX4 1000

# Throttle % needed to hover
param set-default MPC_THR_HOVER 0.60

@Theotime_Balaguer was this looking good parameter-wise?