Create a gist now

Instantly share code, notes, and snippets.

RC回路のP制御
/*
Vi(t) = RC*Vo(t)' + Vo(t)
*/
#include<stdio.h>
#include<stdlib.h>
#define GAIN_P 1.0 //比例ゲイン
#define R 1.0
#define C 1.0
#define INT_TIME 0.1
double P,dTime;
double FD( double dCommand, double dVal );
int main(void){
double dV,FDback;
double dQ,dI,dVo;
int j;
printf("feed---Vi(t)=RCVo(t)'+Vo(t)---\n");
//初期値
dVo=0;//コンデンサーの電位差
dQ=0;//コンデンサーの電気量
dTime=0;//時刻
for(j=0;j<500;j++){
//コントーラー
FDback = FD(1,dVo);
//抵抗の電位差
dV = FDback - dVo;
//電流
dI = dV/R;
//電気量
dQ = dQ + dI*INT_TIME;
//コンデンサーの電位差
dVo = dQ/C;
//時刻
dTime = dTime + INT_TIME;
printf("TIME=%.1f\tVo=%f\tP=%f\n",dTime,dVo,P);
}
return 0;
}
double FD( double dCommand, double dVal ){
double dErr;
double dRet;
//誤差
dErr = dCommand - dVal;
P = GAIN_P*dErr;
dRet = P;
return dRet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment