历史上的今天
今天是:2025年04月06日(星期日)
2020年04月06日 | MSP432E401Y单片机智能小车PID调速代码
2020-04-06 来源:eefocus
* MSP432E401Y
* Description:PID处理函数
* 引脚:
*
* Author: Robin.J
***************************************************************************/
#include #include "ti/devices/msp432e4/driverlib/driverlib.h" float iError_l , iIncpid_l; //当前误差 float iError_r , iIncpid_r; //当前误差 float variable_l; float variable_r; extern int ch_l,ch_r; //extern float ch; //PID初始化 void IncPIDInit(void) { sptr->SetPoint_l = 30.0; sptr->SetPoint_r = 30.0; //设定值 sptr->LastError_l = 0; //前1次误差值 sptr->PrevError_l = 0; //前2次误差值 sptr->LastError_r = 0; //前1次误差值 sptr->PrevError_r = 0; //前2次误差值 sptr->Proportion_r = 0.4;//0.5;//0.8; //比例 sptr->Integral_r = 0.024;//0.026;//0.15; //积分 sptr->Derivative_r = 0.0; //微分 sptr->Proportion_l = 0.8; //比例 sptr->Integral_l = 0.15; //积分 sptr->Derivative_l = 0.0; //微分 sptr->A_r = sptr->Proportion_r + sptr->Integral_r + sptr->Derivative_r; sptr->B_r = -(2*sptr->Derivative_r + sptr->Proportion_r); sptr->C_r = sptr->Derivative_r; sptr->A_l = sptr->Proportion_l + sptr->Integral_l + sptr->Derivative_l; sptr->B_l= -(2*sptr->Derivative_l + sptr->Proportion_l); sptr->C_l = sptr->Derivative_l; sptr->iError_l = 0; //当前误差 sptr->iError_r = 0; sptr->iIncpid_l=0; //增量误差 sptr->iIncpid_r=0; sptr->limit = 49; } /* 左轮PID控制*/ float IncPIDCalc_l(float NextPoint) { if(ch_l != 0){ sptr->SetPoint_l = ch_l; iError_l = sptr->SetPoint_l - NextPoint; //增量计算 }else{ return 0; } // iError_l = sptr->SetPoint_l - NextPoint; //增量计算 sptr->iIncpid_l =(sptr->A_l * iError_l //E[k]项 + sptr->B_l * sptr->LastError_l //E[k-1]项 + sptr->C_l * sptr->PrevError_l); //E[k-2]项 variable_l =iError_l - sptr->LastError_l; sptr->PrevError_l = sptr->LastError_l; //存储误差,用于下次计算 sptr->LastError_l = iError_l; /*PWM limiting function, PWM value is 80, minimum is 0 */ // if(sptr->iIncpid >= 0) // { // if(sptr->iIncpid <= sptr->limit){ // // sptr->iIncpid += (pwm_set*100); // } // else{ // sptr->iIncpid = (int)(sptr->limit + pwm_set * 100); // } // } // else if(sptr->iIncpid < 0){ // // if(sptr->iIncpid >= -sptr->limit){ // // sptr->iIncpid += (pwm_set*100); // } // else{ // // sptr->iIncpid =(int)(pwm_set-sptr->limit); // } // // } if(sptr->iIncpid_l >= sptr->limit) { sptr->iIncpid_l = sptr->limit; } else if(sptr->iIncpid_l < -sptr->limit){ sptr->iIncpid_l = -sptr->limit; } return(sptr->iIncpid_l); //返回增量值 } /* 右轮PID控制*/ float IncPIDCalc_r(float NextPoint) { if(ch_r != 0){ sptr->SetPoint_r = ch_r; iError_r = sptr->SetPoint_r - NextPoint; //增量计算 }else{ return 0; } //iError_r = sptr->SetPoint_r - NextPoint; //增量计算 sptr->iIncpid_r =(sptr->A_r * iError_r //E[k]项 + sptr->B_r * sptr->LastError_r //E[k-1]项 + sptr->C_r * sptr->PrevError_r); //E[k-2]项 variable_r =iError_r - sptr->LastError_r; sptr->PrevError_r = sptr->LastError_r; //存储误差,用于下次计算 sptr->LastError_r = iError_r; if(sptr->iIncpid_r >= sptr->limit) { sptr->iIncpid_r = sptr->limit; } else if(sptr->iIncpid_r < -sptr->limit){ sptr->iIncpid_r = -sptr->limit; } return(sptr->iIncpid_r); //返回增量值 } /******************* (C) COPYRIGHT 2018 DY EleTe *****END OF FILE************/
史海拾趣
|
NVE公司产品指导书!与大家分享!美国NVE品牌采用尖端巨磁阻技术研发的超高速数字隔离器资料,相比传统得光耦器件,美国NVE产品在传送波特率、封装体积、使用寿命上都有了阶越性的提高。 2007年诺贝尔物理学奖颁给了GMR技术 ...… 查看全部问答> |
|
我现在想做一个设备记录现场温度的. 正在选择数据存储芯片. 每条数据的格式大概是:年月日时分秒温度。一天大概需要记录300条数据。要求数据要保存30天以上。请大家帮忙。… 查看全部问答> |
|
3G Android移动开发名家大讲堂(12月19日Google北京总部 作为目前最流行的Linux开源平台,Google公司的Android手机操作系统,在2007年11月推出后,即受到了广大技术爱好者的普遍关注。凭借其开放性和优异性,Android平台在发展的过程中也得到了包括大手机厂商和著名移动运营商在内的业界的广泛支持。目前 ...… 查看全部问答> |
|
坛里有没高手,弄zigbee方面啊~ 请教高手,我在使用TI的z-stack SampleApp例子使用组寻址方式,做的一个无线数据收发测试,当大于130ms左右发送数据包就会产生丢包现象~~… 查看全部问答> |
|
大家好,我想从串口3脚上窃电,请问谁有办法?或者告诉我用什么IC可以,市面上一直有这个东西,就是不知道怎么做到的,请各位大侠帮帮忙呀,我知道电流不大,没多大用,但是我很想知道它是怎么做成的。谢谢啦 !!… 查看全部问答> |
|
http://blog.ednchina.com/computer00/139637/message.aspx在STM32中,有五个时钟源,为HSI、HSE、LSI、LSE、PLL。①、HSI是高速内部时钟,RC振荡器,频率为8MHz。②、HSE是高速外部时钟,可接石英/陶瓷谐振器,或者接外部时钟源,频率范围为4 ...… 查看全部问答> |




