mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
遥控器键鼠
This commit is contained in:
@@ -69,6 +69,9 @@ void RobotCMDInit()
|
||||
gimbal_cmd_send.yaw = 0;
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_ZERO_FORCE;
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_ZERO_FORCE;
|
||||
shoot_cmd_send.shoot_mode = SHOOT_OFF;
|
||||
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||
shoot_cmd_send.friction_mode = FRICTION_OFF;
|
||||
|
||||
robot_state = ROBOT_STOP; // 启动时机器人进入工作模式,后续加入所有应用初始化完成之后再进入
|
||||
}
|
||||
@@ -112,6 +115,8 @@ static void CalcOffsetAngle()
|
||||
static void RemoteControlSet()
|
||||
{
|
||||
shoot_cmd_send.bullet_speed = 30;
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||
// // 云台参数,确定云台控制数据
|
||||
// if (switch_is_mid(rc_data[TEMP].rc.switch_left)) // 左侧开关状态为[中],视觉模式
|
||||
// {
|
||||
@@ -123,34 +128,46 @@ static void RemoteControlSet()
|
||||
{
|
||||
chassis_direction = CHASSIS_ALIGN;
|
||||
yaw_chassis_align_ecd = 2716;
|
||||
|
||||
}
|
||||
else if (abs(rc_data[TEMP].rc.rocker_r_) > 500)
|
||||
{
|
||||
chassis_direction = CHASSIS_SIDLE;
|
||||
yaw_chassis_align_ecd = 765;
|
||||
}
|
||||
|
||||
chassis_cmd_send.vx = 0.003f * ((float)rc_data[TEMP].rc.rocker_r_ + (float)rc_data[TEMP].rc.rocker_r1);
|
||||
|
||||
// 右拨杆拨下去,底盘旋转
|
||||
if (switch_is_down(rc_data[TEMP].rc.switch_right))
|
||||
{
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
|
||||
}
|
||||
|
||||
if (switch_is_mid(rc_data[TEMP].rc.switch_left))
|
||||
{
|
||||
chassis_cmd_send.delta_leglen = -0.000001f * (abs(rc_data[TEMP].rc.dial) > 100 ? (float)rc_data[TEMP].rc.dial : 0);
|
||||
}
|
||||
chassis_cmd_send.vx = 0.003f * ((float)rc_data[TEMP].rc.rocker_r_ + (float)rc_data[TEMP].rc.rocker_r1);
|
||||
|
||||
gimbal_cmd_send.yaw -= 0.001f * (float)rc_data[TEMP].rc.rocker_l_;
|
||||
gimbal_cmd_send.pitch -= 0.0004f * (float)rc_data[TEMP].rc.rocker_l1;
|
||||
gimbal_cmd_send.pitch -= 0.0006f * (float)rc_data[TEMP].rc.rocker_l1;
|
||||
// 摇杆控制的软件限位
|
||||
gimbal_cmd_send.pitch = float_constrain(gimbal_cmd_send.pitch, -35.0f, 30.0f);
|
||||
// gimbal_cmd_send.yaw = float_constrain(gimbal_cmd_send.yaw, -180.0f, 180.0f);
|
||||
gimbal_cmd_send.pitch = float_constrain(gimbal_cmd_send.pitch, PITCH_MIN_ANGLE, PITCH_MAX_ANGLE);
|
||||
|
||||
// 底盘参数,目前没有加入小陀螺(调试似乎暂时没有必要),系数需要调整
|
||||
|
||||
// 摩擦轮控制,拨轮向上打为负,向下为正
|
||||
if (rc_data[TEMP].rc.dial < -100) // 向上超过100,打开摩擦轮
|
||||
shoot_cmd_send.friction_mode = FRICTION_ON;
|
||||
else
|
||||
shoot_cmd_send.friction_mode = FRICTION_OFF;
|
||||
// 拨弹控制,遥控器固定为一种拨弹模式,可自行选择
|
||||
if (rc_data[TEMP].rc.dial < -400)
|
||||
shoot_cmd_send.load_mode = LOAD_BURSTFIRE;
|
||||
else
|
||||
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||
if (switch_is_down(rc_data[TEMP].rc.switch_left))
|
||||
{
|
||||
if (rc_data[TEMP].rc.dial < -100) // 向上超过100,打开摩擦轮
|
||||
shoot_cmd_send.friction_mode = FRICTION_ON;
|
||||
else
|
||||
shoot_cmd_send.friction_mode = FRICTION_OFF;
|
||||
// 拨弹控制,遥控器固定为一种拨弹模式,可自行选择
|
||||
if (rc_data[TEMP].rc.dial < -400)
|
||||
shoot_cmd_send.load_mode = LOAD_BURSTFIRE;
|
||||
else
|
||||
shoot_cmd_send.load_mode = LOAD_STOP;
|
||||
}
|
||||
|
||||
// // 射频控制,固定每秒1发,后续可以根据左侧拨轮的值大小切换射频,
|
||||
// if( rc_data[TEMP].rc.switch_left == 3)
|
||||
// {
|
||||
@@ -169,6 +186,54 @@ static void RemoteControlSet()
|
||||
*/
|
||||
static void MouseKeySet()
|
||||
{
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||
|
||||
gimbal_cmd_send.yaw -= 0.1f * rc_data[TEMP].mouse.x;
|
||||
gimbal_cmd_send.pitch -= 0.1f * rc_data[TEMP].mouse.y;
|
||||
|
||||
gimbal_cmd_send.pitch = float_constrain(gimbal_cmd_send.pitch, PITCH_MIN_ANGLE, PITCH_MAX_ANGLE);
|
||||
|
||||
chassis_cmd_send.vx = BALANCE_MAX_SPEED * (float)(rc_data[TEMP].key[KEY_PRESS].w - rc_data[TEMP].key[KEY_PRESS].s
|
||||
+ rc_data[TEMP].key[KEY_PRESS].a - rc_data[TEMP].key[KEY_PRESS].d);
|
||||
|
||||
chassis_cmd_send.delta_leglen = (float)(rc_data[TEMP].key[KEY_PRESS].e - rc_data[TEMP].key[KEY_PRESS].c) * 0.001f;
|
||||
|
||||
if (rc_data[TEMP].key[KEY_PRESS].w || rc_data[TEMP].key[KEY_PRESS].s)
|
||||
{
|
||||
chassis_cmd_send.direction = CHASSIS_ALIGN;
|
||||
}
|
||||
else if (rc_data[TEMP].key[KEY_PRESS].a || rc_data[TEMP].key[KEY_PRESS].d)
|
||||
{
|
||||
chassis_cmd_send.direction = CHASSIS_SIDLE;
|
||||
}
|
||||
|
||||
switch (rc_data[TEMP].key_count[KEY_PRESS][Key_Q] % 2) // Q 小陀螺
|
||||
{
|
||||
case 0:
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||
break;
|
||||
default:
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (rc_data[TEMP].key_count[KEY_PRESS][Key_F] % 2) // F 摩擦轮
|
||||
{
|
||||
case 0:
|
||||
shoot_cmd_send.friction_mode = FRICTION_OFF;
|
||||
break;
|
||||
default:
|
||||
shoot_cmd_send.friction_mode = FRICTION_ON;
|
||||
break;
|
||||
}
|
||||
|
||||
if(rc_data[TEMP].mouse.press_r)
|
||||
{
|
||||
gimbal_cmd_send.yaw = ( vision_recv_data->yaw == 0 ? gimbal_cmd_send.yaw : vision_recv_data->yaw );
|
||||
gimbal_cmd_send.pitch =( vision_recv_data->pitch == 0 ? gimbal_cmd_send.pitch : vision_recv_data->pitch );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +248,7 @@ static void EmergencyHandler()
|
||||
|
||||
if (switch_is_down(rc_data[TEMP].rc.switch_left) || switch_is_mid(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[下],遥控器控制
|
||||
{
|
||||
if (rc_data[TEMP].rc.dial > 300 || robot_state == ROBOT_STOP) // 还需添加重要应用和模块离线的判断
|
||||
if ((rc_data[TEMP].rc.dial > 300 && switch_is_down(rc_data[TEMP].rc.switch_left)) || robot_state == ROBOT_STOP) // 还需添加重要应用和模块离线的判断
|
||||
{
|
||||
robot_state = ROBOT_STOP;
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_ZERO_FORCE;
|
||||
@@ -201,6 +266,7 @@ static void EmergencyHandler()
|
||||
shoot_cmd_send.shoot_mode = SHOOT_ON;
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||
chassis_cmd_send.direction = CHASSIS_ALIGN;
|
||||
}
|
||||
}
|
||||
else if (switch_is_up(rc_data[TEMP].rc.switch_left)) // 遥控器左侧开关状态为[上],键盘控制
|
||||
@@ -210,6 +276,9 @@ static void EmergencyHandler()
|
||||
case 0:
|
||||
robot_state = ROBOT_READY;
|
||||
shoot_cmd_send.shoot_mode = SHOOT_ON;
|
||||
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
|
||||
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
|
||||
chassis_cmd_send.direction = CHASSIS_ALIGN;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user