Quadcopter won't stabelize with PID.

Hi Everyone,

Since i’m building a quadcopter and finally at the point of stabelizing it through PID I haven’t been any further. No matter what I try i can’t get the right PID values. I’m using the PID Library. It’s not because the pid is not working. I can see the difference clearly even the ‘KD’ will smooth it to a certain point, but it’s oscillating to much. I have doubts if the arduino can process everything fast enough. I don’t know much about Hz rate’s etc. Another doubt I have is that my MPU is not accurate enough. I have the CMPS11 which give kalmanfiltered angles without any decimal’s. Could this have any influence on how precise the pid will compute it, does it make sense at all to the motor output? At first I used the mpu9015 (same as mpu 6015, but with magnetometer), but I had troubles with it, which you can read in another topic from me. That one gives the angles with two decimals.

I made a video to give you an idea how it peforms right now: https://youtu.be/KakVR_XOJWY

As you can see it hangs mostly to the left side and then it correct it a bit and falls back to that side.

I’m stuck because I don’t know where I need to look. Is it the CMPS11, the processing speed of the arduino(mega 2560 ADK) or still the PID values…

For who want’s to look at the code, here you go. It’s a bit messy right now: See attachment.

Some of the code have been derived from this(Especially the PID implementation): Arduino-Quadcopter/Quadcopter at master · benripley/Arduino-Quadcopter · GitHub

There is some dutch comments, sorry about that. :stuck_out_tongue: With ‘mpullcore’ I control the motor output. When everything works the distance sensor need to take this over.

Ohw, I don’t use any radio control. :wink:

If you need more information, let me know!

Thankz. :slight_smile:

Regards,

Mart

quadpid.ino (10 KB)

Are you using the ultrasonic sensor?
pulseIn is blocking.

Yeah, I use it yeah, but it doesn't control the motor right now. Do you want to say that the pulseln is the bottleneck? Because it waits for when it's HIGH and LOW?

Regards,

Mart

I suspect your problem is that pulseIn takes variable amounts of time, depending on range, which I would imagine will screw your PID.

Aha, I'm going to remove that piece of code and will let you know how it went. ;)

Thankz!

Regards,

Mart

Hi,

I had removed that piece of code and I had even the samplerate of the pidcontroller reduced to 1ms instead of 10ms, at first I thought it had maked a little difference, but it's negligible. It does still the same, it corrects it a little and then fallsback to the left side. I have tried different pid settings. If I set the P higher (800/1000) it will flip from side to side. I won't mainstain a smooth level.

Right now I had calibrated the esc to make sure it won't has different throttle ranges, but even that wasn't the cause. I found out when the motors begins the right motor goes a little quicker than the left motor. It's titlting it to the left side, but it could be caused by the PID, although it sounds a bit weird to me because in my opinion it need to correct to the right side of the quadcopter. ;p

Has it nothing to do with the CMPS11? Because the agles are int's and not float's or double's?

Regards,

Mart