From 648de9f3705b8cb22b58e552d47ab039f714a3cc Mon Sep 17 00:00:00 2001 From: NeoZng Date: Fri, 2 Dec 2022 22:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=AF=8F=E4=B8=AA=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A=E4=BA=86=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 7 +- Makefile | 4 +- VSCode+Ozone使用方法.md | 2 +- application/chassis/chassis.c | 22 +- application/chassis/chassis.h | 21 -- application/cmd/chassis_cmd.c | 110 ++-------- application/cmd/chassis_cmd.h | 31 +-- application/cmd/gimbal_cmd.c | 364 ++++------------------------------ application/cmd/gimbal_cmd.h | 37 +--- application/gimbal/gimbal.c | 11 +- application/gimbal/gimbal.h | 11 - application/robot_def.h | 176 +++++++++++++++- application/shoot/shoot.c | 10 +- application/shoot/shoot.h | 11 - modules/monitor/monitor.c | 1 + modules/monitor/monitor.h | 6 + modules/monitor/monitor.md | 0 17 files changed, 294 insertions(+), 530 deletions(-) create mode 100644 modules/monitor/monitor.c create mode 100644 modules/monitor/monitor.h create mode 100644 modules/monitor/monitor.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 26f9b34..826f45c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,7 +24,12 @@ "message_center.h": "c", "stddef.h": "c", "stm32_hal_legacy.h": "c", - "message_buffer.h": "c" + "message_buffer.h": "c", + "robot_def.h": "c", + "remote_control.h": "c", + "gimbal_cmd.h": "c", + "chassis_cmd.h": "c", + "referee.h": "c" }, "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools", } \ No newline at end of file diff --git a/Makefile b/Makefile index 1a54f43..0c2c22d 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,7 @@ modules/remote/remote_control.c \ modules/super_cap/super_cap.c \ modules/can_comm/can_comm.c \ modules/message_center/message_center.c \ +modules/monitor/monitor.hc \ application/gimbal/gimbal.c \ application/chassis/chassis.c \ application/shoot/shoot.c \ @@ -226,7 +227,8 @@ C_INCLUDES = \ -Imodules/remote \ -Imodules/super_cap \ -Imodules/can_comm \ --Imodules/message_center +-Imodules/message_center \ +-Imodules/monitor # compile gcc flags ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections diff --git a/VSCode+Ozone使用方法.md b/VSCode+Ozone使用方法.md index 0c74618..019a4e3 100644 --- a/VSCode+Ozone使用方法.md +++ b/VSCode+Ozone使用方法.md @@ -155,7 +155,7 @@ ITM是instrument trace macrocell指令追踪宏单元的缩写,它用于提供 > 2022-12-01更新: > -> ​ VSCode上线了一款新的插件: +> ​ **VSCode上线了一款新的插件:** > > ![image-20221201134906999](assets/image-20221201134906999.png) > diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 6fbbc3c..e09a3ab 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -1,5 +1,25 @@ #include "chassis.h" +#include "robot_def.h" +#include "dji_motor.h" +#include "super_cap.h" +#ifdef CHASSIS_BOARD //使用板载IMU获取底盘转动角速度 +#include "ins_task.h" +IMU_Data_t* Chassis_IMU_data; +#endif // CHASSIS_BOARD + +// SuperCAP cap; +static dji_motor_instance* lf; //left right forward back +static dji_motor_instance* rf; +static dji_motor_instance* lb; +static dji_motor_instance* rb; +static Chassis_Ctrl_Cmd_s chassis_cmd_recv; +static Chassis_Upload_Data_s chassis_feedback_data; + +static void mecanum_calculate() +{ + +} @@ -8,7 +28,7 @@ void ChassisInit() } -void ChassisTask() +void ChassisTask() { } \ No newline at end of file diff --git a/application/chassis/chassis.h b/application/chassis/chassis.h index 446e952..49b444b 100644 --- a/application/chassis/chassis.h +++ b/application/chassis/chassis.h @@ -1,27 +1,6 @@ #ifndef CHASSIS_H #define CHASSIS_H -#include "robot_def.h" -#include "dji_motor.h" -#include "super_cap.h" - -#ifdef CHASSIS_BOARD //使用板载IMU获取底盘转动角速度 -#include "ins_task.h" -#endif // CHASSIS_BOARD - -typedef struct -{ -#ifdef CHASSIS_BOARD - IMU_Data_t Chassis_IMU_data; -#endif // CHASSIS_BOARD - // SuperCAP cap; - dji_motor_instance lf; //left right forward - dji_motor_instance rf; - dji_motor_instance lb; - dji_motor_instance rb; - -} chassis; - void ChassisInit(); void ChassisTask(); diff --git a/application/cmd/chassis_cmd.c b/application/cmd/chassis_cmd.c index c05c298..8c7d871 100644 --- a/application/cmd/chassis_cmd.c +++ b/application/cmd/chassis_cmd.c @@ -1,96 +1,22 @@ -// #include -// #include -// void chassis_board_com_lost(void* obj) { -// //暂时没有效用 -// } -// chassis_board_cmd::chassis_board_cmd() : sender([&] { -// can_send::can_send_config config; -// config.device = &BSP_CanTypeDef::can_devices[1]; -// config.can_identifier = 0x003; -// return config; -// }()), -// recver([&] { -// can_recv::can_recv_config config; -// config.device = &BSP_CanTypeDef::can_devices[1]; -// config.can_identifier = 0x004; -// config.lost_callback = chassis_board_com_lost; -// return config; -// }()), -// board_buzzer([&] { -// buzzer::buzzer_config config; -// //底盘音乐2 -// config.music = &buzzer::buzzer_musics[2]; -// config.pwm_device = &BSP_PWM_Typedef::pwm_ports[PWM_BUZZER_PORT]; -// return config; -// }()) { -// robot_mode = robot_stop; -// robot_ready = 0; -// chassis_upload_data = NULL; -// board_recv = recver.recv_data; -// memset(&chassis_control, 0, sizeof(cmd_chassis)); -// memset(&board_send, 0, sizeof(chassis_board_send)); -// } +#include "robot_def.h" +#include "chassis_cmd.h" +#include "referee.h" -// void chassis_board_cmd::update() { -// //初始化为RUN -// robot_mode = robot_run; +#ifndef ONE_BOARD +#include "can_comm.h" +static CANCommInstance *chasiss_can_comm; // 双板通信CAN comm +#endif // !ONE_BOARD -// //判断板间通信在线 -// if (!recver.is_online()) { -// robot_mode = robot_stop; //板间通信掉线,机器人停止 -// } +static Chassis_Ctrl_Cmd_s chassis_cmd; // 发送给chassis应用的控制信息 +static Chassis_Upload_Data_s chassis_fetch_data; // chassis反馈的数据 +static Chassis2Gimbal_Data_s data_to_gimbal_cmd; // 发送给gimbal_cmd的数据,包括热量限制,底盘功率等 +static Gimbal2Chassis_Data_s data_from_gimbal_cmd; // 来自gimbal_cmd的数据,主要是底盘控制量 +static referee_info_t *referee_data; // 裁判系统的数据 -// //接收底盘回传信息,判断底盘IMU在线且初始化完成 -// static subscriber chassis_upload_suber("upload_chassis"); -// if (!chassis_upload_suber.empty()) { -// chassis_upload_data = chassis_upload_suber.pop(); -// if (chassis_upload_data->chassis_status == module_lost) { //底盘模块掉线 -// robot_mode = robot_stop; -// } -// } +void ChassisCMDInit() +{ +} -// if (chassis_upload_data == NULL) { //底盘模块初始化尚未完成,第一次回传数据未收到 -// robot_mode = robot_stop; -// } else { -// board_send.gyro_yaw = chassis_upload_data->chassis_imu->euler[2]; -// } - -// //判断裁判系统是否在线,并处理掉线情况(未实现) -// board_send.heat_limit_remain = 30; //读取裁判系统 -// board_send.bullet_speed_max = 30; //读取裁判系统 - -// //判断除了云台板stop之外,都已经上线,说明底盘板初始化完成,进入ready状态 -// if (robot_mode == robot_run) { -// if (!robot_ready) { -// robot_ready = 1; -// board_buzzer.start(); //播放音乐 -// } -// board_send.chassis_board_status = module_run; -// } else { -// board_send.chassis_board_status = module_lost; -// } - -// //云台板进入stop模式 -// if (board_recv->robot_mode == robot_stop) { -// robot_mode = robot_stop; -// } - -// if (robot_mode == robot_stop) { -// // STOP模式 -// chassis_control.mode = chassis_stop; -// } else { -// // RUN模式 -// // 底盘控制指令 -// chassis_control.mode = board_recv->chassis_mode; -// chassis_control.speed = board_recv->chassis_speed; -// chassis_control.power.power_buffer = 0; //应该由裁判系统获得,未实现 -// chassis_control.power.power_limit = 50; //应该由裁判系统获得,未实现 -// } - -// //发布指令 -// static publisher chassis_puber("cmd_chassis"); -// chassis_puber.push(&chassis_control); - -// //板间通信 -// sender.send(board_send); -// } \ No newline at end of file +void ChassisCMDTask() +{ +} diff --git a/application/cmd/chassis_cmd.h b/application/cmd/chassis_cmd.h index b874790..d93b776 100644 --- a/application/cmd/chassis_cmd.h +++ b/application/cmd/chassis_cmd.h @@ -1,25 +1,8 @@ -// #ifndef _CHASSIS_BOARD_CMD_H_ -// #define _CHASSIS_BOARD_CMD_H_ -// #include -// #include -// #include -// #include -// #include -// class chassis_board_cmd { -// private: -// Robot_mode robot_mode; //机器人状态 -// cmd_chassis chassis_control; //发送给底盘的控制量 -// upload_chassis* chassis_upload_data; //底盘模块回传数据 -// chassis_board_send board_send; //发送给云台主控的数据 -// can_send sender; //板间通信发送 -// can_recv recver; //板间通信接收 -// gimbal_board_send* board_recv; //板间通信接收数据指针 -// void* referee; //裁判系统(尚未完成) -// buzzer board_buzzer; //蜂鸣器 -// uint8_t robot_ready; //底盘板是否准备好 -// public: -// chassis_board_cmd(); -// void update(); -// }; +#ifndef CHASSIS_CMD_H +#define CHASSIS_CMD_H -// #endif \ No newline at end of file +void ChassisCMDInit(); + +void ChassisCMDTask(); + +#endif // !CHASSIS_CMD_H \ No newline at end of file diff --git a/application/cmd/gimbal_cmd.c b/application/cmd/gimbal_cmd.c index 0d82a89..edbf924 100644 --- a/application/cmd/gimbal_cmd.c +++ b/application/cmd/gimbal_cmd.c @@ -1,336 +1,44 @@ -// #include "gimbal_board_cmd.h" +#include "robot_def.h" +#include "gimbal_cmd.h" +#include "remote_control.h" +#include "ins_task.h" +#include "master_process.h" -// #include "bsp_can.h" -// #include "bsp_log.h" -// #include "bsp_uart.h" -// #include "common.h" -// #include "pub_sub.h" -// #include "string.h" -// #define INIT_FORWARD 3152 // 云台朝向底盘正前时云台yaw编码器值 +#ifndef ONE_BOARD +#include "can_comm.h" +static CANCommInstance *chasiss_can_comm; +#endif // !ONE_BOARD -// void gimbal_board_com_lost(void* obj) { -// //暂时没有效用 -// } +static Gimbal_Ctrl_Cmd_s gimbal_cmd_send; // 传递给云台的控制信息 +static Shoot_Ctrl_Cmd_s shoot_cmd_send; // 传递给发射的控制信息 +static Gimbal_Upload_Data_s gimbal_fetch_data; // 从云台获取的反馈信息 +static Shoot_Upload_Data_s shoot_fetch_data; // 从发射获取的反馈信息 +static Gimbal2Chassis_Data_s data_to_chassis_cmd; // 发送给底盘CMD应用的控制信息,主要是遥控器和UI绘制相关 +static Chassis2Gimbal_Data_s data_from_chassis_cmd; // 从底盘CMD应用接收的控制信息,底盘功率枪口热量等 +static RC_ctrl_t *remote_control_data; // 遥控器数据 +static Vision_Recv_s *vision_recv_data; // 视觉接收数据 +static Vision_Send_s *vision_send_data; // 视觉发送数据 -// //此处涉及到lamdba表达式的应用 -// gimbal_board_cmd::gimbal_board_cmd() : sender([&] { -// //板间通信:发 -// can_send::can_send_config config; -// config.device = &BSP_CanTypeDef::can_devices[1]; -// config.can_identifier = 0x004; -// return config; -// }()), -// recver([&] { -// //板间通信:收 -// can_recv::can_recv_config config; -// config.device = &BSP_CanTypeDef::can_devices[1]; -// config.can_identifier = 0x003; -// config.notify_func = NULL; -// config.lost_callback = gimbal_board_com_lost; -// return config; -// }()), -// pc([&] { -// //小电脑通信配置 -// canpc::canpc_config config; -// config.device = &BSP_CanTypeDef::can_devices[0]; -// config.recv_identifer = 0x001; -// return config; -// }()), -// remote([&] { -// dt7Remote::dt7_config config; -// config.uart_device = &BSP_UART_Typedef::uart_ports[UART_REMOTE_PORT]; -// return config; -// }()), -// board_buzzer([&] { -// buzzer::buzzer_config config; -// config.pwm_device = &BSP_PWM_Typedef::pwm_ports[PWM_BUZZER_PORT]; -// config.music = &buzzer::buzzer_musics[1]; -// return config; -// }()) { -// robot_mode = robot_stop; -// robot_ready = 0; -// autoaim_mode = auto_aim_off; -// gimbal_upload_data = NULL; -// //指针指向接收的实际数据 -// board_recv = recver.recv_data; -// memset(&gimbal_control, 0, sizeof(cmd_gimbal)); -// memset(&shoot_control, 0, sizeof(cmd_shoot)); -// memset(&board_send, 0, sizeof(gimbal_board_send)); -// } +static void CalcOffsetAngle() +{ +} -// float get_offset_angle(short init_forward, short now_encoder) { -// short tmp = 0; -// if (init_forward < 4096) { -// if (now_encoder > init_forward && now_encoder <= 4096 + init_forward) { -// tmp = now_encoder - init_forward; -// } else if (now_encoder > 4096 + init_forward) { -// tmp = -8192 + now_encoder - init_forward; -// } else { -// tmp = now_encoder - init_forward; -// } -// } else { -// if (now_encoder > init_forward) { -// tmp = now_encoder - init_forward; -// } else if (now_encoder <= init_forward && now_encoder >= init_forward - 4096) { -// tmp = now_encoder - init_forward; -// } else { -// tmp = now_encoder + 8192 - init_forward; -// } -// } -// return tmp * 360.0 / 8192.0; -// } +static void SetRobotMode() +{ +} -// void gimbal_board_cmd::update() { -// //第一步,判断机器人工作模式 +static void SetCtrlData() +{ +} -// //初始化为RUN -// robot_mode = robot_run; +static void SetCtrlMessage() +{ +} -// //判断板间通信在线 -// if (!recver.is_online()) { -// robot_mode = robot_stop; //板间通信掉线,机器人停止 -// } +void GimbalCMDInit() +{ +} -// //接收云台回传信息,判断云台IMU在线且初始化完成 -// static subscriber gimbal_upload_suber("upload_gimbal"); -// if (!gimbal_upload_suber.empty()) { -// gimbal_upload_data = gimbal_upload_suber.pop(); -// if (gimbal_upload_data->gimbal_status == module_lost) { //云台模块掉线 -// robot_mode = robot_stop; -// } -// //计算云台和底盘的夹角 offset_angle -// board_send.chassis_speed.offset_angle = get_offset_angle(INIT_FORWARD, *gimbal_upload_data->yaw_encoder); -// pc.pc_send_data.euler[0] = gimbal_upload_data->gimbal_imu->euler[0]; -// pc.pc_send_data.euler[1] = gimbal_upload_data->gimbal_imu->euler[1]; -// pc.pc_send_data.euler[2] = gimbal_upload_data->gimbal_imu->euler[2]; -// pc.pc_send_data.auto_mode_flag = auto_aim_normal; -// } - -// if (gimbal_upload_data == NULL) { //云台模块初始化尚未完成,第一次回传数据未收到 -// robot_mode = robot_stop; -// } - -// //如果除遥控器之外都已经上线,说明机器人初始化完成,进入ready状态 -// if (robot_mode == robot_run) { -// if (!robot_ready) { -// robot_ready = 1; -// board_buzzer.start(); //蜂鸣器播放初始化提示音 -// } -// } - -// //遥控器判断 -// if (!remote.monitor_item.is_online()) { -// //遥控器掉线 -// robot_mode = robot_stop; -// } else if (remote.data.input_mode == dt7Remote::RC_Stop) { -// //遥控器处于stop档位 -// robot_mode = robot_stop; -// } - -// //第二步,机器人控制主要逻辑 -// // STOP模式 -// if (robot_mode == robot_stop) { -// stop_mode_update(); -// } -// // 运行模式 -// if (robot_mode == robot_run) { -// //遥控器控制模式 -// if (remote.data.input_mode == dt7Remote::RC_Remote) { -// remote_mode_update(); -// } else if (remote.data.input_mode == dt7Remote::RC_MouseKey) { -// mouse_key_mode_update(); -// } -// } -// //发布命令,板间通信 -// send_cmd_and_data(); -// } - -// void gimbal_board_cmd::stop_mode_update() { -// board_send.robot_mode = robot_stop; -// board_send.chassis_mode = chassis_stop; -// gimbal_control.gimbal_mode = gimbal_stop; -// shoot_control.shoot_mode = shoot_stop; -// shoot_control.bullet_mode = bullet_holdon; -// } - -// void gimbal_board_cmd::remote_mode_update() { -// //云台控制参数 -// gimbal_control.gimbal_mode = gimbal_run; -// gimbal_control.yaw -= 0.04f * ((float)remote.data.rc.ch2 - CHx_BIAS); -// gimbal_control.pitch = -1.0f * ((float)remote.data.rc.ch3 - CHx_BIAS); -// gimbal_control.rotate_feedforward = 0; //目前没有使用小陀螺前馈 - -// //底盘控制参数 -// if (remote.data.rc.s1 == 1) { -// //小陀螺模式 -// board_send.chassis_mode = chassis_rotate_run; -// board_send.chassis_speed.vy = 16.0 * 0.6 * (float)(remote.data.rc.ch1 - CHx_BIAS); -// board_send.chassis_speed.vx = 16.0 * 0.6 * (float)(remote.data.rc.ch0 - CHx_BIAS); -// } else { -// //底盘跟随模式 -// board_send.chassis_mode = chassis_run_follow_offset; -// board_send.chassis_speed.vy = 16.0 * (float)(remote.data.rc.ch1 - CHx_BIAS); -// board_send.chassis_speed.vx = 16.0 * (float)(remote.data.rc.ch0 - CHx_BIAS); -// } - -// //发射机构控制 -// if (remote.data.rc.s1 == 2) { -// shoot_control.bullet_mode = bullet_holdon; //在发射停止位关闭播弹轮 -// shoot_control.shoot_mode = shoot_stop; //在发射停止位关闭摩擦轮 -// //弹仓盖控制 -// if (remote.data.rc.ch4 > CHx_BIAS + 400) shoot_control.mag_mode = magazine_open; -// if (remote.data.rc.ch4 < CHx_BIAS - 400) shoot_control.mag_mode = magazine_close; -// } else { -// //发弹控制 -// shoot_control.shoot_mode = shoot_run; //开摩擦轮 -// shoot_control.bullet_mode = bullet_continuous; //连续发射 -// shoot_control.fire_rate = 0.01f * (float)(remote.data.rc.ch4 - CHx_BIAS); //射频 -// shoot_control.heat_limit_remain = board_recv->heat_limit_remain; //下板传回的热量剩余 -// shoot_control.bullet_speed = board_recv->bullet_speed_max; //下板传回的子弹速度上限 -// } -// } - -// void gimbal_board_cmd::mouse_key_mode_update() { -// // r:小陀螺模式 -// if (remote.data.key_single_press_cnt.r != remote.last_data.key_single_press_cnt.r) { -// if (board_send.chassis_mode != chassis_rotate_run) { -// board_send.chassis_mode = chassis_rotate_run; //小陀螺模式 -// gimbal_control.gimbal_mode = gimbal_run; //云台正常模式 -// } else { -// board_send.chassis_mode = chassis_run_follow_offset; //底盘跟随云台 -// gimbal_control.gimbal_mode = gimbal_run; //云台正常模式 -// } -// } -// // v:云台底盘独立模式 -// if (remote.data.key_single_press_cnt.v != remote.last_data.key_single_press_cnt.v) { -// if (board_send.chassis_mode != chassis_run || gimbal_control.gimbal_mode != gimbal_run) { -// board_send.chassis_mode = chassis_run; //底盘独立模式 -// gimbal_control.gimbal_mode = gimbal_run; //云台正常模式 -// } else { -// board_send.chassis_mode = chassis_run_follow_offset; //底盘跟随云台 -// gimbal_control.gimbal_mode = gimbal_run; //云台正常模式 -// } -// } -// // x:云台跟随底盘模式 -// if (remote.data.key_single_press_cnt.x != remote.last_data.key_single_press_cnt.x) { -// if (board_send.chassis_mode != chassis_run || gimbal_control.gimbal_mode != gimbal_middle) { -// board_send.chassis_mode = chassis_run; //底盘独立模式 -// gimbal_control.gimbal_mode = gimbal_run; //云台跟随底盘模式 -// } else { -// board_send.chassis_mode = chassis_run_follow_offset; //底盘跟随云台 -// gimbal_control.gimbal_mode = gimbal_run; //云台正常模式 -// } -// } -// // z:爬坡模式(待添加) -// // f:正常自瞄模式 -// if (remote.data.key_single_press_cnt.f != remote.last_data.key_single_press_cnt.f) { -// if (autoaim_mode != auto_aim_normal) { -// autoaim_mode = auto_aim_normal; -// } else { -// autoaim_mode = auto_aim_off; -// } -// } -// // g:小符 -// if (remote.data.key_single_press_cnt.f != remote.last_data.key_single_press_cnt.f) { -// if (autoaim_mode != auto_aim_buff_small) { -// autoaim_mode = auto_aim_buff_small; -// } else { -// autoaim_mode = auto_aim_off; -// } -// } -// // b:大符 -// if (remote.data.key_single_press_cnt.f != remote.last_data.key_single_press_cnt.f) { -// if (autoaim_mode != auto_aim_buff_big) { -// autoaim_mode = auto_aim_buff_big; -// } else { -// autoaim_mode = auto_aim_off; -// } -// } -// pc.pc_send_data.auto_mode_flag = autoaim_mode; -// // c:开关弹仓 -// if (remote.data.key_single_press_cnt.c != remote.last_data.key_single_press_cnt.c) { -// if (shoot_control.mag_mode == magazine_open) { -// shoot_control.mag_mode = magazine_close; -// } else { -// shoot_control.mag_mode = magazine_open; -// } -// } -// //底盘控制参数 -// // wasd -// if (remote.data.key_down.w) board_send.chassis_speed.vy = 8000; -// if (remote.data.key_down.s) board_send.chassis_speed.vy = -8000; -// if (remote.data.key_down.d) board_send.chassis_speed.vx = 8000; -// if (remote.data.key_down.a) board_send.chassis_speed.vx = -8000; - -// //按住ctrl减速 -// if (remote.data.key_down.ctrl) { -// board_send.chassis_speed.vx /= 3.0; -// board_send.chassis_speed.vy /= 3.0; -// } - -// //按住shift加速 -// if (remote.data.key_down.shift) { -// board_send.chassis_speed.vx *= 3.0; -// board_send.chassis_speed.vy *= 3.0; -// } - -// // q和e -// if (remote.data.key_down.q) { -// if (board_send.chassis_mode == chassis_run) { -// board_send.chassis_speed.rotate = -90; -// } else if (board_send.chassis_mode == chassis_run_follow_offset) { -// gimbal_control.yaw -= 15; //通过控制云台yaw轴带动底盘 -// } -// } - -// if (remote.data.key_down.e) { -// if (board_send.chassis_mode == chassis_run) { -// board_send.chassis_speed.rotate = 90; -// } else if (board_send.chassis_mode == chassis_run_follow_offset) { -// gimbal_control.yaw += 15; //通过控制云台yaw轴带动底盘 -// } -// } - -// //云台控制参数 -// if (gimbal_control.gimbal_mode == gimbal_run) { -// if (autoaim_mode == auto_aim_off) { -// gimbal_control.yaw -= 0.5f * (0.7f * (remote.data.mouse.x) + 0.3f * (remote.last_data.mouse.x)); -// gimbal_control.pitch -= -0.1f * ((float)remote.data.mouse.y); -// } else { -// //计算真实yaw值 -// float yaw_target = pc.pc_recv_data->yaw * 8192.0 / 2 / pi + gimbal_upload_data->gimbal_imu->round * 8192.0; -// if (pc.pc_recv_data->yaw - gimbal_upload_data->gimbal_imu->euler[2] > pi) yaw_target -= 8192; -// if (pc.pc_recv_data->yaw - gimbal_upload_data->gimbal_imu->euler[2] < -pi) yaw_target += 8192; -// gimbal_control.yaw = yaw_target; -// gimbal_control.pitch = pc.pc_recv_data->roll * 8192.0 / 2 / pi; // 根据当前情况决定,pitch轴反馈为陀螺仪roll -// } -// } else if (gimbal_control.gimbal_mode == gimbal_middle) { -// //云台跟随底盘模式,待完善 -// } - -// //发射机构控制参数 -// if (remote.data.rc.s1 == 2) { -// shoot_control.bullet_mode = bullet_holdon; -// shoot_control.shoot_mode = shoot_stop; -// } else { -// //发弹控制,单发,双发, 射频和小电脑控制待完善 -// shoot_control.shoot_mode = shoot_run; //开摩擦轮 -// shoot_control.heat_limit_remain = board_recv->heat_limit_remain; //下板传回的热量剩余 -// shoot_control.bullet_speed = board_recv->bullet_speed_max; //下板传回的子弹速度上限 -// shoot_control.fire_rate = 3; //固定射频 -// if (remote.data.mouse.press_l) { -// shoot_control.bullet_mode = bullet_continuous; -// } else { -// shoot_control.bullet_mode = bullet_holdon; -// } -// } -// } - -// void gimbal_board_cmd::send_cmd_and_data() { -// static publisher gimbal_puber("cmd_gimbal"); -// static publisher shoot_puber("cmd_shoot"); -// gimbal_puber.push(&gimbal_control); -// shoot_puber.push(&shoot_control); -// sender.send(board_send); -// pc.send(pc.pc_send_data); -// } \ No newline at end of file +void GimbalCMDTask() +{ +} diff --git a/application/cmd/gimbal_cmd.h b/application/cmd/gimbal_cmd.h index eff9bc9..8f0931d 100644 --- a/application/cmd/gimbal_cmd.h +++ b/application/cmd/gimbal_cmd.h @@ -1,35 +1,8 @@ -// #ifndef _GIMBAL_ROBOT_CMD_H -// #define _GIMBAL_ROBOT_CMD_H -// #include -// #include -// #include -// #include -// #include -// class gimbal_board_cmd { -// private: -// gimbal_board_send board_send; //需要发送给下板的板间通信数据 -// cmd_gimbal gimbal_control; //发送给云台的控制量 -// cmd_shoot shoot_control; //发送给发射机构的控制量 +#ifndef GIMBAL_CMD_H +#define GIMBAL_CMD_H -// can_send sender; //板间通信发送 -// can_recv recver; //板间通信接收 -// chassis_board_send* board_recv; //板间通信接收数据指针 -// canpc pc; //小电脑视觉数据 -// dt7Remote remote; //遥控器 -// Robot_mode robot_mode; //机器人模式 -// uint8_t robot_ready; //机器人准备好标志位 -// AutoAim_mode autoaim_mode; //机器人自瞄模式 -// buzzer board_buzzer; //蜂鸣器 -// upload_gimbal* gimbal_upload_data; //云台模块回传的数据 +void GimbalCMDInit(); -// void stop_mode_update(); //机器人停止模式更新函数 -// void remote_mode_update(); //机器人遥控器模式更新函数 -// void mouse_key_mode_update(); //机器人键鼠模式更新函数 -// void send_cmd_and_data(); //发布指令和板间通信 +void GimbalCMDTask(); -// public: -// gimbal_board_cmd(); -// void update(); -// }; - -// #endif \ No newline at end of file +#endif // !GIMBAL_CMD_H \ No newline at end of file diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index 050ea37..a1fb2d8 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -1,11 +1,18 @@ #include "gimbal.h" +#include "robot_def.h" +#include "dji_motor.h" +#include "ins_task.h" + +static IMU_Data_t Gimbal_IMU_data; // 云台IMU数据 +static dji_motor_instance yaw; // yaw电机 +static dji_motor_instance pitch; // pitch电机 +static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自gimbal_cmd的控制信息 +static Gimbal_Upload_Data_s gimbal_feedback_data; // 回传给gimbal_cmd的云台状态信息 void GimbalInit() { - } void GimbalTask() { - } \ No newline at end of file diff --git a/application/gimbal/gimbal.h b/application/gimbal/gimbal.h index b66b72a..ca6eb17 100644 --- a/application/gimbal/gimbal.h +++ b/application/gimbal/gimbal.h @@ -1,17 +1,6 @@ #ifndef GIMBAL_H #define GIMBAL_H -#include "robot_def.h" -#include "dji_motor.h" -#include "ins_task.h" - -typedef struct -{ - IMU_Data_t Gimbal_IMU_data; - dji_motor_instance yaw; - dji_motor_instance pitch; -} gimbal; - void GimbalInit(); void GimbalTask(); diff --git a/application/robot_def.h b/application/robot_def.h index 4287804..5a11a77 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -1,11 +1,181 @@ #ifndef ROBOT_DEF_H #define ROBOT_DEF_H +#include "ins_task.h" +#include "master_process.h" +#include "stdint-gcc.h" + /* 开发板类型定义,烧录时注意不要弄错对应功能;修改定义后需要重新编译 */ -#define ONE_BOARD //单板控制整车 -#define CHASSIS_BOARD //底盘板 -#define GIMBAL_BOARD //云台板 +/* 只能存在一个宏定义! */ +#define ONE_BOARD // 单板控制整车 +// #define CHASSIS_BOARD //底盘板 +// #define GIMBAL_BOARD //云台板 + +/* 重要参数定义,注意根据不同机器人进行修改 */ +#define YAW_MID_ECD + +#if (defined(ONE_BOARD) && defined(CHASSIS_BOARD)) || \ + (defined(ONE_BOARD) && defined(GIMBAL_BOARD)) || \ + (defined(CHASSIS_BOARD) && defined(GIMBAL_BOARD)) +#error Conflict board definition! You can only define one type. +#endif // 检查是否出现定义冲突 + +#pragma pack(1) // 压缩结构体,取消字节对齐 + +/* -------------------------基本控制模式和数据类型定义-------------------------*/ +/** + * @brief 这些枚举类型和结构体会作为CMD控制数据和各应用的反馈数据的一部分 + * + */ + +// 应用状态 +typedef enum +{ + APP_OFFLINE, + APP_ONLINE, + APP_ERROR, +} App_Status_e; + +// 底盘模式设置 +typedef enum +{ + CHASSIS_ZERO_FORCE, // 电流零输入 + CHASSIS_ROTATE, // 小陀螺模式 + CHASSIS_NO_FOLLOW, // 不跟随,允许全向平移 + CHASSIS_FOLLOW_GIMBAL_YAW, // 跟随模式,底盘叠加角度环控制 +} chassis_mode_e; + +// 云台模式设置 +typedef enum +{ + GIMBAL_ZERO_FORCE, // 电流零输入 + GIMBAL_FREE_MODE, // 云台自由运动模式,反馈值为电机total_angle + GIMBAL_GYRO_MODE, // 云台陀螺仪反馈模式,反馈值为陀螺仪pitch,total_yaw_angle + GIMBAL_VISUAL_MODE, // 视觉模式,反馈值为陀螺仪,输入为视觉数据 +} gimbal_mode_e; + +// 发射模式设置 +typedef enum +{ + FRICTION_OFF, // 摩擦轮关闭 + FRICTION_ON, // 摩擦轮开启 +} shoot_mode_e; + +typedef enum +{ + LID_CLOSE, // 弹舱盖打开 + LID_ON, // 弹舱盖关闭 +} lid_mode_e; + +typedef enum +{ + LOAD_STOP, // 停止发射 + LOAD_REVERSE, // 反转 + LOAD_1_BULLET, // 单发 + LOAD_3_BULLET, // 三发 + LOAD_BURSTFIRE, // 连发 +} loader_mode_e; + +// 功率限制,从裁判系统获取 +typedef struct +{ // 功率控制 + uint8_t power_limit; + uint8_t buffer_power_rest; +} Chassis_Power_Data_s; + +/* ------------CMD模块之间的控制数据传递,应当由gimbal_cmd和chassis_cmd订阅------------ */ +/** + * @brief 对于双板通信的情况,两个CMD模块各有一个can comm. + * + */ + +// gimbal_cmd发布的底盘控制数据,由chassis_cmd订阅 +// 注意这里没有功率限制,为了兼容双板模式,先让chassis_cmd订阅,后者会添加功率信息再发布 +typedef struct +{ + // 速度控制 + float vx; // 前进方向速度 + float vy; // 横移方向速度 + float wz; // 旋转速度 + float offset_angle; // 底盘和归中位置的夹角 + + chassis_mode_e chassis_mode; +} Gimbal2Chassis_Data_s; + +// chassis_cmd发布的裁判系统和底盘信息相关的数据,由gimbal_cmd订阅 +typedef struct +{ + float chassis_real_rotate_wz; + uint8_t rest_heat; + Bullet_Speed_e bullet_speed; + Enemy_Color_e enemy_color; // 0 for blue, 1 for red +} Chassis2Gimbal_Data_s; + + + + +/* ----------------CMD应用发布的控制数据,应当由gimbal/chassis/shoot订阅---------------- */ +/** + * @brief 对于双板情况,遥控器和pc在云台,裁判系统在底盘 + * + */ +// chassis_cmd根据raw ctrl data添加功率限制后发布的底盘控制数据,由chassis订阅 +typedef struct +{ + Chassis_Power_Data_s chassis_power; + Gimbal2Chassis_Data_s chassis_cmd; +} Chassis_Ctrl_Cmd_s; + +// gimbal_cmd发布的云台控制数据,由gimbal订阅 +typedef struct +{ // 云台角度控制 + float yaw; + float pitch; + float chassis_rotate_wz; + + gimbal_mode_e gimbal_mode; +} Gimbal_Ctrl_Cmd_s; + +// gimba_cmd发布的发射控制数据,由shoot订阅 +typedef struct +{ // 发射弹速控制 + loader_mode_e load_mode; + lid_mode_e lid_mode; + shoot_mode_e shoot_mode; + Bullet_Speed_e bullet_speed; + uint8_t rest_heat; +} Shoot_Ctrl_Cmd_s; + + + + +/* ----------------gimbal/shoot/chassis发布的反馈数据----------------*/ +/** + * @brief 由cmd订阅,其他应用也可以根据需要获取. + * + */ + +typedef struct +{ +#ifdef CHASSIS_BOARD + attitude_t chassis_imu_data; +#endif // CHASSIS_BOARD +} Chassis_Upload_Data_s; + +typedef struct +{ + attitude_t gimbal_imu_data; +} Gimbal_Upload_Data_s; + +typedef struct +{ + // code to go here + // ... +} Shoot_Upload_Data_s; + +#pragma pack() // 开启字节对齐 + #endif // !ROBOT_DEF_H \ No newline at end of file diff --git a/application/shoot/shoot.c b/application/shoot/shoot.c index 3e83dfc..1104d25 100644 --- a/application/shoot/shoot.c +++ b/application/shoot/shoot.c @@ -1,11 +1,17 @@ #include "shoot.h" +#include "robot_def.h" +#include "dji_motor.h" + +static dji_motor_instance *friction_l; // 左摩擦轮 +static dji_motor_instance *friction_r; // 右摩擦轮 +static dji_motor_instance *loader; // 拨盘电机 +static Shoot_Ctrl_Cmd_s shoot_cmd_recv; // 来自gimbal_cmd的发射控制信息 +static Shoot_Upload_Data_s shoot_feedback_data; // 反馈回gimbal_cmd的发射状态信息 void ShootInit() { - } void ShootTask() { - } \ No newline at end of file diff --git a/application/shoot/shoot.h b/application/shoot/shoot.h index e90084f..a6463d1 100644 --- a/application/shoot/shoot.h +++ b/application/shoot/shoot.h @@ -1,17 +1,6 @@ #ifndef SHOOT_H #define SHOOT_H -#include "robot_def.h" -#include "dji_motor.h" - -typedef struct -{ - dji_motor_instance friction_l; - dji_motor_instance friction_r; - dji_motor_instance loader; - -} shoot; - void ShootInit(); void ShootTask(); diff --git a/modules/monitor/monitor.c b/modules/monitor/monitor.c new file mode 100644 index 0000000..8a7d7ac --- /dev/null +++ b/modules/monitor/monitor.c @@ -0,0 +1 @@ +#include "monitor.h" \ No newline at end of file diff --git a/modules/monitor/monitor.h b/modules/monitor/monitor.h new file mode 100644 index 0000000..5048c55 --- /dev/null +++ b/modules/monitor/monitor.h @@ -0,0 +1,6 @@ +#ifndef MONITOR_H +#define MONITOR_H + + + +#endif // !MONITOR_H \ No newline at end of file diff --git a/modules/monitor/monitor.md b/modules/monitor/monitor.md new file mode 100644 index 0000000..e69de29