param.set_value() works...sometimes

Firmware/software/electronics/mechanics
Post Reply
mzhao
Beginner
Posts: 4
Joined: Thu Aug 31, 2017 8:46 am

param.set_value() works...sometimes

Post by mzhao »

I'm encountering this issue where I am using cf.param.set_value(_,_) to help tune PID gains. However, when I try to change a few of them at once, and I check the log to see if they've changed, it's somewhat inconsistent whether or not the parameter changes.

In particular, what's happening is like this:
Say I have in the firmware kp=6.0, ki=1.0, kd=0.1. I have three successive lines of cf.param.set_value(_,_) to change these values to 0.0. In each run of my code (which does quite a bit more than just changing the PID gains), the link with the CF is closed. I am logging the pid gains to keep track of whether or not the PID gains have changed or not
After one run, none of these values change. After the second run, the kp value changes. The third run, nothing changes, but ki changes on the fourth. etc etc.
This doesn't have to happen every other time the code is run, but the point is that it changes, but inconsistently so.
I'm looking for some way to guarantee that the parameters change when param.set_value() is called.

Thanks!
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: param.set_value() works...sometimes

Post by kristoffer »

It might be that you close the link before the parameters have been sent to the Crazyflie over the radio.

Check out https://github.com/bitcraze/crazyflie-l ... icparam.py, lines 120 - 133
To ensure that data has been transferred to the Crazyflie, a callback is registered before the parameter is set. When the callback (_a_pitch_kd_callback in the example) is called, we know that the parameter has been set and the link can be closed.
mzhao
Beginner
Posts: 4
Joined: Thu Aug 31, 2017 8:46 am

Re: param.set_value() works...sometimes

Post by mzhao »

I had been using the param.set_value() command in a separate python code that I had written, but without the callbacks.

I think I'll just use the basicparam.py script to change the PID values before running my own code while tuning.

Thanks!
Post Reply