OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3620|回复: 8

stm32f103中while(1)不按照设定的进行循环?

[复制链接]

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
发表于 2017-5-7 12:31:34 | 显示全部楼层 |阅读模式
1金钱
我想不通为什么每循环30周期,arhs_contrl_PID()函数会那么不按照规律性的来个50ms突变然后归于正常。详细的看图
111.png

PA8脚的波形

PA8脚的波形

最佳答案

查看完整内容[请看2#楼]

问题找到了,是24L01的问题。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:31:35 | 显示全部楼层
问题找到了,是24L01的问题。
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:33:34 | 显示全部楼层
求解求解求解啊,arhs_contrl_PID( )函数里边就是PID的计算和陀螺仪的读取,还有一个遥控停止。其他的没了
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:41:11 | 显示全部楼层
顶!!
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:42:46 | 显示全部楼层
快来大神
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:45:04 | 显示全部楼层
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 12:55:04 | 显示全部楼层
[mw_shl_code=c,true]void ahrs_control_PID_moto(void)   //1ؼü×Ö£oo½×Ë ¿ØÖÆ ′®¼&#182ID μç»ú
{
      if(mpu_dmp_get_data(&Angle.pitch ,&Angle.roll,&Angle.yaw)==0)//íóÂYòÇ×¼±¸oÃáË
        {
             MPU_Get_Accelerometer(&Acc.X ,&Acc.Y ,&Acc.Z );          //μÃμ½μļóËù¶è
             MPU_Get_Gyroscope(&Gyro.X ,&Gyro.Y ,&Gyro.Z);      //μÃμ½μÄíóÂYòÇ
                   MPU_Get_GYRO();                                    //¸üDÂíóÂYòÇ
                   contrl_pid(); //PID ctl and pwm       
              }       

}
/*******************************************************/
[/mw_shl_code]
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 13:01:21 | 显示全部楼层
[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)        //è&#231;1&#251;&#195;&#187;óD&#189;óêüμ&#189;è&#206;o&#206;êy&#190;Y&#190;í&#213;a&#209;ù&#214;′DD
                                        {
                                         TIM_SetCompare1(TIM2,moto1);
                                         TIM_SetCompare2(TIM2,moto2);
                                         TIM_SetCompare3(TIM2,moto3);
                                         TIM_SetCompare4(TIM2,moto4);          //&#203;&#196;&#184;&#246;í¨μà&#182;&#212;ó|&#203;&#196;&#184;&#246;μ&#231;&#187;ú
                                        }
                         else
                                         while(1)
                                         {
                                                 TIM_SetCompare1(TIM2,val);
                                                 TIM_SetCompare2(TIM2,val);
                                                 TIM_SetCompare3(TIM2,val);
                                                 TIM_SetCompare4(TIM2,val);                                 //&#203;&#196;&#184;&#246;í¨μà&#182;&#212;ó|&#203;&#196;&#184;&#246;μ&#231;&#187;ú
                                         }       
                }
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;//&#187;y·&#214;&#207;T·ù         
                         if(pitch.core_Sn<-10)
                                 pitch.core_Sn=-10;//&#187;y·&#214;&#207;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;//&#187;y·&#214;&#207;T·ù         
                                        if(roll.core_Sn<-10)
                                        roll.core_Sn=-10;//&#187;y·&#214;&#207;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;//&#187;y·&#214;&#207;T·ù         //&#187;y·&#214;&#207;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]
回复

使用道具 举报

2

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2017-4-16
在线时间
19 小时
 楼主| 发表于 2017-5-7 13:03:48 | 显示全部楼层
代码也上去了,来个大神指导指导我
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-8-21 14:41

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表