资源简介
PID autoTune PID 自整定算法C代码,开源的andonid
代码片段和文件信息
#if ARDUINO >= 100
#include “Arduino.h“
#else
#include “WProgram.h“
#endif
#include
PID_ATune::PID_ATune(double* Input double* Output)
{
input = Input;
output = Output;
controlType =0 ; //default to PI
noiseBand = 0.5;
running = false;
oStep = 30;
SetLookbackSec(10);
lastTime = millis();
}
void PID_ATune::Cancel()
{
running = false;
}
int PID_ATune::Runtime()
{
justevaled=false;
if(peakCount>9 && running)
{
running = false;
FinishUp();
return 1;
}
unsigned long now = millis();
if((now-lastTime) lastTime = now;
double refVal = *input;
justevaled=true;
if(!running)
{ //initialize working variables the first time around
peakType = 0;
peakCount=0;
justchanged=false;
absMax=refVal;
absMin=refVal;
setpoint = refVal;
running = true;
outputStart = *output;
*output = outputStart+oStep;
}
else
{
if(refVal>absMax)absMax=refVal;
if(refVal }
//oscillate the output base on the input‘s relation to the setpoint
if(refVal>setpoint+noiseBand) *output = outputStart-oStep;
else if (refVal
//bool isMax=true isMin=true;
isMax=true;isMin=true;
//id peaks
for(int i=nLookBack-1;i>=0;i--)
{
double val = lastInputs[i];
if(isMax) isMax = refVal>val;
if(isMin) isMin = refVal lastInputs[i+1] = lastInputs[i];
}
lastInputs[0] = refVal;
if(nLookBack<9)
{ //we don‘t want to trust the maxes or mins until the inputs array has been filled
return 0;
}
if(isMax)
{
if(peakType==0)peakType=1;
if(peakType==-1)
{
peakType = 1;
justchanged=true;
peak2 = peak1;
}
peak1 = now;
peaks[peakCount] = refVal;
}
else if(isMin)
{
if(peakType==0)peakType=-1;
if(peakType==1)
{
peakType=-1;
peakCount++;
justchanged=true;
}
if(peakCount<10)peaks[peakCount] = refVal;
}
if(justchanged && peakCount>2)
{ //we‘ve transitioned. check if we can autotune based on the last peaks
double avgSeparation = (abs(peaks[peakCount-1]-peaks[peakCount-2])+abs(peaks[peakCount-2]-peaks[peakCount-3]))/2;
if( avgSeparation < 0.05*(absMax-absMin))
{
FinishUp();
running = false;
return 1;
}
}
justchanged=false;
return 0;
}
void PID_ATune::FinishUp()
{
*output = outputStart;
//we can generate tuning parameters!
Ku = 4*(2*oStep)/((absMax-absMin)*3.14159);
Pu = (double)(peak1-peak2) / 1000;
}
double PID_ATune::GetKp()
{
return controlType==1 ? 0.6 * Ku : 0.4 * Ku;
}
double PID_ATune::GetKi()
{
return controlType==1? 1.2*Ku / Pu : 0.48 * Ku / Pu; // Ki = Kc/Ti
}
double PID_ATune::GetKd()
{
return controlType==1? 0.075 * Ku * Pu : 0; //Kd = Kc * Td
}
void PID_ATune::SetOutputS
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3673 2016-10-19 18:31 PID_AutoTune_v0.cpp
文件 1735 2016-10-19 18:32 PID_AutoTune_v0.h
----------- --------- ---------- ----- ----
5408 2
相关资源
- RapidIO 2.2 Specification
- RapidIO_Rev_2.2_Specification
- 基于DSP的大功率开关电源的设计方案
- 基于DSP的大功率开关电源设计
- BLDC电机PID算法
- 基于双闭环模糊PID控制器的开关电源
- pid 模拟测试软件
- 基于RBF神经网络在线辨识的永磁同步
-
Lipase-catalyzed synthesis and the lipid me
- 中微子双β衰变的CUPID-Mo实验:性能
- 智能车模糊控制
- LabVIEW实现Fuzzy_PID的补充资源
- 四轴飞控源码 PID参考apm 采用了dmp自带
- 平衡小车之家全套资料
- 基于ARM的高精度PID温度控制器_张军
- 基于STM32F07单片机风洞程序
- 基于51单片机的直流电机PID控制
- 基于STM32的智能服务型多功能多足机器
- 基于STM32PID电机控制
- STM32直流有刷电机PID控制
- STM32F407. 基于PID速度环的步进电机速度
- 基于stm32F103的两轮自平衡小车
- 模糊PID算法控制
- 倒立摆调试,使用步进电机,完全成
- STM32F103 模糊自整定位置式PID控制电机
- 基于模糊控制与神经网络的智能PID温
- USB的驱动vid—1f3a—pid—efe8驱动
- 西门子博途编的PID温度模拟量控制
- 基于PID控制方式的4A开关电源-multisi
- 无人机飞行PID控制及智能PID控制技术
评论
共有 条评论