Question about `EstimatorInterface` Parameters

@bresch sorry to keep tagging you with questions. please let me know if you would prefer I didn’t!

I’ve been reading through the PX4 EKF code in great detail, and I have come across a bit of it that I don’t understand. The EstimatorInterface interface class has this parameters struct as a member.

The struct has default values hard coded, which seem to correspond to the default values in the overall system parameters.

However, I can’t find where this particular struct ever gets written to? I was trying to understand how a few of the parameters interact, and got quite confused about which parameter was the one of importance. Specifically, sometimes the code uses _param_ekf2_min_rng as the minimum range distance, which is loaded from the PX4 parameters. Other times it uses _params->rng_gnd_clearance which seems to be loaded from this parameters struct. I had assumed these were the same values at all times, so the struct would be updated from the PX4 parameters. However, it seems to be the opposite, in that the PX4 parameters, as held in the EKF2 instance, are set by the parameters object, meaning they are synced, but the parameters defaults take precedence.

Can you help me understand what I am misunderstanding? Thanks!

Hi @profxavr ,

(it’s fine if you tag me for EKF-related questions, otherwise I might miss them)

Regarding the parameters, the struct is initialized with the values you see in common.h, but they are then linked to the PX4 parameters in EKF2.cpp. So for example, _param_ekf2_predict_us(_params->filter_update_interval_us) links filter_update_interval_us to _param_ekf2_predict_us (which is EKF2_PREDICT_US).

This means that when reading the value of _params.filter_update_interval_us, you’ll get the value of EKF2_PREDICT_US directly (except in the unit tests where the EKF2 is not running).

In your example, _params.rng_gnd_clearance contains the value of EKF2_MIN_RNG.

Hope this is clear enough. Also note that some of the parameters defined in the struct are not directly bound to a parameter, in this case the default value is always used.

Awesome. Thank you for the help!

AH. There IS something about the constructors that is like a backwards link. I guess I didn’t look closely enough at the instantiation code for the Params? I was expecting to see something overloading the () operator or something. However there are sEcrEts hidden in your DEFINE_PARAMETERS macro. Is that where the linking happens?

I was confused because normally like x(a) sets x to a when used in a member initializer list.

I’ll have another post up bugging you again soon. It’s related to what you pointed out in my previous post about the vertical terrain estimate jump.

The parameter is first linked with a variable in the struct using this constructor: PX4-Autopilot/platforms/common/include/px4_platform_common/param.h at 93c25efb62ebb0ed44b0f259fa1508aab081b2a1 · PX4/PX4-Autopilot · GitHub

The “internal” value of the parameter is then a reference to that variable and when the param update function is called, the value of the reference is changed, so the variable in the EKF param struct is also changed accordingly. It’s a 2-way link since one is just the reference of the other one.

1 Like

Thanks for the explanation and finding where the link happens for me!