Go Down

Topic: Accelerometer+DC motor PID tunings help (Read 1 time) previous topic - next topic


Nov 03, 2014, 03:33 pm Last Edit: Nov 03, 2014, 03:35 pm by steelgoofy

I' ve a MPU6050 accelerometer, and a 12V DC motor (with a prop on it d = 20cm).
I've built a system, image here:

As the motor rotating the prop lift force, and so I want the system to keep horizontal. I have the arduino and the MPU 6050 at the middle, the MPU gives the X accel from -16000 to 16000 in int. 0 is the 0° turn, 16000 is 90°to the left, -16000 is 90°to the right.

I'm using the arduino PID library.
The input is the "X accel"
Setpoint is "0"
Output is the duty cycle (0...255)

Code: [Select]

#include <PID_v1.h>
#include <Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX;

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Define Tuning Parameters
double  Kp, Ki,  Kd;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

void setup()
Wire.write(0x6B);  // PWR_MGMT_1 register
Wire.write(0);     // set to zero (wakes up the MPU-6050)

Input = AcX;
Setpoint = 0;
 //turn the PID on
void loop()
Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
AcX=Wire.read()<<8 | Wire.read();  
Input = AcX;

I would like to know how to tune the Kp, Ki, Kd values, I know the basics of PID, but I never used it in practice. I guess the Ki and the Kd should be much less than the Kp.


This looks like a good beginner PID tuning tutorial:


A Google search for PID Tuning will turn up more tutorials.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up