mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-25 11:57:46 +08:00
将默认视觉通信换为usb虚拟串口,修复视觉发送roll错误;增加了attach调试支持
This commit is contained in:
@@ -46,7 +46,7 @@ static void IMU_Temperature_Ctrl(void)
|
||||
}
|
||||
|
||||
// 使用加速度计的数据初始化Roll和Pitch,而Yaw置0,这样可以避免在初始时候的姿态估计误差
|
||||
static void InitQuaternion(float* init_q4)
|
||||
static void InitQuaternion(float *init_q4)
|
||||
{
|
||||
float acc_init[3] = {0};
|
||||
float gravity_norm[3] = {0, 0, 1}; // 导航系重力加速度矢量,归一化后为(0,0,1)
|
||||
@@ -68,7 +68,7 @@ static void InitQuaternion(float* init_q4)
|
||||
Cross3d(acc_init, gravity_norm, axis_rot);
|
||||
Norm3d(axis_rot);
|
||||
init_q4[0] = cosf(angle / 2.0f);
|
||||
for(uint8_t i = 0; i < 2; ++i)
|
||||
for (uint8_t i = 0; i < 2; ++i)
|
||||
init_q4[i + 1] = axis_rot[i] * sinf(angle / 2.0f); // 轴角公式,第三轴为0(没有z轴分量)
|
||||
}
|
||||
|
||||
@@ -154,8 +154,8 @@ void INS_Task(void)
|
||||
INS.Pitch = QEKF_INS.Pitch;
|
||||
INS.Roll = QEKF_INS.Roll;
|
||||
INS.YawTotalAngle = QEKF_INS.YawTotalAngle;
|
||||
|
||||
VisionSetAltitude(INS.Yaw,INS.Pitch);
|
||||
|
||||
VisionSetAltitude(INS.Yaw, INS.Pitch, INS.Roll);
|
||||
}
|
||||
|
||||
// temperature control
|
||||
|
||||
@@ -9,14 +9,32 @@
|
||||
*
|
||||
*/
|
||||
#include "master_process.h"
|
||||
#include "bsp_usart.h"
|
||||
#include "usart.h"
|
||||
#include "seasky_protocol.h"
|
||||
#include "daemon.h"
|
||||
#include "bsp_log.h"
|
||||
#include "robot_def.h"
|
||||
|
||||
static Vision_Recv_s recv_data;
|
||||
static Vision_Send_s send_data;
|
||||
|
||||
void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Speed_e bullet_speed)
|
||||
{
|
||||
send_data.enemy_color = enemy_color;
|
||||
send_data.work_mode = work_mode;
|
||||
send_data.bullet_speed = bullet_speed;
|
||||
}
|
||||
|
||||
void VisionSetAltitude(float yaw, float pitch, float roll)
|
||||
{
|
||||
send_data.yaw = yaw;
|
||||
send_data.pitch = pitch;
|
||||
send_data.roll = roll;
|
||||
}
|
||||
|
||||
#ifdef VISION_USE_UART
|
||||
|
||||
#include "bsp_usart.h"
|
||||
#include "daemon.h"
|
||||
|
||||
static USARTInstance *vision_usart_instance;
|
||||
static DaemonInstance *vision_daemon_instance;
|
||||
|
||||
@@ -45,9 +63,9 @@ static void VisionOfflineCallback(void *id)
|
||||
USARTServiceInit(vision_usart_instance);
|
||||
}
|
||||
|
||||
/* 视觉通信初始化 */
|
||||
Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle)
|
||||
{
|
||||
#ifdef VISION_USE_UART
|
||||
USART_Init_Config_s conf;
|
||||
conf.module_callback = DecodeVision;
|
||||
conf.recv_buff_size = VISION_RECV_SIZE;
|
||||
@@ -61,15 +79,16 @@ Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle)
|
||||
.reload_count = 10,
|
||||
};
|
||||
vision_daemon_instance = DaemonRegister(&daemon_conf);
|
||||
#endif // VISION_USE_UART
|
||||
|
||||
return &recv_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 发送函数
|
||||
*
|
||||
*
|
||||
* @param send 待发送数据
|
||||
*
|
||||
*
|
||||
*/
|
||||
void VisionSend()
|
||||
{
|
||||
@@ -88,15 +107,40 @@ void VisionSend()
|
||||
// 若使用了daemon,则也可以使用DMA发送.
|
||||
}
|
||||
|
||||
void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Speed_e bullet_speed)
|
||||
#endif // VISION_USE_UART
|
||||
|
||||
#ifdef VISION_USE_VCP
|
||||
|
||||
#include "bsp_usb.h"
|
||||
static uint8_t *vis_recv_buff;
|
||||
|
||||
static void DecodeVision(uint16_t recv_len)
|
||||
{
|
||||
send_data.enemy_color = enemy_color;
|
||||
send_data.work_mode = work_mode;
|
||||
send_data.bullet_speed = bullet_speed;
|
||||
uint16_t flag_register;
|
||||
get_protocol_info(vis_recv_buff, &flag_register, (uint8_t *)&recv_data.pitch);
|
||||
// TODO: code to resolve flag_register;
|
||||
}
|
||||
|
||||
void VisionSetAltitude(float yaw, float pitch)
|
||||
/* 视觉通信初始化 */
|
||||
Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle)
|
||||
{
|
||||
send_data.yaw = yaw;
|
||||
send_data.pitch = pitch;
|
||||
UNUSED(_handle); // 仅为了消除警告
|
||||
USB_Init_Config_s conf = {0};
|
||||
conf.rx_cbk = DecodeVision;
|
||||
vis_recv_buff = USBInit(conf);
|
||||
return &recv_data;
|
||||
}
|
||||
|
||||
void VisionSend()
|
||||
{
|
||||
static uint16_t flag_register;
|
||||
static uint8_t send_buff[VISION_SEND_SIZE];
|
||||
static uint16_t tx_len;
|
||||
// TODO: code to set flag_register
|
||||
flag_register = 30 << 8 | 0b00000001;
|
||||
// 将数据转化为seasky协议的数据包
|
||||
get_protocol_send_data(0x02, flag_register, &send_data.yaw, 3, send_buff, &tx_len);
|
||||
USBTransmit(send_buff, tx_len);
|
||||
}
|
||||
|
||||
#endif // VISION_USE_VCP
|
||||
|
||||
@@ -77,6 +77,7 @@ typedef struct
|
||||
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
} Vision_Send_s;
|
||||
#pragma pack()
|
||||
|
||||
@@ -108,6 +109,6 @@ void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Spee
|
||||
* @param yaw
|
||||
* @param pitch
|
||||
*/
|
||||
void VisionSetAltitude(float yaw, float pitch);
|
||||
void VisionSetAltitude(float yaw, float pitch, float roll);
|
||||
|
||||
#endif // !MASTER_PROCESS_H
|
||||
Reference in New Issue
Block a user