Page 1 of 1

[SOLVED] Kalman filter reset

Posted: Thu Jul 25, 2019 5:15 pm
by juangallostra
Setup: I have been playing around with setting / reading parameters via the Python API (based on the 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,
} 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?

Re: Kalman filter reset

Posted: Fri Jul 26, 2019 8:14 am
by kimberly

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

Re: Kalman filter reset

Posted: Fri Jul 26, 2019 4:36 pm
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!

Re: [SOLVED] Kalman filter reset

Posted: Sat Jul 27, 2019 9:05 pm
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.

Re: [SOLVED] Kalman filter reset

Posted: Tue Jul 30, 2019 12:06 pm
by kimberly
Perfect :D thanks for double checking!