Академический Документы
Профессиональный Документы
Культура Документы
E G N Karunaratne
080224 L
Mechatronics & System Automation Applications EE 4320
Intrigal gain
I_output += double.Parse(numKi.Text)*omega_error*dt;
Derivative gain
A low pass filter is added to prevent the system from becoming unstable. Mechatronics & System Automation Applications |EE4320 1
tempD += D_output * dt; D_output = (double.Parse(numKd.Text) *omega_error) - tempD;
1 2 implementation:
temp1 += (motor_input * Km * dt) / L; temp2 += (motor_output * R * dt) / L; motor_output = temp1 - temp2;
3 4 implementation:
temp3 += (load_input * dt) / J; temp4 += (load_output * b * dt) / J; load_output = temp3 - temp4;
Code
using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; ZedGraph;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //Graph curves RollingPointPairList speed_actual = new RollingPointPairList(1200); RollingPointPairList speed_desired = new RollingPointPairList(1200); int tickStart = 0; double P_output, D_output, I_output, tempD, temp1, temp2, temp3, temp4, dt,motor_output,omega_out;
/* ************************************************************************************************** * Generate motor simulation model output * * Description : This function impliments the DC motor model * * Arguments : motor_input is the input to the DC motor model * : motor_output is the prvious output of the motor model * * Returns : motor_output is the new output of the motor model ************************************************************************************************** */ private double motor(double motor_input, double motor_output) { double Km = double.Parse(numKm.Text); //Motor Constant double L = double.Parse(numL.Text); //Motor Inductance double R = double.Parse(numR.Text); //Motor Resistance temp1 += (motor_input * Km * dt) / L; temp2 += (motor_output * R * dt) / L; motor_output = temp1 - temp2; return motor_output; }
/* ************************************************************************************************** * Generate load model output * * Description : This function impliments the load model * * Arguments : load_input is the input to the load model * : load_output is the prvious output of the load model * * Returns : load_output is the new output of the load model ************************************************************************************************** */ private double motor_load(double load_input, double load_output) { double J = double.Parse(numJ.Text); //Load Inertia double b = double.Parse(numB.Text); //Load Friction temp3 += (load_input * dt) / J;
/* ************************************************************************************************** * Generate Back EMF of the motor model * * Description : This function impliments the Back EMF of the motor model * * Arguments : omega_out is the output speed of the motor model in rad/s * * Returns : Vemf is the Back EMF of the motor model ************************************************************************************************** */ private double back_EMF(double omega_out) { double Kb = double.Parse(numKb.Text); //Back EMF Constant double Vemf = omega_out* Kb; return Vemf; }
/* ************************************************************************************************** * Constrain output * * Description : Used to bound values to prevent system from been unstable * * Arguments : value is the input value to be checked * * Returns : bounded value ************************************************************************************************** */ private double Constrain(double value) { int min = -1000; int max = 1000; if (value > max) { value = max; } if (value < min) { value = min; } return value; } /* ************************************************************************************************** * Timer #1 Interrupt handler * * Description : Scan user inputs and populate outputs * * Arguments : windows form objects * * Returns : none ************************************************************************************************** */ private void timer1_Tick(object sender, EventArgs e) { double time = (Environment.TickCount - tickStart) / 1000.0; double omega_desired = double.Parse(txtOmegaInput.Text); //Desired Speed dt = timer1.Interval / 1000.0; double omega_error = omega_desired - omega_out; double Va = PID_Controller_output(omega_error); double Vemf = back_EMF(omega_out); double motor_input = Va - Vemf; motor_output = motor(motor_input, motor_output); omega_out = motor_load(motor_output, omega_out);
/* ************************************************************************************************** * Timer #2 Interrupt handler * * Description : Update Graph * * Arguments : windows form objects * * Returns : none ************************************************************************************************** */ private void timer2_Tick(object sender, EventArgs e) { if (zg1.GraphPane.CurveList.Count <= 0) return; // Get the first Curve Item in the graph LineItem curve = zg1.GraphPane.CurveList[0] as LineItem; if (curve == null) return; // Get the PointPairList IPointListEdit list = curve.Points as IPointListEdit; // If this is null, it means the reference at curve.Points does not // support IPointListEdit, so we won't be able to modify it if (list == null) return; // Time is measured in seconds double time = (Environment.TickCount - tickStart) / 1000.0; // Keep the X scale at a rolling 30 second interval, with one // major step between the max X value and the end of the axis Scale xScale = zg1.GraphPane.XAxis.Scale; if (time > xScale.Max - xScale.MajorStep) { xScale.Max = time + xScale.MajorStep; xScale.Min = xScale.Max - 30.0; } try { // Make sure the Y axis is rescaled to accommodate actual data zg1.AxisChange(); // Force a redraw zg1.Invalidate(); } catch (Exception) { } }
/* ************************************************************************************************** * Timer #2 Interrupt handler * * Description : Initialize Graph * * Arguments : windows form objects *
KP = 10, KI = 10, KD = 10
KP = 10, KI = 50, KD = 20
KP = 20, KI = 50, KD = 30
Derivative erivative
Summer
Inverter
Integral