diff --git a/src/config.js b/src/config.js index aa8f381..847e27b 100644 --- a/src/config.js +++ b/src/config.js @@ -8,12 +8,11 @@ export const MJPEG_MANUAL_URL = 'http://192.168.0.11/stream?topic=/vision/result export const MJPEG_DEBUG_URL = 'http://192.168.0.11/stream?topic=/vision/debug_image&mode=debug' // ROS 话题 -export const CMD_WHEEL_TOPIC = '/cmd_wheel' +export const CMD_WHEEL_TOPIC = '/cmd_chassis' export const CMD_GIMBAL_TOPIC = '/cmd_gimbal' // 键盘控制参数 -export const MAX_LINEAR = 0.5 // m/s -export const MAX_ANGULAR = 1.0 // rad/s -export const WHEEL_SEPARATION = 0.2 // 轮距(m) +export const BASE_SPEED = 0.5 // 直线基础速度 +export const YAW_VELOCITY = 1.0 // 角度速率,度每秒 // 云台角度速率 (度/秒) export const GIMBAL_PITCH_DEG_S = 10 diff --git a/src/views/ManualMode.vue b/src/views/ManualMode.vue index e25af1a..807a23b 100644 --- a/src/views/ManualMode.vue +++ b/src/views/ManualMode.vue @@ -24,7 +24,7 @@ import { onBeforeRouteLeave } from 'vue-router' import { MJPEG_MANUAL_URL, ROSBRIDGE_URL, CMD_WHEEL_TOPIC, CMD_GIMBAL_TOPIC, - MAX_LINEAR, MAX_ANGULAR, WHEEL_SEPARATION, + BASE_SPEED, YAW_VELOCITY, GIMBAL_PITCH_DEG_S, GIMBAL_YAW_DEG_S, API_GIMBAL_MODE_SWITCH, API_CHASSIS_MODE_SWITCH, API_LASER, } from '../config.js' @@ -38,7 +38,7 @@ connect(ROSBRIDGE_URL) const pressed = new Set() const laserOn = ref(false) let animId = null -let lastVel = { left: 0, right: 0, pitch: 0, yaw: 0 } +let lastVel = { linear: 0, angular: 0, pitch: 0, yaw: 0 } function onKeyDown(e) { if (['KeyW','KeyA','KeyS','KeyD','ArrowUp','ArrowDown','ArrowLeft','ArrowRight'].includes(e.code)) { @@ -59,33 +59,29 @@ function onKeyUp(e) { } function computeVelocities() { - const linear = (pressed.has('KeyW') ? MAX_LINEAR : 0) - (pressed.has('KeyS') ? MAX_LINEAR : 0) - const angular = (pressed.has('KeyA') ? MAX_ANGULAR : 0) - (pressed.has('KeyD') ? MAX_ANGULAR : 0) + const linear = (pressed.has('KeyW') ? BASE_SPEED : 0) - (pressed.has('KeyS') ? BASE_SPEED : 0) + const angular = (pressed.has('KeyA') ? YAW_VELOCITY : 0) - (pressed.has('KeyD') ? YAW_VELOCITY : 0) const pitch = (pressed.has('ArrowDown') ? GIMBAL_PITCH_DEG_S : 0) - (pressed.has('ArrowUp') ? GIMBAL_PITCH_DEG_S : 0) const yaw = (pressed.has('ArrowLeft') ? GIMBAL_YAW_DEG_S : 0) - (pressed.has('ArrowRight') ? GIMBAL_YAW_DEG_S : 0) - const halfSep = WHEEL_SEPARATION / 2 - const left = linear - angular * halfSep - const right = linear + angular * halfSep - - return { left, right, pitch, yaw } + return { linear, angular, pitch, yaw } } function startLoop() { function tick() { - const { left, right, pitch, yaw } = computeVelocities() - const changed = left !== lastVel.left || right !== lastVel.right || pitch !== lastVel.pitch || yaw !== lastVel.yaw + const { linear, angular, pitch, yaw } = computeVelocities() + const changed = linear !== lastVel.linear || angular !== lastVel.angular || pitch !== lastVel.pitch || yaw !== lastVel.yaw if (changed) { publish(CMD_WHEEL_TOPIC, 'std_msgs/Float32MultiArray', { - data: [left, right], + data: [linear, angular], layout: { dim: [], data_offset: 0 }, }) publish(CMD_GIMBAL_TOPIC, 'geometry_msgs/Twist', { linear: { x: 0, y: 0, z: 0 }, angular: { x: 0, y: pitch, z: yaw }, }) - lastVel = { left, right, pitch, yaw } + lastVel = { linear, angular, pitch, yaw } } if (pressed.size === 0) {