点击蓝字 ╳ 关注我们
王维平
OpenHarmony知识体系工作组
简介
硬件配置资源
原理概括
PID算法介绍
两步搭建样例工程
关键算法讲解
float g_middleAngle = 1.0;//平衡角度
float g_kpBalance = -85800.0;
float g_kdBalance = -400;
static int ControlBalance(float angle, short gyro)
{
int outpwm = 0;
float angleBias = 0.0;
float gyroBias = 0.0;
float tempAngle = 0.0;
float tempGyro = 0.0;
tempAngle = 0 - angle;//极性控制
tempGyro = 0 - gyro;
angleBias = g_middleAngle - tempAngle;
gyroBias = 0 - tempGyro;
outpwm = (g_kpBalance / 100 * angleBias + g_kdBalance
* gyroBias / 100);
return outpwm;
}
float g_kpSpeed = 95800.0;
float g_kiSpeed = 200;
static int ControlSpeed(long int left, long int right)
{
int outpwm = 0;
int speedBias = 0;
int speedBiasLowpass = 0;
static int speed_i = 0;
float a = 0.68;
static int speedBiasLast = 0;
speedBias = 0 - left - right;
speedBiasLowpass = (1 - a) * speedBias
+ a * speedBiasLast;
speedBiasLast = speedBiasLowpass;
speed_i += speedBiasLowpass;
speed_i = limit_data(speed_i, SPEED_H, SPEED_L);
outpwm = (g_kpSpeed * speedBiasLowpass / 100 +
gkiSpeed * speed_i / 100);
return outpwm;
}
static int ControlTurn(short gyro)
{
int outpwm;
outpwm = g_kpTurn * gyro;
return outpwm;
}
总结
相关链接
https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md
https://gitee.com/openharmony-sig/vendor_oh_fun
https://gitee.com/bearpi/bearpi-hm_nano/tree/master/applications/BearPi/BearPi-HM_Nano/docs/quick-start
https://gitee.com/openharmony-sig/knowledge/blob/master/docs/co-construct_demos/README_zh.md
https://growing.openharmony.cn/mainPlay/learnPathMaps?id=19
https://gitee.com/openharmony-sig/knowledge_demo_smart_home
原文标题:玩转OpenHarmony PID:教你打造两轮平衡车
文章出处:【微信公众号:OpenAtom OpenHarmony】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !