0

Please I'm working on a quadcopter, and I have to made my own flight controller based on arduino uno.
First of all please how can I get a filtred angular velocity and linear acceleration from the MPU6050, is the following code give us the angular velocity in deg/sec and the linear velocity in m/s2 ?

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

and is this pid value in this following code is right ?

 accel_reading = ax;
 accel_corrected = accel_reading - accel_offset;
 accel_corrected = map(accel_corrected, -16800, 16800, -90, 90);
 accel_corrected = constrain(accel_corrected, -90, 90);
 accel_angle = (float)(accel_corrected * accel_scale);
 err = angle_setpoint - accel_angle ;
 P = Kp * err ;
 I += (Ki * err) ;
 D = Kd * (err - errp);
 pid = P + I + D;

Thank you.

Nick Gammon
38.9k13 gold badges69 silver badges125 bronze badges
asked Jul 31, 2016 at 17:49

2 Answers 2

1

How can I convert PID correction values to an PWM brushless command?

you have to do that yourself. you have to figure out first how to correct a pid value directionally. for example, should you increase the duty cycle if pid is positive or negative?

after that, you will need to map the pid value to a range for your pwm dc.

basically, it is application / task specific, and you are in complete charge.

answered Jan 28, 2017 at 19:34
0

You convert PID outputs to process outputs by selecting appropriate Kp, Ki, and Kd constants -- they translate the error components into a process output. For example, if you want 10 degrees of error to give you a full-scale analogWrite() adjustment, set Kp=255.0/10. Ki and Kd will depend on the (unspecified) sampling interval. If the measurements are noisy, you can use the Ki term to do some filtering work, but if you filter it prior to the PID, it will reduce the performance of the PID.

Code-wise, you are missing some sort oferrp=err; code, you need more than acceleration in the x direction to calculate an angle, (atan2(az,ax) or some such, depending on orientation), and your PID scheme doesn't protect against common problems like out-of-range, integral windup, or inconsistent sampling interval. You should investigate the http://playground.arduino.cc/Code/PIDLibrary for a more robust implementation than you've half-coded above.

answered Aug 1, 2016 at 4:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.