首页 > 精品范文库 > 5号文库
计算机控制——PID编程实现
编辑:雨雪飘飘 识别码:14-257986 5号文库 发布时间: 2023-03-30 20:22:28 来源:网络

实验一

DDC单回路PID控制实验指导书

实验目的通过实验掌握DDC单回路PID控制程序编制及调试方法。

实验内容

1.控制系统如图所示,G(S)=

K1

/

(1+T1S)2

D(Z)采用数字PID控制规律,T为采样周期。

2.对象动态特性实验

(1)

将G(S)离散化,写出输入/输出差分方程。

(不必考虑零阶保持器)

(2)

用C语言编制程序。

(3)

取三个不同采样周期,绘制当输入U1为阶跃给定值时,输出的响应曲线,并打印。

3.单回路PID控制实验

(1)

根据上述动态特性曲线,采用工程整定方法整定PID参数。

(2)

采用具有积分分离的数字PID算法,并进行以下三个实验:

a.无积分分离或阀值β过大;

b.β适中

c.β过小

(3)用C或C++语言编制程序。

(4)

按以上3种情况,绘制当r(t)=1时,y(t)和u(t)的阶跃响应曲线,并打印。

(5)

分别改变Kp,Ti,Td,并观察它们对调节品质的影响。

实验步骤

1.对象动态特性实验

(1)差分方程见附录:

(2)编制程序如下:

#include“iostream.h“

#include“fstream.h“

void

main()

{

fstream

outfile(“data1.xls“,ios::out);

int

i,j;

int

t;

for(j=0;j<3;j++)

{

cout<<“输入采样周期:“;

cin>>t;

double

u[100];

double

y[100];

for(i=0;i<100;i++)

{

u[i]=1.0;

y[i]=0.0;

}

for(i=2;(i-2)*t<100;i++)

{

y[i]=u[i]/(1.0+100.0/t/t+20.0/t)-(100.0/t/t)*y[i-2]/(1.0+100.0/t/t+20.0/t)+(200.0/t/t+20.0/t)*y[i-1]/(1.0+100.0/t/t+20.0/t);

}

for(i=1;(i-1)*t<100;i++)

cout<

for(i=2;(i-2)*t<100;i++)

{

outfile<<(i-2)*t<<'\t';

}

outfile<<'\n';

for(i=1;(i-1)*t<100;i++)

{

outfile<

}

outfile<<'\n';

}

outfile.close();

}

(3)输出结果如下:

周期T=1:

0

0.00826446

0.0232908

0.0437812

0.068618

0.0968417

0.127631

0.160287

0.194215

0.228913

0.263963

0.299012

0.333772

0.368005

0.40152

0.434164

0.465819

0.496395

0.525827

0.554069

0.581095

0.606893

0.631462

0.654813

0.676964

0.69794

0.717773

0.736495

0.754146

0.770766

0.786395

0.801078

0.814856

0.827773

0.839872

0.851194

0.861781

0.871673

0.880908

0.889525

0.89756

0.905047

0.912019

0.918508

0.924544

0.930157

0.935372

0.940217

0.944715

0.948889

0.952761

0.956351

0.959679

0.962763

0.965619

0.968264

0.970712

0.972977

0.975072

0.97701

0.978802

0.980457

0.981987

0.9834

0.984705

0.98591

0.987023

0.988049

0.988996

0.98987

0.990676

0.991419

0.992104

0.992735

0.993317

0.993853

0.994347

0.994802

0.995221

0.995606

0.995961

0.996288

0.996589

0.996866

0.99712

0.997355

0.99757

0.997768

0.99795

0.998118

0.998272

0.998413

0.998543

0.998663

0.998773

0.998874

0.998967

0.999052

0.99913

0.990937

周期T=2:

0

0.0277778

0.0740741

0.131944

0.196245

0.263224

0.330204

0.395323

0.457341

0.515483

0.569318

0.618667

0.66353

0.704031

0.740378

0.772831

0.801678

0.827219

0.849756

0.86958

0.886969

0.902185

0.915468

0.927041

0.937104

0.94584

0.953411

0.959962

0.965624

0.970511

0.974724

0.978351

0.981472

0.984154

0.986456

0.988431

0.990124

0.991574

0.992815

0.993877

0.994784

0.995559

0.99622

0.996784

0.997266

0.997676

0.998025

0.998323

0.998576

0.998791

周期T=3:

0

0.0532544

0.135184

0.229719

0.326677

0.419907

0.505964

0.583196

0.651091

0.709847

0.760066

0.802559

0.838217

0.867932

0.892549

0.912837

0.929483

0.943089

0.95417

0.963168

0.970453

0.976338

0.98108

0.984893

0.987954

0.990407

0.992369

0.993937

0.995187

0.996183

0.996976

0.997606

0.998106

0.998503

阶跃曲线图如下:

周期T分别1,2,3。

2.单回路PID控制实验

(1)工程整定程序如下:

#include“iostream.h“

void

main()

{

int

i,k;

double

t,k1;

double

m,n,x,l,c,p,f,d;

double

j=0;

cout<<“输入采样周期:“;

cin>>t;

double

u[100];

double

e[100];

double

y[100];

for(i=0;i<100;i++)

{

u[i]=1.0;

y[i]=0.0;

}

for(i=2;i<100;i++)

{

y[i]=u[i]/(1.0+100.0/t/t+20.0/t)-(100.0/t/t)*y[i-2]/(1.0+100.0/t/t+20.0/t)+(200.0/t/t+20.0/t)*y[i-1]/(1.0+100.0/t/t+20.0/t);

}

for(i=1;i<100;i++)

{

if(j<=(y[i+1]-y[i]))

{

j=y[i+1]-y[i];

k=i;

k1=(k-1)*t;

}

}

m=(y[k]+y[k+1])/2.0;

n=(2.0*k1+t)/2.0;

x=(y[k+1]-y[k])/t;

l=n-m/x;

c=(1.0-m)/x+n-l;

cout<<“最大值k1的取值及对应的输出值:“<

cout<<“斜率“<

cout<<“延迟为“<<(l+t/2.0)<<'\n'<<“时间常数为“<

cout<<“延迟/时间常数为“<<((l+t/2.0)/c)<

if(((l+t/2.0)/c)>=0.2)

{

p=0.38*(((l+t/2.0)/c)+0.88)/(((l+t/2.0)/c)-0.15);

f=0.81*c+0.19*(l+t/2.0);

d=0.25*c;

}

else

{

p=1.2*c/(l+t/2.0);

f=2*(l+t/2.0);

d=0.5*(l+t/2.0);

}

cout<<“整定参数为:“<

cout<<“Kp=“<

cout<<“Ti=“<

cout<<“Td=“<

}

(2)输出结果:

Kp=11.5323

Ti=5.93767

Td=1.48442

注:以上整定的参数是在采样周期T=1时候的结果,为简化处理,采用该参数作为PID调节器的参数。

3.具有积分分离的控制系统

(1)差分方程见附录:

(2)编制程序如下:

#include“iostream.h“

#include“math.h“

#include“fstream.h“

void

main()

{

fstream

outfile(“data1.xls“,ios::out);

int

i,k,i1;

double

t,k1;

double

m,n,x,l,c,p,f,d;

double

sx,aa,bb,cc,dd1,dd2,ee,ff;

double

j=0.0;

cout<<“输入采样周期:“;

cin>>t;

double

u[100];

double

e[100];

double

y[100];

double

u1[100];

double

y1[100];

double

r[100];

for(i=0;i<100;i++)

{

u[i]=1.0;

y[i]=0.0;

}

for(i=2;i<100;i++)

{

y[i]=u[i]/(1.0+100.0/t/t+20.0/t)-(100.0/t/t)*y[i-2]/(1.0+100.0/t/t+20.0/t)+(200.0/t/t+20.0/t)*y[i-1]/(1.0+100.0/t/t+20.0/t);

}

for(i=1;i<100;i++)

{

if(j<=(y[i+1]-y[i]))

{

j=y[i+1]-y[i];

k=i;

k1=(k-1)*t;

}

}

m=(y[k]+y[k+1])/2.0;

n=(2.0*k1+t)/2.0;

x=(y[k+1]-y[k])/t;

l=n-m/x;

c=(1.0-m)/x+n-l;

cout<<“最大值k1的取值及对应的输出值:“<

cout<<“斜率“<

cout<<“延迟为“<<(l+t/2.0)<<'\n'<<“时间常数为“<

cout<<“延迟/时间常数为“<<((l+t/2.0)/c)<

if(((l+t/2.0)/c)>=0.2)

{

p=0.38*(((l+t/2.0)/c)+0.88)/(((l+t/2.0)/c)-0.15);

f=0.81*c+0.19*(l+t/2.0);

d=0.25*c;

}

else

{

p=1.2*c/(l+t/2.0);

f=2*(l+t/2.0);

d=0.5*(l+t/2.0);

}

cout<<“整定参数为:“<

cout<<“Kp=“<

cout<<“Ti=“<

cout<<“Td=“<

//以上为PID整定程序。

//以下为给定值阶跃程序。

aa=(1.0+10.0/t)*(1.0+10.0/t);

bb=20.0*(1.0+10.0/t)/t;

cc=100.0/t/t;

dd1=(1.0+t/f+d/t);

dd2=(1.0+d/t);

ee=(1.0+2.0*d/t);

ff=d/t;

cout<<“相关参数:“;

cout<

for(i1=0;i1<3;i1++)

{

cout<<“输入积分限:“;

cin>>sx;

for(i=0;i<100;i++)

{

r[i]=1.0;

e[i]=0.0;

u1[i]=0.0;

y1[i]=0.0;

}

u1[1]=p*aa*dd1*r[1]/(aa+p*dd1);

y1[1]=0.0;

e[1]=1.0;

if(sx

{

u1[2]=u1[1]*(aa+bb+p*ee)/(aa+p*dd2)+p/(aa+p*dd2)*(aa*dd2*r[2]-(bb*dd2+aa*ee)*r[1]);

}

else

{

u1[2]=u1[1]*(aa+bb+p*ee)/(aa+p*dd1)+p/(aa+p*dd1)*(aa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20.0/t);

e[i]=r[i]-y1[i];

}

cout<<“U1的曲线为“<

for(i=1;i<100;i++)

{

cout<

}

cout<<“Y1的曲线为“<

for(i=1;i<100;i++)

{

cout<

}

for(i=1;i<99;i++)

{

outfile<<(i-1)*t<<'\t';

}

outfile<

for(i=1;i<99;i++)

{

outfile<

}

outfile<

for(i=1;i<99;i++)

{

outfile<

}

outfile<

}

outfile.close();

}

(3)输出结果如下:

积分限较小时:

U(t)的阶跃数据:

24.4192

7.15003

7.78128

8.88198

10.2042

11.4284

12.4845

13.34

13.9896

14.4474

14.7386

14.8941

14.9459

14.9241

14.8549

14.7598

14.6554

14.5536

14.4619

14.3848

14.3238

14.2786

14.2479

14.2294

14.2206

14.219

14.053

13.6271

12.9086

11.9133

10.6904

9.3101

7.85126

6.39212

5.00304

3.7415

2.64943

1.7523

1.05978

0.567597

0.260096

0.113266

0.0978047

0.182037

0.334471

0.525867

0.730763

0.928452

1.10343

1.24538

1.34887

1.41261

1.43878

1.43203

1.39868

1.34586

1.28081

1.2103

1.14023

1.07534

1.01911

0.973701

0.940112

0.918292

0.907367

0.905858

0.911911

0.923503

0.938622

0.95541

0.972268

0.987918

1.00143

1.01223

1.02004

1.02489

1.02699

1.02674

1.02462

1.02115

1.01686

1.01221

1.00761

1.00339

0.999785

0.996925

0.994871

0.99361

0.993076

0.99316

0.993731

0.994651

0.99578

0.996993

0.998186

0.999273

1.0002

1.00092

Y(t)的阶跃数据:

0

0.0590912

0.0793344

0.108921

0.144686

0.183027

0.222545

0.26227

0.301567

0.340049

0.377505

0.413839

0.449027

0.48308

0.516023

0.547882

0.578674

0.608408

0.637082

0.664687

0.691209

0.716634

0.740949

0.764147

0.786225

0.807189

0.825649

0.840851

0.852565

0.860958

0.866481

0.869756

0.871478

0.872336

0.872954

0.873851

0.875412

0.87789

0.881402

0.885952

0.891445

0.897718

0.904563

0.911748

0.919044

0.926238

0.933147

0.939625

0.945569

0.950917

0.955644

0.959761

0.963306

0.966333

0.968914

0.971122

0.973033

0.974715

0.976231

0.977633

0.978959

0.98024

0.981492

0.982725

0.98394

0.985132

0.986295

0.987417

0.988489

0.989502

0.990447

0.991319

0.992116

0.992836

0.993483

0.994059

0.99457

0.995023

0.995424

0.995781

0.996101

0.996389

0.996652

0.996894

0.997119

0.997329

0.997528

0.997715

0.997893

0.998061

0.99822

0.998369

0.998509

0.998638

0.998758

0.998868

0.998968

0.999059

积分限适中时:

U(t)阶跃数据:

24.4192

7.15003

7.78128

8.88198

10.2042

11.4284

12.4845

13.34

13.9896

14.4474

14.7386

14.8941

14.7672

14.2898

13.4565

12.3083

10.9172

9.3717

7.76455

6.18356

4.70436

3.3861

2.26929

1.37576

0.710003

0.261792

0.00934006

-0.0771805

-0.0321806

0.108506

0.310302

0.541977

0.777111

0.99493

1.18059

1.32501

1.42425

1.47879

1.4925

1.47165

1.42396

1.35768

1.28088

1.20089

1.12384

1.05451

0.996192

0.950756

0.918787

0.899794

0.892458

0.894891

0.904882

0.920123

0.938395

0.957713

0.976416

0.993231

1.00728

1.01807

1.02545

1.02955

1.03072

1.02944

1.0263

1.02189

1.01679

1.0115

1.00644

1.00194

0.998209

0.995367

0.993441

0.992388

0.992108

0.992467

0.993308

0.994474

0.995813

0.997192

0.998502

0.999661

1.00061

1.00133

1.00181

1.00206

1.00211

1.00199

1.00175

1.00144

1.00108

1.00071

1.00037

1.00007

0.99982

0.999636

0.999516

0.999455

Y(t)阶跃数据:

0

0.0590912

0.0793344

0.108921

0.144686

0.183027

0.222545

0.26227

0.301567

0.340049

0.377505

0.413839

0.44755

0.477838

0.504466

0.527621

0.54778

0.565583

0.581732

0.596908

0.61171

0.626613

0.641952

0.657918

0.674567

0.691839

0.709585

0.727593

0.745616

0.763398

0.780695

0.797292

0.813014

0.827731

0.841364

0.85388

0.865287

0.87563

0.884979

0.893423

0.901064

0.908003

0.91434

0.920168

0.925568

0.930607

0.935341

0.93981

0.944043

0.948061

0.951872

0.955483

0.958893

0.962103

0.96511

0.967914

0.970517

0.972921

0.975133

0.977159

0.979012

0.980701

0.982241

0.983644

0.984923

0.986091

0.987162

0.988144

0.98905

0.989886

0.990661

0.991381

0.99205

0.992672

0.993252

0.993791

0.994292

0.994756

0.995186

0.995583

0.995949

0.996285

0.996594

0.996877

0.997135

0.997372

0.997587

0.997785

0.997965

0.99813

0.998281

0.998419

0.998547

0.998664

0.998771

0.998871

0.998963

0.999047

积分限较大时:

U(t)阶跃数据:

24.4192

5.79003

4.22453

2.73086

1.40502

0.311285

-0.516072

-1.06929

-1.36234

-1.42551

-1.29994

-1.03238

-0.670674

-0.259986

0.15994

0.556627

0.905789

1.19147

1.40554

1.54674

1.61938

1.63192

1.59553

1.5227

1.42609

1.31756

1.20746

1.10418

1.01393

0.940705

0.886467

0.851387

0.834199

0.832578

0.843526

0.863724

0.889843

0.918784

0.947864

0.974927

0.998397

1.01728

1.0311

1.03988

1.04397

1.04402

1.04084

1.0353

1.02829

1.02061

1.01296

1.00589

0.999811

0.994962

0.991453

0.989273

0.988315

0.988405

0.989325

0.990843

0.992727

0.994765

0.996779

0.998624

1.0002

1.00145

1.00234

1.00288

1.0031

1.00305

1.00279

1.00237

1.00187

1.00133

1.0008

1.00032

0.999907

0.999588

0.999363

0.999229

0.999179

0.999199

0.999273

0.999386

0.999521

0.999665

0.999804

0.999929

1.00003

1.00012

1.00017

1.00021

1.00022

1.00021

1.00019

1.00016

1.00012

1.00008

Y(t)阶跃数据:

0

0.0478515

0.0499398

0.0580858

0.0719652

0.0911499

0.115102

0.143185

0.174691

0.208868

0.244955

0.282216

0.319965

0.357592

0.394577

0.4305

0.465041

0.497978

0.529178

0.558588

0.586214

0.612115

0.636384

0.659133

0.680485

0.700565

0.719487

0.737356

0.754261

0.770276

0.785457

0.79985

0.813486

0.826389

0.838578

0.850068

0.86087

0.871001

0.880477

0.889318

0.897547

0.905189

0.912276

0.918837

0.924908

0.930521

0.93571

0.940509

0.944948

0.949059

0.952868

0.9564

0.959678

0.962721

0.965549

0.968175

0.970615

0.972881

0.974984

0.976934

0.978741

0.980414

0.98196

0.983389

0.984707

0.985922

0.987042

0.988073

0.989022

0.989895

0.990699

0.991439

0.992119

0.992746

0.993324

0.993856

0.994346

0.994798

0.995215

0.9956

0.995955

0.996282

0.996583

0.996861

0.997116

0.997352

0.997568

0.997768

0.997951

0.998119

0.998273

0.998415

0.998545

0.998665

0.998774

0.998875

0.998968

0.999052

实验分析

1.经过离散化后的系统稳定性不如之前优越,若周期选取适当可以保证系统的稳定性;

2.采样周期T越小,越接近系统的真实工作情况,控制精度越高。同时从数据看出,T越大,输出的阶跃曲线上升的越快;

3.经过工程整定后的PID参数具有较好的控制效果;

4.选取的采样周期不一样,整定的PID参数也不一样;

5.积分限选取的较小,会出现稳态偏差。积分限选取过大会出现超调。当积分限选取适中时,可以达到理想的控制要求。

6.

计算机控制——PID编程实现
TOP