RobotKernal-UESTC/Code/MowingRobot/pibot_ros/ros_ws/run1.py

33 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
import subprocess
import keyboard
def execute_launch(launch_file, launch_args=[]):
# 构造启动命令
launch_command = ["roslaunch", launch_file] + launch_args
# 启动一个新的终端并执行对应的.launch文件
subprocess.Popen(['gnome-terminal', '--', 'bash',' '.join(launch_command)])
# 监听按键事件
def on_press(event):
key = event.name
# 检查按键是否对应一个.launch文件
launch_files = {
'a': ('/home/firefly/pibot_ros/ros_ws/src/upbot_vision/launch/upbot_vision.launch', []), # stereo
'b': ('/home/firefly/pibot_ros/ros_ws/src/pibot_navigation/launch/nav.launch', ['map_name:=10_10m']), # nav
'c': ('/home/firefly/pibot_ros/ros_ws/src/ipa_coverage_planning/ipa_room_exploration/ros/test/room_exploration_client.launch', ['robot_env:=10_10m']), # client
'd': ('/home/firefly/pibot_ros/ros_ws/src/ipa_coverage_planning/ipa_room_exploration/ros/launch/room_exploration_action_server.launch', []), # server
}
if key in launch_files:
# 获取对应的.launch文件和参数
launch_file, launch_args = launch_files[key]
# 执行对应的.launch文件
execute_launch(launch_file, launch_args)
keyboard.on_press(on_press)
# 运行程序
keyboard.wait('q') # 等待按下 'q' 键