2014年6月18日 星期三

DC Motor Speed PID Control with Arduino

It is a new MechLab for NCKU ME next semester, a PID controller!
Hardware:





Source Code on Github: https://github.com/kvzhao/ME-PIDLab

The crucial part of the PID code is listed below
void loop()
{
    // Run a period to estimate more precise speed
    Motor.Tick();
    // Run for one Second
    delay(SamplingTime);
    Motor.Tock();

    // Read rotation speed from Encoder
    Input = Motor.getSpeedRPS();

    // PID Compute
    PID_Controller.Compute();
    if ((Output-prevOutput) >= oscGap) {
      //Output = prevOutput;
    }
    Motor.setSpeed(Output);
    prevOutput = Output;
    // Show Data
    /*
    Serial.print("Input: ");
    Serial.println(Input);
    Serial.print("Setpoint: "); 
    Serial.println(Setpoint);    
    Serial.print("Error: ");
    Serial.println(error);
    Serial.print("Output: "); 
    Serial.println(Output);*/
    Serial.println(error);
    // wait a little while
    delay(5);
}


My first test result (with KP=98, KI=8, PD=5)
There is almost no steady state error, however overshoot happens.
Next step is to tune the parameters and control the motor smoothly!

Some useful references



沒有留言:

張貼留言