資源簡介
使用STM32單片機控制,運用PID算法通過串口達到預(yù)定目標值
使用串口2,上位機COM口需要根據(jù)實際情況選擇
代碼片段和文件信息
#include?“pid.h“
#include?“stdio.h“
#include?“stdlib.h“?
struct?_pid
{
float?SetSpeed;?
float?ActualSpeed;?
float?err;?
float?err_last;?
float?err_next;
float?Kp?Ki?Kd;?
float?voltage;?
float?integral;
}pid;
void?PID_init()
{
pid.SetSpeed?=?0.0;
pid.ActualSpeed?=?0.0;
pid.err?=?0.0;
pid.err_last?=?0.0;
pid.err_next?=?0.0;
pid.Kp?=?0.52;
pid.Ki?=?0.04;
pid.Kd?=?0.12;
}
float?PID_realize(float?speed)?
{
int?index?=?0;
pid.SetSpeed?=?speed;
pid.err?=?pid.SetSpeed?-?pid.ActualSpeed;
if?(abs(pid.err)?>?180)
{
index?=?0;
}
else?
{
index?=?1;
pid.integral?=?pid.err?+?pid.integral;
}
pid.voltage?=?pid.Kp*pid.err?+?index?*?pid.Ki*pid.integral?+?pid.Kd*(pid.err?-?pid.err_last);
pid.ActualSpeed?=?pid.vol
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-05-14?12:00??試驗1:積分分離型PID\
?????目錄???????????0??2019-05-14?15:00??試驗1:積分分離型PID\BSP\
?????文件?????????922??2019-05-14?15:00??試驗1:積分分離型PID\BSP\pid.c
?????文件?????????428??2019-05-11?15:06??試驗1:積分分離型PID\BSP\pid.h
?????目錄???????????0??2019-05-14?12:00??試驗1:積分分離型PID\CORE\
?????文件???????17273??2010-06-07?10:25??試驗1:積分分離型PID\CORE\core_cm3.c
?????文件???????85714??2011-02-09?14:59??試驗1:積分分離型PID\CORE\core_cm3.h
?????文件???????15503??2011-03-10?10:52??試驗1:積分分離型PID\CORE\startup_stm32f10x_hd.s
?????目錄???????????0??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\
?????文件??????308180??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART.axf
?????文件????????1444??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART.build_log.htm
?????文件???????30328??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART.hex
?????文件???????72148??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART.htm
?????文件?????????517??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART.lnp
?????文件?????????479??2018-10-27?19:24??試驗1:積分分離型PID\OBJ\USART.sct
?????文件???????22448??2019-05-14?15:00??試驗1:積分分離型PID\OBJ\USART_USART.dep
?????文件????????3939??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\core_cm3.crf
?????文件?????????101??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\core_cm3.d
?????文件???????11236??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\core_cm3.o
?????文件??????349952??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\delay.crf
?????文件????????1666??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\delay.d
?????文件??????383896??2019-05-14?12:32??試驗1:積分分離型PID\OBJ\delay.o
?????文件??????350472??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\key.crf
?????文件????????1637??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\key.d
?????文件??????385528??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\key.o
?????文件??????349499??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\led.crf
?????文件????????1598??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\led.d
?????文件??????383480??2019-04-28?17:27??試驗1:積分分離型PID\OBJ\led.o
?????文件??????354825??2019-05-14?14:46??試驗1:積分分離型PID\OBJ\main.crf
?????文件????????1766??2019-05-14?14:46??試驗1:積分分離型PID\OBJ\main.d
?????文件??????390104??2019-05-14?14:46??試驗1:積分分離型PID\OBJ\main.o
............此處省略105個文件信息
評論
共有 條評論