From 02b3af15c750774ee22123ac1b0391e83937a86e Mon Sep 17 00:00:00 2001 From: NeoZng Date: Fri, 9 Dec 2022 14:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=81=A5=E6=8E=A7?= =?UTF-8?q?=E5=99=A8=E6=91=87=E6=9D=86=E5=80=BC=E8=A7=A3=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chassis/chassis.c | 6 +++--- application/cmd/robot_cmd.c | 14 +++++++------- application/gimbal/gimbal.c | 4 ++-- application/robot_def.h | 7 +++---- application/shoot/shoot.c | 21 ++++++++------------- modules/remote/remote_control.c | 10 +++++----- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/application/chassis/chassis.c b/application/chassis/chassis.c index 311c62d..3fcf815 100644 --- a/application/chassis/chassis.c +++ b/application/chassis/chassis.c @@ -59,15 +59,15 @@ void ChassisInit() { // 四个轮子的参数一样,改tx_id和反转标志位即可 Motor_Init_Config_s chassis_motor_config = { - .can_init_config.can_handle=&hcan2, + .can_init_config.can_handle=&hcan1, .controller_param_init_config = { .speed_PID = { - .Kp=1, + .Kp=10, .Ki=0, .Kd=0, }, .current_PID = { - .Kp=1, + .Kp=10, .Ki=0, .Kd=0, }, diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index a525911..e807a35 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -98,8 +98,8 @@ static void RemoteControlSet() // 左侧开关状态为[下],或视觉未识别到目标,纯遥控器拨杆控制 if (switch_is_down(rc_data[TEMP].rc.s[1]) || vision_recv_data->target_state == NO_TARGET) { // 按照摇杆的输出大小进行角度增量,增益系数需调整 - gimbal_cmd_send.yaw += 0.04f * (float)rc_data[TEMP].rc.joystick[2]; - gimbal_cmd_send.pitch += 0.5f * (float)rc_data[TEMP].rc.joystick[3]; + gimbal_cmd_send.yaw += 0.0015f * (float)rc_data[TEMP].rc.joystick[2]; + gimbal_cmd_send.pitch += 0.0025f * (float)rc_data[TEMP].rc.joystick[3]; gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE; } @@ -114,9 +114,9 @@ static void RemoteControlSet() ; // 弹舱舵机控制,待添加servo_motor模块,关闭 // 摩擦轮控制,后续可以根据左侧拨轮的值大小切换射频 if (rc_data[TEMP].rc.joystick[4] > 100) - shoot_cmd_send.shoot_mode = FRICTION_ON; + shoot_cmd_send.friction_mode = FRICTION_ON; else - shoot_cmd_send.shoot_mode = FRICTION_OFF; + shoot_cmd_send.friction_mode = FRICTION_OFF; // 拨弹控制,目前固定为连发 if (rc_data[TEMP].rc.joystick[4] > 500) shoot_cmd_send.load_mode = LOAD_BURSTFIRE; @@ -143,9 +143,9 @@ static void EmergencyHandler() if (rc_data[TEMP].rc.joystick[4] > 300) // 还需添加重要应用和模块离线的判断 { robot_state = ROBOT_STOP; // 遥控器左上侧拨轮打满,进入紧急停止模式 - gimbal_cmd_send.gimbal_mode == GIMBAL_ZERO_FORCE; - chassis_cmd_send.chassis_mode == CHASSIS_ZERO_FORCE; - shoot_cmd_send.shoot_mode == SHOOT_STOP; + gimbal_cmd_send.gimbal_mode = GIMBAL_ZERO_FORCE; + chassis_cmd_send.chassis_mode = CHASSIS_ZERO_FORCE; + shoot_cmd_send.load_mode = SHOOT_STOP; return; } // if(rc_data[TEMP].rc.joystick[4]<-300 && 各个模块正常) diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index d5e4411..f8fb668 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -22,7 +22,7 @@ void GimbalInit() Motor_Init_Config_s yaw_config = { .can_init_config = { .can_handle = &hcan1, - .tx_id = 1, + .tx_id = 2, }, .controller_param_init_config = { .angle_PID = { @@ -51,7 +51,7 @@ void GimbalInit() Motor_Init_Config_s pitch_config = { .can_init_config = { .can_handle = &hcan1, - .tx_id = 2, + .tx_id = 1, }, .controller_param_init_config = { .angle_PID = { diff --git a/application/robot_def.h b/application/robot_def.h index 07bd0cf..3d30cc5 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -52,14 +52,13 @@ * @brief 这些枚举类型和结构体会作为CMD控制数据和各应用的反馈数据的一部分 * */ -//机器人状态 +// 机器人状态 typedef enum { ROBOT_STOP, ROBOT_WORKING, } Robot_Status_e; - // 应用状态 typedef enum { @@ -94,7 +93,7 @@ typedef enum { FRICTION_OFF, // 摩擦轮关闭 FRICTION_ON, // 摩擦轮开启 -} shoot_mode_e; +} friction_mode_e; typedef enum { @@ -153,7 +152,7 @@ typedef struct { loader_mode_e load_mode; lid_mode_e lid_mode; - shoot_mode_e shoot_mode; + friction_mode_e friction_mode; Bullet_Speed_e bullet_speed; // 弹速枚举 uint8_t rest_heat; float shoot_rate; // 连续发射的射频,unit per s,发/秒 diff --git a/application/shoot/shoot.c b/application/shoot/shoot.c index 1da35f6..e84ac5a 100644 --- a/application/shoot/shoot.c +++ b/application/shoot/shoot.c @@ -24,17 +24,17 @@ void ShootInit() // 左摩擦轮 Motor_Init_Config_s left_friction_config = { .can_init_config = { - .can_handle = &hcan1, - .tx_id = 1, + .can_handle = &hcan2, + .tx_id = 6, }, .controller_param_init_config = { .speed_PID = { - .Kp=1, + .Kp=10, .Ki=0, .Kd=0, }, .current_PID = { - .Kp=1, + .Kp=10, .Ki=0, .Kd=0, }, @@ -51,8 +51,8 @@ void ShootInit() // 右摩擦轮 Motor_Init_Config_s right_friction_config = { .can_init_config = { - .can_handle = &hcan1, - .tx_id = 2, + .can_handle = &hcan2, + .tx_id = 5, }, .controller_param_init_config = { .speed_PID = { @@ -77,8 +77,8 @@ void ShootInit() // 拨盘电机 Motor_Init_Config_s loader_config = { .can_init_config = { - .can_handle = &hcan1, - .tx_id = 3, + .can_handle = &hcan2, + .tx_id = 7, }, .controller_param_init_config = { .angle_PID = { @@ -87,11 +87,6 @@ void ShootInit() .Ki = 1, .Kd = 2, }, - .angle_PID = { - .Kp=1, - .Ki=0, - .Kd=0, - }, .speed_PID = { .Kp=1, .Ki=0, diff --git a/modules/remote/remote_control.c b/modules/remote/remote_control.c index 0eb8634..cd94c54 100644 --- a/modules/remote/remote_control.c +++ b/modules/remote/remote_control.c @@ -19,11 +19,11 @@ static void sbus_to_rc(volatile const uint8_t *sbus_buf) { memcpy(&rc_ctrl[1], &rc_ctrl[TEMP], sizeof(RC_ctrl_t)); // 保存上一次的数据 // 摇杆,直接解算时减去偏置 - rc_ctrl[TEMP].rc.joystick[0] = (sbus_buf[0] | (sbus_buf[1] << 8)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 0 - rc_ctrl[TEMP].rc.joystick[1] = ((sbus_buf[1] >> 3) | (sbus_buf[2] << 5)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 1 - rc_ctrl[TEMP].rc.joystick[2] = ((sbus_buf[2] >> 6) | (sbus_buf[3] << 2) | (sbus_buf[4] << 10)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 2 - rc_ctrl[TEMP].rc.joystick[3] = ((sbus_buf[4] >> 1) | (sbus_buf[5] << 7)) & 0x07ff - RC_CH_VALUE_OFFSET; //!< Channel 3 - rc_ctrl[TEMP].rc.joystick[4] = sbus_buf[16] | (sbus_buf[17] << 8) - RC_CH_VALUE_OFFSET; // 左侧拨轮 + rc_ctrl[TEMP].rc.joystick[0] = ((sbus_buf[0] | (sbus_buf[1] << 8)) & 0x07ff) - RC_CH_VALUE_OFFSET; //!< Channel 0 + rc_ctrl[TEMP].rc.joystick[1] = (((sbus_buf[1] >> 3) | (sbus_buf[2] << 5)) & 0x07ff) - RC_CH_VALUE_OFFSET; //!< Channel 1 + rc_ctrl[TEMP].rc.joystick[2] = (((sbus_buf[2] >> 6) | (sbus_buf[3] << 2) | (sbus_buf[4] << 10)) & 0x07ff) - RC_CH_VALUE_OFFSET; //!< Channel 2 + rc_ctrl[TEMP].rc.joystick[3] = (((sbus_buf[4] >> 1) | (sbus_buf[5] << 7)) & 0x07ff) - RC_CH_VALUE_OFFSET; //!< Channel 3 + rc_ctrl[TEMP].rc.joystick[4] = (sbus_buf[16] | (sbus_buf[17] << 8)) - RC_CH_VALUE_OFFSET; // 左侧拨轮 // 开关,0左1右 rc_ctrl[TEMP].rc.s[0] = ((sbus_buf[5] >> 4) & 0x0003); //!< Switch left rc_ctrl[TEMP].rc.s[1] = ((sbus_buf[5] >> 4) & 0x000C) >> 2; //!< Switch right