refactor(modules): 按角色重排 modules/ 目录,消除命名不一致
原 modules/ 下目录大小写混用(BMI088/BUZZER/DR16/IST8310/LED/PID 为大写,
attitude/c_comm/filter/gimbal/ins/motor/referee/shoot 为小写),且把第三方
移植代码(QuaternionEKF/kalman_filter)与本工程封装(ins)混在同一目录。
新结构(全部小写,按角色分层,第三方代码单独隔离):
modules/
algorithm/ pid.c/h filter.c/h 通用算法
imu/ attitude.c/h ins.c/h 姿态与惯导封装
imu/qekf/ QuaternionEKF.c/h kalman_filter.c/h
(移植自 Wang Hongxi INS 例程)
sensor/ bmi088.c/h ist8310.c/h 板载传感器驱动
comms/ dr16.c/h c_comm.c/h referee.c/h
motor/ dji_motor.c/h 电机抽象
control/ gimbal.c/h shoot.c/h 整车控制逻辑
(底盘为 chassis.c/h)
dev/ led.c/h buzzer.c/h 板级指示/发声
共移动 58 个文件(每板 29 个),旧目录全部删除。
工程文件同步(每个工程各 2 个):
- .uvprojx: Modules 分组 16 个 <FilePath> 改为新路径;
2 个非空 <IncludePath> 元素:15 个旧模块路径收敛为 8 个新目录,
并顺带删除陈旧项 ../modules/AHRS(目录根本不存在,legacy 时代残留)
与冗余项 ..\bsp(与 ../Bsp/Inc 重复)
- .uvoptx: 16 个 <PathWithFileName> 同步
关于"为什么不用改源码": Keil 的 include 靠 IncludePath 解析,本工程所有
#include 都是纯文件名形式(无路径限定),所以移动目录只需改工程配置。
另外 .h 完全不登记在工程里(只有 16 个 .c 被登记),故头文件只需移动。
回归验证(无法在此环境编译,用等价判据):
- 两个工程引用的 98 / 95 个 <FilePath> 全部真实存在
- 磁盘上 47 / 45 个 .c 全部仍被工程引用 —— 即没有任何文件掉出编译
- 2 个 IncludePath 元素均含全部 8 个新模块目录,无旧路径残留
- 所有 IncludePath 指向的目录均真实存在
- .uvprojx/.uvoptx XML 良构
- 两棵树结构一致(chassis/gimbal 等板级差异符合预期)
⚠️ 仍需在 Keil 里点一次编译确认(见 README 的构建章节)。
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
/* =============================================================================
|
||||
* shoot.c - 发射机构:摩擦轮 2xM3508(0x200 CAN1 槽1/2)+ 拨弹 M2006
|
||||
* 逻辑(与 legacy 一致):
|
||||
* 摩擦轮开关受发射机构上电状态门控(可由 DEBUG_SHOOT_WITHOUT_REFEREE 绕过),
|
||||
* 开启时联动激光(PC8=TIM3_CH3 PWM,占空比 0/满 对应关/开)
|
||||
* 拨弹仅在摩擦轮开启后允许;fire=GIMBAL_RAMMER_SPEED(-5400),eject 反向
|
||||
* 拨弹电流经 shoot_share_rammer_current() 交给云台共帧发送(0x1FF CAN1)
|
||||
* ========================================================================== */
|
||||
#include "shoot.h"
|
||||
#include "gimbal.h"
|
||||
#include "pid.h"
|
||||
#include "tim.h"
|
||||
#include "robot_param.h"
|
||||
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
uint8_t shoot_friction_flag = 0;
|
||||
|
||||
static PID_PositionTypeDef friction_l_pid, friction_r_pid, rammer_pid;
|
||||
|
||||
/* 激光:PC8 = TIM3_CH3(10kHz PWM,ARR=8399),占空比 0/满 对应关/开 */
|
||||
#define LASER_ON() __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, 8399)
|
||||
#define LASER_OFF() __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, 0)
|
||||
|
||||
static void laser_init(void)
|
||||
{
|
||||
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, 0);
|
||||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
|
||||
}
|
||||
|
||||
void shoot_init(void)
|
||||
{
|
||||
PID_PositionStructureInit(&friction_l_pid, 0);
|
||||
PID_PositionSetParameter(&friction_l_pid, GIMBAL_FRICTION_WHEEL_KP, GIMBAL_FRICTION_WHEEL_KI, GIMBAL_FRICTION_WHEEL_KD);
|
||||
PID_PositionSetEkRange(&friction_l_pid, -5, 5);
|
||||
PID_PositionSetOUTRange(&friction_l_pid, -15000, 15000);
|
||||
|
||||
PID_PositionStructureInit(&friction_r_pid, 0);
|
||||
PID_PositionSetParameter(&friction_r_pid, GIMBAL_FRICTION_WHEEL_KP, GIMBAL_FRICTION_WHEEL_KI, GIMBAL_FRICTION_WHEEL_KD);
|
||||
PID_PositionSetEkRange(&friction_r_pid, -5, 5);
|
||||
PID_PositionSetOUTRange(&friction_r_pid, -15000, 15000);
|
||||
|
||||
PID_PositionStructureInit(&rammer_pid, GIMBAL_RAMMER_SPEED);
|
||||
PID_PositionSetParameter(&rammer_pid, GIMBAL_RAMMER_KP, GIMBAL_RAMMER_KI, GIMBAL_RAMMER_KD);
|
||||
PID_PositionSetEkRange(&rammer_pid, -20, 20);
|
||||
PID_PositionSetOUTRange(&rammer_pid, -30000, 30000);
|
||||
|
||||
laser_init();
|
||||
}
|
||||
|
||||
void shoot_control(uint8_t friction_on, uint8_t fire, uint8_t eject, uint8_t shooter_power_on)
|
||||
{
|
||||
/* 摩擦轮(与 legacy 逻辑一致:发射机构上电才允许开启;
|
||||
* 台架调试时可经 DEBUG_SHOOT_WITHOUT_REFEREE 绕过裁判系统检查) */
|
||||
if (friction_on && (shooter_power_on || DEBUG_SHOOT_WITHOUT_REFEREE))
|
||||
{
|
||||
friction_l_pid.Need_Value = -GIMBAL_FRICTION_WHEEL_SPEED;
|
||||
friction_r_pid.Need_Value = GIMBAL_FRICTION_WHEEL_SPEED;
|
||||
LASER_ON();
|
||||
shoot_friction_flag = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
friction_l_pid.Need_Value = 0;
|
||||
friction_r_pid.Need_Value = 0;
|
||||
LASER_OFF();
|
||||
shoot_friction_flag = 0;
|
||||
}
|
||||
|
||||
/* 拨弹:仅在摩擦轮开启时允许 */
|
||||
if (shoot_friction_flag)
|
||||
{
|
||||
if (fire)
|
||||
rammer_pid.Need_Value = GIMBAL_RAMMER_SPEED;
|
||||
else if (eject)
|
||||
rammer_pid.Need_Value = -GIMBAL_RAMMER_SPEED;
|
||||
else
|
||||
rammer_pid.Need_Value = 0;
|
||||
}
|
||||
else
|
||||
rammer_pid.Need_Value = 0;
|
||||
|
||||
PID_PositionCalc(&friction_l_pid, motor_friction_l.fdb.rotor_speed);
|
||||
PID_PositionCalc(&friction_r_pid, motor_friction_r.fdb.rotor_speed);
|
||||
PID_PositionCalc(&rammer_pid, motor_rammer.fdb.rotor_speed);
|
||||
|
||||
/* 拨弹电流交给云台控制帧统一发送(0x1FF CAN1 共帧) */
|
||||
shoot_share_rammer_current((int16_t)rammer_pid.OUT);
|
||||
}
|
||||
|
||||
void shoot_send_cmd(void)
|
||||
{
|
||||
dji_motor_send_current_low(&hcan1, (int16_t)friction_l_pid.OUT, (int16_t)friction_r_pid.OUT, 0, 0);
|
||||
}
|
||||
|
||||
void shoot_output_zero(void)
|
||||
{
|
||||
dji_motor_send_current_low(&hcan1, 0, 0, 0, 0);
|
||||
LASER_OFF();
|
||||
shoot_friction_flag = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user