1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
float PFC(int,int,int,float,float,float,float *);
int main(void)
{
float sortie_precedente[200];//buffer= r*tech
float SP=100;
int tech=1;
int trbf=45;
int i=0;//variable de gestion de tableau
//Simulation processus
int t=0;//variable simulation temps
//process
int taup=35;
float ap=exp(-tech/taup);
float bp=1-ap;
float Kp=1.7;
int r=200;
float PV[1500];
float MV[1500];
//initialisation tableau de sortie_modele sortie_precedente
for (i=0;i<200;i++)
{
sortie_precedente[i]=0;
}
//initialisation PV
for (i=0;i<200;i++)
{
PV[i]=0;
}
//initialisation MV
for (i=0;i<200;i++)
{
MV[i]=0;
}
//Simulation regulation processus
for(t=(2+r);t<=1500;t++)
{
PV[t]=ap*PV[t-1]+bp*(Kp*MV[t-1-r]); // process
MV[t]=PFC(tech,trbf,r,PV[t],SP,MV[t-1],sortie_precedente);
}
//Affichage de quelques valeurs pour comparer avec simulation scilab
for(i=0;i<1500;i+=100)
{
printf("PV[%d] = %f \n",i,PV[i]);
}
return 0;
}
float PFC(int tech,int trbf,int retard,float PV,float SP,float MV_1,float *sortie_precedente)
{
//initialisation variables
int i=0;//Variable de gestion du tableau
int temps=0;
float d,MV,sm,spred=0;
float taum=30.0;
float km=1.0;
float sm_r=0;
//Paramètres du modèle
float am=exp(-tech/taum);
float bm=1-am;
float lh=1-exp(-tech*3/trbf);
//sortie modèle
sm=am*sortie_precedente[0]+MV_1*bm*km;
// prediction
spred=PV+(sm-sortie_precedente[retard-1])*1;
//Calcul de la MV
d=(SP-spred)*lh+sm*bm;
MV=d/(km*bm);
//Mise a jour du buffer sortie_precedente
for(i=199;i>0;i--)
{
sortie_precedente[i]=sortie_precedente[i-1];
}
sortie_precedente[0]=sm;
//Contraintes liés à la vitesse réelle de l'actionneur
if (MV>(MV_1+4))
{
MV=MV_1+4;
}
if (MV<(MV_1-4))
{
MV=MV_1-4;
}
return MV;
} |
Partager