I went to control the DC position with angle 30 or any anlge
I went to control the DC position with angle 30\' or any anlge
R: armature resistance= 5.35
L: armature inductance=3.93 mH
b: motor viscous friction constant = 3.867E-6
J: Total Moment of Inertia for Motor and Load =8.75e-6 kg.m2
Kt: motor torque constant=0.0316 Nm/A
Ke: back emf constant=0.0316 Vrad/s
if you can help me with PID Control and how to write the code .
Solution
#ifndef PID_H_ #define PID_H_ #include //Defineparameter #define epsilon 0.01 #define dt0.01 //100mslooptime #define MAX 4 //ForCurrent Saturation #define MIN -4
#define Kp 0.1 #define Kd 0.01 #define Ki 0.005 floatPIDcal(floatsetpoint,float actual_position) { staticfloat pre_error= 0; staticfloat integral=0; float error; float derivative; float output; //CaculateP,I,D error = setpoint -actual_position; //Incaseof errortoosmall then stop integration if(abs(error)> epsilon) { integral =integral+ error*dt; } derivative= (error -pre_error)/dt; output=Kp*error+ Ki*integral+ Kd*derivative; //Saturation Filter if(output> MAX) { output= MAX; } elseif(output< MIN) { output= MIN; } //Update error pre_error= error; return output; } #endif /*PID_H_*/ afterthatembed PID Code:- >>>> functionoutput =fcn(error) %Declarestatic value persistentpre_error;
if isempty(pre_error) pre_error= 0; end persistentintegral; if isempty(integral) integral=0; end %Constant Value epsilon = 0.01; dt = 0.01; Kp = 5; Kd = 3; Ki = 0.01; if(abs(error)> epsilon) integral=integral +error*dt; end derivative=(error -pre_error)/dt; output =Kp*error + Ki*integral +Kd*derivative; pre_error = error;
