我有一个运行 ros2 启动文件的 python 文件
process = subprocess.Popen(["/opt/ros/humble/bin/ros2", "launch", "blaunch_pkg", "on_startup.launch.py"])
process = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
print("STDOUT OF ROS:", stdout.decode())
print("STDERR OF ROS:", stderr.decode())
process.wait()
exit()
这是我的服务:
[Unit]
Description=My Python Script
After=network.target
[Service]
Environment=PYTHONPATH=(my python path)
Enviroment=AMENT_PREFIX_PATH=(my ament prefix path)
Enviroment=CMAKE_PREFIX_PATH=(my ament cmake prefix path)
ExecStart=/bin/python3.10 (my path to service_startup.py)
WorkingDirectory= (my working directory)
StandardOutput=append:/var/log/my_script.log
StandardError=inherit
Restart=always
User=tubo
[Install]
WantedBy=multi-user.target
我的错误日志记录不一致,每次更改都会得到不同的错误日志记录(例如,如果我更改正在使用的 python 路径)。在当前配置下,该服务处于活动状态,但有时运行时没有错误,但启动文件没有实际运行,有时会出现以下错误:
OSError: Environment variable 'AMENT_PREFIX_PATH' is not set or empty
STDOUT OF ROS:
STDERR OF ROS:
STDOUT OF ROS:
STDERR OF ROS: