Er_sentry/User/module/cmd.h
2025-10-17 20:03:28 +08:00

98 lines
2.2 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.

/*
该文件cmd用于对各种命令的中转处理以防止在remote遥控器任务中过于冗杂堆叠
*/
#ifndef __CMD_H
#define __CMD_H
#include "bsp/struct_typedef.h"
#include "device/device.h"
// 遥控器状态
typedef enum
{
RC_DR16,
RC_LD,
RC_ET16s,
Control_loss
} rc_type_t;
/* 拨杆位置 */
typedef enum
{
CMD_SW_ERR = 0,
CMD_SW_UP = 1,
CMD_SW_MID = 3,
CMD_SW_DOWN = 2,
} CMD_SwitchPos_t;
// 遥控器数据
typedef struct
{
rc_type_t rc_type;
struct
{
float ch_l_x; /* 遥控器左侧摇杆横轴值,上为正 */
float ch_l_y; /* 遥控器左侧摇杆纵轴值,右为正 */
float ch_r_x; /* 遥控器右侧摇杆横轴值,上为正 */
float ch_r_y; /* 遥控器右侧摇杆纵轴值,右为正 */
CMD_SwitchPos_t sw_r; /* 右侧拨杆位置 */
CMD_SwitchPos_t sw_l; /* 左侧拨杆位置 */
} __attribute__((packed)) DJ;
struct
{
float ch_l_x; /* 遥控器左侧摇杆横轴值,上为正 */
float ch_l_y; /* 遥控器左侧摇杆纵轴值,右为正 */
float ch_r_x; /* 遥控器右侧摇杆横轴值,上为正 */
float ch_r_y; /* 遥控器右侧摇杆纵轴值,右为正 */
CMD_SwitchPos_t key_A;
CMD_SwitchPos_t key_B;
CMD_SwitchPos_t key_C;
CMD_SwitchPos_t key_D;
CMD_SwitchPos_t key_E;
CMD_SwitchPos_t key_F;
CMD_SwitchPos_t key_G;
CMD_SwitchPos_t key_H;
int16_t knob_left; // 左旋钮
int16_t knob_right; // 右旋钮
} __attribute__((packed)) LD;
} __attribute__((packed)) CMD_RC_t;
/*底盘模式*/
typedef enum
{
STOP, // 底盘平行
RC, // 遥控模式
LOCK, // 底盘锁死
} Chassis_mode_t;
typedef struct
{
int cmd_power_on_safe; // 上电安全标志
Chassis_mode_t mode;
// 遥控器输出值
fp32 Vx;
fp32 Vy;
fp32 Vw;
fp32 throttle;
} CMD_t;
void CMD_Init(CMD_t *cmd);
void CMD_ParseRc(CMD_t *cmd, CMD_RC_t *rc);
static void CMD_remote(const CMD_RC_t *rc, CMD_t *cmd);
int8_t CMD_CtrlSet(CMD_t *cmd, const CMD_RC_t *rc);
static void CMD_RcLostLogic(CMD_t *cmd);
#endif