2026rc_r1/User/module/chassis.h
2026-03-17 04:38:02 +08:00

145 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include "bsp/struct_typedef.h"
#include "component/pid.h"
#include "device/motor_rm.h"
#include "device/motor_vesc.h"
#include "device/bmi088.h"
#include "module/cmd.h"
#define CHASSIS_OK (0)
#define CHASSIS_ERR (-1)
#define CHASSIS_ERR_NULL (-2)
#define CHASSIS_ERR_MODE (-3) /*CMD_ChassisMode_t */
#define CHASSIS_ERR_TYPE (-4) /*Chassis_Type_t */
// 纵向/横向
#define radians atan(1.0f * 390 /390) // 角度制
// 四个舵轮的安装误差
typedef struct
{
fp32 MOTOR_OFFSET[4];
} MotorOffset_t;
typedef struct
{
BMI088_t bmi088;
/*可通过该枚举类型来决定Imu的数据量纲*/
enum
{
IMU_DEGREE, // 角度值0-360
IMU_RADIAN // 弧度制0-2pi)
} angle_mode;
AHRS_Eulr_t imu_eulr; // 解算后存放欧拉角(弧度制)
} ChassisImu_t;
/*底盘参数结构体*/
typedef struct
{
/*该部分决定PID的参数整定在config中修改*/
KPID_Params_t C6020Omega_param;
KPID_Params_t C6020Angle_param;
MOTOR_RM_Param_t motor_6020_param[4]; // 四个6020电机
/*5065轮向电机pid在上位机vesc调 */
VESC_Param_t motor_5065_param[4]; // 四个5065电机
} Chassis_Param_t;
typedef struct
{
fp32 Vx;
fp32 Vy;
fp32 Vw;
fp32 mul; // 油门倍率
} ChassisMove_Vec;
typedef struct
{
float rotor5065_out[4];
float rotor6020_out[4];
} Chassis_out_t;
typedef struct
{
uint32_t last_wakeup;
float dt;
Chassis_mode_t mode;
ChassisMove_Vec move_vec; // 最终输入速度
/*期望的底盘输出值(此处为舵轮解算出的各个电机的期望输出值)ֵ*/
struct
{
fp32 rotor5065_jiesuan_1[4];
fp32 rotor5065_jiesuan_2[4];
fp32 rotor6020_jiesuan_1[4];
fp32 rotor6020_jiesuan_2[4];
// fp32 rotor6020_elur_yaw;
fp32 motor6020_target[4];
fp32 motor5065_target[4];
} hopemotorout;
struct
{
fp32 final_6020out[4];
fp32 final_5065out[4];
} final_out;
struct
{
fp32 rotor_rpm5065[4];
fp32 rotor_current5065[4];
fp32 rotor_angle5065[4];
fp32 rotor_rpm6020[4];
fp32 rotor_angle6020[4];
fp32 rotor_current6020[4];
fp32 rotor_temp6020[4];
} motorfeedback;
struct
{
KPID_t chassis_6020anglePid[4];
KPID_t chassis_6020OmegaPid[4];
} pid;
uint8_t keeping_angle_flag; // 是否处于保持角度模式
// AHRS_Eulr_t set_point; // 底盘纠正目标角
// fp32 angle_current; // 当前角度
// fp32 angle_piancha; // 偏差角度
// fp32 yaw_out; // 角度pid输出值
ChassisImu_t pos088; // 088的实时姿态
MotorOffset_t motoroffset; // 5065校准数据
Chassis_Param_t *param; // 一些固定的参数
LowPassFilter2p_t filled[11]; // 低通滤波器
float keep_angle[4]; // 保持的 6020 角度
Chassis_out_t out;
} Chassis_t;
int8_t Chassis_init(Chassis_t *c, Chassis_Param_t *param, float target_freq);
int8_t Chassis_update(Chassis_t *c);
int8_t Chassis_Control(Chassis_t *c, Chassis_CMD_t *c_cmd,uint32_t now);
void Chassis_speed_calculate(Chassis_t *c, Chassis_CMD_t *c_cmd);
void Chassis_Setoutput(Chassis_t *c);
#ifdef __cplusplus
}
#endif