[SOLVED] Kalman filter reset

Firmware/software/electronics
Post Reply
juangallostra
Beginner
Posts: 3
Joined: Thu Jul 25, 2019 2:15 pm

[SOLVED] Kalman filter reset

Post by juangallostra »

Setup: I have been playing around with setting / reading parameters via the Python API (based on the basicparam.py example) and I would appreciate if someone could shed some light on the following issue:

When the parameter stabilizer.estimator is set to 2, trying to set kalman.resetEstimation to 1 (via self._cf.param.set_value) has no effect and it remains at 0 no matter how many times I try. However, if I first set stabilizer.estimator to 1 and then set kalman.resetEstimation to 1 then the value changes without problems. The thing that I don't get from this behavior is that, taking a look at the following enum

Code: Select all

typedef enum {
  anyEstimator = 0,
  complementaryEstimator,
  kalmanEstimator,
  StateEstimatorTypeCount,
} StateEstimatorType;


- which is defined in estimator.h and it is from where the logged parameter stabilizer.estimator takes its value- it seems that a value of 2 for the stabilizer.estimator parameter means that the kalman estimator is being used whereas a value of 1 means that the complementary estimator is being used.

Does that mean that when using the Kalman estimator there isn't the possibility to reset the estimation or am I misunderstanding something?
Last edited by juangallostra on Fri Jul 26, 2019 4:36 pm, edited 1 time in total.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Kalman filter reset

Post by kimberly »

Hi!

I've investigated the situation a little bit, and tried to replicate this through the cfclient, and you are right about your observation. If the estimator is set to 2 (kalmanEstimator), and if the kalman.resetEstimation is put to 1, it seems like it stays 0. However, if you look into the code of the firmware, this makes a bit more sense (estimator_kalman.c line 228):

Code: Select all

  if (coreData.resetEstimation) { estimatorKalmanInit(); coreData.resetEstimation = false; }
So what is essentially happening here, is that once you put the parameter on 1, the Kalman filter will reset and once that has been done, it will put the resetEstimation value right back to 0 or else it will keep on resetting. This happens so fast that on your end you will only see the value being 0, but actually the number value change went so fast that it wasn't able to communicate it quick enough to your computer.

The reason why the reset value stays on 1 with the estimator set to 1 (complementaryEstimator), is that the above line is never reached because it is a different estimator. The value is 1 but nothing is being reset.

Does this make more sense to you? Usually it helps to sniff out the firmware to see what is being done to that value and you could also add a log for yourself that is triggered once the initialization has been done (and goes back to 0 in a few seconds), so you will have a bit more feedback on the process.

Ps. thanks for your very clarifying post with the additional information. It made it very easy for me to see where the issue was :D
juangallostra
Beginner
Posts: 3
Joined: Thu Jul 25, 2019 2:15 pm

Re: Kalman filter reset

Post by juangallostra »

Hi kimberly and thanks for the quick reply.

Your explanation is very clear and it solves all the questions I had about this issue. The behavior I was observing makes total sense now.

I'll keep your suggestions in mind for when I face similar problems in the future! Thanks again for your help!
juangallostra
Beginner
Posts: 3
Joined: Thu Jul 25, 2019 2:15 pm

Re: [SOLVED] Kalman filter reset

Post by juangallostra »

Just to close the issue, I have performed several tests im order to validate Kimberly’s explanation.

I have added a call to ledSeq inside the piece of code where the parameter is reset to 0 after being set to 1. Not surprisingly, the LED flashes when the parameter is set via the Python API.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: [SOLVED] Kalman filter reset

Post by kimberly »

Perfect :D thanks for double checking!
Post Reply