I am working on this short assignment where I have to find the right PD values for a simulated quadcopter. I have to reach 0.9 meters under 1 second with an overshoot of less than 5%. This is my code:

function [ u ] = pd_controller(~, s, s_des, params)
%PD_CONTROLLER  PD controller for the height
%   s: 2x1 vector containing the current state [z; v_z]
%   s_des: 2x1 vector containing desired state [z; v_z]
%   params: robot parameters

% u = 0;

error = s_des - s;
z_des = 0.9;

Kp = 0.5;
Kv = 1.0;

u = params.mass*(z_des + Kp*error(1) + Kv*error(2) + params.gravity);


So far this is my output:

enter image description here

I've tried many different value combinations and so far this is the closest that I could get.

  • 1
    $\begingroup$ Why are you adding z_des to the control? That looks wrong. $\endgroup$ – holmeski Aug 2 at 21:50
  • $\begingroup$ @holmeski Initially it was in the starter code. Now that I removed it, the drone does not lift off at all. $\endgroup$ – oo92 Aug 2 at 21:52
  • $\begingroup$ If you set the control to m*(g + I), what's the lowest I can be while still driving the vehicle upwards? $\endgroup$ – holmeski Aug 2 at 22:04

You are controlling a second order system. Set both kp and kv to 4.

If the system does not reach your desired altitude then there are additional problems with the code.

| improve this answer | |
  • $\begingroup$ It doesn't work. $\endgroup$ – oo92 Aug 3 at 0:15
  • $\begingroup$ It is likely that there is an error in your setup. Those gains should see the natural frequency to 2 with a damping ratio of 1. Are you sure that you're setting the mass correctly? $\endgroup$ – holmeski Aug 3 at 0:55
  • $\begingroup$ The code you see above is all I got $\endgroup$ – oo92 Aug 3 at 1:05
  • 1
    $\begingroup$ I recommend checking out my comment to your question. Find the smallest u that will drive the quad off the ground. Start with u=mg then u=mg +.1 and so on until you find some value , let's call it k, that will just drive the quad off the ground. Then try the control law u=m*(kp e(1) + kve(2) +g) + k. That should get you close to the desired error. $\endgroup$ – holmeski Aug 3 at 2:10
  • 1
    $\begingroup$ Also, have you checked all the values to make sure they make sense? Do the desired position and velocity make sense? Is the mass real? $\endgroup$ – holmeski Aug 3 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.