专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
stm32f103中while(1)不按照设定的进行循环?
2019-08-19 19:34
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
12872
8
1557
我想不通为什么每循环30周期,arhs_contrl_PID()函数会那么不按照规律性的来个50ms突变然后归于正常。详细的看图
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
a133760
1楼-- · 2019-08-21 00:26
[mw_shl_code=applescript,true]void all_ch()
{
moto1=(int16_t) (moto1+thr1);
moto2=(int16_t) (moto2+thr2);
moto3=(int16_t) (moto3+thr3);
moto4=(int16_t) (moto4+thr4);
if(moto1>move_Vmin)
moto1=move_Vmin;
if(moto1<move_Vmax)
moto1=move_Vmax;
if(moto2>move_Vmin)
moto2=move_Vmin;
if(moto2<move_Vmax)
moto2=move_Vmax;
if(moto3>move_Vmin)
moto3=move_Vmin;
if(moto3<move_Vmax)
moto3=move_Vmax;
if(moto4>move_Vmin)
moto4=move_Vmin;
if(moto4<move_Vmax)
moto4=move_Vmax;
if(NRF24L01_RxPacket(rxbuf)==1) //èç1ûûóD½óêüμ½èÎoÎêy¾Y¾íÕaÑùÖ′DD
{
TIM_SetCompare1(TIM2,moto1);
TIM_SetCompare2(TIM2,moto2);
TIM_SetCompare3(TIM2,moto3);
TIM_SetCompare4(TIM2,moto4); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
else
while(1)
{
TIM_SetCompare1(TIM2,val);
TIM_SetCompare2(TIM2,val);
TIM_SetCompare3(TIM2,val);
TIM_SetCompare4(TIM2,val); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
}
void contrl_pid(void)
{
// float x1,x2,x3;
moto1=0;
moto2=0;
moto3=0;
moto4=0;
/*shell pitch*/
for(ave_n=0;ave_n<5;ave_n++)
{
pitch.shell_xn=Angle_SET.pitch;
pitch.shell_error=pitch.shell_Set - pitch.shell_xn;
pitch.shell_Sn +=pitch.shell_error;
if(pitch.shell_Sn>0.5)
pitch.shell_Sn=0.4;
if(pitch.shell_Sn<-0.5)
pitch.shell_Sn=-0.4;
pitch.shell_out= pitch.shell_kp*pitch.shell_error + pitch.shell_ki*pitch.shell_Sn + pitch.shell_kd*( pitch.shell_error - pitch.shell_error_last );
pitch.shell_error_last=pitch.shell_error; //shell contrl renew data
/*core pitch*/
pitch.core_xn=MPU6050_GYRO_LAST.X/65.6; //?????
pitch.error=pitch.shell_out - pitch.core_xn;
pitch.core_Sn += pitch.error;
if(pitch.core_Sn>10)
pitch.core_Sn=10;//»y·ÖÏT·ù
if(pitch.core_Sn<-10)
pitch.core_Sn=-10;//»y·ÖÏT·ù
pitch.core_out=pitch.core_kp*pitch.error + pitch.core_ki*pitch.core_Sn + pitch.core_kd*( pitch.error - pitch.last_error );
pitch.last_error=pitch.error;
//Sum+=pitch.core_out;
//delay_us(100);
//pitch.core_out=Sum/5.0;
moto1=moto1 + pitch.core_out;
moto2=moto2 + pitch.core_out;
moto3=moto3 - pitch.core_out;
moto4=moto4 - pitch.core_out;
/*shell roll*/
roll.shell_xn=Angle_SET.roll;
roll.shell_error=roll.shell_Set - roll.shell_xn;
roll.shell_Sn +=roll.shell_error;
if(roll.shell_Sn>2)
roll.shell_Sn=2;
if(roll.shell_Sn<-2)
roll.shell_Sn=-2;
roll.shell_out=roll.shell_kp*roll.shell_error + roll.shell_ki*roll.shell_Sn + roll.shell_kd*( roll.shell_error - roll.shell_error_last );
roll.shell_error_last=roll.shell_error;//renew data
/*core roll*/
roll.core_xn=MPU6050_GYRO_LAST.Y /65.6; //????? ?00?s
roll.error = roll.shell_out - roll.core_xn;
roll.core_Sn+=roll.error;
if(roll.core_Sn>10)
roll.core_Sn=10;//»y·ÖÏT·ù
if(roll.core_Sn<-10)
roll.core_Sn=-10;//»y·ÖÏT·ù
roll.core_out=roll.core_kp*roll.error + roll.core_ki * roll.core_Sn + roll.core_kd*(roll.error - roll.last_error);
roll.last_error=roll.error;
moto1=moto1 + roll.core_out;
moto2=moto2 - roll.core_out;
moto3=moto3 - roll.core_out;
moto4=moto4 + roll.core_out;
/*shell yaw*/
yaw.shell_xn=Angle_SET.yaw;
yaw.shell_error=yaw.shell_Set - yaw.shell_xn;
yaw.shell_Sn += yaw.shell_error;
if(yaw.shell_Sn>0.5)
yaw.shell_Sn=0.4;
if(yaw.shell_Sn<-0.5)
yaw.shell_Sn=-0.4;
yaw.shell_out=yaw.shell_kp*yaw.shell_error + yaw.shell_ki*yaw.shell_Sn + yaw.shell_kd*( yaw.shell_error - yaw.shell_error_last );
yaw.shell_error_last=yaw.shell_error;
/*core yaw*/
yaw.core_xn=MPU6050_GYRO_LAST.Z /65.6;
yaw.error = yaw.shell_out - yaw.core_xn;
yaw.core_Sn+=yaw.error;
if(yaw.core_Sn>10)
yaw.core_Sn=10;
if(yaw.core_Sn<-10)
yaw.core_Sn=-10;//»y·ÖÏT·ù //»y·ÖÏT·ù
yaw.core_out=yaw.core_kp*yaw.error + yaw.core_ki * yaw.core_Sn + yaw.core_kd*(yaw.error - yaw.last_error);
yaw.last_error=yaw.error;
moto1=moto1 + yaw.core_out;
moto2=moto2 - yaw.core_out;
moto3=moto3 + yaw.core_out;
moto4=moto4 - yaw.core_out;
delay_us(200);
}
moto1=moto1/5.0;
moto2=moto2/5.0;
moto3=moto3/5.0;
moto4=moto4/5.0;
all_ch();
}[/mw_shl_code]
加载中...
a133760
2楼-- · 2019-08-21 05:39
代码也上去了,来个大神指导指导我
加载中...
上一页
1
2
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
STM32开发板免费用活动
7 个回答
stm32 处理 DHT11占用太多时间,大家程序是怎么设计的
8 个回答
分享一个STM32单片机做的离线编程器代码
9 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
{
moto1=(int16_t) (moto1+thr1);
moto2=(int16_t) (moto2+thr2);
moto3=(int16_t) (moto3+thr3);
moto4=(int16_t) (moto4+thr4);
if(moto1>move_Vmin)
moto1=move_Vmin;
if(moto1<move_Vmax)
moto1=move_Vmax;
if(moto2>move_Vmin)
moto2=move_Vmin;
if(moto2<move_Vmax)
moto2=move_Vmax;
if(moto3>move_Vmin)
moto3=move_Vmin;
if(moto3<move_Vmax)
moto3=move_Vmax;
if(moto4>move_Vmin)
moto4=move_Vmin;
if(moto4<move_Vmax)
moto4=move_Vmax;
if(NRF24L01_RxPacket(rxbuf)==1) //èç1ûûóD½óêüμ½èÎoÎêy¾Y¾íÕaÑùÖ′DD
{
TIM_SetCompare1(TIM2,moto1);
TIM_SetCompare2(TIM2,moto2);
TIM_SetCompare3(TIM2,moto3);
TIM_SetCompare4(TIM2,moto4); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
else
while(1)
{
TIM_SetCompare1(TIM2,val);
TIM_SetCompare2(TIM2,val);
TIM_SetCompare3(TIM2,val);
TIM_SetCompare4(TIM2,val); //Ëĸöí¨μà¶Ôó|Ëĸöμç»ú
}
}
void contrl_pid(void)
{
// float x1,x2,x3;
moto1=0;
moto2=0;
moto3=0;
moto4=0;
/*shell pitch*/
for(ave_n=0;ave_n<5;ave_n++)
{
pitch.shell_xn=Angle_SET.pitch;
pitch.shell_error=pitch.shell_Set - pitch.shell_xn;
pitch.shell_Sn +=pitch.shell_error;
if(pitch.shell_Sn>0.5)
pitch.shell_Sn=0.4;
if(pitch.shell_Sn<-0.5)
pitch.shell_Sn=-0.4;
pitch.shell_out= pitch.shell_kp*pitch.shell_error + pitch.shell_ki*pitch.shell_Sn + pitch.shell_kd*( pitch.shell_error - pitch.shell_error_last );
pitch.shell_error_last=pitch.shell_error; //shell contrl renew data
/*core pitch*/
pitch.core_xn=MPU6050_GYRO_LAST.X/65.6; //?????
pitch.error=pitch.shell_out - pitch.core_xn;
pitch.core_Sn += pitch.error;
if(pitch.core_Sn>10)
pitch.core_Sn=10;//»y·ÖÏT·ù
if(pitch.core_Sn<-10)
pitch.core_Sn=-10;//»y·ÖÏT·ù
pitch.core_out=pitch.core_kp*pitch.error + pitch.core_ki*pitch.core_Sn + pitch.core_kd*( pitch.error - pitch.last_error );
pitch.last_error=pitch.error;
//Sum+=pitch.core_out;
//delay_us(100);
//pitch.core_out=Sum/5.0;
moto1=moto1 + pitch.core_out;
moto2=moto2 + pitch.core_out;
moto3=moto3 - pitch.core_out;
moto4=moto4 - pitch.core_out;
/*shell roll*/
roll.shell_xn=Angle_SET.roll;
roll.shell_error=roll.shell_Set - roll.shell_xn;
roll.shell_Sn +=roll.shell_error;
if(roll.shell_Sn>2)
roll.shell_Sn=2;
if(roll.shell_Sn<-2)
roll.shell_Sn=-2;
roll.shell_out=roll.shell_kp*roll.shell_error + roll.shell_ki*roll.shell_Sn + roll.shell_kd*( roll.shell_error - roll.shell_error_last );
roll.shell_error_last=roll.shell_error;//renew data
/*core roll*/
roll.core_xn=MPU6050_GYRO_LAST.Y /65.6; //????? ?00?s
roll.error = roll.shell_out - roll.core_xn;
roll.core_Sn+=roll.error;
if(roll.core_Sn>10)
roll.core_Sn=10;//»y·ÖÏT·ù
if(roll.core_Sn<-10)
roll.core_Sn=-10;//»y·ÖÏT·ù
roll.core_out=roll.core_kp*roll.error + roll.core_ki * roll.core_Sn + roll.core_kd*(roll.error - roll.last_error);
roll.last_error=roll.error;
moto1=moto1 + roll.core_out;
moto2=moto2 - roll.core_out;
moto3=moto3 - roll.core_out;
moto4=moto4 + roll.core_out;
/*shell yaw*/
yaw.shell_xn=Angle_SET.yaw;
yaw.shell_error=yaw.shell_Set - yaw.shell_xn;
yaw.shell_Sn += yaw.shell_error;
if(yaw.shell_Sn>0.5)
yaw.shell_Sn=0.4;
if(yaw.shell_Sn<-0.5)
yaw.shell_Sn=-0.4;
yaw.shell_out=yaw.shell_kp*yaw.shell_error + yaw.shell_ki*yaw.shell_Sn + yaw.shell_kd*( yaw.shell_error - yaw.shell_error_last );
yaw.shell_error_last=yaw.shell_error;
/*core yaw*/
yaw.core_xn=MPU6050_GYRO_LAST.Z /65.6;
yaw.error = yaw.shell_out - yaw.core_xn;
yaw.core_Sn+=yaw.error;
if(yaw.core_Sn>10)
yaw.core_Sn=10;
if(yaw.core_Sn<-10)
yaw.core_Sn=-10;//»y·ÖÏT·ù //»y·ÖÏT·ù
yaw.core_out=yaw.core_kp*yaw.error + yaw.core_ki * yaw.core_Sn + yaw.core_kd*(yaw.error - yaw.last_error);
yaw.last_error=yaw.error;
moto1=moto1 + yaw.core_out;
moto2=moto2 - yaw.core_out;
moto3=moto3 + yaw.core_out;
moto4=moto4 - yaw.core_out;
delay_us(200);
}
moto1=moto1/5.0;
moto2=moto2/5.0;
moto3=moto3/5.0;
moto4=moto4/5.0;
all_ch();
}[/mw_shl_code]
一周热门 更多>