MF32BSP_XerolySkinner 2.0.0
C++版本的驱动库
载入中...
搜索中...
未找到
bsp_PID.cpp
浏览该文件的文档.
1/*----------------------------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2022 Yuankang Liang(XerolySkinner)
4 #
5 # 本软件按原样提供,无任何明示或暗示
6 # 在任何情况下,作者都不承担任何损害赔偿责任
7 #
8 # 使用的许可声明:
9 # 1. 不得歪曲本软件的来源,你不能声称你编写了原始软件.
10 # 2. 免费授予以任何目的,前提是版权声明出现在所有副本中.
11 # 并且版权声明和许可声明同时出现.
12 # 3. 你有使用,复制,修改,分发,和销售本软件的许可.
13 # 4. 如果你在产品中使用,产品文档中的声明是赞赏的但不是必须的.
14 # 5. 本通知不得从任何来源删除或更改.
15 #
16 # Yuankang Liang(XerolySkinner)
17 # E-mail:zabbcccbbaz@163.com
18 # QQ:2715099320
19 # Mobile Phone:13005636215
20 #
21 # All rights reserved.
22 */
23
35//----------------------------------------------------------------------------------------------------
36// 头文件
37//
38#include "bsp_PID.h"
40//----------------------------------------------------------------------------------------------------
41// 类函数
42//
48float bsp_Position_PID::PID(float temp) {
49 float thisError;
50 thisError = target - temp; //当前误差等于设定值减去当前值
51 integral += thisError; //误差积分,把所有误差累加起来
52 result =
53 Kp * thisError +
54 Ki * integral +
55 Kd * (thisError - lasterror);
56 lasterror = thisError;
57
58 if (result_H == result_L)return result;
60 else if (result <= result_L)result == result_L;
61 return result;
62}
63//----------------------------------------------------------------------------------------------------
69float bsp_Increment_PID::PID(float temp) {
70 float thisError=target - temp; //当前误差等于设定值减去当前值
71 float increment;
72 float pError, dError, iError;
73
74 pError = thisError - lasterror;
75 iError = thisError;
76 dError = thisError - 2 * lasterror + preerror;
77
78 increment =
79 Kp * pError +
80 Ki * iError +
81 Kd * dError; //增量计算
82 preerror = lasterror; //存放偏差用于下次运算
83 lasterror = thisError; //存放偏差用于下次运算
84 result += increment; //上次结果叠加增量
85
86 if (result_H == result_L)return result;
88 else if (result <= result_L)result == result_L;
89 return result;}
90//----------------------------------------------------------------------------------------------------
91//----------------------------------------------------------------------------------------------------
97 integral = 0; //积分值
98 lasterror = 0; //前一拍偏差
99 result = 0; //输出值
100 }
101//----------------------------------------------------------------------------------------------------
107 lasterror = 0; //前一拍偏差
108 preerror = 0; //前两拍偏差
109 result = 0; //输出值
110 }
111//----------------------------------------------------------------------------------------------------
112//----------------------------------------------------------------------------------------------------
119void bsp_Position_PID::set(float P, float I, float D) {
120 Kp = P; Ki = I; Kd = D;}
121//----------------------------------------------------------------------------------------------------
128void bsp_Increment_PID::set(float P, float I, float D) {
129 Kp = P; Ki = I; Kd = D;}
131//----------------------------------------------------------------------------------------------------
132// 构造函数
133//
144}
145//----------------------------------------------------------------------------------------------------
156 float Kp, float Ki, float Kd, float target,
157 float result_H, float result_L) {
167}
168//----------------------------------------------------------------------------------------------------
170//----------------------------------------------------------------------------------------------------
181}
182//----------------------------------------------------------------------------------------------------
193 float Kp, float Ki, float Kd, float target,
194 float result_H, float result_L) {
204}
205//----------------------------------------------------------------------------------------------------
实现了PID算法
float result_L
输出最低值
Definition: bsp_PID.h:95
bsp_Increment_PID(void)
Definition: bsp_PID.cpp:171
float Ki
微分系数
Definition: bsp_PID.h:88
~bsp_Increment_PID(void)
Definition: bsp_PID.cpp:206
float Kp
比例系数
Definition: bsp_PID.h:86
float target
设定值
Definition: bsp_PID.h:85
float result
输出值
Definition: bsp_PID.h:89
float PID(float temp)
PID算法
Definition: bsp_PID.cpp:69
float preerror
前两拍偏差
Definition: bsp_PID.h:92
float result_H
输出最高值
Definition: bsp_PID.h:94
void clean(void)
清理历史数据
Definition: bsp_PID.cpp:106
float lasterror
前一拍偏差
Definition: bsp_PID.h:91
float Kd
积分系数
Definition: bsp_PID.h:87
void set(float P, float I, float D)
PID参数设置
Definition: bsp_PID.cpp:128
float target
设定值
Definition: bsp_PID.h:55
float lasterror
前一拍偏差
Definition: bsp_PID.h:62
float result_H
输出最高值
Definition: bsp_PID.h:64
float Kd
积分系数
Definition: bsp_PID.h:57
float result_L
输出最低值
Definition: bsp_PID.h:65
float Ki
微分系数
Definition: bsp_PID.h:58
float result
输出值
Definition: bsp_PID.h:59
void clean(void)
清理历史数据
Definition: bsp_PID.cpp:96
~bsp_Position_PID(void)
Definition: bsp_PID.cpp:169
float integral
积分值
Definition: bsp_PID.h:61
float Kp
比例系数
Definition: bsp_PID.h:56
bsp_Position_PID(void)
Definition: bsp_PID.cpp:134
float PID(float temp)
PID算法
Definition: bsp_PID.cpp:48
void set(float P, float I, float D)
PID参数设置
Definition: bsp_PID.cpp:119