This post documents how to add support for tuning PID using transmitter. The complete code can be found in my Github.
PID tuning is known to be a very tedious process. Being able to tune using transmitter will greatly save time as one does not need to do re-flash the program every time after changing just one single value.
To tune PID using transmitter, one first needs to enable more channels in RC transmitter. The transmitter I use is Frsky Taranis Q X7. I referred to this video to set up channel 5 of the RC transmitter to report the value of SF switch.
In the main application, if the value of channel 5 is detected to be at its maximum, it will enter PID tuning mode. In this mode, instead of controlling quadcopter, roll, pitch and yaw sticks will adjust P, I, D values respectively. An example is given below
if (cmd.desiredPitch == CMD_PITCH_MIN) { float curKp = Controller::GetInstance().mAttController_pitch.GetKp() - 0.1; LOGI("TunePID: Kp to %f\r\n", curKp); Controller::GetInstance().mAttController_roll.SetKp(curKp); Controller::GetInstance().mAttController_pitch.SetKp(curKp); LED_Blink(LED_ONBOARD, 4); }
If channel 5 is detected to be at its minimum, the main application will switch back to normal operation mode and user can proceed to arm and fly the quadcopter normally.
Despite the above setup, I still had to manually try and adjust the resolution of change of each PID value. Furthermore, I need to remember how many times I have adjusted each value and update the default PID values accordingly after each trial. So tuning PID still remains a relatively tedious process especially in my case where I do not have a set of working default value.
No comments:
Post a Comment