Quadcopter PID controller

5.1k views Asked by At

Context

My task is to design and build a velocity PID controller for a micro quadcopter than flies indoors. The room where the quadcopter is flying is equipped with a camera-based high accuracy indoor tracking system that can provide both velocity and position data for the quadcopter. The resulting system should be able to accept a target velocity for each axis (x, y, z) and drive the quadcopter with that velocity.

The control inputs for the quadcopter are roll/pitch/yaw angles and thrust percentage for altitude.

My idea is to implement a PID controller for each axis where the SP is the desired velocity in that direction, the measured value is the velocity provided by the tracking system and the output value is the roll/pitch/yaw angle and respectively thrust percent.

Unfortunately, because this is my first contact with control theory, I am not sure if I am heading in the right direction.

Questions

  • I understand the basic PID controller principle, but it is still unclear to me how it can convert velocity (m/s) into roll/pitch/yaw (radians) by only summing errors and multiplying with a constant? Yes, velocity and roll/pitch are directly proportional, so does it mean that by multiplying with the right constant yields a correct result?

  • For the case of the vertical velocity controller, if the velocity is set to 0, the quadcopter should actually just maintain its altitude without ascending or descending. How can this be integrated with the PID controller so that the thrust values is not 0 (should keep hovering, not fall) when the error is actually 0? Should I add a constant term to the output?

  • Once the system has been implemented, what would be a good approach on tuning the PID gain parameters? Manual trial and error?

  • The next step in the development of the system is an additional layer of position PID controllers that take as a setpoint a desired position (x,y,z), the measured positions are provided by the indoor tracking system and the outputs are x/y/z velocities. Is this a good approach? The reason for the separation of these PID control layers is that the project is part of a larger framework that promotes re-usability. Would it be better to just use a single layer of PID controllers that directly take position coordinates as setpoints and output roll/pitch/yaw/thrust values?

3

There are 3 answers

1
YMW On BEST ANSWER
  • That's the basic idea. You could theoretically wind up with several constants in the system to convert from one unit to another. In your case, your P,I, D constants will implicitly include the right conversion factors. for example, if in an idealized system you would want to control the angle by feedback with P=0.5 in degrees, bu all you have access to is speed, and you know that 5 degrees of tilt gives 1 m/s, then you would program the P controller to multiply the measured speed by 0.1 and the result would be the control input for the angle.
  • I think the best way to do that is to implement a SISO PID controller not on height (h) but on vertical speed (dh/dt) with thrust percentage as the ouput, but I am not sure about that.
  • Unfortunately, if you have no advance knowledge about the parameters, that will be the only way to go. I recommend an environment that won't do much damage if the quadcopter crashes...
  • That sounds like a good way to go
0
user2826084 On

My blog may be of interest to you: http://oskit.se/quadcopter-control-and-how-to-really-implement-it/

The basic principle is easy to understand. Tuning is much harder. It took me the most time to actually figure out what to feed into the pid controller and small things like the + and - signs on variables. But eventually I solved these problems.

The best way to test PID controller is to have some way to set your values dynamically so that you don't have to recompile your firmware every time. I use mavlink in my quadcopter firmware that I work on. With mavlink the copter can easily be configured using any ground control software that supports mavlink protocol.

Start small, build a working copter with using a ready made controller, then write your own. Then test it and tune it and experiment. You will never truly understand PID controllers unless you try building a copter yourself. My bare metal software development library can assist you with making it easier to write your software without having to worry about hardware driver implementation. Link: https://github.com/mkschreder/martink

0
Erkan On

If you are using python programming language, you can use ddcontrol framework. You can estimate a transfer function by SISO data. You can use tfest function for this purpose. And then you can optimize a PID Controller by using pidopt function.