Skip to content

Commit 3f23eb4

Browse files
committed
stm32代码和参考文档
1 parent 562bb60 commit 3f23eb4

13 files changed

+83
-459
lines changed

ai/day06_auto_drive/01_自动驾驶.ipynb

Lines changed: 7 additions & 454 deletions
Large diffs are not rendered by default.

ai/day07_auto_drive/02_自动驾驶上路.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
"name": "python",
178178
"nbconvert_exporter": "python",
179179
"pygments_lexer": "ipython3",
180-
"version": "3.7.9"
180+
"version": "3.7.4"
181181
}
182182
},
183183
"nbformat": 4,

ai/day07_auto_drive/03_仿真测试部署.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
"name": "python",
304304
"nbconvert_exporter": "python",
305305
"pygments_lexer": "ipython3",
306-
"version": "3.7.9"
306+
"version": "3.7.4"
307307
}
308308
},
309309
"nbformat": 4,

ai/day07_auto_drive/04_方向盘控制.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"name": "python",
7373
"nbconvert_exporter": "python",
7474
"pygments_lexer": "ipython3",
75-
"version": "3.7.9"
75+
"version": "3.7.4"
7676
}
7777
},
7878
"nbformat": 4,

ai/day08_auto_drive/03_数据增强.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@
10521052
"name": "python",
10531053
"nbconvert_exporter": "python",
10541054
"pygments_lexer": "ipython3",
1055-
"version": "3.7.9"
1055+
"version": "3.7.4"
10561056
}
10571057
},
10581058
"nbformat": 4,

ai/day08_auto_drive/04_带数据增强的完整流程.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@
649649
"name": "python",
650650
"nbconvert_exporter": "python",
651651
"pygments_lexer": "ipython3",
652-
"version": "3.7.9"
652+
"version": "3.7.4"
653653
}
654654
},
655655
"nbformat": 4,

stm32全套开发环境/code.zip

2.78 MB
Binary file not shown.
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Created by Kaijun on 2020/9/11.
3+
//
4+
#include "PID.h"
5+
#include <cstdio>
6+
7+
PID::PID(float kp, float ki, float kd) {
8+
this->kp = kp;
9+
this->ki = ki;
10+
this->kd = kd;
11+
}
12+
13+
float PID::compute(float target, float current) {
14+
// 计算误差
15+
float error = target - current;
16+
// 误差的累计
17+
intergral +=error;
18+
// 本次误差和上一次误差的差异
19+
derivative = error - prevError;
20+
21+
// 套用pid的公式
22+
pwm += kp*error + ki*intergral + kd*derivative;
23+
// 记录上一次的误差
24+
prevError = error;
25+
26+
return pwm;
27+
}
28+
29+
void PID::reset(){
30+
pwm = 0;
31+
intergral = 0;
32+
derivative = 0;
33+
prevError = 0;
34+
}

stm32全套开发环境/资料/PID.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Created by Kaijun on 2020/9/11.
3+
//
4+
5+
#ifndef HEIMAROBOTV4_PID_H
6+
#define HEIMAROBOTV4_PID_H
7+
8+
9+
class PID {
10+
public:
11+
PID(float kp,float ki,float kd);
12+
float kp;
13+
float ki;
14+
float kd;
15+
16+
float pwm;
17+
// 上一次的误差
18+
float prevError;
19+
// 积分
20+
float intergral;
21+
// 微分
22+
float derivative;
23+
/**
24+
* pid的计算函数
25+
* @param target 目标值
26+
* @param current 当前值
27+
* @return pwm
28+
*/
29+
float compute(float target,float current);
30+
/**
31+
* 重置所有的误差: 当设置的速度 和 上一次不一样
32+
*/
33+
void reset();
34+
};
35+
36+
37+
#endif //HEIMAROBOTV4_PID_H

0 commit comments

Comments
 (0)