常驻嘉宾
- 积分
- 5905
- 威望
- 1946
- 贡献
- 3251
- 兑换币
- 809
- 注册时间
- 2012-2-7
- 在线时间
- 354 小时
|
void Motor_Regler(void)
{
volatile float power_value = 0.0,error_value = 0.0,gyro_value = 0.0;
static unsigned char FB_Flag = 0,Front_Count = 0,Behind_Count = 0; //???这我想不灵清啊,static后面会用来计数的?
error_value = QingJiao/57.3; //用弧度制
gyro_value = Gyro_Data;
////倾角检测
// OutData[3]=error_value;
Integral += error_value;
Different = Error1_Old - Error2_Old;
Error2_Old = Error1_Old;
Error1_Old = error_value;
// OutData[0] = (float)D_Value*Different;
power_value = fabs((float)P_Value*error_value + (float)I_Value*Integral + (float)D_Value*Different);//PID
OutData[3]=power_value;
if(power_value < -ADJ_Value) power_value = -ADJ_Value;
if(power_value > ADJ_Value) power_value = ADJ_Value;
//power_value=0.3*power_value*power_value+Min_Power;
if(error_value>0) //正向倾角判断 正向调节角度 0~Pi/12.0
{
Front_Count = 0;
Behind_Count++;
if(5==Behind_Count) //连续5次检测为正向倾角时标志位置位,
{
Behind_Count = 0;
FB_Flag = 8;
}
这段程序我想不明白 ,他在函数中定义static变量FB_Flag = 0,Front_Count = 0,Behind_Count = 0;后面却用来计数?难道static可以多次赋值?求高手解释,谢过!!
|
|