超电上车成功,pitch限位写好,侧向发射
This commit is contained in:
parent
c17f3f6cb7
commit
713a9e1a4d
|
@ -51,10 +51,7 @@ static SuperCapInstance *cap; // 超级电
|
||||||
static DJIMotorInstance *motor_lf, *motor_rf, *motor_lb, *motor_rb; // left right forward back
|
static DJIMotorInstance *motor_lf, *motor_rf, *motor_lb, *motor_rb; // left right forward back
|
||||||
static PowerMeterInstance *power_meter;
|
static PowerMeterInstance *power_meter;
|
||||||
float chassis_power = 0;
|
float chassis_power = 0;
|
||||||
static first_order_filter_type_t vx_filter;
|
|
||||||
static first_order_filter_type_t vy_filter;
|
|
||||||
const static float32_t chassis_x_order_filter=0.05f;
|
|
||||||
const static float32_t chassis_y_order_filter=0.05f;
|
|
||||||
|
|
||||||
/* 用于自旋变速策略的时间变量 */
|
/* 用于自旋变速策略的时间变量 */
|
||||||
// static float t;
|
// static float t;
|
||||||
|
@ -116,15 +113,16 @@ void ChassisInit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SuperCap_Init_Config_s cap_conf = {
|
// SuperCap_Init_Config_s cap_conf = {
|
||||||
.can_config = {
|
// .can_config = {
|
||||||
.can_handle = &hcan2,
|
// .can_handle = &hcan2,
|
||||||
.tx_id = 0x302, // 超级电容默认接收id
|
// .tx_id = 0x210,
|
||||||
.rx_id = 0x301, // 超级电容默认发送id,注意tx和rx在其他人看来是反的
|
// .rx_id = 0x211,
|
||||||
}};
|
// }};
|
||||||
cap = SuperCapInit(&cap_conf); // 超级电容初始化
|
// cap = SuperCapInit(&cap_conf); // 超级电容初始化
|
||||||
first_order_filter_init(&vy_filter,0.002f,&chassis_y_order_filter);
|
// SuperCapSetPower(cap,70); // 超级电容限制功率
|
||||||
first_order_filter_init(&vx_filter,0.002f,&chassis_x_order_filter);
|
|
||||||
|
|
||||||
// PowerMeter_Init_Config_s power_conf = {
|
// PowerMeter_Init_Config_s power_conf = {
|
||||||
// .can_config = {
|
// .can_config = {
|
||||||
// .can_handle = &hcan2,
|
// .can_handle = &hcan2,
|
||||||
|
@ -268,6 +266,14 @@ void ChassisTask()
|
||||||
case CHASSIS_ROTATE: // 自旋,同时保持全向机动;当前wz维持定值,后续增加不规则的变速策略
|
case CHASSIS_ROTATE: // 自旋,同时保持全向机动;当前wz维持定值,后续增加不规则的变速策略
|
||||||
chassis_cmd_recv.wz = 4500;
|
chassis_cmd_recv.wz = 4500;
|
||||||
break;
|
break;
|
||||||
|
case CHASSIS_VERTICAL_YAW:
|
||||||
|
chassis_cmd_recv.offset_angle -= 90;
|
||||||
|
chassis_cmd_recv.wz = 2.0f * chassis_cmd_recv.offset_angle * abs(chassis_cmd_recv.offset_angle);
|
||||||
|
if(chassis_cmd_recv.wz > 4500)
|
||||||
|
chassis_cmd_recv.wz = 4500;
|
||||||
|
if(chassis_cmd_recv.wz < -4500)
|
||||||
|
chassis_cmd_recv.wz = -4500;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -278,12 +284,6 @@ void ChassisTask()
|
||||||
cos_theta = arm_cos_f32(chassis_cmd_recv.offset_angle * DEGREE_2_RAD);
|
cos_theta = arm_cos_f32(chassis_cmd_recv.offset_angle * DEGREE_2_RAD);
|
||||||
sin_theta = arm_sin_f32(chassis_cmd_recv.offset_angle * DEGREE_2_RAD);
|
sin_theta = arm_sin_f32(chassis_cmd_recv.offset_angle * DEGREE_2_RAD);
|
||||||
|
|
||||||
first_order_filter_cali(&vx_filter,chassis_cmd_recv.vx);
|
|
||||||
first_order_filter_cali(&vy_filter,chassis_cmd_recv.vy);
|
|
||||||
|
|
||||||
chassis_cmd_recv.vy = vy_filter.out;
|
|
||||||
chassis_cmd_recv.vx = vx_filter.out;
|
|
||||||
|
|
||||||
chassis_vx = chassis_cmd_recv.vx * cos_theta - chassis_cmd_recv.vy * sin_theta;
|
chassis_vx = chassis_cmd_recv.vx * cos_theta - chassis_cmd_recv.vy * sin_theta;
|
||||||
chassis_vy = chassis_cmd_recv.vx * sin_theta + chassis_cmd_recv.vy * cos_theta;
|
chassis_vy = chassis_cmd_recv.vx * sin_theta + chassis_cmd_recv.vy * cos_theta;
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ void ChassisTask()
|
||||||
// chassis_feedback_data.bullet_speed = referee_data->GameRobotState.shooter_id1_17mm_speed_limit;
|
// chassis_feedback_data.bullet_speed = referee_data->GameRobotState.shooter_id1_17mm_speed_limit;
|
||||||
// chassis_feedback_data.rest_heat = referee_data->PowerHeatData.shooter_heat0;
|
// chassis_feedback_data.rest_heat = referee_data->PowerHeatData.shooter_heat0;
|
||||||
|
|
||||||
chassis_feedback_data.cap_power = cap->cap_msg.power;
|
chassis_feedback_data.cap_vol = cap->cap_msg.cap_vol;
|
||||||
// 推送反馈消息
|
// 推送反馈消息
|
||||||
#ifdef ONE_BOARD
|
#ifdef ONE_BOARD
|
||||||
PubPushMessage(chassis_pub, (void *)&chassis_feedback_data);
|
PubPushMessage(chassis_pub, (void *)&chassis_feedback_data);
|
||||||
|
|
|
@ -61,9 +61,8 @@ static Shoot_Upload_Data_s shoot_fetch_data; // 从发射获取的反馈信息
|
||||||
static Robot_Status_e robot_state; // 机器人整体工作状态
|
static Robot_Status_e robot_state; // 机器人整体工作状态
|
||||||
static referee_info_t* referee_data; // 用于获取裁判系统的数据
|
static referee_info_t* referee_data; // 用于获取裁判系统的数据
|
||||||
static referee_info_vt_t* referee_vt_data;
|
static referee_info_vt_t* referee_vt_data;
|
||||||
extern float horizontal_angle;
|
float DeltaPitchAngle=0,PitchMotorAngle=0;
|
||||||
//static int target_index = -1;
|
static float base_HP=12.0f;
|
||||||
static uint16_t base_HP;
|
|
||||||
|
|
||||||
void RobotCMDInit()
|
void RobotCMDInit()
|
||||||
{
|
{
|
||||||
|
@ -141,23 +140,23 @@ static void death_check()
|
||||||
|
|
||||||
static void update_ui_data()
|
static void update_ui_data()
|
||||||
{
|
{
|
||||||
|
base_HP+=0.01f;
|
||||||
|
if(base_HP >=24)
|
||||||
|
{base_HP=12.0f;}
|
||||||
|
|
||||||
ui_data.chassis_mode = chassis_cmd_send.chassis_mode;
|
ui_data.chassis_mode = chassis_cmd_send.chassis_mode;
|
||||||
ui_data.gimbal_mode = gimbal_cmd_send.gimbal_mode;
|
ui_data.gimbal_mode = gimbal_cmd_send.gimbal_mode;
|
||||||
ui_data.friction_mode = shoot_cmd_send.friction_mode;
|
ui_data.friction_mode = shoot_cmd_send.friction_mode;
|
||||||
ui_data.shoot_mode = shoot_cmd_send.shoot_mode;
|
ui_data.shoot_mode = shoot_cmd_send.shoot_mode;
|
||||||
ui_data.Chassis_Power_Data.chassis_power_mx = referee_data->GameRobotState.chassis_power_limit;
|
ui_data.Chassis_Power_Data.chassis_power_mx = referee_data->GameRobotState.chassis_power_limit;
|
||||||
ui_data.Vision_fire = aim_select.suggest_fire;
|
ui_data.Vision_fire = aim_select.suggest_fire;
|
||||||
//ui_data.Chassis_Power_Data.cap_power =
|
ui_data.Chassis_Power_Data.cap_vol = base_HP;
|
||||||
}
|
}
|
||||||
static void pitch_limit()
|
static void pitch_limit()
|
||||||
{
|
{
|
||||||
// if(gimbal_fetch_data.pitch_motor_total_angle > horizontal_angle + 1500)
|
PitchMotorAngle = -0.0019f * gimbal_fetch_data.pitch_motor_total_angle - 0.4059;//电机旋转导致的云台相对底盘角度
|
||||||
// gimbal_cmd_send.pitch -= 0.1f;
|
DeltaPitchAngle = gimbal_fetch_data.gimbal_imu_data.Pitch - PitchMotorAngle;
|
||||||
// if(gimbal_fetch_data.pitch_motor_total_angle < horizontal_angle - 4000)
|
gimbal_cmd_send.pitch = LIMIT_MIN_MAX(gimbal_cmd_send.pitch, PITCH_MIN_ANGLE-DeltaPitchAngle, PITCH_MAX_ANGLE-DeltaPitchAngle);
|
||||||
// gimbal_cmd_send.pitch += 0.1f;
|
|
||||||
//@TODO:把限位去掉了,记得加回来
|
|
||||||
// if(gimbal_cmd_send.pitch>18) gimbal_cmd_send.pitch = 18;
|
|
||||||
// if(gimbal_cmd_send.pitch<-38) gimbal_cmd_send.pitch = -38;
|
|
||||||
}
|
}
|
||||||
static void auto_aim_mode()
|
static void auto_aim_mode()
|
||||||
{
|
{
|
||||||
|
@ -343,46 +342,6 @@ static void MouseKeySet()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// switch (rc_data[TEMP].mouse.press_r) // 右键自瞄模式
|
|
||||||
// {
|
|
||||||
// case 1:
|
|
||||||
// if((vision_recv_data->x == 0 && vision_recv_data->y == 0 && vision_recv_data->z == 0
|
|
||||||
// && vision_recv_data->vx == 0 && vision_recv_data->vy == 0 &&
|
|
||||||
// vision_recv_data->vz == 0))
|
|
||||||
// hand_aim_mode();
|
|
||||||
// else
|
|
||||||
// auto_aim_mode();
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// hand_aim_mode();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// switch (rc_data[TEMP].mouse.press_l) // 左键发射模式
|
|
||||||
// {
|
|
||||||
// case 1:
|
|
||||||
// if(shoot_cmd_send.friction_mode == FRICTION_ON)
|
|
||||||
// {
|
|
||||||
// if(rc_data[TEMP].mouse.press_r && rc_data[TEMP].mouse.press_l)
|
|
||||||
// {
|
|
||||||
// if(aim_select.suggest_fire == 1)
|
|
||||||
// shoot_cmd_send.load_mode = LOAD_1_BULLET;
|
|
||||||
// else
|
|
||||||
// shoot_cmd_send.load_mode = LOAD_STOP;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// shoot_cmd_send.load_mode = LOAD_1_BULLET;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// shoot_cmd_send.load_mode = LOAD_STOP;
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// shoot_cmd_send.load_mode = LOAD_STOP;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
switch (rc_data[TEMP].key_count[KEY_PRESS][Key_R] % 2) // R键手动刷新UI
|
switch (rc_data[TEMP].key_count[KEY_PRESS][Key_R] % 2) // R键手动刷新UI
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -414,13 +373,22 @@ static void MouseKeySet()
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||||
gimbal_cmd_send.gimbal_mode = GIMBAL_FREE_MODE;
|
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
|
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
|
||||||
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
switch (rc_data[TEMP].key[KEY_PRESS].z) // Z键侧身用于瞄准
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
chassis_cmd_send.chassis_mode = CHASSIS_VERTICAL_YAW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (rc_data[TEMP].key[KEY_PRESS].shift) // 待添加 按shift允许超功率 消耗缓冲能量
|
switch (rc_data[TEMP].key[KEY_PRESS].shift) // 待添加 按shift允许超功率 消耗缓冲能量
|
||||||
{
|
{
|
||||||
|
@ -442,13 +410,66 @@ static void MouseKeySet()
|
||||||
*/
|
*/
|
||||||
static void VTMouseKeySet()
|
static void VTMouseKeySet()
|
||||||
{
|
{
|
||||||
chassis_cmd_send.vx = vt_data[TEMP].key[KEY_PRESS].a * 1500 - vt_data[TEMP].key[KEY_PRESS].d * 1500; // 系数待测
|
chassis_cmd_send.vx = vt_data[TEMP].key[KEY_PRESS].a * 10000 - vt_data[TEMP].key[KEY_PRESS].d * 10000; // 系数待测
|
||||||
chassis_cmd_send.vy = vt_data[TEMP].key[KEY_PRESS].w * 800 - vt_data[TEMP].key[KEY_PRESS].s * 800;
|
chassis_cmd_send.vy = vt_data[TEMP].key[KEY_PRESS].w * 10000 - vt_data[TEMP].key[KEY_PRESS].s * 10000;
|
||||||
|
|
||||||
gimbal_cmd_send.yaw -= (float)vt_data[TEMP].mouse.x / 660 * 5; // 系数待测
|
gimbal_cmd_send.yaw -= (float)vt_data[TEMP].mouse.x / 660 * 10; // 系数待测
|
||||||
gimbal_cmd_send.pitch += (float)vt_data[TEMP].mouse.y / 660 * 10;
|
gimbal_cmd_send.pitch += (float)vt_data[TEMP].mouse.y / 660 * 10;
|
||||||
|
|
||||||
|
|
||||||
|
aim_select.suggest_fire = 0;
|
||||||
|
if (vt_data[TEMP].mouse.press_l && (!vt_data[TEMP].mouse.press_r)) // 左键发射模式
|
||||||
|
{
|
||||||
|
if (shoot_cmd_send.friction_mode == FRICTION_ON) {
|
||||||
|
shoot_cmd_send.load_mode = LOAD_1_BULLET;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ((!vt_data[TEMP].mouse.press_l) && (!vt_data[TEMP].mouse.press_r))
|
||||||
|
{
|
||||||
|
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vt_data[TEMP].mouse.press_r) // 右键自瞄模式
|
||||||
|
{
|
||||||
|
if ((vision_recv_data->x == 0 && vision_recv_data->y == 0 && vision_recv_data->z == 0
|
||||||
|
&& vision_recv_data->vx == 0 && vision_recv_data->vy == 0 &&
|
||||||
|
vision_recv_data->vz == 0))
|
||||||
|
{
|
||||||
|
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
else {
|
||||||
|
auto_aim_mode();
|
||||||
|
if (aim_select.suggest_fire == 1 && vt_data[TEMP].mouse.press_l &&
|
||||||
|
shoot_cmd_send.friction_mode == FRICTION_ON) {
|
||||||
|
shoot_cmd_send.load_mode = LOAD_1_BULLET;
|
||||||
|
} else {
|
||||||
|
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (vt_data[TEMP].key[KEY_PRESS].v) // V键开启连发//
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
shoot_cmd_send.shoot_rate= 300;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
shoot_cmd_send.shoot_rate = 50;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (vt_data[TEMP].key_count[KEY_PRESS][Key_R] % 2) // R键手动刷新UI
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
MyUIInit();
|
||||||
|
vt_data[TEMP].key_count[KEY_PRESS][Key_R]++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
switch (vt_data[TEMP].key_count[KEY_PRESS][Key_F] % 2) // F键开关摩擦轮
|
switch (vt_data[TEMP].key_count[KEY_PRESS][Key_F] % 2) // F键开关摩擦轮
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -458,6 +479,57 @@ static void VTMouseKeySet()
|
||||||
shoot_cmd_send.friction_mode = FRICTION_ON;
|
shoot_cmd_send.friction_mode = FRICTION_ON;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
switch (vt_data[TEMP].key_count[KEY_PRESS][Key_Q] % 2) // Q键开关倍镜
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
shoot_cmd_send.tele_mode = TELE_CLOSE;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
shoot_cmd_send.tele_mode = TELE_OPEN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (vt_data[TEMP].key_count[KEY_PRESS][Key_E] % 2) // E键开关小陀螺
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
if(!vt_data[TEMP].key[KEY_PRESS].z)
|
||||||
|
{
|
||||||
|
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||||
|
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
chassis_cmd_send.chassis_mode = CHASSIS_VERTICAL_YAW;
|
||||||
|
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
|
||||||
|
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
// switch (vt_data[TEMP].key[KEY_PRESS].z) // Z键侧身用于瞄准
|
||||||
|
// {
|
||||||
|
// case 0:
|
||||||
|
// chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// chassis_cmd_send.chassis_mode = CHASSIS_VERTICAL_YAW;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
switch (vt_data[TEMP].key[KEY_PRESS].shift) // 待添加 按shift允许超功率 消耗缓冲能量
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pitch_limit();
|
||||||
|
death_check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -511,8 +583,11 @@ void RobotCMDTask()
|
||||||
switch_is_mid(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[下],[中],遥控器控制
|
switch_is_mid(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[下],[中],遥控器控制
|
||||||
RemoteControlSet();
|
RemoteControlSet();
|
||||||
else if (switch_is_up(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[上],键盘控制
|
else if (switch_is_up(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[上],键盘控制
|
||||||
|
{
|
||||||
//MouseKeySet();
|
//MouseKeySet();
|
||||||
VTMouseKeySet();
|
VTMouseKeySet();
|
||||||
|
}
|
||||||
|
|
||||||
EmergencyHandler(); // 处理模块离线和遥控器急停等紧急情况
|
EmergencyHandler(); // 处理模块离线和遥控器急停等紧急情况
|
||||||
|
|
||||||
// 设置视觉发送数据,还需增加加速度和角速度数据
|
// 设置视觉发送数据,还需增加加速度和角速度数据
|
||||||
|
|
|
@ -16,7 +16,7 @@ static Publisher_t *gimbal_pub; // 云台应用消息发布者
|
||||||
static Subscriber_t *gimbal_sub; // cmd控制消息订阅者
|
static Subscriber_t *gimbal_sub; // cmd控制消息订阅者
|
||||||
static Gimbal_Upload_Data_s gimbal_feedback_data; // 回传给cmd的云台状态信息
|
static Gimbal_Upload_Data_s gimbal_feedback_data; // 回传给cmd的云台状态信息
|
||||||
static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自cmd的控制信息
|
static Gimbal_Ctrl_Cmd_s gimbal_cmd_recv; // 来自cmd的控制信息
|
||||||
float horizontal_angle=0;
|
|
||||||
|
|
||||||
void GimbalInit()
|
void GimbalInit()
|
||||||
{
|
{
|
||||||
|
@ -103,18 +103,13 @@ void GimbalInit()
|
||||||
gimbal_pub = PubRegister("gimbal_feed", sizeof(Gimbal_Upload_Data_s));
|
gimbal_pub = PubRegister("gimbal_feed", sizeof(Gimbal_Upload_Data_s));
|
||||||
gimbal_sub = SubRegister("gimbal_cmd", sizeof(Gimbal_Ctrl_Cmd_s));
|
gimbal_sub = SubRegister("gimbal_cmd", sizeof(Gimbal_Ctrl_Cmd_s));
|
||||||
}
|
}
|
||||||
void horizontal_check()
|
|
||||||
{
|
|
||||||
if(fabsf(gimba_IMU_data->Pitch) <= 1e-2)
|
|
||||||
horizontal_angle = pitch_motor->measure.total_angle;
|
|
||||||
}
|
|
||||||
/* 机器人云台控制核心任务,后续考虑只保留IMU控制,不再需要电机的反馈 */
|
/* 机器人云台控制核心任务,后续考虑只保留IMU控制,不再需要电机的反馈 */
|
||||||
void GimbalTask()
|
void GimbalTask()
|
||||||
{
|
{
|
||||||
// 获取云台控制数据
|
// 获取云台控制数据
|
||||||
// 后续增加未收到数据的处理
|
// 后续增加未收到数据的处理
|
||||||
SubGetMessage(gimbal_sub, &gimbal_cmd_recv);
|
SubGetMessage(gimbal_sub, &gimbal_cmd_recv);
|
||||||
|
|
||||||
// @todo:现在已不再需要电机反馈,实际上可以始终使用IMU的姿态数据来作为云台的反馈,yaw电机的offset只是用来跟随底盘
|
// @todo:现在已不再需要电机反馈,实际上可以始终使用IMU的姿态数据来作为云台的反馈,yaw电机的offset只是用来跟随底盘
|
||||||
// 根据控制模式进行电机反馈切换和过渡,视觉模式在robot_cmd模块就已经设置好,gimbal只看yaw_ref和pitch_ref
|
// 根据控制模式进行电机反馈切换和过渡,视觉模式在robot_cmd模块就已经设置好,gimbal只看yaw_ref和pitch_ref
|
||||||
switch (gimbal_cmd_recv.gimbal_mode)
|
switch (gimbal_cmd_recv.gimbal_mode)
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
/* 机器人重要参数定义,注意根据不同机器人进行修改,浮点数需要以.0或f结尾,无符号以u结尾 */
|
/* 机器人重要参数定义,注意根据不同机器人进行修改,浮点数需要以.0或f结尾,无符号以u结尾 */
|
||||||
// 云台参数
|
// 云台参数
|
||||||
#define YAW_CHASSIS_ALIGN_ECD 2.691132 // 云台和底盘对齐指向相同方向时的电机position值,需要加上PI,因为单圈角度计算里增加了PI若对云台有机械改动需要修改
|
#define YAW_CHASSIS_ALIGN_ECD 2.812502 // 云台和底盘对齐指向相同方向时的电机position值,需要加上PI,因为单圈角度计算里增加了PI若对云台有机械改动需要修改
|
||||||
#define YAW_ECD_GREATER_THAN_4096 1 // ALIGN_ECD值是否大于4096,是为1,否为0;用于计算云台偏转角度
|
#define YAW_ECD_GREATER_THAN_4096 1 // ALIGN_ECD值是否大于4096,是为1,否为0;用于计算云台偏转角度
|
||||||
#define PITCH_HORIZON_ECD 3412 // 云台处于水平位置时编码器值,若对云台有机械改动需要修改
|
#define PITCH_HORIZON_ECD 3412 // 云台处于水平位置时编码器值,若对云台有机械改动需要修改
|
||||||
#define PITCH_MAX_ANGLE 0 // 云台竖直方向最大角度 (注意反馈如果是陀螺仪,则填写陀螺仪的角度)
|
#define PITCH_MAX_ANGLE 13 // 云台竖直方向最大角度 (注意反馈如果是陀螺仪,则填写陀螺仪的角度)
|
||||||
#define PITCH_MIN_ANGLE 0 // 云台竖直方向最小角度 (注意反馈如果是陀螺仪,则填写陀螺仪的角度)
|
#define PITCH_MIN_ANGLE -35 // 云台竖直方向最小角度 (注意反馈如果是陀螺仪,则填写陀螺仪的角度)
|
||||||
// 发射参数
|
// 发射参数
|
||||||
#define ONE_BULLET_DELTA_ANGLE 1933.272 // 发射一发弹丸拨盘转动的距离,由机械设计图纸给出
|
#define ONE_BULLET_DELTA_ANGLE 1933.272 // 发射一发弹丸拨盘转动的距离,由机械设计图纸给出
|
||||||
#define REDUCTION_RATIO_LOADER 27.0f // 拨盘电机的减速比,英雄需要修改为3508的19.0f//初始是49,增加为27
|
#define REDUCTION_RATIO_LOADER 27.0f // 拨盘电机的减速比,英雄需要修改为3508的19.0f//初始是49,增加为27
|
||||||
|
@ -86,6 +86,7 @@ typedef enum
|
||||||
CHASSIS_ROTATE, // 小陀螺模式
|
CHASSIS_ROTATE, // 小陀螺模式
|
||||||
CHASSIS_NO_FOLLOW, // 不跟随,允许全向平移
|
CHASSIS_NO_FOLLOW, // 不跟随,允许全向平移
|
||||||
CHASSIS_FOLLOW_GIMBAL_YAW, // 跟随模式,底盘叠加角度环控制
|
CHASSIS_FOLLOW_GIMBAL_YAW, // 跟随模式,底盘叠加角度环控制
|
||||||
|
CHASSIS_VERTICAL_YAW,
|
||||||
} chassis_mode_e;
|
} chassis_mode_e;
|
||||||
|
|
||||||
// 云台模式设置
|
// 云台模式设置
|
||||||
|
@ -128,7 +129,7 @@ typedef enum
|
||||||
typedef struct
|
typedef struct
|
||||||
{ // 功率控制
|
{ // 功率控制
|
||||||
uint16_t chassis_power_mx;
|
uint16_t chassis_power_mx;
|
||||||
float cap_power;
|
float cap_vol;
|
||||||
} Chassis_Power_Data_s;
|
} Chassis_Power_Data_s;
|
||||||
|
|
||||||
/* ----------------CMD应用发布的控制数据,应当由gimbal/chassis/shoot订阅---------------- */
|
/* ----------------CMD应用发布的控制数据,应当由gimbal/chassis/shoot订阅---------------- */
|
||||||
|
@ -189,7 +190,7 @@ typedef struct
|
||||||
// float real_vx;
|
// float real_vx;
|
||||||
// float real_vy;
|
// float real_vy;
|
||||||
// float real_wz;
|
// float real_wz;
|
||||||
float cap_power;
|
float cap_vol;
|
||||||
uint8_t rest_heat; // 剩余枪口热量
|
uint8_t rest_heat; // 剩余枪口热量
|
||||||
Enemy_Color_e enemy_color; // 0 for blue, 1 for red
|
Enemy_Color_e enemy_color; // 0 for blue, 1 for red
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ typedef enum
|
||||||
LEN_robot_hurt = 1, // 0x0206
|
LEN_robot_hurt = 1, // 0x0206
|
||||||
LEN_shoot_data = 7, // 0x0207
|
LEN_shoot_data = 7, // 0x0207
|
||||||
LEN_receive_data = 6 + Communicate_Data_LEN, // 0x0301
|
LEN_receive_data = 6 + Communicate_Data_LEN, // 0x0301
|
||||||
LEN_self_control = 12, // 0x0304
|
LEN_self_control = 12, // 0x0303
|
||||||
LEN_remote_control = 12, // 0x0304
|
LEN_remote_control = 12, // 0x0304
|
||||||
|
|
||||||
} JudgeDataLength_e;
|
} JudgeDataLength_e;
|
||||||
|
|
|
@ -92,8 +92,7 @@ void MyUIInit()
|
||||||
UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[2]);
|
UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[2]);
|
||||||
UICharDraw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600, "frict:");
|
UICharDraw(&UI_State_sta[3], "ss3", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 600, "frict:");
|
||||||
UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[3]);
|
UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[3]);
|
||||||
// UICharDraw(&UI_State_sta[4], "ss4", UI_Graph_ADD, 8, UI_Color_Pink, 15, 2, 150, 550, "lid:");
|
|
||||||
// UICharRefresh(&referee_recv_info->referee_id, UI_State_sta[4]);
|
|
||||||
|
|
||||||
// 绘制车辆状态标志,动态
|
// 绘制车辆状态标志,动态
|
||||||
// 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新
|
// 由于初始化时xxx_last_mode默认为0,所以此处对应UI也应该设为0时对应的UI,防止模式不变的情况下无法置位flag,导致UI无法刷新
|
||||||
|
@ -118,7 +117,7 @@ void MyUIInit()
|
||||||
// 底盘功率显示,动态
|
// 底盘功率显示,动态
|
||||||
UIFloatDraw(&UI_Energy[1], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 2, 850, 230, referee_recv_info->GameRobotState.chassis_power_limit*1000);
|
UIFloatDraw(&UI_Energy[1], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 2, 850, 230, referee_recv_info->GameRobotState.chassis_power_limit*1000);
|
||||||
// 能量条初始状态
|
// 能量条初始状态
|
||||||
// UILineDraw(&UI_Energy[2], "sd6", UI_Graph_ADD, 8, UI_Color_Pink, 30, 720, 160, 1020, 160);
|
UILineDraw(&UI_Energy[2], "sd6", UI_Graph_ADD, 8, UI_Color_Pink, 30, 720, 160, 1020, 160);
|
||||||
|
|
||||||
UIGraphRefresh(&referee_recv_info->referee_id, 2, UI_Energy[1], UI_Energy[2]);
|
UIGraphRefresh(&referee_recv_info->referee_id, 2, UI_Energy[1], UI_Energy[2]);
|
||||||
}
|
}
|
||||||
|
@ -254,10 +253,17 @@ static void MyUIRefresh(referee_info_t *referee_recv_info, Referee_Interactive_i
|
||||||
if (_Interactive_data->Referee_Interactive_Flag.Power_flag == 1)
|
if (_Interactive_data->Referee_Interactive_Flag.Power_flag == 1)
|
||||||
{
|
{
|
||||||
UIFloatDraw(&UI_Energy[1], "sd5", UI_Graph_Change, 8, UI_Color_Green, 18, 2, 2, 850, 230, _Interactive_data->Chassis_Power_Data.chassis_power_mx * 1000);
|
UIFloatDraw(&UI_Energy[1], "sd5", UI_Graph_Change, 8, UI_Color_Green, 18, 2, 2, 850, 230, _Interactive_data->Chassis_Power_Data.chassis_power_mx * 1000);
|
||||||
// UILineDraw(&UI_Energy[2], "sd6", UI_Graph_Change, 8, UI_Color_Pink, 30, 720, 160, (uint32_t)750 + _Interactive_data->Chassis_Power_Data.chassis_power_mx * 30, 160);
|
UIGraphRefresh(&referee_recv_info->referee_id, 1, UI_Energy[1]);
|
||||||
UIGraphRefresh(&referee_recv_info->referee_id, 2, UI_Energy[1], UI_Energy[2]);
|
|
||||||
_Interactive_data->Referee_Interactive_Flag.Power_flag = 0;
|
_Interactive_data->Referee_Interactive_Flag.Power_flag = 0;
|
||||||
}
|
}
|
||||||
|
//Cap
|
||||||
|
if (_Interactive_data->Referee_Interactive_Flag.Cap_flag == 1)
|
||||||
|
{
|
||||||
|
UILineDraw(&UI_Energy[2], "sd6", UI_Graph_Change, 8, UI_Color_Pink, 30, 720, 160, 720 + (_Interactive_data->Chassis_Power_Data.cap_vol-12) * 42, 160);
|
||||||
|
UIGraphRefresh(&referee_recv_info->referee_id, 1, UI_Energy[2]);
|
||||||
|
_Interactive_data->Referee_Interactive_Flag.Cap_flag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//line
|
//line
|
||||||
if (_Interactive_data->Referee_Interactive_Flag.Vision_flag == 1)
|
if (_Interactive_data->Referee_Interactive_Flag.Vision_flag == 1)
|
||||||
{
|
{
|
||||||
|
@ -322,6 +328,11 @@ static void UIChangeCheck(Referee_Interactive_info_t *_Interactive_data)
|
||||||
_Interactive_data->Referee_Interactive_Flag.Power_flag = 1;
|
_Interactive_data->Referee_Interactive_Flag.Power_flag = 1;
|
||||||
_Interactive_data->Chassis_last_Power_Data.chassis_power_mx = _Interactive_data->Chassis_Power_Data.chassis_power_mx;
|
_Interactive_data->Chassis_last_Power_Data.chassis_power_mx = _Interactive_data->Chassis_Power_Data.chassis_power_mx;
|
||||||
}
|
}
|
||||||
|
if (_Interactive_data->Chassis_Power_Data.cap_vol != _Interactive_data->Chassis_last_Power_Data.cap_vol)
|
||||||
|
{
|
||||||
|
_Interactive_data->Referee_Interactive_Flag.Cap_flag = 1;
|
||||||
|
_Interactive_data->Chassis_last_Power_Data.cap_vol = _Interactive_data->Chassis_Power_Data.cap_vol;
|
||||||
|
}
|
||||||
if (_Interactive_data->Vision_fire != _Interactive_data->last_Vision_fire)
|
if (_Interactive_data->Vision_fire != _Interactive_data->last_Vision_fire)
|
||||||
{
|
{
|
||||||
_Interactive_data->Referee_Interactive_Flag.Vision_flag = 1;
|
_Interactive_data->Referee_Interactive_Flag.Vision_flag = 1;
|
||||||
|
|
|
@ -55,6 +55,7 @@ typedef struct
|
||||||
uint32_t lid_flag : 1;
|
uint32_t lid_flag : 1;
|
||||||
uint32_t friction_flag : 1;
|
uint32_t friction_flag : 1;
|
||||||
uint32_t Power_flag : 1;
|
uint32_t Power_flag : 1;
|
||||||
|
uint32_t Cap_flag : 1;
|
||||||
uint32_t Vision_flag :1;
|
uint32_t Vision_flag :1;
|
||||||
} Referee_Interactive_Flag_t;
|
} Referee_Interactive_Flag_t;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
/*
|
|
||||||
* @Descripttion:
|
|
||||||
* @version:
|
|
||||||
* @Author: Chenfu
|
|
||||||
* @Date: 2022-12-02 21:32:47
|
|
||||||
* @LastEditTime: 2022-12-05 15:29:49
|
|
||||||
*/
|
|
||||||
#include "super_cap.h"
|
#include "super_cap.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
|
||||||
static SuperCapInstance *super_cap_instance = NULL; // 可以由app保存此指针
|
static SuperCapInstance *super_cap_instance = NULL; // 可以由app保存此指针
|
||||||
|
|
||||||
static void SuperCapRxCallback(CANInstance *_instance)
|
static void SuperCapRxCallback(CANInstance *_instance)
|
||||||
|
@ -17,16 +11,17 @@ static void SuperCapRxCallback(CANInstance *_instance)
|
||||||
SuperCap_Msg_s *Msg;
|
SuperCap_Msg_s *Msg;
|
||||||
rxbuff = _instance->rx_buff;
|
rxbuff = _instance->rx_buff;
|
||||||
Msg = &super_cap_instance->cap_msg;
|
Msg = &super_cap_instance->cap_msg;
|
||||||
Msg->vol = (uint16_t)(rxbuff[0] << 8 | rxbuff[1]);
|
Msg->input_vol = (int16_t)(rxbuff[1] << 8 | rxbuff[0]);
|
||||||
Msg->current = (uint16_t)(rxbuff[2] << 8 | rxbuff[3]);
|
Msg->cap_vol = (int16_t)(rxbuff[3] << 8 | rxbuff[2]);
|
||||||
Msg->power = (uint16_t)(rxbuff[4] << 8 | rxbuff[5]);
|
Msg->input_cur = (int16_t)(rxbuff[5] << 8 | rxbuff[4]);
|
||||||
|
Msg->power_set = (int16_t)(rxbuff[7] << 8 | rxbuff[6]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s *supercap_config)
|
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s *supercap_config)
|
||||||
{
|
{
|
||||||
super_cap_instance = (SuperCapInstance *)malloc(sizeof(SuperCapInstance));
|
super_cap_instance = (SuperCapInstance *)malloc(sizeof(SuperCapInstance));
|
||||||
memset(super_cap_instance, 0, sizeof(SuperCapInstance));
|
memset(super_cap_instance, 0, sizeof(SuperCapInstance));
|
||||||
|
|
||||||
supercap_config->can_config.can_module_callback = SuperCapRxCallback;
|
supercap_config->can_config.can_module_callback = SuperCapRxCallback;
|
||||||
super_cap_instance->can_ins = CANRegister(&supercap_config->can_config);
|
super_cap_instance->can_ins = CANRegister(&supercap_config->can_config);
|
||||||
return super_cap_instance;
|
return super_cap_instance;
|
||||||
|
@ -38,6 +33,15 @@ void SuperCapSend(SuperCapInstance *instance, uint8_t *data)
|
||||||
CANTransmit(instance->can_ins,1);
|
CANTransmit(instance->can_ins,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SuperCapSetPower(SuperCapInstance *instance, float power_set)
|
||||||
|
{
|
||||||
|
uint16_t tmpPower = (uint16_t)(power_set * 100);
|
||||||
|
uint8_t data[8] = {0};
|
||||||
|
data[0] = tmpPower >> 8;
|
||||||
|
data[1] = tmpPower;
|
||||||
|
SuperCapSend(instance,data);
|
||||||
|
}
|
||||||
|
|
||||||
SuperCap_Msg_s SuperCapGet(SuperCapInstance *instance)
|
SuperCap_Msg_s SuperCapGet(SuperCapInstance *instance)
|
||||||
{
|
{
|
||||||
return instance->cap_msg;
|
return instance->cap_msg;
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
/*
|
|
||||||
* @Descripttion:
|
|
||||||
* @version:
|
|
||||||
* @Author: Chenfu
|
|
||||||
* @Date: 2022-12-02 21:32:47
|
|
||||||
* @LastEditTime: 2022-12-05 15:25:46
|
|
||||||
*/
|
|
||||||
#ifndef SUPER_CAP_H
|
#ifndef SUPER_CAP_H
|
||||||
#define SUPER_CAP_H
|
#define SUPER_CAP_H
|
||||||
|
|
||||||
|
@ -13,9 +6,10 @@
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t vol; // 电压
|
int16_t input_vol; // 输入电压
|
||||||
uint16_t current; // 电流
|
int16_t cap_vol; // 电容电压
|
||||||
uint16_t power; // 功率
|
int16_t input_cur; // 输入电流
|
||||||
|
int16_t power_set; // 设定功率
|
||||||
} SuperCap_Msg_s;
|
} SuperCap_Msg_s;
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
@ -34,7 +28,7 @@ typedef struct
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化超级电容
|
* @brief 初始化超级电容
|
||||||
*
|
*
|
||||||
* @param supercap_config 超级电容初始化配置
|
* @param supercap_config 超级电容初始化配置
|
||||||
* @return SuperCapInstance* 超级电容实例指针
|
* @return SuperCapInstance* 超级电容实例指针
|
||||||
*/
|
*/
|
||||||
|
@ -42,10 +36,18 @@ SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s *supercap_config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 发送超级电容控制信息
|
* @brief 发送超级电容控制信息
|
||||||
*
|
*
|
||||||
* @param instance 超级电容实例
|
* @param instance 超级电容实例
|
||||||
* @param data 超级电容控制信息
|
* @param data 超级电容控制信息
|
||||||
*/
|
*/
|
||||||
void SuperCapSend(SuperCapInstance *instance, uint8_t *data);
|
void SuperCapSend(SuperCapInstance *instance, uint8_t *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发送超级电容目标功率
|
||||||
|
*
|
||||||
|
* @param instance 超级电容实例
|
||||||
|
* @param power_set 超级电容目标功率
|
||||||
|
*/
|
||||||
|
void SuperCapSetPower(SuperCapInstance *instance, float power_set);
|
||||||
|
|
||||||
#endif // !SUPER_CAP_Hd
|
#endif // !SUPER_CAP_Hd
|
||||||
|
|
Loading…
Reference in New Issue