优化了点击pid计算流程,修复了bsp未初始化的异常,修复了数个未定义和隐式声明的警告

This commit is contained in:
NeoZng
2022-12-09 18:25:35 +08:00
parent 02b3af15c7
commit 37c23ddb79
16 changed files with 104 additions and 75 deletions

View File

@@ -59,17 +59,19 @@ void ChassisInit()
{
// 四个轮子的参数一样,改tx_id和反转标志位即可
Motor_Init_Config_s chassis_motor_config = {
.can_init_config.can_handle=&hcan1,
.can_init_config.can_handle = &hcan1,
.controller_param_init_config = {
.speed_PID = {
.Kp=10,
.Ki=0,
.Kd=0,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
.current_PID = {
.Kp=10,
.Ki=0,
.Kd=0,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
},
.controller_setting_init_config = {
@@ -78,26 +80,27 @@ void ChassisInit()
.outer_loop_type = SPEED_LOOP,
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
},
.motor_type = M3508};
chassis_motor_config.can_init_config.tx_id=1;
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
.motor_type = M3508,
};
chassis_motor_config.can_init_config.tx_id = 1;
chassis_motor_config.controller_setting_init_config.reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_lf = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=2,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
chassis_motor_config.can_init_config.tx_id = 2,
chassis_motor_config.controller_setting_init_config.reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_rf = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=3,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
chassis_motor_config.can_init_config.tx_id = 3,
chassis_motor_config.controller_setting_init_config.reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_lb = DJIMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id=4,
chassis_motor_config.controller_setting_init_config.reverse_flag=MOTOR_DIRECTION_REVERSE;
chassis_motor_config.can_init_config.tx_id = 4,
chassis_motor_config.controller_setting_init_config.reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_rb = DJIMotorInit(&chassis_motor_config);
referee_data = RefereeInit(&huart6);
SuperCap_Init_Config_s cap_conf = {
.can_config = {
.can_handle = &hcan2,

View File

@@ -99,8 +99,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.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;
gimbal_cmd_send.pitch += 0.002f * (float)rc_data[TEMP].rc.joystick[3];
gimbal_cmd_send.gimbal_mode = GIMBAL_FREE_MODE;
}
// 底盘参数,目前没有加入小陀螺(调试似乎没有必要),系数需要调整
@@ -145,7 +145,7 @@ static void EmergencyHandler()
robot_state = ROBOT_STOP; // 遥控器左上侧拨轮打满,进入紧急停止模式
gimbal_cmd_send.gimbal_mode = GIMBAL_ZERO_FORCE;
chassis_cmd_send.chassis_mode = CHASSIS_ZERO_FORCE;
shoot_cmd_send.load_mode = SHOOT_STOP;
shoot_cmd_send.shoot_mode = SHOOT_OFF;
return;
}
// if(rc_data[TEMP].rc.joystick[4]<-300 && 各个模块正常)

View File

@@ -16,24 +16,27 @@ static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自gimbal_cmd的控制信息
void GimbalInit()
{
Gimbal_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源
// Gimbal_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源
// YAW
Motor_Init_Config_s yaw_config = {
.can_init_config = {
.can_handle = &hcan1,
.tx_id = 2,
.tx_id = 1,
},
.controller_param_init_config = {
.angle_PID = {
.Kd = 1,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 2000,
.DeadBand=0.3,
},
.speed_PID = {
.Kd = 1,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 2000,
},
.other_angle_feedback_ptr = &Gimbal_IMU_data->YawTotalAngle,
// 还需要增加角速度额外反馈指针
@@ -44,25 +47,28 @@ void GimbalInit()
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = ANGLE_LOOP,
.close_loop_type = ANGLE_LOOP | SPEED_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
.reverse_flag = MOTOR_DIRECTION_NORMAL,
},
.motor_type = GM6020};
// PITCH
Motor_Init_Config_s pitch_config = {
.can_init_config = {
.can_handle = &hcan1,
.tx_id = 1,
.tx_id = 3,
},
.controller_param_init_config = {
.angle_PID = {
.Kd = 10,
.Ki = 1,
.Kd = 2,
},
.speed_PID = {
.Kd = 1,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 2000,
.DeadBand=0.3,
},
.speed_PID = {
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 2000,
},
.other_angle_feedback_ptr = &Gimbal_IMU_data->Pitch,
// 还需要增加角速度额外反馈指针
@@ -73,7 +79,7 @@ void GimbalInit()
.speed_feedback_source = MOTOR_FEED,
.outer_loop_type = ANGLE_LOOP,
.close_loop_type = ANGLE_LOOP | SPEED_LOOP,
.reverse_flag = MOTOR_DIRECTION_REVERSE,
.reverse_flag = MOTOR_DIRECTION_NORMAL,
},
.motor_type = GM6020,
};

View File

@@ -1,3 +1,4 @@
#include "bsp_init.h"
#include "robot.h"
#include "robot_def.h"
@@ -12,6 +13,7 @@
void RobotInit()
{
BSPInit();
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)
ChassisInit();
#endif

View File

@@ -88,8 +88,14 @@ typedef enum
GIMBAL_GYRO_MODE, // 云台陀螺仪反馈模式,反馈值为陀螺仪pitch,total_yaw_angle,底盘可以为小陀螺和跟随模式
} gimbal_mode_e;
// 发射模式设置
typedef enum
{
SHOOT_ON,
SHOOT_OFF,
}shoot_mode_e;
typedef enum
{
FRICTION_OFF, // 摩擦轮关闭
FRICTION_ON, // 摩擦轮开启
@@ -103,7 +109,6 @@ typedef enum
typedef enum
{
SHOOT_STOP, // 停止整个发射模块,后续可能隔离出来
LOAD_STOP, // 停止发射
LOAD_REVERSE, // 反转
LOAD_1_BULLET, // 单发
@@ -150,6 +155,7 @@ typedef struct
// cmd发布的发射控制数据,由shoot订阅
typedef struct
{
shoot_mode_e shoot_mode;
loader_mode_e load_mode;
lid_mode_e lid_mode;
friction_mode_e friction_mode;

View File

@@ -29,14 +29,16 @@ void ShootInit()
},
.controller_param_init_config = {
.speed_PID = {
.Kp=10,
.Ki=0,
.Kd=0,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
.current_PID = {
.Kp=10,
.Ki=0,
.Kd=0,
.Kp = 10,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
},
.controller_setting_init_config = {
@@ -56,14 +58,16 @@ void ShootInit()
},
.controller_param_init_config = {
.speed_PID = {
.Kp=1,
.Ki=0,
.Kd=0,
.Kp = 1,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
.current_PID = {
.Kp=1,
.Ki=0,
.Kd=0,
.Kp = 1,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
},
.controller_setting_init_config = {
@@ -83,19 +87,22 @@ void ShootInit()
.controller_param_init_config = {
.angle_PID = {
// 如果启用位置环来控制发弹,需要较大的I值保证输出力矩的线性度否则出现接近拨出的力矩大幅下降
.Kd = 10,
.Kp = 10,
.Ki = 1,
.Kd = 2,
.MaxOut = 200,
},
.speed_PID = {
.Kp=1,
.Ki=0,
.Kd=0,
.Kp = 1,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
.current_PID = {
.Kp=1,
.Ki=0,
.Kd=0,
.Kp = 1,
.Ki = 0,
.Kd = 0,
.MaxOut = 200,
},
},
.controller_setting_init_config = {
@@ -121,7 +128,7 @@ void ShootTask()
SubGetMessage(shoot_sub, &shoot_cmd_recv);
// 对shoot mode等于SHOOT_STOP的情况特殊处理,直接停止所有电机
if (shoot_cmd_recv.load_mode == SHOOT_STOP)
if (shoot_cmd_recv.shoot_mode == SHOOT_OFF)
{
DJIMotorStop(friction_l);
DJIMotorStop(friction_r);
@@ -175,15 +182,15 @@ void ShootTask()
{
case SMALL_AMU_15:
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_r, 0);
break;
case SMALL_AMU_18:
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_r, 0);
break;
case SMALL_AMU_30:
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_l, 0);
DJIMotorSetRef(friction_r, 0);
break;
default:
break;