Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e52785886f | ||
|
|
ebe3c2243d | ||
|
|
c406c6a392 | ||
|
|
695262bcd1 | ||
|
|
6d581c4c04 | ||
|
|
740dc38e96 |
@@ -324,11 +324,6 @@
|
||||
<pMon>BIN\CMSIS_AGDI.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ST-LINKIII-KEIL_SWO</Key>
|
||||
<Name>-U-O206 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMRTXEVENTFLAGS</Key>
|
||||
@@ -352,7 +347,7 @@
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>CMSIS_AGDI</Key>
|
||||
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
@@ -365,7 +360,7 @@
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>param_default</ItemText>
|
||||
<ItemText>chassis</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
@@ -375,42 +370,47 @@
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>shoot</ItemText>
|
||||
<ItemText>gimbal_out</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>param_hero</ItemText>
|
||||
<ItemText>for_chassis</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ref</ItemText>
|
||||
<ItemText>task_runtime</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>for_chassis</ItemText>
|
||||
<ItemText>ref</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>cap_out,0x0A</ItemText>
|
||||
<ItemText>for_chassis</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>7</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>pm01_od,0x0A</ItemText>
|
||||
<ItemText>for_cap</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>8</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>cap,0x0A</ItemText>
|
||||
<ItemText>ref</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>9</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ref</ItemText>
|
||||
<ItemText>param_default</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>10</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>shoot</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow4>
|
||||
@@ -1283,7 +1283,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>User/bsp</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -1507,7 +1507,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>User/component</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
||||
Binary file not shown.
19245
MDK-ARM/DevC/DevC.hex
19245
MDK-ARM/DevC/DevC.hex
File diff suppressed because it is too large
Load Diff
70
Middlewares/Third_Party/Protocol/protocol.h
vendored
70
Middlewares/Third_Party/Protocol/protocol.h
vendored
@@ -7,13 +7,15 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define AI_NOTICE_AUTOAIM (1 << 0)
|
||||
#define AI_NOTICE_HITBUFF (1 << 1)
|
||||
#define AI_NOTICE_AUTOMATIC (1 << 2)
|
||||
#define AI_NOTICE_FIRE (1 << 3)
|
||||
#define AI_NOTICE_SEARCH_ARMOR (1 << 4)
|
||||
|
||||
#define AI_ID_MCU (0xC4)
|
||||
#define AI_ID_REF (0xA8)
|
||||
@@ -21,66 +23,70 @@ extern "C" {
|
||||
#define AI_TEAM_RED (0x01)
|
||||
#define AI_TEAM_BLUE (0x02)
|
||||
|
||||
typedef uint8_t Protocol_ID_t;
|
||||
typedef uint8_t Protocol_ID_t;
|
||||
|
||||
/* 电控 -> 视觉 MCU数据结构体*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
struct __attribute__((packed)) {
|
||||
/* 电控 -> 视觉 MCU数据结构体*/
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
struct __attribute__((packed))
|
||||
{
|
||||
float q0;
|
||||
float q1;
|
||||
float q2;
|
||||
float q3;
|
||||
} quat; /* 四元数 */
|
||||
|
||||
struct __attribute__((packed))
|
||||
{
|
||||
float yaw;
|
||||
float pit;
|
||||
float rol;
|
||||
} gimbal; /* 欧拉角 */
|
||||
uint8_t notice; /* 控制命令 */
|
||||
} Protocol_UpDataMCU_t;
|
||||
|
||||
float ball_speed; /* 子弹初速度 */
|
||||
|
||||
struct __attribute__((packed)) {
|
||||
float left;
|
||||
float right;
|
||||
} distance; /* 左右距离(哨兵) */
|
||||
|
||||
float chassis_speed; /* 底盘速度(哨兵) */
|
||||
} Protocol_UpDataMCU_t;
|
||||
|
||||
/* 电控 -> 视觉 裁判系统数据结构体*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
/* 电控 -> 视觉 裁判系统数据结构体*/
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint16_t team; /* 本身队伍 */
|
||||
uint16_t time; /* 比赛开始时间 */
|
||||
} Protocol_UpDataReferee_t;
|
||||
} Protocol_UpDataReferee_t;
|
||||
|
||||
/* 视觉 -> 电控 数据结构体*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
struct __attribute__((packed)) {
|
||||
/* 视觉 -> 电控 数据结构体*/
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
struct __attribute__((packed))
|
||||
{
|
||||
float yaw; /* 偏航角(Yaw angle) */
|
||||
float pit; /* 俯仰角(Pitch angle) */
|
||||
float rol; /* 翻滚角(Roll angle) */
|
||||
} gimbal; /* 欧拉角 */
|
||||
|
||||
uint8_t notice; /* 控制命令 */
|
||||
|
||||
struct __attribute__((packed)) {
|
||||
struct __attribute__((packed))
|
||||
{
|
||||
float vx; /* x轴移动速度 */
|
||||
float vy; /* y轴移动速度 */
|
||||
float wz; /* z轴转动速度 */
|
||||
} chassis_move_vec; /* 底盘移动向量 */
|
||||
} Protocol_DownData_t;
|
||||
uint8_t notice; /* 控制命令 */
|
||||
} Protocol_DownData_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
Protocol_UpDataMCU_t data;
|
||||
uint16_t crc16;
|
||||
} Protocol_UpPackageMCU_t;
|
||||
} Protocol_UpPackageMCU_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
Protocol_UpDataReferee_t data;
|
||||
uint16_t crc16;
|
||||
} Protocol_UpPackageReferee_t;
|
||||
} Protocol_UpPackageReferee_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
Protocol_DownData_t data;
|
||||
uint16_t crc16;
|
||||
} Protocol_DownPackage_t;
|
||||
} Protocol_DownPackage_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ static void CMD_PcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
|
||||
cmd->gimbal.delta_eulr.yaw =
|
||||
(float)rc->mouse.x * dt_sec * cmd->param->sens_mouse;
|
||||
cmd->gimbal.delta_eulr.pit =
|
||||
(float)(rc->mouse.y) * dt_sec * cmd->param->sens_mouse;
|
||||
(float)(-rc->mouse.y) * dt_sec * cmd->param->sens_mouse;
|
||||
cmd->chassis.ctrl_vec.vx = cmd->chassis.ctrl_vec.vy = 0.0f;
|
||||
cmd->shoot.reverse_trig = false;
|
||||
|
||||
@@ -170,7 +170,7 @@ static void CMD_PcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
|
||||
cmd->shoot.reverse_trig = true;
|
||||
}
|
||||
if (CMD_BehaviorOccurredRc(rc, cmd, CMD_BEHAVIOR_FOLLOWGIMBAL35)) {
|
||||
cmd->chassis.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
||||
cmd->chassis.mode = CHASSIS_MODE_FOLLOW_GIMBAL_35;
|
||||
}
|
||||
/* 保存当前按下的键位状态 */
|
||||
cmd->key_last = rc->key;
|
||||
|
||||
@@ -27,6 +27,10 @@ inline float AbsClip(float in, float limit) {
|
||||
return (in < -limit) ? -limit : ((in > limit) ? limit : in);
|
||||
}
|
||||
|
||||
float fAbs(float in){
|
||||
return (in > 0) ? in : -in;
|
||||
}
|
||||
|
||||
inline void Clip(float *origin, float min, float max) {
|
||||
if (*origin > max) *origin = max;
|
||||
if (*origin < min) *origin = min;
|
||||
@@ -112,3 +116,17 @@ inline float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm) {
|
||||
/* 不为裁判系统设定值时,计算转速 */
|
||||
return 60.0f * (float)bullet_speed / (M_2PI * fric_radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 断言失败处理
|
||||
*
|
||||
* @param file 文件名
|
||||
* @param line 行号
|
||||
*/
|
||||
void VerifyFailed(const char *file, uint32_t line) {
|
||||
UNUSED(file);
|
||||
UNUSED(line);
|
||||
while (1) {
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ float InvSqrt(float x);
|
||||
|
||||
float AbsClip(float in, float limit);
|
||||
|
||||
float fAbs(float in);
|
||||
|
||||
void Clip(float *origin, float min, float max);
|
||||
|
||||
float Sign(float in);
|
||||
@@ -104,3 +106,53 @@ float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
/**
|
||||
* @brief 如果表达式的值为假则运行处理函数
|
||||
*
|
||||
*/
|
||||
#define ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
VerifyFailed(__FILE__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
|
||||
/**
|
||||
* @brief 未定DEBUG,表达式不会运行,断言被忽略
|
||||
*
|
||||
*/
|
||||
#define ASSERT(expr) ((void)(0))
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
/**
|
||||
* @brief 如果表达式的值为假则运行处理函数
|
||||
*
|
||||
*/
|
||||
#define VERIFY(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
VerifyFailed(__FILE__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
|
||||
/**
|
||||
* @brief 表达式会运行,忽略表达式结果
|
||||
*
|
||||
*/
|
||||
#define VERIFY(expr) ((void)(expr))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief 断言失败处理
|
||||
*
|
||||
* @param file 文件名
|
||||
* @param line 行号
|
||||
*/
|
||||
void VerifyFailed(const char *file, uint32_t line);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
AI
|
||||
AI
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
@@ -12,31 +12,45 @@
|
||||
#include "component\crc16.h"
|
||||
#include "component\crc8.h"
|
||||
#include "component\user_math.h"
|
||||
#include "component\filter.h"
|
||||
|
||||
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
#define AI_LEN_RX_BUFF (sizeof(Protocol_DownPackage_t))
|
||||
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
static volatile uint32_t drop_message = 0;
|
||||
|
||||
static osThreadId_t thread_alert;
|
||||
static uint8_t rxbuf[AI_LEN_RX_BUFF];
|
||||
|
||||
static bool inited = false;
|
||||
|
||||
static osThreadId_t thread_alert;
|
||||
|
||||
/* Private function -------------------------------------------------------- */
|
||||
|
||||
static void Ai_RxCpltCallback(void) {
|
||||
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
static void Ai_IdleLineCallback(void) {
|
||||
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
int8_t AI_Init(AI_t *ai) {
|
||||
if (ai == NULL) return DEVICE_ERR_NULL;
|
||||
UNUSED(ai);
|
||||
ASSERT(ai);
|
||||
if (inited) return DEVICE_ERR_INITED;
|
||||
if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL;
|
||||
VERIFY((thread_alert = osThreadGetId()) != NULL);
|
||||
|
||||
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_RX_CPLT_CB,
|
||||
Ai_RxCpltCallback);
|
||||
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_IDLE_LINE_CB,
|
||||
Ai_IdleLineCallback);
|
||||
|
||||
inited = true;
|
||||
return 0;
|
||||
}
|
||||
@@ -48,9 +62,9 @@ int8_t AI_Restart(void) {
|
||||
}
|
||||
|
||||
int8_t AI_StartReceiving(AI_t *ai) {
|
||||
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI),
|
||||
(uint8_t *)&(ai->form_host),
|
||||
sizeof(ai->form_host)) == HAL_OK)
|
||||
UNUSED(ai);
|
||||
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI), rxbuf,
|
||||
AI_LEN_RX_BUFF) == HAL_OK)
|
||||
return DEVICE_OK;
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
@@ -60,17 +74,12 @@ bool AI_WaitDmaCplt(void) {
|
||||
SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
int8_t AI_ParseHost(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||
(void)cmd_host;
|
||||
if (!CRC16_Verify((const uint8_t *)&(ai->form_host), sizeof(ai->form_host)))
|
||||
int8_t AI_ParseHost(AI_t *ai) {
|
||||
if (!CRC16_Verify((const uint8_t *)&(rxbuf), sizeof(ai->from_host)))
|
||||
goto error;
|
||||
cmd_host->gimbal_delta.pit = ai->form_host.data.gimbal.pit;
|
||||
cmd_host->gimbal_delta.yaw = ai->form_host.data.gimbal.yaw;
|
||||
cmd_host->gimbal_delta.rol = ai->form_host.data.gimbal.rol;
|
||||
cmd_host->fire = (ai->form_host.data.notice & AI_NOTICE_FIRE);
|
||||
cmd_host->chassis_move_vec.vx = ai->form_host.data.chassis_move_vec.vx;
|
||||
cmd_host->chassis_move_vec.vy = ai->form_host.data.chassis_move_vec.vy;
|
||||
cmd_host->chassis_move_vec.wz = ai->form_host.data.chassis_move_vec.wz;
|
||||
ai->ai_online = true;
|
||||
memcpy(&(ai->from_host), rxbuf, sizeof(ai->from_host));
|
||||
memset(rxbuf, 0, AI_LEN_RX_BUFF);
|
||||
return DEVICE_OK;
|
||||
|
||||
error:
|
||||
@@ -78,11 +87,20 @@ error:
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
|
||||
void AI_PackCmd(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||
cmd_host->gimbal_delta.yaw = ai->from_host.data.gimbal.yaw;
|
||||
cmd_host->gimbal_delta.pit = ai->from_host.data.gimbal.pit;
|
||||
cmd_host->fire = (ai->from_host.data.notice & AI_NOTICE_FIRE);
|
||||
cmd_host->chassis_move_vec.vx = ai->from_host.data.chassis_move_vec.vx;
|
||||
cmd_host->chassis_move_vec.vy = ai->from_host.data.chassis_move_vec.vy;
|
||||
cmd_host->chassis_move_vec.wz = ai->from_host.data.chassis_move_vec.wz;
|
||||
}
|
||||
|
||||
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||
if (ai == NULL) return DEVICE_ERR_NULL;
|
||||
if (cmd_host == NULL) return DEVICE_ERR_NULL;
|
||||
|
||||
memset(&(ai->form_host), 0, sizeof(ai->form_host));
|
||||
ai->ai_online = false;
|
||||
memset(&(ai->from_host), 0, sizeof(ai->from_host));
|
||||
memset(cmd_host, 0, sizeof(*cmd_host));
|
||||
return 0;
|
||||
}
|
||||
@@ -131,3 +149,4 @@ int8_t AI_StartSend(AI_t *ai, bool ref_update) {
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ extern "C" {
|
||||
#include "component\ahrs.h"
|
||||
#include "component\cmd.h"
|
||||
#include "component\user_math.h"
|
||||
#include "component\filter.h"
|
||||
#include "device\device.h"
|
||||
#include "device\referee.h"
|
||||
#include "protocol.h"
|
||||
@@ -37,7 +38,7 @@ typedef struct __packed {
|
||||
typedef struct __packed {
|
||||
osThreadId_t thread_alert;
|
||||
|
||||
Protocol_DownPackage_t form_host;
|
||||
Protocol_DownPackage_t from_host;
|
||||
|
||||
struct {
|
||||
AI_UpPackageReferee_t ref;
|
||||
@@ -45,6 +46,7 @@ typedef struct __packed {
|
||||
} to_host;
|
||||
|
||||
CMD_AI_Status_t status;
|
||||
bool ai_online;
|
||||
} AI_t;
|
||||
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
@@ -53,11 +55,15 @@ int8_t AI_Restart(void);
|
||||
|
||||
int8_t AI_StartReceiving(AI_t *ai);
|
||||
bool AI_WaitDmaCplt(void);
|
||||
int8_t AI_ParseHost(AI_t *ai, CMD_Host_t *cmd_host);
|
||||
int8_t AI_ParseHost(AI_t *ai);
|
||||
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host);
|
||||
int8_t AI_PackMCU(AI_t *ai, const AHRS_Quaternion_t *quat);
|
||||
int8_t AI_PackRef(AI_t *ai, const Referee_ForAI_t *ref);
|
||||
int8_t AI_StartSend(AI_t *ai, bool option);
|
||||
void AI_PackCmd(AI_t *ai, CMD_Host_t *cmd_host);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -66,12 +66,9 @@ static osThreadId_t thread_alert;
|
||||
static CAN_t *gcan;
|
||||
static bool inited = false;
|
||||
|
||||
volatile pm01_od_t pm01_od;
|
||||
|
||||
/* Private function -------------------------------------------------------- */
|
||||
static void CAN_Motor_Decode(CAN_MotorFeedback_t *feedback,
|
||||
const uint8_t *raw)
|
||||
{
|
||||
const uint8_t *raw) {
|
||||
uint16_t raw_angle = (uint16_t)((raw[0] << 8) | raw[1]);
|
||||
int16_t raw_current = (int16_t)((raw[4] << 8) | raw[5]);
|
||||
|
||||
@@ -82,44 +79,36 @@ static void CAN_Motor_Decode(CAN_MotorFeedback_t *feedback,
|
||||
feedback->temp = raw[6];
|
||||
}
|
||||
|
||||
void CAN_Cap_Decode(CAN_CapFeedback_t *feedback, const uint8_t *raw)
|
||||
{
|
||||
void CAN_Cap_Decode(CAN_CapFeedback_t *feedback, const uint8_t *raw) {
|
||||
feedback->input_volt = (float)((raw[1] << 8) | raw[0]) / (float)CAN_CAP_RES;
|
||||
feedback->cap_volt = (float)((raw[3] << 8) | raw[2]) / (float)CAN_CAP_RES;
|
||||
feedback->input_curr = (float)((raw[5] << 8) | raw[4]) / (float)CAN_CAP_RES;
|
||||
feedback->target_power = (float)((raw[7] << 8) | raw[6]) / (float)CAN_CAP_RES;
|
||||
}
|
||||
|
||||
void CAN_Tof_Decode(CAN_Tof_t *tof, const uint8_t *raw)
|
||||
{
|
||||
void CAN_Tof_Decode(CAN_Tof_t *tof, const uint8_t *raw) {
|
||||
tof->dist = (float)((raw[2] << 16) | (raw[1] << 8) | raw[0]) / 1000.0f;
|
||||
tof->status = raw[3];
|
||||
tof->signal_strength = (raw[5] << 8) | raw[4];
|
||||
}
|
||||
|
||||
static void CAN_CAN1RxFifoMsgPendingCallback(void)
|
||||
{
|
||||
static void CAN_CAN1RxFifoMsgPendingCallback(void) {
|
||||
HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_1), CAN_MOTOR_RX_FIFO,
|
||||
&raw_rx1.rx_header, raw_rx1.rx_data);
|
||||
osMessageQueuePut(gcan->msgq_raw, &raw_rx1, 0, 0);
|
||||
}
|
||||
|
||||
static void CAN_CAN2RxFifoMsgPendingCallback(void)
|
||||
{
|
||||
static void CAN_CAN2RxFifoMsgPendingCallback(void) {
|
||||
HAL_CAN_GetRxMessage(BSP_CAN_GetHandle(BSP_CAN_2), CAN_CAP_RX_FIFO,
|
||||
&raw_rx2.rx_header, raw_rx2.rx_data);
|
||||
osMessageQueuePut(gcan->msgq_raw, &raw_rx2, 0, 0);
|
||||
}
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param)
|
||||
{
|
||||
if (can == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
if (inited)
|
||||
return DEVICE_ERR_INITED;
|
||||
if ((thread_alert = osThreadGetId()) == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param) {
|
||||
if (can == NULL) return DEVICE_ERR_NULL;
|
||||
if (inited) return DEVICE_ERR_INITED;
|
||||
if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL;
|
||||
|
||||
can->msgq_raw = osMessageQueueNew(32, sizeof(CAN_RawRx_t), NULL);
|
||||
|
||||
@@ -161,16 +150,13 @@ int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param)
|
||||
}
|
||||
|
||||
int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
|
||||
CAN_t *can)
|
||||
{
|
||||
if (output == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
CAN_t *can) {
|
||||
if (output == NULL) return DEVICE_ERR_NULL;
|
||||
|
||||
int16_t motor1, motor2, motor3, motor4;
|
||||
int16_t yaw_motor, pit_motor;
|
||||
int16_t fric1_motor, fric2_motor, fric3_motor, trig_motor;
|
||||
switch (group)
|
||||
{
|
||||
int16_t fric1_motor, fric2_motor, trig_motor;
|
||||
switch (group) {
|
||||
case CAN_MOTOR_GROUT_CHASSIS:
|
||||
motor1 =
|
||||
(int16_t)(output->chassis.named.m1 * (float)CAN_M3508_MAX_ABS_LSB);
|
||||
@@ -219,10 +205,7 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
|
||||
raw_tx.tx_data[6] = 0;
|
||||
raw_tx.tx_data[7] = 0;
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal.yaw),
|
||||
&raw_tx.tx_header, raw_tx.tx_data,
|
||||
&(can->mailbox.gimbal));
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal.pitch),
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->gimbal),
|
||||
&raw_tx.tx_header, raw_tx.tx_data,
|
||||
&(can->mailbox.gimbal));
|
||||
// HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot),
|
||||
@@ -236,8 +219,6 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
|
||||
(int16_t)(output->shoot.named.fric1 * (float)CAN_M3508_MAX_ABS_LSB);
|
||||
fric2_motor =
|
||||
(int16_t)(output->shoot.named.fric2 * (float)CAN_M3508_MAX_ABS_LSB);
|
||||
fric3_motor =
|
||||
(int16_t)(output->shoot.named.fric3 * (float)CAN_M3508_MAX_ABS_LSB);
|
||||
trig_motor =
|
||||
(int16_t)(output->shoot.named.trig * (float)CAN_M2006_MAX_ABS_LSB);
|
||||
|
||||
@@ -250,17 +231,14 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
|
||||
raw_tx.tx_data[1] = (uint8_t)(fric1_motor & 0xFF);
|
||||
raw_tx.tx_data[2] = (uint8_t)((fric2_motor >> 8) & 0xFF);
|
||||
raw_tx.tx_data[3] = (uint8_t)(fric2_motor & 0xFF);
|
||||
raw_tx.tx_data[4] = (uint8_t)((fric3_motor >> 8) & 0xFF);
|
||||
raw_tx.tx_data[5] = (uint8_t)(fric3_motor & 0xFF);
|
||||
raw_tx.tx_data[6] = (uint8_t)((trig_motor >> 8) & 0xFF);
|
||||
raw_tx.tx_data[7] = (uint8_t)(trig_motor & 0xFF);
|
||||
raw_tx.tx_data[4] = (uint8_t)((trig_motor >> 8) & 0xFF);
|
||||
raw_tx.tx_data[5] = (uint8_t)(trig_motor & 0xFF);
|
||||
raw_tx.tx_data[6] = 0;
|
||||
raw_tx.tx_data[7] = 0;
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->shoot),
|
||||
&raw_tx.tx_header, raw_tx.tx_data,
|
||||
&(can->mailbox.shoot));
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->trig),
|
||||
&raw_tx.tx_header, raw_tx.tx_data,
|
||||
&(can->mailbox.shoot));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -269,16 +247,12 @@ int8_t CAN_Motor_Control(CAN_MotorGroup_t group, CAN_Output_t *output,
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx)
|
||||
{
|
||||
if (can == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
if (can_rx == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx) {
|
||||
if (can == NULL) return DEVICE_ERR_NULL;
|
||||
if (can_rx == NULL) return DEVICE_ERR_NULL;
|
||||
|
||||
uint32_t index;
|
||||
switch (can_rx->rx_header.StdId)
|
||||
{
|
||||
switch (can_rx->rx_header.StdId) {
|
||||
case CAN_M3508_M1_ID:
|
||||
case CAN_M3508_M2_ID:
|
||||
case CAN_M3508_M3_ID:
|
||||
@@ -290,12 +264,12 @@ int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx)
|
||||
|
||||
case CAN_M3508_FRIC1_ID:
|
||||
case CAN_M3508_FRIC2_ID:
|
||||
case CAN_M3508_FRIC3_ID:
|
||||
case CAN_M2006_TRIG_ID:
|
||||
index = can_rx->rx_header.StdId - CAN_M3508_FRIC1_ID;
|
||||
can->recive_flag |= 1 << (index + 6);
|
||||
CAN_Motor_Decode(&(can->motor.shoot.as_array[index]), can_rx->rx_data);
|
||||
break;
|
||||
|
||||
case CAN_GM6020_YAW_ID:
|
||||
case CAN_GM6020_PIT_ID:
|
||||
index = can_rx->rx_header.StdId - CAN_GM6020_YAW_ID;
|
||||
@@ -310,84 +284,24 @@ int8_t CAN_StoreMsg(CAN_t *can, CAN_RawRx_t *can_rx)
|
||||
can->recive_flag |= 1 << 10;
|
||||
CAN_Tof_Decode(&(can->tof), can_rx->rx_data);
|
||||
break;
|
||||
//超电
|
||||
case 0x600:
|
||||
pm01_od.ccr = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.ccr = pm01_od.ccr;
|
||||
break;
|
||||
case 0x601:
|
||||
pm01_od.p_set = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.p_set = pm01_od.p_set;
|
||||
break;
|
||||
case 0x602:
|
||||
pm01_od.v_set = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.v_set = pm01_od.v_set;
|
||||
break;
|
||||
|
||||
case 0x603:
|
||||
pm01_od.i_set = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.i_set = pm01_od.i_set;
|
||||
break;
|
||||
|
||||
case 0x610:
|
||||
pm01_od.sta_code.all = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.sta_code.all = pm01_od.sta_code.all;
|
||||
pm01_od.err_code = (uint16_t)can_rx->rx_data[2] << 8 | can_rx->rx_data[3];
|
||||
can->cap.cap_od.err_code = pm01_od.err_code;
|
||||
break;
|
||||
|
||||
case 0x611:
|
||||
pm01_od.p_in = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.p_in = pm01_od.p_in;
|
||||
pm01_od.v_in = (uint16_t)can_rx->rx_data[2] << 8 | can_rx->rx_data[3];
|
||||
can->cap.cap_od.v_in = pm01_od.v_in;
|
||||
pm01_od.i_in = (uint16_t)can_rx->rx_data[4] << 8 | can_rx->rx_data[5];
|
||||
can->cap.cap_od.i_in = pm01_od.i_in;
|
||||
break;
|
||||
|
||||
case 0x612:
|
||||
pm01_od.p_out = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.p_out = pm01_od.p_out;
|
||||
pm01_od.v_out = (uint16_t)can_rx->rx_data[2] << 8 | can_rx->rx_data[3];
|
||||
can->cap.cap_od.v_out = pm01_od.v_out;
|
||||
pm01_od.i_out = (uint16_t)can_rx->rx_data[4] << 8 | can_rx->rx_data[5];
|
||||
can->cap.cap_od.i_out = pm01_od.i_out;
|
||||
break;
|
||||
|
||||
case 0x613:
|
||||
pm01_od.temp = (uint16_t)can_rx->rx_data[0] << 8 | can_rx->rx_data[1];
|
||||
can->cap.cap_od.temp = pm01_od.temp;
|
||||
pm01_od.total_time = (uint16_t)can_rx->rx_data[2] << 8 | can_rx->rx_data[3];
|
||||
can->cap.cap_od.total_time = pm01_od.total_time;
|
||||
pm01_od.run_time = (uint16_t)can_rx->rx_data[4] << 8 | can_rx->rx_data[5];
|
||||
can->cap.cap_od.run_time = pm01_od.run_time;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
bool CAN_CheckFlag(CAN_t *can, uint32_t flag)
|
||||
{
|
||||
if (can == NULL)
|
||||
return false;
|
||||
bool CAN_CheckFlag(CAN_t *can, uint32_t flag) {
|
||||
if (can == NULL) return false;
|
||||
return (can->recive_flag & flag) == flag;
|
||||
}
|
||||
|
||||
int8_t CAN_ClearFlag(CAN_t *can, uint32_t flag)
|
||||
{
|
||||
if (can == NULL)
|
||||
return DEVICE_ERR_NULL;
|
||||
int8_t CAN_ClearFlag(CAN_t *can, uint32_t flag) {
|
||||
if (can == NULL) return DEVICE_ERR_NULL;
|
||||
can->recive_flag &= ~flag;
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
//不用这里
|
||||
int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can) {
|
||||
float power_limit = output->power_limit;
|
||||
|
||||
uint16_t cap = (uint16_t)(power_limit * CAN_CAP_RES);
|
||||
@@ -405,203 +319,8 @@ int8_t CAN_Cap_Control(CAN_CapOutput_t *output, CAN_t *can)
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
//添加的电容控制 int型函数
|
||||
//超电控制
|
||||
/**
|
||||
* @brief 控制命令发送
|
||||
* @param[in] new_cmd 0x00: 停机
|
||||
0x01: 运行,不打开输出负载开关(只给超级电容充电)
|
||||
0x02: 运行,打开输出负载开关(正常运行使用该指令)
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_cmd_send(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
|
||||
uint16_t cmd = output->new_cmd;
|
||||
// uint16_t cmd = 2;
|
||||
|
||||
raw_tx.tx_header.StdId = 0x600;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_DATA;
|
||||
raw_tx.tx_header.DLC = 0x04;
|
||||
raw_tx.tx_data[0] = (uint8_t)(cmd >> 8 );
|
||||
raw_tx.tx_data[1] = (uint8_t)(cmd & 0xFF);
|
||||
raw_tx.tx_data[2] = 0x00;
|
||||
raw_tx.tx_data[3] = (0x00 == 0x01); //反正demo里设置的是0x00,不管了
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置功率
|
||||
* @param[in] new_power:新的功率值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_power_send(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
uint16_t cmd = output->new_power;
|
||||
//uint16_t cmd = 5000;
|
||||
|
||||
raw_tx.tx_header.StdId = 0x601;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_DATA;
|
||||
raw_tx.tx_header.DLC = 0x04;
|
||||
raw_tx.tx_data[0] = (uint8_t)(cmd >> 8 );
|
||||
raw_tx.tx_data[1] = (uint8_t)(cmd & 0xFF);
|
||||
raw_tx.tx_data[2] = 0x00;
|
||||
raw_tx.tx_data[3] = (0x00 == 0x01); //save_flg
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置输出电压
|
||||
* @param[in] new_volt:新的电压值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_voltage_send(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
uint16_t cmd = output->new_voltage;
|
||||
// uint16_t cmd = 2400;
|
||||
|
||||
raw_tx.tx_header.StdId = 0x602;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_DATA;
|
||||
raw_tx.tx_header.DLC = 0x04;
|
||||
raw_tx.tx_data[0] = (uint8_t)(cmd >> 8 );
|
||||
raw_tx.tx_data[1] = (uint8_t)(cmd & 0xFF);
|
||||
raw_tx.tx_data[2] = 0x00;
|
||||
raw_tx.tx_data[3] = (0x00 == 0x01); //save_flg
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief 设置输出电流
|
||||
* @param[in] new_volt:新的电流值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_current_send(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
uint16_t cmd = output->new_current;
|
||||
// uint16_t cmd = 500;
|
||||
|
||||
raw_tx.tx_header.StdId = 0x603;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_DATA;
|
||||
raw_tx.tx_header.DLC = 0x04;
|
||||
raw_tx.tx_data[0] = (uint8_t)(cmd >> 8 );
|
||||
raw_tx.tx_data[1] = (uint8_t)(cmd & 0xFF);
|
||||
raw_tx.tx_data[2] = 0x00;
|
||||
raw_tx.tx_data[3] = (0x00 == 0x01); //save_flg
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取输入信息
|
||||
* @param[in] new_volt:新的电流值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_input_send(CAN_t *can)
|
||||
{
|
||||
|
||||
raw_tx.tx_header.StdId = 0x611;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_REMOTE;
|
||||
raw_tx.tx_header.DLC = 0x00;
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取输出信息
|
||||
* @param[in] new_volt:新的电流值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_output_send(CAN_t *can)
|
||||
{
|
||||
|
||||
raw_tx.tx_header.StdId = 0x612;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_REMOTE;
|
||||
raw_tx.tx_header.DLC = 0x00;
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取其他信息
|
||||
* @param[in] new_volt:新的电流值
|
||||
save_flg: 0x00: 不保存至EEPROM 0x01: 保存至EEPROM
|
||||
* @retval none
|
||||
*/
|
||||
int8_t CAN_Cap_other_send(CAN_t *can)
|
||||
{
|
||||
raw_tx.tx_header.StdId = 0x613;
|
||||
raw_tx.tx_header.IDE = CAN_ID_STD;
|
||||
raw_tx.tx_header.RTR = CAN_RTR_REMOTE;
|
||||
raw_tx.tx_header.DLC = 0x00;
|
||||
|
||||
HAL_CAN_AddTxMessage(BSP_CAN_GetHandle(can->param->cap), &raw_tx.tx_header,
|
||||
raw_tx.tx_data, &(can->mailbox.cap));
|
||||
return DEVICE_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 超电容器参数设置
|
||||
* @param cap_out 电容输出结构体
|
||||
* @param can can总线
|
||||
* @retval none
|
||||
*/
|
||||
void Can_Set_send(CAN_CapOutput_t *output, CAN_t *can)
|
||||
{
|
||||
|
||||
CAN_Cap_input_send(can);//获取输入信息
|
||||
osDelay(1);
|
||||
CAN_Cap_output_send(can);//获取输出信息
|
||||
osDelay(1);
|
||||
//// CAN_Cap_other_send(can);//获取其他信息
|
||||
//// osDelay(1);
|
||||
CAN_Cap_cmd_send(output, can);//控制命令发送
|
||||
osDelay(1);
|
||||
CAN_Cap_power_send(output, can);//设置功率
|
||||
osDelay(1);
|
||||
CAN_Cap_voltage_send(output, can);//设置输出电压
|
||||
osDelay(1);
|
||||
CAN_Cap_current_send(output, can);//设置输出电流
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CAN_CAP_HandleOffline(CAN_Capacitor_t *cap, CAN_CapOutput_t *cap_out,
|
||||
float power_chassis)
|
||||
{
|
||||
float power_chassis) {
|
||||
cap->cap_status = CAN_CAP_STATUS_OFFLINE;
|
||||
cap_out->power_limit = power_chassis;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,9 @@ extern "C" {
|
||||
#define CAN_MOTOR_GIMBAL_PIT_RECV (1 << 5)
|
||||
#define CAN_MOTOR_SHOOT_FRIC1_RECV (1 << 6)
|
||||
#define CAN_MOTOR_SHOOT_FRIC2_RECV (1 << 7)
|
||||
#define CAN_MOTOR_SHOOT_FRIC3_RECV (1 << 8)
|
||||
#define CAN_MOTOR_SHOOT_TRIG_RECV (1 << 9)
|
||||
#define CAN_MOTOR_CAP_RECV (1 << 10)
|
||||
#define CAN_TOF_RECV (1 << 11)
|
||||
#define CAN_MOTOR_SHOOT_TRIG_RECV (1 << 8)
|
||||
#define CAN_MOTOR_CAP_RECV (1 << 9)
|
||||
#define CAN_TOF_RECV (1 << 10)
|
||||
|
||||
#define CAN_REC_CHASSIS_FINISHED \
|
||||
(CAN_MOTOR_CHASSIS_1_RECV | CAN_MOTOR_CHASSIS_2_RECV | \
|
||||
@@ -34,7 +33,7 @@ extern "C" {
|
||||
(CAN_MOTOR_GIMBAL_YAW_RECV | CAN_MOTOR_GIMBAL_PIT_RECV)
|
||||
#define CAN_REC_SHOOT_FINISHED \
|
||||
(CAN_MOTOR_SHOOT_FRIC1_RECV | CAN_MOTOR_SHOOT_FRIC2_RECV | \
|
||||
CAN_MOTOR_SHOOT_FRIC3_RECV |CAN_MOTOR_SHOOT_TRIG_RECV)
|
||||
CAN_MOTOR_SHOOT_TRIG_RECV)
|
||||
#define CAN_REC_CAP_FINISHED CAN_MOTOR_CAP_RECV
|
||||
#define CAN_REC_TOF_FINISHED CAN_TOF_RECV
|
||||
|
||||
@@ -73,23 +72,16 @@ typedef enum {
|
||||
|
||||
CAN_M3508_FRIC1_ID = 0x205, /* 5 */
|
||||
CAN_M3508_FRIC2_ID = 0x206, /* 6 */
|
||||
CAN_M3508_FRIC3_ID = 0x207, /* 7 */
|
||||
CAN_M2006_TRIG_ID = 0x208, /* 8 */
|
||||
CAN_M2006_TRIG_ID = 0x207, /* 7 */
|
||||
|
||||
CAN_GM6020_YAW_ID = 0x209, /* 5 */
|
||||
CAN_GM6020_PIT_ID = 0x20A, /* 6 */
|
||||
} CAN_MotorId_t;
|
||||
|
||||
typedef struct {
|
||||
BSP_CAN_t yaw;
|
||||
BSP_CAN_t pitch;
|
||||
} Gimbal_CAN_t;
|
||||
|
||||
typedef struct {
|
||||
BSP_CAN_t chassis;
|
||||
Gimbal_CAN_t gimbal;
|
||||
BSP_CAN_t gimbal;
|
||||
BSP_CAN_t shoot;
|
||||
BSP_CAN_t trig;
|
||||
BSP_CAN_t cap;
|
||||
} CAN_Params_t;
|
||||
|
||||
@@ -118,7 +110,6 @@ enum CAN_MotorGimbal_e {
|
||||
enum CAN_MotorShoot_e {
|
||||
CAN_MOTOR_SHOOT_FRIC1 = 0,
|
||||
CAN_MOTOR_SHOOT_FRIC2,
|
||||
CAN_MOTOR_SHOOT_FRIC3,
|
||||
CAN_MOTOR_SHOOT_TRIG,
|
||||
CAN_MOTORSHOOT_NUM,
|
||||
};
|
||||
@@ -156,17 +147,12 @@ typedef union {
|
||||
struct {
|
||||
float fric1;
|
||||
float fric2;
|
||||
float fric3;
|
||||
float trig;
|
||||
} named;
|
||||
} CAN_ShootOutput_t;
|
||||
|
||||
typedef struct {
|
||||
float power_limit;
|
||||
uint16_t new_cmd;//can的超电控制设置数值
|
||||
uint16_t new_power;
|
||||
uint16_t new_voltage;
|
||||
uint16_t new_current;
|
||||
} CAN_CapOutput_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -214,7 +200,6 @@ typedef union {
|
||||
struct {
|
||||
CAN_MotorFeedback_t fric1;
|
||||
CAN_MotorFeedback_t fric2;
|
||||
CAN_MotorFeedback_t fric3;
|
||||
CAN_MotorFeedback_t trig;
|
||||
} named;
|
||||
} CAN_ShootMotor_t;
|
||||
@@ -236,61 +221,11 @@ typedef struct {
|
||||
uint8_t tx_data[CAN_TX_BUF_SIZE_MAX];
|
||||
} CAN_RawTx_t;
|
||||
|
||||
//超电
|
||||
typedef union
|
||||
{
|
||||
|
||||
uint16_t all;
|
||||
struct {
|
||||
uint16_t rdy: 1; /*!< bit0 就绪 */
|
||||
uint16_t run: 1; /*!< bit1 运行 */
|
||||
uint16_t alm: 1; /*!< bit2 报警 */
|
||||
uint16_t pwr: 1; /*!< bit3 电源开关 */
|
||||
uint16_t load: 1; /*!< bit4 负载开关 */
|
||||
uint16_t cc: 1; /*!< bit5 恒流 */
|
||||
uint16_t cv: 1; /*!< bit6 恒压 */
|
||||
uint16_t cw: 1; /*!< bit7 恒功率 */
|
||||
uint16_t revd: 7; /*!< bit8-14 保留 */
|
||||
uint16_t flt: 1; /*!< bit15 故障 */
|
||||
}bit;
|
||||
|
||||
}csr_t;
|
||||
|
||||
typedef struct mb_reg_type{
|
||||
|
||||
uint16_t ccr; /*!< 8000H 控制寄存器 */
|
||||
uint16_t p_set; /*!< 8001H 输入功率限制 */
|
||||
uint16_t v_set; /*!< 8002H 输出电压设置 */
|
||||
uint16_t i_set; /*!< 8003H 输出电流限制 */
|
||||
csr_t sta_code; /*!< 8100H 状态标志位 */
|
||||
uint16_t err_code; /*!< 8101H 故障代码 */
|
||||
int16_t v_in; /*!< 8102H 输入电压 */
|
||||
int16_t i_in; /*!< 8103H 输入电流 */
|
||||
int16_t p_in; /*!< 8104H 输入功率 */
|
||||
int16_t v_out; /*!< 8105H 输出电压 */
|
||||
int16_t i_out; /*!< 8106H 输出电流 */
|
||||
int16_t p_out; /*!< 8107H 输出功率 */
|
||||
int16_t temp; /*!< 8108H 温度 */
|
||||
uint16_t total_time; /*!< 8109H 累计时间 */
|
||||
uint16_t run_time; /*!< 810AH 运行时间 */
|
||||
|
||||
volatile uint16_t pm01_access_id; /* 正在访问的标识符 */
|
||||
volatile uint16_t pm01_response_flg; /* 控制器响应成功标志位 */
|
||||
|
||||
uint16_t g_cmd_set ;
|
||||
uint16_t g_power_set ;
|
||||
uint16_t g_vout_set ;
|
||||
uint16_t g_iout_set ;
|
||||
|
||||
}pm01_od_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
float percentage;// 电容器的百分比状态
|
||||
float percentage;
|
||||
CAN_CapStatus_t cap_status;
|
||||
CAN_CapFeedback_t cap_feedback;
|
||||
volatile pm01_od_t cap_od;
|
||||
} CAN_Capacitor_t;//
|
||||
} CAN_Capacitor_t;
|
||||
|
||||
typedef struct {
|
||||
CAN_ChassisMotor_t chassis;
|
||||
@@ -337,16 +272,6 @@ void CAN_CAP_HandleOffline(CAN_Capacitor_t *cap, CAN_CapOutput_t *cap_out,
|
||||
|
||||
void CAN_Tof_Decode(CAN_Tof_t *tof, const uint8_t *raw);
|
||||
|
||||
//添加send函数
|
||||
int8_t CAN_Cap_cmd_send(CAN_CapOutput_t *output, CAN_t *can);
|
||||
int8_t CAN_Cap_power_send(CAN_CapOutput_t *output, CAN_t *can);
|
||||
int8_t CAN_Cap_voltage_send(CAN_CapOutput_t *output, CAN_t *can);
|
||||
int8_t CAN_Cap_current_send(CAN_CapOutput_t *output, CAN_t *can);
|
||||
int8_t CAN_Cap_output_send(CAN_t *can);
|
||||
int8_t CAN_Cap_input_send(CAN_t *can);
|
||||
int8_t CAN_Cap_other_send(CAN_t *can);
|
||||
void Can_Set_send(CAN_CapOutput_t *output, CAN_t *can);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -116,27 +116,23 @@ void Referee_HandleOffline(Referee_t *referee) {
|
||||
}
|
||||
|
||||
int8_t Referee_Parse(Referee_t *ref) {
|
||||
// 将裁判系统状态切换为运行状态
|
||||
REF_SWITCH_STATUS(*ref, REF_STATUS_RUNNING);
|
||||
|
||||
// 计算接收到的数据长度
|
||||
uint32_t data_length = REF_LEN_RX_BUFF - __HAL_DMA_GET_COUNTER(BSP_UART_GetHandle(BSP_UART_REF)->hdmarx);
|
||||
uint32_t data_length =
|
||||
REF_LEN_RX_BUFF -
|
||||
__HAL_DMA_GET_COUNTER(BSP_UART_GetHandle(BSP_UART_REF)->hdmarx);
|
||||
|
||||
uint8_t index = 0;
|
||||
uint8_t packet_shift;
|
||||
uint8_t packet_length;
|
||||
|
||||
// 遍历接收到的数据包
|
||||
while (index < data_length && rxbuf[index] == REF_HEADER_SOF) {
|
||||
packet_shift = index;
|
||||
Referee_Header_t *header = (Referee_Header_t *)(rxbuf + index);
|
||||
index += sizeof(*header);
|
||||
if (index - packet_shift >= data_length) goto error;
|
||||
|
||||
// 验证CRC8校验
|
||||
if (!CRC8_Verify((uint8_t *)header, sizeof(*header))) goto error;
|
||||
|
||||
// 验证数据包头
|
||||
if (header->sof != REF_HEADER_SOF) goto error;
|
||||
|
||||
Referee_CMDID_t *cmd_id = (Referee_CMDID_t *)(rxbuf + index);
|
||||
@@ -147,7 +143,6 @@ int8_t Referee_Parse(Referee_t *ref) {
|
||||
void *origin;
|
||||
size_t size;
|
||||
|
||||
// 根据命令ID解析数据包内容
|
||||
switch (*cmd_id) {
|
||||
case REF_CMD_ID_GAME_STATUS:
|
||||
origin = &(ref->game_status);
|
||||
@@ -161,10 +156,25 @@ int8_t Referee_Parse(Referee_t *ref) {
|
||||
origin = &(ref->game_robot_hp);
|
||||
size = sizeof(ref->game_robot_hp);
|
||||
break;
|
||||
case REF_CMD_ID_DART_STATUS:
|
||||
origin = &(ref->dart_status);
|
||||
size = sizeof(ref->dart_status);
|
||||
break;
|
||||
case REF_CMD_ID_ICRA_ZONE_STATUS:
|
||||
origin = &(ref->icra_zone);
|
||||
size = sizeof(ref->icra_zone);
|
||||
break;
|
||||
case REF_CMD_ID_FIELD_EVENTS:
|
||||
origin = &(ref->field_event);
|
||||
size = sizeof(ref->field_event);
|
||||
break;
|
||||
case REF_CMD_ID_SUPPLY_ACTION:
|
||||
origin = &(ref->supply_action);
|
||||
size = sizeof(ref->supply_action);
|
||||
break;
|
||||
case REF_CMD_ID_REQUEST_SUPPLY:
|
||||
origin = &(ref->request_supply);
|
||||
size = sizeof(ref->request_supply);
|
||||
case REF_CMD_ID_WARNING:
|
||||
origin = &(ref->warning);
|
||||
size = sizeof(ref->warning);
|
||||
@@ -189,6 +199,10 @@ int8_t Referee_Parse(Referee_t *ref) {
|
||||
origin = &(ref->robot_buff);
|
||||
size = sizeof(ref->robot_buff);
|
||||
break;
|
||||
case REF_CMD_ID_DRONE_ENERGY:
|
||||
origin = &(ref->drone_energy);
|
||||
size = sizeof(ref->drone_energy);
|
||||
break;
|
||||
case REF_CMD_ID_ROBOT_DMG:
|
||||
origin = &(ref->robot_danage);
|
||||
size = sizeof(ref->robot_danage);
|
||||
@@ -209,71 +223,26 @@ int8_t Referee_Parse(Referee_t *ref) {
|
||||
origin = &(ref->dart_client);
|
||||
size = sizeof(ref->dart_client);
|
||||
break;
|
||||
case REF_CMD_ID_ROBOT_POS_TO_SENTRY:
|
||||
origin = &(ref->pos_sentry);
|
||||
size = sizeof(ref->pos_sentry);
|
||||
break;
|
||||
case REF_CMD_ID_RADAR_MARK:
|
||||
origin = &(ref->radar_mark);
|
||||
size = sizeof(ref->radar_mark);
|
||||
break;
|
||||
case REF_CMD_ID_SENTRY_DECISION:
|
||||
origin = &(ref->sentry_decision);
|
||||
size = sizeof(ref->sentry_decision);
|
||||
break;
|
||||
case REF_CMD_ID_RADAR_DECISION:
|
||||
origin = &(ref->radar_decision);
|
||||
size = sizeof(ref->radar_decision);
|
||||
break;
|
||||
case REF_CMD_ID_INTER_STUDENT:
|
||||
origin = &(ref->interactive_data);
|
||||
size = sizeof(ref->interactive_data);
|
||||
break;
|
||||
case REF_CMD_ID_INTER_STUDENT_CUSTOM:
|
||||
origin = &(ref->custom_robot_data);
|
||||
size = sizeof(ref->custom_robot_data);
|
||||
break;
|
||||
origin = &(ref->custom);
|
||||
size = sizeof(ref->custom);
|
||||
case REF_CMD_ID_CLIENT_MAP:
|
||||
origin = &(ref->client_map);
|
||||
size = sizeof(ref->client_map);
|
||||
break;
|
||||
case REF_CMD_ID_KEYBOARD_MOUSE:
|
||||
origin = &(ref->keyboard_mouse);
|
||||
size = sizeof(ref->keyboard_mouse);
|
||||
break;
|
||||
case REF_CMD_ID_MAP_ROBOT_DATA:
|
||||
origin = &(ref->map_robot_data);
|
||||
size = sizeof(ref->map_robot_data);
|
||||
break;
|
||||
case REF_CMD_ID_CUSTOM_KEYBOARD_MOUSE:
|
||||
origin = &(ref->custom_keyboard_mouse);
|
||||
size = sizeof(ref->custom_keyboard_mouse);
|
||||
break;
|
||||
case REF_CMD_ID_SENTRY_POS_DATA:
|
||||
origin = &(ref->sentry_pos_data);
|
||||
size = sizeof(ref->sentry_pos_data);
|
||||
break;
|
||||
case REF_CMD_ID_ROBOT_POS_DATA:
|
||||
origin = &(ref->custom_info);
|
||||
size = sizeof(ref->custom_info);
|
||||
break;
|
||||
case REF_CMD_ID_DATA:
|
||||
origin = &(ref->custom_data);
|
||||
size = sizeof(ref->custom_data);
|
||||
break;
|
||||
default:
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
|
||||
// 计算数据包长度
|
||||
packet_length = sizeof(Referee_Header_t) + sizeof(Referee_CMDID_t) + size + sizeof(Referee_Tail_t);
|
||||
packet_length = sizeof(Referee_Header_t) + sizeof(Referee_CMDID_t) + size +
|
||||
sizeof(Referee_Tail_t);
|
||||
index += size;
|
||||
if (index - packet_shift >= data_length) goto error;
|
||||
|
||||
index += sizeof(Referee_Tail_t);
|
||||
if (index - packet_shift != packet_length) goto error;
|
||||
|
||||
// 验证CRC16校验并复制数据
|
||||
if (CRC16_Verify((uint8_t *)(rxbuf + packet_shift), packet_length))
|
||||
memcpy(origin, target, size);
|
||||
else
|
||||
@@ -303,12 +272,8 @@ int8_t Referee_MoveData(void *data, void *tmp, uint32_t len) {
|
||||
|
||||
int8_t Referee_SetHeader(Referee_Interactive_Header_t *header,
|
||||
Referee_StudentCMDID_t cmd_id, uint8_t sender_id) {
|
||||
// 设置数据命令ID
|
||||
header->data_cmd_id = cmd_id;
|
||||
|
||||
// 根据发送者ID设置发送者和接收者ID
|
||||
if (sender_id <= REF_BOT_RED_RADER) {
|
||||
switch (sender_id) {
|
||||
if (sender_id <= REF_BOT_RED_RADER) switch (sender_id) {
|
||||
case REF_BOT_RED_HERO:
|
||||
header->sender_ID = REF_BOT_RED_HERO;
|
||||
header->receiver_ID = REF_CL_RED_HERO;
|
||||
@@ -340,9 +305,9 @@ int8_t Referee_SetHeader(Referee_Interactive_Header_t *header,
|
||||
header->sender_ID = REF_BOT_RED_RADER;
|
||||
break;
|
||||
default:
|
||||
return -1; // 无效的发送者ID
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
else
|
||||
switch (sender_id) {
|
||||
case REF_BOT_BLU_HERO:
|
||||
header->sender_ID = REF_BOT_BLU_HERO;
|
||||
@@ -375,10 +340,9 @@ int8_t Referee_SetHeader(Referee_Interactive_Header_t *header,
|
||||
header->sender_ID = REF_BOT_BLU_RADER;
|
||||
break;
|
||||
default:
|
||||
return -1; // 无效的发送者ID
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0; // 成功
|
||||
return 0;
|
||||
}
|
||||
|
||||
int8_t Referee_PackUI(Referee_UI_t *ui, Referee_t *ref) {
|
||||
|
||||
@@ -21,11 +21,11 @@ extern "C" {
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
#define REF_SWITCH_STATUS(ref, stat) ((ref).ref_status = (stat))
|
||||
#define CHASSIS_POWER_MAX_WITHOUT_REF 2000.0f /* 裁判系统离线底盘最大功率 */
|
||||
#define CHASSIS_POWER_MAX_WITHOUT_REF 50.0f /* 裁判系统离线底盘最大功率 */
|
||||
|
||||
#define REF_UI_MAX_GRAPIC_NUM (7) /* 最大图形数量 */
|
||||
#define REF_UI_MAX_STRING_NUM (7) /* 最大字符串数量 */
|
||||
#define REF_UI_MAX_DEL_NUM (3) /* 最大删除数量 */
|
||||
#define REF_UI_MAX_GRAPIC_NUM (7)
|
||||
#define REF_UI_MAX_STRING_NUM (7)
|
||||
#define REF_UI_MAX_DEL_NUM (3)
|
||||
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
typedef struct __packed {
|
||||
@@ -38,39 +38,30 @@ typedef struct __packed {
|
||||
typedef enum { REF_STATUS_OFFLINE = 0, REF_STATUS_RUNNING } Referee_Status_t;
|
||||
|
||||
typedef enum {
|
||||
REF_CMD_ID_GAME_STATUS = 0x0001, //比赛状态数据,固定以1Hz频率发送
|
||||
REF_CMD_ID_GAME_RESULT = 0x0002, //比赛结果数据,比赛结束触发发送
|
||||
REF_CMD_ID_GAME_ROBOT_HP = 0x0003, //机器人血量数据,固定以3Hz频率发送
|
||||
//REF_CMD_ID_DART_STATUS = 0x0004,
|
||||
// REF_CMD_ID_ICRA_ZONE_STATUS = 0x0005,
|
||||
REF_CMD_ID_FIELD_EVENTS = 0x0101, //场地事件数据,固定以1Hz频率发送
|
||||
//REF_CMD_ID_SUPPLY_ACTION = 0x0102,
|
||||
//REF_CMD_ID_REQUEST_SUPPLY = 0x0103,
|
||||
REF_CMD_ID_WARNING = 0x0104, //裁判警告数据
|
||||
REF_CMD_ID_DART_COUNTDOWN = 0x0105, //飞镖发射相关数据
|
||||
REF_CMD_ID_ROBOT_STATUS = 0x0201, //机器人性能体系数据
|
||||
REF_CMD_ID_POWER_HEAT_DATA = 0x0202, //实时底盘缓冲能量和射击热量数据
|
||||
REF_CMD_ID_ROBOT_POS = 0x0203, //机器人位置数据
|
||||
REF_CMD_ID_ROBOT_BUFF = 0x0204, //机器人增益和底盘能量数据
|
||||
//REF_CMD_ID_DRONE_ENERGY = 0x0205,
|
||||
REF_CMD_ID_ROBOT_DMG = 0x0206, //伤害状态数据
|
||||
REF_CMD_ID_SHOOT_DATA = 0x0207, //实时射击数据
|
||||
REF_CMD_ID_BULLET_REMAINING = 0x0208, //允许发弹量
|
||||
REF_CMD_ID_RFID = 0x0209, //机器人RFID模块状态
|
||||
REF_CMD_ID_DART_CLIENT = 0x020A, //飞镖选手端指令数据
|
||||
REF_CMD_ID_ROBOT_POS_TO_SENTRY = 0X020B, //地面机器人位置数据
|
||||
REF_CMD_ID_RADAR_MARK = 0X020C, //雷达标记进度数据
|
||||
REF_CMD_ID_SENTRY_DECISION = 0x020D, //哨兵自主决策相关信息同步
|
||||
REF_CMD_ID_RADAR_DECISION = 0x020E, //雷达自主决策相关信息同步
|
||||
REF_CMD_ID_INTER_STUDENT = 0x0301, //机器人交互数据
|
||||
REF_CMD_ID_INTER_STUDENT_CUSTOM = 0x0302, //自定义控制器与机器人交互数据
|
||||
REF_CMD_ID_CLIENT_MAP = 0x0303, //选手端小地图交互数据
|
||||
REF_CMD_ID_KEYBOARD_MOUSE = 0x0304, //键鼠遥控数据
|
||||
REF_CMD_ID_MAP_ROBOT_DATA = 0x0305, //选手端小地图接收雷达数据
|
||||
REF_CMD_ID_CUSTOM_KEYBOARD_MOUSE = 0X0306, //自定义控制器与选手端交互数据
|
||||
REF_CMD_ID_SENTRY_POS_DATA = 0x0307, //选手端小地图接收哨兵数据
|
||||
REF_CMD_ID_ROBOT_POS_DATA = 0x0308, //选手端小地图接受机器人消息
|
||||
REF_CMD_ID_DATA = 0x0309, //自定义控制器接收机器人数据
|
||||
REF_CMD_ID_GAME_STATUS = 0x0001,
|
||||
REF_CMD_ID_GAME_RESULT = 0x0002,
|
||||
REF_CMD_ID_GAME_ROBOT_HP = 0x0003,
|
||||
REF_CMD_ID_DART_STATUS = 0x0004,
|
||||
REF_CMD_ID_ICRA_ZONE_STATUS = 0x0005,
|
||||
REF_CMD_ID_FIELD_EVENTS = 0x0101,
|
||||
REF_CMD_ID_SUPPLY_ACTION = 0x0102,
|
||||
REF_CMD_ID_REQUEST_SUPPLY = 0x0103,
|
||||
REF_CMD_ID_WARNING = 0x0104,
|
||||
REF_CMD_ID_DART_COUNTDOWN = 0x0105,
|
||||
REF_CMD_ID_ROBOT_STATUS = 0x0201,
|
||||
REF_CMD_ID_POWER_HEAT_DATA = 0x0202,
|
||||
REF_CMD_ID_ROBOT_POS = 0x0203,
|
||||
REF_CMD_ID_ROBOT_BUFF = 0x0204,
|
||||
REF_CMD_ID_DRONE_ENERGY = 0x0205,
|
||||
REF_CMD_ID_ROBOT_DMG = 0x0206,
|
||||
REF_CMD_ID_SHOOT_DATA = 0x0207,
|
||||
REF_CMD_ID_BULLET_REMAINING = 0x0208,
|
||||
REF_CMD_ID_RFID = 0x0209,
|
||||
REF_CMD_ID_DART_CLIENT = 0x020A,
|
||||
REF_CMD_ID_INTER_STUDENT = 0x0301,
|
||||
REF_CMD_ID_INTER_STUDENT_CUSTOM = 0x0302,
|
||||
REF_CMD_ID_CLIENT_MAP = 0x0303,
|
||||
REF_CMD_ID_KEYBOARD_MOUSE = 0x0304,
|
||||
} Referee_CMDID_t;
|
||||
|
||||
typedef struct __packed {
|
||||
@@ -78,18 +69,19 @@ typedef struct __packed {
|
||||
uint8_t game_progress : 4;
|
||||
uint16_t stage_remain_time;
|
||||
uint64_t sync_time_stamp;
|
||||
} Referee_GameStatus_t;/* 0x0001 */
|
||||
} Referee_GameStatus_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t winner;
|
||||
} Referee_GameResult_t;/* 0x0002 */
|
||||
} Referee_GameResult_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint16_t red_1;
|
||||
uint16_t red_2;
|
||||
uint16_t red_3;
|
||||
uint16_t red_4;
|
||||
uint16_t reserved;
|
||||
uint16_t red_5;
|
||||
uint16_t red_6;
|
||||
uint16_t red_7;
|
||||
uint16_t red_outpose;
|
||||
uint16_t red_base;
|
||||
@@ -97,11 +89,12 @@ typedef struct __packed {
|
||||
uint16_t blue_2;
|
||||
uint16_t blue_3;
|
||||
uint16_t blue_4;
|
||||
uint16_t reserved1;
|
||||
uint16_t blue_5;
|
||||
uint16_t blue_6;
|
||||
uint16_t blue_7;
|
||||
uint16_t blue_outpose;
|
||||
uint16_t blue_base;
|
||||
} Referee_GameRobotHP_t;/* 0x0003 */
|
||||
} Referee_GameRobotHP_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t dart_belong;
|
||||
@@ -128,44 +121,51 @@ typedef struct __packed {
|
||||
} Referee_ICRAZoneStatus_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint32_t exchange_nooverlap_status : 1;
|
||||
uint32_t exchange_overlap_status : 1;
|
||||
uint32_t supply_status : 1;
|
||||
uint32_t energy_mech_small_status : 1;
|
||||
uint32_t energy_mech_big_status : 1;
|
||||
uint32_t highland_annular : 2;
|
||||
uint32_t highland_trapezium_1 : 2;
|
||||
uint32_t last_hit_time : 9;
|
||||
uint32_t last_hit_target : 3;
|
||||
uint32_t activation_status : 2;
|
||||
uint32_t res : 9;
|
||||
} Referee_FieldEvents_t;/* 0x0101 */
|
||||
uint8_t copter_pad : 2;
|
||||
uint8_t energy_mech : 2;
|
||||
uint8_t virtual_shield : 1;
|
||||
uint32_t res : 27;
|
||||
} Referee_FieldEvents_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t supply_id;
|
||||
uint8_t robot_id;
|
||||
uint8_t supply_step;
|
||||
uint8_t supply_sum;
|
||||
} Referee_SupplyAction_t;/* 0x0102 */
|
||||
} Referee_SupplyAction_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t place_holder; /* TODO */
|
||||
} Referee_RequestSupply_t;/* 0x0103 */
|
||||
} Referee_RequestSupply_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t level;
|
||||
uint8_t robot_id;
|
||||
uint8_t count;
|
||||
} Referee_Warning_t;/* 0x0104 */
|
||||
} Referee_Warning_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t countdown;
|
||||
uint16_t dart_last_target : 3;
|
||||
uint16_t attack_count : 2;
|
||||
uint16_t dart_target : 2;
|
||||
uint16_t res : 8;
|
||||
} Referee_DartCountdown_t;/* 0x0105 */
|
||||
} Referee_DartCountdown_t;
|
||||
|
||||
// typedef struct __packed {
|
||||
// uint8_t robot_id;
|
||||
// uint8_t robot_level;
|
||||
// uint16_t remain_hp;
|
||||
// uint16_t max_hp;
|
||||
// uint16_t shoot_id1_17_cooling_rate;
|
||||
// uint16_t shoot_id1_17_heat_limit;
|
||||
// uint16_t shoot_id1_17_speed_limit;
|
||||
// uint16_t shoot_id2_17_cooling_rate;
|
||||
// uint16_t shoot_id2_17_heat_limit;
|
||||
// uint16_t shoot_id2_17_speed_limit;
|
||||
// uint16_t shoot_42_cooling_rate;
|
||||
// uint16_t shoot_42_heat_limit;
|
||||
// uint16_t shoot_42_speed_limit;
|
||||
// uint16_t chassis_power_limit;
|
||||
// uint8_t power_gimbal_output : 1;
|
||||
// uint8_t power_chassis_output : 1;
|
||||
// uint8_t power_shoot_output : 1;
|
||||
// } Referee_RobotStatus_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t robot_id;
|
||||
@@ -188,15 +188,22 @@ typedef struct __packed {
|
||||
uint16_t shoot_id1_17_heat;
|
||||
uint16_t shoot_id2_17_heat;
|
||||
uint16_t shoot_42_heat;
|
||||
} Referee_PowerHeat_t; /* 0x0202 */
|
||||
} Referee_PowerHeat_t;
|
||||
|
||||
typedef struct __packed {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float yaw;
|
||||
} Referee_RobotPos_t; /* 0x0203 */
|
||||
} Referee_RobotPos_t;
|
||||
|
||||
// typedef struct __packed {
|
||||
// uint8_t healing : 1;
|
||||
// uint8_t cooling_acc : 1;
|
||||
// uint8_t defense_buff : 1;
|
||||
// uint8_t attack_buff : 1;
|
||||
// uint8_t res : 4;
|
||||
// } Referee_RobotBuff_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t healing_buff;
|
||||
@@ -204,17 +211,16 @@ typedef struct __packed {
|
||||
uint8_t defense_buff;
|
||||
uint8_t vulnerability_buff;
|
||||
uint16_t attack_buff;
|
||||
uint8_t remaining_energy;
|
||||
} Referee_RobotBuff_t; /* 0x0204 */
|
||||
} Referee_RobotBuff_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t attack_countdown;
|
||||
} Referee_DroneEnergy_t; /* 0x0205 *///删
|
||||
} Referee_DroneEnergy_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t armor_id : 4;
|
||||
uint8_t damage_type : 4;
|
||||
} Referee_RobotDamage_t; /* 0x0206 */
|
||||
} Referee_RobotDamage_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t bullet_type;
|
||||
@@ -227,106 +233,38 @@ typedef struct __packed {
|
||||
uint16_t bullet_17_remain;
|
||||
uint16_t bullet_42_remain;
|
||||
uint16_t coin_remain;
|
||||
} Referee_BulletRemain_t;/* 0x0208 */
|
||||
} Referee_BulletRemain_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint32_t own_base : 1; //0
|
||||
uint32_t own_highland_annular : 1; //1
|
||||
uint32_t enemy_highland_annular : 1; //2
|
||||
uint32_t own_trapezium_R3B3 : 1; //3
|
||||
uint32_t enemy_trapezium_R3B3 : 1; //4
|
||||
uint32_t own_slope_before : 1; //坡道前5
|
||||
uint32_t own_slope_after : 1; //坡道后6
|
||||
uint32_t enemy_slope_before : 1; //坡道前7
|
||||
uint32_t enemy_slope_after : 1; //坡道后8
|
||||
uint32_t own_crosses_above : 1; //增益点 上方9
|
||||
uint32_t own_crosses_below : 1; //增益点 下方10
|
||||
uint32_t enemy_crosses_above : 1; //增益点 上方11
|
||||
uint32_t enemy_crosses_below : 1; //增益点 下方12
|
||||
uint32_t own_highway_above : 1; //公路 上方13
|
||||
uint32_t own_highway_below : 1; //公路 下方14
|
||||
uint32_t enemy_highway_above : 1; //公路 上方15
|
||||
uint32_t enemy_highway_below : 1; //公路 下方16
|
||||
uint32_t own_fortress : 1; //己方堡垒增益点17
|
||||
uint32_t own_outpost : 1; //己方前哨站增益点18
|
||||
uint32_t own_RMUL : 1; //己方RMUL增益点19
|
||||
uint32_t enemy_RMDL : 1; //敌方RMDL增益点20
|
||||
uint32_t own_island : 1; //己方资源岛 21
|
||||
uint32_t enemy_island : 1; //敌方资源岛 22
|
||||
uint32_t centre : 1; //中心 23
|
||||
uint32_t res : 8;
|
||||
} Referee_RFID_t;/* 0x0209 */
|
||||
uint8_t base : 1;
|
||||
uint8_t high_ground : 1;
|
||||
uint8_t energy_mech : 1;
|
||||
uint8_t slope : 1;
|
||||
uint8_t outpose : 1;
|
||||
uint8_t resource : 1;
|
||||
uint8_t healing_card : 1;
|
||||
uint32_t res : 24;
|
||||
} Referee_RFID_t;
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t opening_status;
|
||||
uint8_t opening;
|
||||
uint8_t target;
|
||||
uint16_t target_changable_countdown;
|
||||
uint8_t target_changable_countdown;
|
||||
uint8_t dart1_speed;
|
||||
uint8_t dart2_speed;
|
||||
uint8_t dart3_speed;
|
||||
uint8_t dart4_speed;
|
||||
uint16_t last_dart_launch_time;
|
||||
uint16_t operator_cmd_launch_time;
|
||||
} Referee_DartClient_t;/* 0x020A */
|
||||
|
||||
typedef struct __packed {
|
||||
float hero_x;
|
||||
float hero_y;
|
||||
float engineer_x;
|
||||
float engineer_y;
|
||||
float standard_3_x;
|
||||
float standard_3_y;
|
||||
float standard_4_x;
|
||||
float standard_4_y;
|
||||
float reserved;
|
||||
float reserved1;
|
||||
} Referee_Robot_Position_t;/* 0x020B */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint8_t mark_hero_progress;
|
||||
uint8_t mark_engineer_progress;
|
||||
uint8_t mark_standard_3_progress;
|
||||
uint8_t mark_standard_4_progress;
|
||||
uint8_t mark_sentry_progress;
|
||||
}Referee_Radar_mark_data_t; /* 0x020C */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint32_t exchanged_bullet_num : 11;
|
||||
uint32_t exchanged_bullet_times : 4;
|
||||
uint32_t exchanged_blood_times : 4;
|
||||
uint32_t Confirmation_resurrection : 1;
|
||||
uint32_t now_resurrection : 1;
|
||||
uint32_t money : 10;
|
||||
uint32_t res : 1;
|
||||
uint16_t state : 1;
|
||||
uint16_t quantity : 11;
|
||||
uint16_t res1 : 4;
|
||||
} Referee_Sentry_Info_t; /* 0x020D */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint8_t qualification : 2;
|
||||
uint8_t enemy_status : 1;
|
||||
uint8_t res : 5;
|
||||
} Referee_Radar_Info_t; /* 0x020E */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint16_t data_cmd_id; /* 子内容ID */
|
||||
uint16_t sender_id;
|
||||
uint16_t receiver_id;
|
||||
uint8_t user_data[112];
|
||||
} Referee_Interaction_Data_t; /* 0x0301 */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint8_t data[30];
|
||||
} Referee_custom_robot_data_t; /* 0x0302 */
|
||||
} Referee_DartClient_t;
|
||||
|
||||
typedef struct __packed {
|
||||
float position_x;
|
||||
float position_y;
|
||||
float position_z;
|
||||
uint8_t commd_keyboard;
|
||||
uint8_t robot_id;
|
||||
uint8_t cmd_source;
|
||||
} Referee_ClientMap_t;/* 0x0303 */
|
||||
uint16_t robot_id;
|
||||
} Referee_ClientMap_t;
|
||||
|
||||
typedef struct __packed {
|
||||
int16_t mouse_x;
|
||||
@@ -336,74 +274,10 @@ typedef struct __packed {
|
||||
int8_t button_r;
|
||||
uint16_t keyboard_value;
|
||||
uint16_t res;
|
||||
} Referee_KeyboardMouse_t;/* 0x0304 */
|
||||
|
||||
typedef struct __packed {
|
||||
uint16_t hero_position_x;
|
||||
uint16_t hero_position_y;
|
||||
uint16_t engineer_position_x;
|
||||
uint16_t engineer_position_y;
|
||||
uint16_t infantry_3_position_x;
|
||||
uint16_t infantry_3_position_y;
|
||||
uint16_t infantry_4_position_x;
|
||||
uint16_t infantry_4_position_y;
|
||||
uint16_t infantry_5_position_x;
|
||||
uint16_t infantry_5_position_y;
|
||||
uint16_t sentry_position_x;
|
||||
uint16_t sentry_position_y;
|
||||
} Referee_map_robot_data_t;/* 0x0305 */
|
||||
|
||||
typedef struct __packed {
|
||||
uint16_t key_value;
|
||||
uint16_t x_position : 12;
|
||||
uint16_t mouse_left : 4;
|
||||
uint16_t y_position : 12;
|
||||
uint16_t mouse_right : 4;
|
||||
uint16_t res;
|
||||
} Referee_custom_client_data_t; /* 0x0306 */
|
||||
|
||||
typedef struct __packed {
|
||||
uint8_t intention;
|
||||
uint16_t start_position_x;
|
||||
uint16_t start_position_y;
|
||||
int8_t delta_x[49];
|
||||
int8_t delta_y[49];
|
||||
uint16_t sender_id;
|
||||
} Referee_map_data_t;/* 0x0307 */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint16_t sender_id;
|
||||
uint16_t receiver_id;
|
||||
uint8_t user_data[30];
|
||||
}Referee_custom_info_t; /* 0x0308 */
|
||||
|
||||
typedef struct __packed
|
||||
{
|
||||
uint8_t data[30];
|
||||
}Referee_robot_custom_data_t; /* 0x0309*/
|
||||
} Referee_KeyboardMouse_t;
|
||||
|
||||
typedef uint16_t Referee_Tail_t;
|
||||
|
||||
// typedef enum {
|
||||
// REF_BOT_RED_HERO = 1,
|
||||
// REF_BOT_RED_ENGINEER = 2,
|
||||
// REF_BOT_RED_INFANTRY_1 = 3,
|
||||
// REF_BOT_RED_INFANTRY_2 = 4,
|
||||
// REF_BOT_RED_INFANTRY_3 = 5,
|
||||
// REF_BOT_RED_DRONE = 6,
|
||||
// REF_BOT_RED_SENTRY = 7,
|
||||
// REF_BOT_RED_RADER = 9,
|
||||
// REF_BOT_BLU_HERO = 101,
|
||||
// REF_BOT_BLU_ENGINEER = 102,
|
||||
// REF_BOT_BLU_INFANTRY_1 = 103,
|
||||
// REF_BOT_BLU_INFANTRY_2 = 104,
|
||||
// REF_BOT_BLU_INFANTRY_3 = 105,
|
||||
// REF_BOT_BLU_DRONE = 106,
|
||||
// REF_BOT_BLU_SENTRY = 107,
|
||||
// REF_BOT_BLU_RADER = 109,
|
||||
// } Referee_RobotID_t;//
|
||||
|
||||
typedef enum {
|
||||
REF_BOT_RED_HERO = 1,
|
||||
REF_BOT_RED_ENGINEER = 2,
|
||||
@@ -412,10 +286,7 @@ typedef enum {
|
||||
REF_BOT_RED_INFANTRY_3 = 5,
|
||||
REF_BOT_RED_DRONE = 6,
|
||||
REF_BOT_RED_SENTRY = 7,
|
||||
REF_BOT_RED_DART = 8,
|
||||
REF_BOT_RED_RADER = 9,
|
||||
REF_BOT_RED_OUTPOST = 10,
|
||||
REF_BOT_RED_BASE = 11,
|
||||
REF_BOT_BLU_HERO = 101,
|
||||
REF_BOT_BLU_ENGINEER = 102,
|
||||
REF_BOT_BLU_INFANTRY_1 = 103,
|
||||
@@ -423,27 +294,9 @@ typedef enum {
|
||||
REF_BOT_BLU_INFANTRY_3 = 105,
|
||||
REF_BOT_BLU_DRONE = 106,
|
||||
REF_BOT_BLU_SENTRY = 107,
|
||||
REF_BOT_BLU_DART = 108,
|
||||
REF_BOT_BLU_RADER = 109,
|
||||
REF_BOT_BLU_OUTPOST = 110,
|
||||
REF_BOT_BLU_BASE = 111,
|
||||
} Referee_RobotID_t;//
|
||||
} Referee_RobotID_t;
|
||||
|
||||
|
||||
// typedef enum {
|
||||
// REF_CL_RED_HERO = 0x0101,
|
||||
// REF_CL_RED_ENGINEER = 0x0102,
|
||||
// REF_CL_RED_INFANTRY_1 = 0x0103,
|
||||
// REF_CL_RED_INFANTRY_2 = 0x0104,
|
||||
// REF_CL_RED_INFANTRY_3 = 0x0105,
|
||||
// REF_CL_RED_DRONE = 0x0106,
|
||||
// REF_CL_BLU_HERO = 0x0165,
|
||||
// REF_CL_BLU_ENGINEER = 0x0166,
|
||||
// REF_CL_BLU_INFANTRY_1 = 0x0167,
|
||||
// REF_CL_BLU_INFANTRY_2 = 0x0168,
|
||||
// REF_CL_BLU_INFANTRY_3 = 0x0169,
|
||||
// REF_CL_BLU_DRONE = 0x016A,
|
||||
// } Referee_ClientID_t;//选手端ID
|
||||
typedef enum {
|
||||
REF_CL_RED_HERO = 0x0101,
|
||||
REF_CL_RED_ENGINEER = 0x0102,
|
||||
@@ -457,20 +310,8 @@ typedef enum {
|
||||
REF_CL_BLU_INFANTRY_2 = 0x0168,
|
||||
REF_CL_BLU_INFANTRY_3 = 0x0169,
|
||||
REF_CL_BLU_DRONE = 0x016A,
|
||||
REF_CL_REFEREE_SERVER = 0x8080, /* 裁判系统服务器,用于哨兵和雷达自主决策 */
|
||||
} Referee_ClientID_t;//选手端ID
|
||||
} Referee_ClientID_t;
|
||||
|
||||
|
||||
// typedef enum {
|
||||
// REF_STDNT_CMD_ID_UI_DEL = 0x0100,
|
||||
// REF_STDNT_CMD_ID_UI_DRAW1 = 0x0101,
|
||||
// REF_STDNT_CMD_ID_UI_DRAW2 = 0x0102,
|
||||
// REF_STDNT_CMD_ID_UI_DRAW5 = 0x0103,
|
||||
// REF_STDNT_CMD_ID_UI_DRAW7 = 0x0104,
|
||||
// REF_STDNT_CMD_ID_UI_STR = 0x0110,
|
||||
|
||||
// REF_STDNT_CMD_ID_CUSTOM = 0x0200,
|
||||
// } Referee_StudentCMDID_t;
|
||||
typedef enum {
|
||||
REF_STDNT_CMD_ID_UI_DEL = 0x0100,
|
||||
REF_STDNT_CMD_ID_UI_DRAW1 = 0x0101,
|
||||
@@ -478,9 +319,8 @@ typedef enum {
|
||||
REF_STDNT_CMD_ID_UI_DRAW5 = 0x0103,
|
||||
REF_STDNT_CMD_ID_UI_DRAW7 = 0x0104,
|
||||
REF_STDNT_CMD_ID_UI_STR = 0x0110,
|
||||
|
||||
REF_STDNT_CMD_ID_CUSTOM = 0x0200,
|
||||
REF_STDNT_CMD_ID_SENTRY_CMD = 0X0120,
|
||||
REF_STDNT_CMD_ID_RADAR_CMD = 0X0121,
|
||||
} Referee_StudentCMDID_t;
|
||||
|
||||
typedef struct __packed {
|
||||
@@ -496,40 +336,29 @@ typedef struct __packed {
|
||||
|
||||
typedef struct {
|
||||
Referee_Status_t ref_status;
|
||||
Referee_GameStatus_t game_status; /* 0x0001 */
|
||||
Referee_GameResult_t game_result; /* 0x0002 */
|
||||
Referee_GameRobotHP_t game_robot_hp; /* 0x0003 */
|
||||
// Referee_DartStatus_t dart_status;
|
||||
// Referee_ICRAZoneStatus_t icra_zone;
|
||||
Referee_FieldEvents_t field_event; /* 0x0101 */
|
||||
//Referee_SupplyAction_t supply_action; /* 0x0102 */
|
||||
Referee_RequestSupply_t request_supply; /* 0x0103 */
|
||||
Referee_Warning_t warning; /* 0x0104 */
|
||||
Referee_DartCountdown_t dart_countdown; /* 0x0105 */
|
||||
Referee_RobotStatus_t robot_status; /* 0x0201 */
|
||||
Referee_PowerHeat_t power_heat; /* 0x0202 */
|
||||
Referee_RobotPos_t robot_pos; /* 0x0203 */
|
||||
Referee_RobotBuff_t robot_buff; /* 0x0204 */
|
||||
//Referee_DroneEnergy_t drone_energy; /* 0x0205 */
|
||||
Referee_RobotDamage_t robot_danage; /* 0x0206 */
|
||||
Referee_ShootData_t shoot_data; /* 0x0207 */
|
||||
Referee_BulletRemain_t bullet_remain; /* 0x0208 */
|
||||
Referee_RFID_t rfid; /* 0x0209 */
|
||||
Referee_DartClient_t dart_client; /* 0x020A */
|
||||
Referee_Robot_Position_t pos_sentry; /* 0x020B */
|
||||
Referee_Radar_mark_data_t radar_mark; /* 0x020C */
|
||||
Referee_Sentry_Info_t sentry_decision; /* 0x020D */
|
||||
Referee_Radar_Info_t radar_decision; /* 0x020E */
|
||||
// Referee_InterStudent_Custom_t custom;
|
||||
Referee_Interaction_Data_t interactive_data; /* 0x0301 */
|
||||
Referee_custom_robot_data_t custom_robot_data; /* 0x0302 */
|
||||
Referee_ClientMap_t client_map; /* 0x0303 */
|
||||
Referee_KeyboardMouse_t keyboard_mouse; /* 0x0304 */
|
||||
Referee_map_robot_data_t map_robot_data; /* 0x0305 */
|
||||
Referee_custom_client_data_t custom_keyboard_mouse; /* 0x0306 */
|
||||
Referee_map_data_t sentry_pos_data; /* 0x0307 */
|
||||
Referee_custom_info_t custom_info; /* 0x0308 */
|
||||
Referee_robot_custom_data_t custom_data; /* 0x0309*/
|
||||
Referee_GameStatus_t game_status;
|
||||
Referee_GameResult_t game_result;
|
||||
Referee_GameRobotHP_t game_robot_hp;
|
||||
Referee_DartStatus_t dart_status;
|
||||
Referee_ICRAZoneStatus_t icra_zone;
|
||||
Referee_FieldEvents_t field_event;
|
||||
Referee_SupplyAction_t supply_action;
|
||||
Referee_RequestSupply_t request_supply;
|
||||
Referee_Warning_t warning;
|
||||
Referee_DartCountdown_t dart_countdown;
|
||||
Referee_RobotStatus_t robot_status;
|
||||
Referee_PowerHeat_t power_heat;
|
||||
Referee_RobotPos_t robot_pos;
|
||||
Referee_RobotBuff_t robot_buff;
|
||||
Referee_DroneEnergy_t drone_energy;
|
||||
Referee_RobotDamage_t robot_danage;
|
||||
Referee_ShootData_t shoot_data;
|
||||
Referee_BulletRemain_t bullet_remain;
|
||||
Referee_RFID_t rfid;
|
||||
Referee_DartClient_t dart_client;
|
||||
Referee_InterStudent_Custom_t custom;
|
||||
Referee_ClientMap_t client_map;
|
||||
Referee_KeyboardMouse_t keyboard_mouse;
|
||||
|
||||
osTimerId_t ui_fast_timer_id;
|
||||
osTimerId_t ui_slow_timer_id;
|
||||
|
||||
@@ -27,41 +27,20 @@
|
||||
*/
|
||||
void Cap_Control(CAN_Capacitor_t *cap, const Referee_ForCap_t *referee,
|
||||
CAN_CapOutput_t *cap_out) {
|
||||
if (referee->ref_status != REF_STATUS_RUNNING) {
|
||||
/* 当裁判系统离线时,依然使用裁判系统进程传来的数据 */
|
||||
cap_out->power_limit = referee->chassis_power_limit;
|
||||
} else {
|
||||
/* 当裁判系统在线时,使用算法控制裁判系统输出(即电容输入) */
|
||||
cap_out->power_limit =
|
||||
PowerLimit_CapInput(referee->chassis_watt, referee->chassis_power_limit,
|
||||
if (referee->ref_status != REF_STATUS_RUNNING) {
|
||||
/* 当裁判系统离线时,依然使用裁判系统进程传来的数据 */
|
||||
cap_out->power_limit = referee->chassis_power_limit;
|
||||
} else {
|
||||
/* 当裁判系统在线时,使用算法控制裁判系统输出(即电容输入) */
|
||||
cap_out->power_limit =
|
||||
PowerLimit_CapInput(referee->chassis_watt, referee->chassis_power_limit,
|
||||
referee->chassis_pwr_buff);
|
||||
}
|
||||
/* 更新电容状态和百分比 */
|
||||
cap->cap_status = CAN_CAP_STATUS_RUNNING;
|
||||
// cap->percentage = Capacity_GetCapacitorRemain(cap->cap_feedback.cap_volt,
|
||||
// cap->cap_feedback.input_volt,
|
||||
// CAP_CUTOFF_VOLT);//电容剩余电量比例
|
||||
cap->percentage = Capacity_GetCapacitorRemain(cap->cap_od.v_out,
|
||||
cap->cap_od.v_in,
|
||||
CAP_CUTOFF_VOLT);//电容剩余电量比例
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 运行设置电容参数
|
||||
*
|
||||
* @param cap_out 电容输出结构体
|
||||
* @param can can总线
|
||||
*/
|
||||
void Cap_Can_Send(CAN_CapOutput_t *cap_out)
|
||||
{
|
||||
cap_out->new_cmd=2;
|
||||
|
||||
cap_out->new_power=5000;
|
||||
|
||||
cap_out->new_voltage=2400;
|
||||
|
||||
cap_out->new_current=100;
|
||||
|
||||
}
|
||||
/* 更新电容状态和百分比 */
|
||||
cap->cap_status = CAN_CAP_STATUS_RUNNING;
|
||||
cap->percentage = Capacity_GetCapacitorRemain(cap->cap_feedback.cap_volt,
|
||||
cap->cap_feedback.input_volt,
|
||||
CAP_CUTOFF_VOLT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,14 +35,6 @@ void Cap_Control(CAN_Capacitor_t *cap, const Referee_ForCap_t *referee,
|
||||
*/
|
||||
void Cap_DumpUI(const CAN_Capacitor_t *cap, Referee_CapUI_t *ui);
|
||||
|
||||
/**
|
||||
* @brief 运行设置电容参数
|
||||
*
|
||||
* @param cap_out 电容输出结构体
|
||||
* @param can can总线
|
||||
*/
|
||||
void Cap_Can_Send(CAN_CapOutput_t *cap_out) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -188,25 +188,19 @@ static const Config_RobotParam_t param_default = {
|
||||
.cover_open_duty = 0.10f,
|
||||
.cover_close_duty = 0.050f,
|
||||
.model = SHOOT_MODEL_17MM,
|
||||
.bullet_speed = 30.f,
|
||||
.bullet_speed = 25.f,
|
||||
.min_shoot_delay = (uint32_t)(1000.0f / 10.0f),
|
||||
}, /* shoot */
|
||||
|
||||
.can = {
|
||||
.chassis = BSP_CAN_1,
|
||||
.gimbal.yaw = BSP_CAN_2,
|
||||
.gimbal.pitch = BSP_CAN_2,
|
||||
.gimbal = BSP_CAN_2,
|
||||
.shoot = BSP_CAN_2,
|
||||
.trig = BSP_CAN_2,
|
||||
.cap = BSP_CAN_1,
|
||||
}, /* can */
|
||||
}; /* param_default */
|
||||
|
||||
#ifdef DEBUG
|
||||
Config_RobotParam_t param_hero = {
|
||||
#else
|
||||
static const Config_RobotParam_t param_hero = {
|
||||
#endif
|
||||
.model = ROBOT_MODEL_HERO,
|
||||
|
||||
.chassis = { /* 底盘模块参数 */
|
||||
@@ -240,7 +234,7 @@ static const Config_RobotParam_t param_hero = {
|
||||
},
|
||||
|
||||
.reverse = {
|
||||
.yaw = false,
|
||||
.yaw = true,
|
||||
},
|
||||
}, /* chassis */
|
||||
|
||||
@@ -248,28 +242,28 @@ static const Config_RobotParam_t param_hero = {
|
||||
.pid = {
|
||||
{
|
||||
/* GIMBAL_PID_YAW_OMEGA_IDX */
|
||||
.k = 0.24f,
|
||||
.k = 0.45f,
|
||||
.p = 1.0f,
|
||||
.i = 0.5f,
|
||||
.d = 0.0f,
|
||||
.i = 6.0f,
|
||||
.d = 0.0008f,
|
||||
.i_limit = 1.0f,
|
||||
.out_limit = 1.0f,
|
||||
.d_cutoff_freq = -1.0f,
|
||||
.range = -1.0f,
|
||||
}, {
|
||||
/* GIMBAL_PID_YAW_ANGLE_IDX */
|
||||
.k = 10.0f,
|
||||
.k = 20.0f,
|
||||
.p = 1.0f,
|
||||
.i = 0.0f,
|
||||
.d = 0.05f,
|
||||
.d = 0.0f,
|
||||
.i_limit = 0.0f,
|
||||
.out_limit = 10.0f,
|
||||
.d_cutoff_freq = -1.0f,
|
||||
.range = M_2PI,
|
||||
}, {
|
||||
/* GIMBAL_PID_PIT_OMEGA_IDX */
|
||||
.k = 0.6f,
|
||||
.p = 1.5f,
|
||||
.k = 0.25f,
|
||||
.p = 1.0f,
|
||||
.i = 0.0f,
|
||||
.d = 0.0f,
|
||||
.i_limit = 1.0f,
|
||||
@@ -278,9 +272,9 @@ static const Config_RobotParam_t param_hero = {
|
||||
.range = -1.0f,
|
||||
}, {
|
||||
/* GIMBAL_PID_PIT_ANGLE_IDX */
|
||||
.k = 3.0f,
|
||||
.p = 5.0f,
|
||||
.i = 2.5f,
|
||||
.k = 12.0f,
|
||||
.p = 1.0f,
|
||||
.i = 0.0f,
|
||||
.d = 0.0f,
|
||||
.i_limit = 0.0f,
|
||||
.out_limit = 10.0f,
|
||||
@@ -289,7 +283,7 @@ static const Config_RobotParam_t param_hero = {
|
||||
},
|
||||
}, /* pid */
|
||||
|
||||
.pitch_travel_rad = 0.9685447f,
|
||||
.pitch_travel_rad = 1.07685447f,
|
||||
|
||||
.low_pass_cutoff_freq = {
|
||||
.out = -1.0f,
|
||||
@@ -297,8 +291,8 @@ static const Config_RobotParam_t param_hero = {
|
||||
},
|
||||
|
||||
.reverse = {
|
||||
.yaw = false,
|
||||
.pit = false,
|
||||
.yaw = true,
|
||||
.pit = true,
|
||||
},
|
||||
}, /* gimbal */
|
||||
|
||||
@@ -333,8 +327,8 @@ static const Config_RobotParam_t param_hero = {
|
||||
.trig = -1.0f,
|
||||
},
|
||||
},
|
||||
.num_trig_tooth = 5.0f,
|
||||
.trig_gear_ratio = 19.0f,
|
||||
.num_trig_tooth = 6.0f,
|
||||
.trig_gear_ratio = 3591.0f / 187.0f,
|
||||
.fric_radius = 0.03f,
|
||||
.cover_open_duty = 0.125f,
|
||||
.cover_close_duty = 0.075f,
|
||||
@@ -345,10 +339,8 @@ static const Config_RobotParam_t param_hero = {
|
||||
|
||||
.can = {
|
||||
.chassis = BSP_CAN_1,
|
||||
.gimbal.yaw = BSP_CAN_1,
|
||||
.gimbal.pitch = BSP_CAN_2,
|
||||
.gimbal = BSP_CAN_2,
|
||||
.shoot = BSP_CAN_2,
|
||||
.trig = BSP_CAN_1,
|
||||
.cap = BSP_CAN_1,
|
||||
}, /* can */
|
||||
}; /* param_hero */
|
||||
@@ -357,7 +349,7 @@ static const Config_RobotParam_t param_hero = {
|
||||
|
||||
static const Config_PilotCfg_t cfg_qs = {
|
||||
.param = {
|
||||
.sens_mouse = 0.01f,
|
||||
.sens_mouse = 0.06f,
|
||||
.sens_rc = 6.0f,
|
||||
.map = {
|
||||
.key_map[CMD_BEHAVIOR_FORE] = {CMD_ACTIVE_PRESSED, CMD_KEY_W},
|
||||
@@ -438,21 +430,17 @@ static const Config_PilotCfgMap_t pilot_cfg_map[] = {
|
||||
*
|
||||
* \param cfg 配置信息
|
||||
*/
|
||||
void Config_Get(Config_t *cfg)
|
||||
{
|
||||
void Config_Get(Config_t *cfg) {
|
||||
BSP_Flash_ReadBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg));
|
||||
cfg->pilot_cfg = Config_GetPilotCfg(cfg->pilot_cfg_name);
|
||||
cfg->robot_param = Config_GetRobotParam(cfg->robot_param_name);
|
||||
/* 防止第一次烧写后访问NULL指针 */
|
||||
if (cfg->robot_param == NULL)
|
||||
cfg->robot_param = ¶m_default;
|
||||
if (cfg->pilot_cfg == NULL)
|
||||
cfg->pilot_cfg = &cfg_qs;
|
||||
if (cfg->robot_param == NULL) cfg->robot_param = ¶m_default;
|
||||
if (cfg->pilot_cfg == NULL) cfg->pilot_cfg = &cfg_qs;
|
||||
/* 防止擦除后全为1 */
|
||||
if ((uint32_t)(cfg->robot_param) == UINT32_MAX)
|
||||
cfg->robot_param = ¶m_default;
|
||||
if ((uint32_t)(cfg->pilot_cfg) == UINT32_MAX)
|
||||
cfg->pilot_cfg = &cfg_qs;
|
||||
if ((uint32_t)(cfg->pilot_cfg) == UINT32_MAX) cfg->pilot_cfg = &cfg_qs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,8 +448,7 @@ void Config_Get(Config_t *cfg)
|
||||
*
|
||||
* \param cfg 配置信息
|
||||
*/
|
||||
void Config_Set(Config_t *cfg)
|
||||
{
|
||||
void Config_Set(Config_t *cfg) {
|
||||
osKernelLock();
|
||||
BSP_Flash_EraseSector(11);
|
||||
BSP_Flash_WriteBytes(CONFIG_BASE_ADDRESS, (uint8_t *)cfg, sizeof(*cfg));
|
||||
@@ -474,14 +461,10 @@ void Config_Set(Config_t *cfg)
|
||||
* @param robot_param_name 机器人参数名称
|
||||
* @return const Config_RobotParam_t* 机器人参数的指针
|
||||
*/
|
||||
const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name)
|
||||
{
|
||||
if (robot_param_name == NULL)
|
||||
return NULL;
|
||||
for (size_t j = 0; robot_param_map[j].name != NULL; j++)
|
||||
{
|
||||
if (strcmp(robot_param_map[j].name, robot_param_name) == 0)
|
||||
{
|
||||
const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name) {
|
||||
if (robot_param_name == NULL) return NULL;
|
||||
for (size_t j = 0; robot_param_map[j].name != NULL; j++) {
|
||||
if (strcmp(robot_param_map[j].name, robot_param_name) == 0) {
|
||||
return robot_param_map[j].param;
|
||||
}
|
||||
}
|
||||
@@ -494,26 +477,20 @@ const Config_RobotParam_t *Config_GetRobotParam(const char *robot_param_name)
|
||||
* @param pilot_cfg_name 操作手配置名称
|
||||
* @return const Config_PilotCfg_t* 操作手配置的指针
|
||||
*/
|
||||
const Config_PilotCfg_t *Config_GetPilotCfg(const char *pilot_cfg_name)
|
||||
{
|
||||
if (pilot_cfg_name == NULL)
|
||||
return NULL;
|
||||
for (size_t j = 0; pilot_cfg_map[j].name != NULL; j++)
|
||||
{
|
||||
if (strcmp(pilot_cfg_map[j].name, pilot_cfg_name) == 0)
|
||||
{
|
||||
const Config_PilotCfg_t *Config_GetPilotCfg(const char *pilot_cfg_name) {
|
||||
if (pilot_cfg_name == NULL) return NULL;
|
||||
for (size_t j = 0; pilot_cfg_map[j].name != NULL; j++) {
|
||||
if (strcmp(pilot_cfg_map[j].name, pilot_cfg_name) == 0) {
|
||||
return pilot_cfg_map[j].param;
|
||||
}
|
||||
}
|
||||
return NULL; /* No match. */
|
||||
}
|
||||
|
||||
const Config_PilotCfgMap_t *Config_GetPilotNameMap(void)
|
||||
{
|
||||
const Config_PilotCfgMap_t *Config_GetPilotNameMap(void) {
|
||||
return pilot_cfg_map;
|
||||
}
|
||||
|
||||
const Config_RobotParamMap_t *Config_GetRobotNameMap(void)
|
||||
{
|
||||
const Config_RobotParamMap_t *Config_GetRobotNameMap(void) {
|
||||
return robot_param_map;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define HEAT_INCREASE_17MM (10.f) /* 每发射一颗17mm弹丸增加10热量 */
|
||||
|
||||
#define BULLET_SPEED_LIMIT_42MM (16.0)
|
||||
#define BULLET_SPEED_LIMIT_17MM (30.0)
|
||||
#define BULLET_SPEED_LIMIT_17MM (25.0)
|
||||
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
@@ -35,7 +35,7 @@ static int8_t Shoot_SetMode(Shoot_t *s, CMD_ShootMode_t mode) {
|
||||
if (mode == s->mode) return SHOOT_OK;
|
||||
|
||||
/* 切换模式后重置PID和滤波器 */
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
PID_Reset(s->pid.fric + i);
|
||||
LowPassFilter2p_Reset(s->filter.in.fric + i, 0.0f);
|
||||
LowPassFilter2p_Reset(s->filter.out.fric + i, 0.0f);
|
||||
@@ -84,7 +84,7 @@ static int8_t Shoot_HeatLimit(Shoot_t *s, Referee_ForShoot_t *s_ref) {
|
||||
/* 检测热量更新后,计算可发射弹丸 */
|
||||
if ((hc->heat != hc->last_heat) || (hc->heat == 0)) {
|
||||
hc->available_shot =
|
||||
(uint32_t)floorf((hc->heat_limit - hc->heat) / hc->heat_increase);
|
||||
(uint32_t)floorf((hc->heat_limit - hc->heat) / hc->heat_increase) - 2;
|
||||
hc->last_heat = hc->heat;
|
||||
}
|
||||
/* 计算已发射弹丸 */
|
||||
@@ -117,7 +117,7 @@ int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq) {
|
||||
s->param = param; /* 初始化参数 */
|
||||
s->mode = SHOOT_MODE_RELAX; /* 设置默认模式 */
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
/* PI控制器初始化PID */
|
||||
PID_Init(s->pid.fric + i, KPID_MODE_NO_D, target_freq,
|
||||
&(param->fric_pid_param));
|
||||
@@ -154,7 +154,7 @@ int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can) {
|
||||
if (s == NULL) return -1;
|
||||
if (can == NULL) return -1;
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
s->feedback.fric_rpm[i] = can->motor.shoot.as_array[i].rotor_speed;
|
||||
}
|
||||
|
||||
@@ -222,10 +222,11 @@ int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FIRE_MODE_CONT: { /* 持续开火模式 */
|
||||
float shoot_freq = HeatLimit_ShootFreq(
|
||||
s->heat_ctrl.heat, s->heat_ctrl.heat_limit, s->heat_ctrl.cooling_rate,
|
||||
s->heat_ctrl.heat_increase, s->param->model == SHOOT_MODEL_17MM);
|
||||
case FIRE_MODE_CONT: { /* Recy模式 */
|
||||
// float shoot_freq = HeatLimit_ShootFreq(
|
||||
// s->heat_ctrl.heat, s->heat_ctrl.heat_limit, s->heat_ctrl.cooling_rate,
|
||||
// s->heat_ctrl.heat_increase, s->param->model == SHOOT_MODEL_17MM);
|
||||
float shoot_freq = 20.0f; //射频
|
||||
s->fire_ctrl.period_ms =
|
||||
(shoot_freq == 0.0f) ? UINT32_MAX : (uint32_t)(1000.f / shoot_freq);
|
||||
break;
|
||||
@@ -245,26 +246,20 @@ int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
|
||||
}
|
||||
|
||||
/* 计算摩擦轮转速的目标值 */
|
||||
// s->setpoint.fric_rpm[1] =
|
||||
// CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius,
|
||||
// (s->param->model == SHOOT_MODEL_17MM));
|
||||
// s->setpoint.fric_rpm[0] = -s->setpoint.fric_rpm[1];
|
||||
|
||||
float fric_rpm = CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius,
|
||||
s->setpoint.fric_rpm[1] =
|
||||
CalculateRpm(s->fire_ctrl.bullet_speed, s->param->fric_radius,
|
||||
(s->param->model == SHOOT_MODEL_17MM));
|
||||
s->setpoint.fric_rpm[0] = -fric_rpm;
|
||||
s->setpoint.fric_rpm[1] = fric_rpm;
|
||||
s->setpoint.fric_rpm[2] = -fric_rpm;
|
||||
s->setpoint.fric_rpm[0] = -s->setpoint.fric_rpm[1];
|
||||
|
||||
/* 计算拨弹电机位置的目标值 */
|
||||
if (((now - s->fire_ctrl.last_shoot) >= s->fire_ctrl.period_ms) &&
|
||||
(s_cmd->fire)) {
|
||||
/* 将拨弹电机角度进行循环加法,每次加(减)射出一颗弹丸的弧度变化 */
|
||||
if (s_cmd->reverse_trig) { /* 反转拨弹 */
|
||||
CircleAdd(&(s->setpoint.trig_angle), -M_2PI / s->param->num_trig_tooth,
|
||||
CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth,
|
||||
M_2PI);
|
||||
} else {
|
||||
CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth,
|
||||
CircleAdd(&(s->setpoint.trig_angle), -M_2PI / s->param->num_trig_tooth,
|
||||
M_2PI);
|
||||
s->fire_ctrl.shooted++;
|
||||
s->fire_ctrl.last_shoot = now;
|
||||
@@ -291,7 +286,7 @@ int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
|
||||
s->out[SHOOT_ACTR_TRIG_IDX] = LowPassFilter2p_Apply(
|
||||
&(s->filter.out.trig), s->out[SHOOT_ACTR_TRIG_IDX]);
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
/* 控制摩擦轮 */
|
||||
s->feedback.fric_rpm[i] = LowPassFilter2p_Apply(
|
||||
&(s->filter.in.fric[i]), s->feedback.fric_rpm[i]);
|
||||
|
||||
@@ -2,46 +2,45 @@
|
||||
* 射击模组
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <cmsis_os2.h>
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#include "component\cmd.h"
|
||||
#include "component\filter.h"
|
||||
#include "component\pid.h"
|
||||
#include "device\can.h"
|
||||
#include "device\referee.h"
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
#define SHOOT_OK (0) /* 运行正常 */
|
||||
#define SHOOT_ERR (-1) /* 运行时发现了其他错误 */
|
||||
#define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */
|
||||
#define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */
|
||||
#include "component\cmd.h"
|
||||
#include "component\filter.h"
|
||||
#include "component\pid.h"
|
||||
#include "device\can.h"
|
||||
#include "device\referee.h"
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
#define SHOOT_OK (0) /* 运行正常 */
|
||||
#define SHOOT_ERR (-1) /* 运行时发现了其他错误 */
|
||||
#define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */
|
||||
#define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */
|
||||
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
|
||||
/* 用enum组合所有PID,方便访问,配合数组使用 */
|
||||
enum Shoot_Acuator_e {
|
||||
/* 用enum组合所有PID,方便访问,配合数组使用 */
|
||||
enum Shoot_Acuator_e {
|
||||
SHOOT_ACTR_FRIC1_IDX = 0, /* 1号摩擦轮相关的索引值 */
|
||||
SHOOT_ACTR_FRIC2_IDX, /* 2号摩擦轮相关的索引值 */
|
||||
SHOOT_ACTR_FRIC3_IDX, /* 3号摩擦轮相关的索引值 */
|
||||
SHOOT_ACTR_TRIG_IDX, /* 扳机电机相关的索引值 */
|
||||
SHOOT_ACTR_NUM, /* 总共的动作器数量 */
|
||||
};
|
||||
};
|
||||
|
||||
/* 发射机构型号 */
|
||||
typedef enum {
|
||||
/* 发射机构型号 */
|
||||
typedef enum {
|
||||
SHOOT_MODEL_17MM = 0, /* 17mm发射机构 */
|
||||
SHOOT_MODEL_42MM, /* 42mm发射机构 */
|
||||
} Shoot_Model_t;
|
||||
} Shoot_Model_t;
|
||||
|
||||
/* 射击参数的结构体,包含所有初始化用的参数,通常是const,存好几组。*/
|
||||
typedef struct {
|
||||
/* 射击参数的结构体,包含所有初始化用的参数,通常是const,存好几组。*/
|
||||
typedef struct {
|
||||
KPID_Params_t fric_pid_param; /* 摩擦轮电机控制PID的参数 */
|
||||
KPID_Params_t trig_pid_param; /* 扳机电机控制PID的参数 */
|
||||
/* 低通滤波器截止频率 */
|
||||
@@ -67,9 +66,9 @@
|
||||
Shoot_Model_t model; /* 发射机构型号 */
|
||||
float bullet_speed; /* 弹丸初速度 */
|
||||
uint32_t min_shoot_delay; /* 通过设置最小射击间隔来设置最大射频 */
|
||||
} Shoot_Params_t;
|
||||
} Shoot_Params_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
float heat; /* 现在热量水平 */
|
||||
float last_heat; /* 之前的热量水平 */
|
||||
float heat_limit; /* 热量上限 */
|
||||
@@ -79,9 +78,9 @@
|
||||
|
||||
float last_bullet_speed; /* 之前的弹丸速度 */
|
||||
uint32_t available_shot; /* 热量范围内还可以发射的数量 */
|
||||
} Shoot_HeatCtrl_t;
|
||||
} Shoot_HeatCtrl_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
uint32_t last_shoot; /* 上次射击时间 单位:ms */
|
||||
bool last_fire; /* 上次开火状态 */
|
||||
bool first_fire; /* 第一次收到开火指令 */
|
||||
@@ -90,13 +89,13 @@
|
||||
float bullet_speed; /* 弹丸初速度 */
|
||||
uint32_t period_ms; /* 弹丸击发延迟 */
|
||||
CMD_FireMode_t fire_mode;
|
||||
} Shoot_FireCtrl_t;
|
||||
} Shoot_FireCtrl_t;
|
||||
|
||||
/*
|
||||
/*
|
||||
* 运行的主结构体,所有这个文件里的函数都在操作这个结构体。
|
||||
* 包含了初始化参数,中间变量,输出变量。
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
uint32_t lask_wakeup;
|
||||
float dt;
|
||||
|
||||
@@ -107,20 +106,20 @@
|
||||
|
||||
/* 反馈信息 */
|
||||
struct {
|
||||
float fric_rpm[3]; /* 摩擦轮电机转速,单位:RPM */
|
||||
float fric_rpm[2]; /* 摩擦轮电机转速,单位:RPM */
|
||||
float trig_motor_angle; /* 拨弹电机角度,单位:弧度 */
|
||||
float trig_angle; /* 拨弹转盘角度,单位:弧度 */
|
||||
} feedback;
|
||||
|
||||
/* PID计算的目标值 */
|
||||
struct {
|
||||
float fric_rpm[3]; /* 摩擦轮电机转速,单位:RPM */
|
||||
float fric_rpm[2]; /* 摩擦轮电机转速,单位:RPM */
|
||||
float trig_angle; /* 拨弹电机角度,单位:弧度 */
|
||||
} setpoint;
|
||||
|
||||
/* 反馈控制用的PID */
|
||||
struct {
|
||||
KPID_t fric[3]; /* 控制摩擦轮 */
|
||||
KPID_t fric[2]; /* 控制摩擦轮 */
|
||||
KPID_t trig; /* 控制拨弹电机 */
|
||||
} pid;
|
||||
|
||||
@@ -128,13 +127,13 @@
|
||||
struct {
|
||||
/* 反馈值滤波器 */
|
||||
struct {
|
||||
LowPassFilter2p_t fric[3]; /* 过滤摩擦轮 */
|
||||
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
|
||||
LowPassFilter2p_t trig; /* 过滤拨弹电机 */
|
||||
} in;
|
||||
|
||||
/* 输出值滤波器 */
|
||||
struct {
|
||||
LowPassFilter2p_t fric[3]; /* 过滤摩擦轮 */
|
||||
LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
|
||||
LowPassFilter2p_t trig; /* 过滤拨弹电机 */
|
||||
} out;
|
||||
} filter;
|
||||
@@ -144,11 +143,11 @@
|
||||
|
||||
float out[SHOOT_ACTR_NUM]; /* 输出数组,通过Shoot_Acuator_e里的值访问 */
|
||||
|
||||
} Shoot_t;
|
||||
} Shoot_t;
|
||||
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief 初始化射击
|
||||
*
|
||||
* \param s 包含射击数据的结构体
|
||||
@@ -157,9 +156,9 @@
|
||||
*
|
||||
* \return 函数运行结果
|
||||
*/
|
||||
int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
|
||||
int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief 更新射击的反馈信息
|
||||
*
|
||||
* \param s 包含射击数据的结构体
|
||||
@@ -167,9 +166,9 @@
|
||||
*
|
||||
* \return 函数运行结果
|
||||
*/
|
||||
int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can);
|
||||
int8_t Shoot_UpdateFeedback(Shoot_t *s, const CAN_t *can);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief 运行射击控制逻辑
|
||||
*
|
||||
* \param s 包含射击数据的结构体
|
||||
@@ -179,33 +178,32 @@
|
||||
*
|
||||
* \return 函数运行结果
|
||||
*/
|
||||
int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
|
||||
int8_t Shoot_Control(Shoot_t *s, CMD_ShootCmd_t *s_cmd,
|
||||
Referee_ForShoot_t *s_ref, uint32_t now);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief 复制射击输出值
|
||||
*
|
||||
* \param s 包含射击数据的结构体
|
||||
* \param out CAN设备射击输出结构体
|
||||
*/
|
||||
void Shoot_DumpOutput(Shoot_t *s, CAN_ShootOutput_t *out);
|
||||
void Shoot_DumpOutput(Shoot_t *s, CAN_ShootOutput_t *out);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief 清空输出值
|
||||
*
|
||||
* \param output 要清空的结构体
|
||||
*/
|
||||
void Shoot_ResetOutput(CAN_ShootOutput_t *output);
|
||||
void Shoot_ResetOutput(CAN_ShootOutput_t *output);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief 导出射击UI数据
|
||||
*
|
||||
* @param s 射击结构体
|
||||
* @param ui UI结构体
|
||||
*/
|
||||
void Shoot_DumpUI(Shoot_t *s, Referee_ShootUI_t *ui);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
void Shoot_DumpUI(Shoot_t *s, Referee_ShootUI_t *ui);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -42,6 +42,7 @@ void Task_Ai(void *argument) {
|
||||
AI_Init(&ai);
|
||||
|
||||
uint32_t tick = osKernelGetTickCount();
|
||||
uint32_t last_online_tick = tick;
|
||||
while (1) {
|
||||
#ifdef DEBUG
|
||||
task_runtime.stack_water_mark.ai = osThreadGetStackSpace(osThreadGetId());
|
||||
@@ -51,17 +52,23 @@ void Task_Ai(void *argument) {
|
||||
|
||||
AI_StartReceiving(&ai);
|
||||
if (AI_WaitDmaCplt()) {
|
||||
AI_ParseHost(&ai, &cmd_host);
|
||||
AI_ParseHost(&ai);
|
||||
last_online_tick = tick;
|
||||
} else {
|
||||
AI_HandleOffline(&ai, &cmd_host);
|
||||
if (tick - last_online_tick > 300) AI_HandleOffline(&ai,&cmd_host);
|
||||
}
|
||||
|
||||
if (ai.status != AI_STATUS_STOP && ai.ai_online){
|
||||
AI_PackCmd(&ai, &cmd_host);
|
||||
osMessageQueueReset(task_runtime.msgq.cmd.raw.host);
|
||||
osMessageQueuePut(task_runtime.msgq.cmd.raw.host, &(cmd_host), 0, 0);
|
||||
}
|
||||
|
||||
osMessageQueueGet(task_runtime.msgq.ai.quat, &(quat), NULL, 0);
|
||||
osMessageQueueGet(task_runtime.msgq.cmd.ai, &(ai.status), NULL, 0);
|
||||
bool ref_update = (osMessageQueueGet(task_runtime.msgq.referee.ai,
|
||||
&(referee_ai), NULL, 0) == osOK);
|
||||
|
||||
AI_PackMCU(&ai, &quat);
|
||||
if (ref_update) AI_PackRef(&ai, &(referee_ai));
|
||||
|
||||
|
||||
@@ -53,17 +53,13 @@ void Task_Can(void *argument) {
|
||||
osMessageQueueReset(task_runtime.msgq.can.feedback.shoot);
|
||||
osMessageQueuePut(task_runtime.msgq.can.feedback.shoot, &can, 0, 0);
|
||||
|
||||
//不注释掉不能用
|
||||
// if (CAN_CheckFlag(&can, CAN_REC_CAP_FINISHED)) {
|
||||
// osMessageQueueReset(task_runtime.msgq.can.feedback.cap);
|
||||
// osMessageQueuePut(task_runtime.msgq.can.feedback.cap, &can, 0, 0);
|
||||
// CAN_ClearFlag(&can, CAN_REC_CAP_FINISHED);
|
||||
// } else {
|
||||
// // Error Handle
|
||||
// }
|
||||
|
||||
if (CAN_CheckFlag(&can, CAN_REC_CAP_FINISHED)) {
|
||||
osMessageQueueReset(task_runtime.msgq.can.feedback.cap);
|
||||
osMessageQueuePut(task_runtime.msgq.can.feedback.cap, &can, 0, 0);
|
||||
CAN_ClearFlag(&can, CAN_REC_CAP_FINISHED);
|
||||
} else {
|
||||
// Error Handle
|
||||
}
|
||||
|
||||
if (CAN_CheckFlag(&can, CAN_REC_TOF_FINISHED)) {
|
||||
osMessageQueueReset(task_runtime.msgq.can.feedback.tof);
|
||||
@@ -88,19 +84,10 @@ void Task_Can(void *argument) {
|
||||
CAN_Motor_Control(CAN_MOTOR_GROUT_SHOOT1, &can_out, &can);
|
||||
}
|
||||
|
||||
// if (osMessageQueueGet(task_runtime.msgq.can.output.cap, &(can_out.cap), 0,
|
||||
// 0) == osOK) {
|
||||
// CAN_Cap_Control(&(can_out.cap), &can);
|
||||
// }
|
||||
|
||||
//在cap的task里计算电容的输出功率消息队列
|
||||
if (osMessageQueueGet(task_runtime.msgq.can.output.cap, &(can_out.cap), 0,
|
||||
0) == osOK) {
|
||||
// CAN_Cap_Control(&(can_out.cap), &can);
|
||||
Can_Set_send(&(can_out.cap), &can);
|
||||
|
||||
|
||||
}
|
||||
CAN_Cap_Control(&(can_out.cap), &can);
|
||||
}
|
||||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +74,6 @@ void Task_Cap(void *argument) {
|
||||
osKernelLock(); /* 锁住RTOS内核防止控制过程中断,造成错误 */
|
||||
/* 根据裁判系统数据计算输出功率 */
|
||||
Cap_Control(&can.cap, &referee_cap, &cap_out);
|
||||
/* 超电参数设置 */
|
||||
Cap_Can_Send(&cap_out);
|
||||
|
||||
osKernelUnlock();
|
||||
/* 将电容输出值发送到CAN */
|
||||
osMessageQueueReset(task_runtime.msgq.can.output.cap);
|
||||
|
||||
Reference in New Issue
Block a user