/*
 * 配置相关
 */

/* Includes ----------------------------------------------------------------- */
#include "user_math.h"
#include "module/config.h"
#include "bsp/can.h"
#include "shoot.h"
#include "chassis.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */

/* Exported variables ------------------------------------------------------- */

// 机器人参数配置
Config_RobotParam_t robot_config = {
.chassis={
    
    .motor_3508_param[0]={BSP_CAN_2,0x201,MOTOR_M3508,false,false},
    .motor_3508_param[1]={BSP_CAN_1,0x202,MOTOR_M3508,false,false},
    .motor_3508_param[2]={BSP_CAN_1,0x203,MOTOR_M3508,false,false},
    .motor_3508_param[3]={BSP_CAN_1,0x204,MOTOR_M3508,false,false},
   
    .motor_6020_param[0]={BSP_CAN_1,0x205,MOTOR_GM6020,false,false},
    .motor_6020_param[1]={BSP_CAN_1,0x206,MOTOR_GM6020,false,false},
    .motor_6020_param[2]={BSP_CAN_1,0x207,MOTOR_GM6020,false,false},
    .motor_6020_param[3]={BSP_CAN_1,0x208,MOTOR_GM6020,false,false},
    
    .C6020Omega_param={
        .k=1.0f,
        .p=0.5f,
        .i=0.1f,
        .d=0.0f,
        .i_limit=1.0f,
        .out_limit=1.0f,
        .d_cutoff_freq= -1.0f,
        .range=-1.0f
    },

    .C6020Angle_param={
        .k=0.2f,
        .p=0.21f,
        .i=0.1f,
        .d=0.0f,
        .i_limit=1.0f,
        .out_limit=30.0f,
        .d_cutoff_freq= -1.0f,
        .range=360
    },

    .M3508v_param={
        .k=0.2f,
        .p=0.25f,
        .i=0.1f,
        .d=0.0f,
        .i_limit=1.0f,
        .out_limit=1.0f,
        .d_cutoff_freq= -1.0f,
        .range=-1.0f
    },

},




	
.gimbal_param = {
	/* 云台欧拉角与角速度自由选择 */
	.Direction={
			.Eulr={
					.pit=Rol,
					.yaw=Yaw,			
				},
			.Gyro={
					.pit=Gyro_x,
					.yaw=Gyro_z,
			},	
//			.Accl={
//					.pit=Accl_z,
//					.yaw=Accl_y,
//			},				
			
	},
	/*欧拉角限位和电机角度限位*/
	 .Limit_t= {
						.pit_max= 0.15,
						.pit_min=-0.23,
		 			/*零点参数*/
				.zero={
					.yaw_encoder=1.26,
					
					.travel={
						.yaw=1.5,				
					},
				},
			},
	 

			.feedforward={
				.imu = {
					.yaw=false,
					.pit=false,
					.K_yaw=0,
					.K_pit=0,
					},

			},
			

				
				.motor={
					/*按自己需求选择电机*/
					.major_yaw=DM,
					.pit=DM,
					.yaw=RM,
					/*是否开启限位*/
					.limit_yaw=false,
					.limit_pit=true,
					.pit_rm_motor={},
					.yaw_rm_motor={BSP_CAN_2,0x209,MOTOR_GM6020,false,false},	
						/*达妙电机参数自己配*/
					.major_yaw_dm_motor={
					    .can=BSP_CAN_2,
							.can_id = 0x1,
							.master_id=0x11,
							.module = MOTOR_DM_J4310,
							.reverse=false
					},
					.pit_dm_motor={
					    .can=BSP_CAN_2,
							.can_id = 0x2,
							.master_id=0x12,
							.module = MOTOR_DM_J4310,
							.reverse=true,					
					},
//					.yaw_dm_motor={},
				},
			.dm_Params_t={
//			.yaw_dm={.kd=0.1,},
//			.yaw_dm_Reduction_ratio=1.0f,//减速比
			.pit_dm={.kd=0.2,},
			.pit_dm_Reduction_ratio=1.0f,
			.major_yaw_dm={.kd=0.1,},
			.major_yaw_dm_Reduction_ratio=1.0f,//减速比
		},
			
    .low_pass_cutoff_freq = {
      .out = -1.0f,
      .gyro = 1000.0f,
    },

        .pid = {
					/* 大yaw参数 */
						.major_yaw_omega={
								.k = 0.0f,
								.p = 0.3f,
								.i = 0.0f,
								.d = 0.0f,
								.i_limit = 0.0f,
								.out_limit = 1.0f,
								.d_cutoff_freq = -1.0f,
								.range = -1.0f						
						},
						.major_yaw_angle={
								.k = 2.0f,
								.p = 40.5f,//36.5
								.i = 0.0f,
								.d = 0.12f,
								.i_limit = 0.0f,
								.out_limit = 7.0f,
								.d_cutoff_freq = 20.0f,
								.range = M_2PI							
						},					
					
					/*欧拉角控制参数*/
			
             .yaw_omega = {
								.k = 0.30f,
								.p = 0.4f,
								.i = 0.01f,
								.d = 0.0f,
								.i_limit = 1.0f,
								.out_limit = 1.0f,
								.d_cutoff_freq = -1.0f,
								.range = -1.0f
            },
            .yaw_angle = {
								.k = 2.0f,
								.p = 2.5f,
								.i = 0.0f,
								.d = 0.0f,
								.i_limit = 0.0f,
								.out_limit = 10.0f,
								.d_cutoff_freq = 0.0f,
								.range = M_2PI
            },
            .pit_omega = {
                .k = 0.3f,
                .p = 0.3f,
                .i = 0.0f,
                .d = 0.0,
                .i_limit = 1.0f,
                .out_limit = 1.0f,
                .d_cutoff_freq = -1.0f,
                .range = -1.0f,
            },
            .pit_angle = {
                .k = -2.0f,
                .p = 9.0f,
                .i = 4.0f,
                .d = 0.1f,
                .i_limit = 1.0f,
                .out_limit = 10.0f,
                .d_cutoff_freq = -1.0f,
                .range = M_2PI,
            },		

						
					}       
		},
	
    .shoot_param = {
        .basic={
          .projectileType=SHOOT_PROJECTILE_17MM,
		      .fric_num=6,
		      .extra_deceleration_ratio=1.0f,
          .num_trig_tooth=5,
          .shot_freq=1.0f,
          .shot_burst_num=3,
          .ratio_multilevel = {0.8f, 1.0f},
        },   
        .jamDetection={
            .enable=true,
            .threshold=310.0f, 
            .suspectedTime=0.5f, 
        },
        .motor={
            .fric = {
                {
                    .param = {
                        .can = BSP_CAN_1,
                        .id = 0x201,
                        .module = MOTOR_M3508,
                        .reverse = false,
                        .gear = false,
                    },
                    .level=1,
                },
                {
                    .param = {
                        .can = BSP_CAN_1,
                        .id = 0x202,
                        .module = MOTOR_M3508,
                        .reverse = true,
                        .gear = false,
                    },
                    .level=1,
                },

            },
            .trig = {
                .can = BSP_CAN_1,
                .id = 0x205,
                .module = MOTOR_M2006,
                .reverse = false,
                .gear=true,
            },
        },
        .pid={      
            .fric_follow = {
                .k=1.0f,
                .p=1.5f,
                .i=0.3f,
                .d=0.0f,
                .i_limit=0.2f,
                .out_limit=0.9f, 
                .d_cutoff_freq=-1.0f,
                .range=-1.0f,
            },
            .fric_err = {
                .k=0.0f,
                .p=4.0f,
                .i=0.4f,
                .d=0.0f,
                .i_limit=0.25f,
                .out_limit=0.25f, 
                .d_cutoff_freq=-1.0f,
                .range=-1.0f, 
            },
            .trig_2006 = {
                .k=2.5f,
                .p=1.0f,
                .i=0.1f,
                .d=0.04f,
                .i_limit=0.4f,
                .out_limit=1.0f,
                .d_cutoff_freq=-1.0f,
                .range=M_2PI,
            },
            .trig_omg_2006 = {
                .k=1.0f,
                .p=1.5f,
                .i=0.3f,
                .d=0.5f,
                .i_limit=0.2f,
                .out_limit=1.0f,
                .d_cutoff_freq=-1.0f,
                .range=-1.0f,
            },
        },
		.filter={
            .fric = {
                .in = 30.0f,
                .out = 30.0f,
            },
            .trig = {
                .in = 30.0f,
                .out = 30.0f,
            },
        },  
    },

		.cmd_param={
        .source_priority = {
            CMD_SRC_RC,
            CMD_SRC_PC,
            CMD_SRC_NUC,
            CMD_SRC_REF,
        },
        .sensitivity = {
            .mouse_sens = 2.0f,
            .move_sens = 1.0f,
            .move_fast_mult = 1.5f,
            .move_slow_mult = 0.5f,
        },
        .rc_mode_map = {
            .sw_left_up   = CHASSIS_MODE_RELAX,
            .sw_left_mid  = CHASSIS_MODE_FOLLOW_GIMBAL,
            .sw_left_down = CHASSIS_MODE_ROTOR,
					
            .gimbal_sw_up   = GIMBAL_MODE_RELAX,
            .gimbal_sw_mid  = GIMBAL_MODE_ABSOLUTE,
            .gimbal_sw_down = GIMBAL_MODE_RELATIVE,
					
						.shoot_sw_up = SHOOT_MODE_SAFE,
						.shoot_sw_mid = SHOOT_MODE_SINGLE,					
						.shoot_sw_down = SHOOT_MODE_BURST,					
					
        },
    },
		
		
};


/**
 * @brief 获取机器人配置参数
 * @return 机器人配置参数指针
 */
Config_RobotParam_t* Config_GetRobotParam(void) {
    return &robot_config;
}

