MPU6050串口发送姿态数据由%.3f改为%f,gambal修改接收数据的个位数,和修改PID值

This commit is contained in:
2023-12-19 09:43:36 +08:00
parent 0f3cf0952c
commit d599512c02
4 changed files with 11 additions and 47 deletions

View File

@ -2,7 +2,7 @@
//#include "math.h"
#include <stdlib.h>
#include <string.h>
u8 USART_RX_BUF[20];
u8 USART_RX_BUF[30];
//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
unsigned short USART_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־
@ -41,8 +41,8 @@ unsigned short USART_RX_STA=0; //
u32 RX_CNT = 0;
u8 f;
u8 x[10];
u8 y[10];
u8 x[12];
u8 y[12];
void USART1_IRQHandler(void)
{
unsigned char res;
@ -61,8 +61,8 @@ void USART1_IRQHandler(void)
else
{
memcpy(x,USART_RX_BUF,f+1);
memcpy(y,USART_RX_BUF+f+1,20-f-1);
memset(USART_RX_BUF,0,20);
memcpy(y,USART_RX_BUF+f+1,30-f-1);
memset(USART_RX_BUF,0,30);
RX_CNT = 0;
}
}

View File

@ -9,11 +9,11 @@
extern float error;
extern u8 USART_RX_BUF[20];
extern u8 USART_RX_BUF[30];
//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
extern unsigned short USART_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־
extern u8 x[10];
extern u8 y[10];
extern u8 x[12];
extern u8 y[12];
void usart1_Init(u32 bound);

View File

@ -163,7 +163,7 @@ void PID_init(void)
// pid_ang_timestamp=SysTick->VAL;
// ////////yyyyyyyyyyyy
pid_vel_P=1.5; //0.1
pid_vel_P=0.8; //0.1
pid_vel_I=0.1; //2
output_vel_ramp=100;
integral_vel_prev=0;
@ -172,30 +172,10 @@ void PID_init(void)
pid_vel_timestamp=SysTick->VAL;
pid_ang_P = 10;
pid_ang_D =0.5;
pid_ang_D =5;
error_ang_prev= 0;
pid_ang_timestamp=SysTick->VAL;
}
//void commander_run(void)
//{
// if((USART_RX_STA&0x8000)!=0)
// {
// switch(USART_RX_BUF[0])
// {
// case 'y': //D
// target = 0 - atof((const char *)(USART_RX_BUF+1));
// break;
// case 'x':
// target =atof((const char *)(USART_RX_BUF+1));
// break;
//
// }
// USART_RX_STA=0;
// }
//}
/******************************************************************************/
float shaftAngle(void)
@ -231,22 +211,6 @@ float LPF_velocity(float x)
return y;
}
/******************************************************************************/
//void PID_init(void)
//{
// pid_vel_P=0.2; //0.1
// pid_vel_I=2.0; //2
// output_vel_ramp=100;
// integral_vel_prev=0;
// error_vel_prev=0;
// output_vel_prev=0;
// pid_vel_timestamp=SysTick->VAL;
//
// pid_ang_P=20;
// pid_ang_D=0.5;
// error_ang_prev=0;
// pid_ang_timestamp=SysTick->VAL;
//}
/******************************************************************************/
float PID_velocity(float error)
{
unsigned long now_us;

View File

@ -39,7 +39,7 @@ int main(void)
GetAngle(&MPU6050,&Angle,0.003f);
float x = Angle.pitch / 180.f * _PI;
float y = Angle.roll / 180.f * _PI;
printf("%.3fy%.3f\r\n",x,y);
printf("%fy%f\r\n",x,y);
//// printf("y%.3f\r\n",Angle.roll / 180.f * _PI);
// printf("A%dA",i);
}