0

I have a python file running the ros2 launch file

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()

and this is my service:

[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

my error logging isnt consistent and i get a different one with each change, (for example if i change the python path being used). With the current configuration, the service is active but sometimes it runs with no errors but without launch file actually running and sometimes it has this error:

OSError: Environment variable 'AMENT_PREFIX_PATH' is not set or empty
STDOUT OF ROS: 
STDERR OF ROS: 
STDOUT OF ROS: 
STDERR OF ROS: 

0

You must log in to answer this question.

Browse other questions tagged .