优化飞行手柄
This commit is contained in:
@@ -15,6 +15,10 @@ class FlightStick(Xbox):
|
||||
# 根据控制模式调整步长
|
||||
current_linear_step = self.linear_step * (0.1 if self.fine_control_mode else 1.0)
|
||||
current_angular_step = self.angular_step * (0.1 if self.fine_control_mode else 1.0)
|
||||
if self.joystick.get_button(2): # A按钮
|
||||
self.fine_control_mode = True
|
||||
if self.joystick.get_button(3): # B按钮
|
||||
self.fine_control_mode = False
|
||||
|
||||
# print(f"步长设置 - 线性: {current_linear_step}, 角度: {current_angular_step}")
|
||||
print(f"精细控制模式: {self.fine_control_mode}")
|
||||
@@ -26,17 +30,16 @@ class FlightStick(Xbox):
|
||||
hat_left = hat[0] == -1 # X-
|
||||
hat_right = hat[0] == 1 # X+
|
||||
# 计算各轴速度
|
||||
pose_speeds['x.vel'] = -current_linear_step if hat_left else (current_linear_step if hat_right else 0.0) # X
|
||||
pose_speeds['y.vel'] = current_linear_step if hat_up else (-current_linear_step if hat_down else 0.0) # Y
|
||||
pose_speeds['x.vel'] = current_linear_step if hat_left else (-current_linear_step if hat_right else 0.0) # X
|
||||
pose_speeds['y.vel'] = -current_linear_step if hat_up else (current_linear_step if hat_down else 0.0) # Y
|
||||
|
||||
# print(f"方向键状态: up={hat_up}, down={hat_down}, left={hat_left}, right={hat_right}")
|
||||
# 油门控制Z轴
|
||||
gas_axis = -self.joystick.get_axis(2)
|
||||
|
||||
# 设置Z速度
|
||||
z_mapping = self.apply_nonlinear_mapping(gas_axis)
|
||||
# print(f"Z轴非线性映射: {gas_axis} -> {z_mapping}")
|
||||
pose_speeds['z.vel'] = z_mapping * current_linear_step # Z
|
||||
if self.joystick.get_button(8): # X按钮
|
||||
pose_speeds['z.vel'] = current_linear_step
|
||||
elif self.joystick.get_button(9): # Y按钮
|
||||
pose_speeds['z.vel'] = -current_linear_step
|
||||
else:
|
||||
pose_speeds['z.vel'] = 0
|
||||
|
||||
|
||||
# 主摇杆X轴控制RX旋转
|
||||
@@ -56,6 +59,11 @@ class FlightStick(Xbox):
|
||||
rz_mapping = self.apply_nonlinear_mapping(self.joystick.get_axis(3))
|
||||
# print(f"RZ轴非线性映射: {z_axis} -> {rz_mapping}")
|
||||
pose_speeds['rz.vel'] = rz_mapping * current_angular_step * 2 # RZ
|
||||
|
||||
pose_speeds['gripper.vel'] = 0
|
||||
if self.joystick.get_button(0): # X按钮
|
||||
pose_speeds['gripper.vel'] = current_linear_step
|
||||
elif self.joystick.get_button(1): # Y按钮
|
||||
pose_speeds['gripper.vel'] = -current_linear_step
|
||||
else:
|
||||
pose_speeds['gripper.vel'] = 0
|
||||
print(f"pose_speeds: {pose_speeds}")
|
||||
return pose_speeds
|
||||
|
||||
Reference in New Issue
Block a user