Hello
I have a ros launch file that starts a few nodes. One of them exits under some conditions and I want to restart it every time when that happens. The whole idea is that I have a process that runs my simulator (specifically Webots). I have another process that starts a controller for my robot and whenever I reset the simulation I want to be able to restart my controller node without everything shutting down. What I have now is (it is a bit 'stupid' but I do not have any better ideas):
controller = Node(
package=my_package,
executable=my_executable,
)
cmd = ['ros2', 'run', 'my_package', 'my_executable']
restart_controller = ExecuteProcess(cmd=cmd,shell=True)
launch_description = LaunchDescription(ARGUMENTS + [
robot_state_publisher,
simulator,
controller,
# Restart controller when it breaks
RegisterEventHandler(
event_handler=launch.event_handlers.OnProcessExit(
target_action=controller,
on_exit=[restart_controller],
)
),
RegisterEventHandler(
event_handler=launch.event_handlers.OnProcessExit(
target_action=restart_controller,
on_exit=[controller],
)
),
# Shutdown launch when Webots exits.
RegisterEventHandler(
event_handler=launch.event_handlers.OnProcessExit(
target_action=simulator,
on_exit=[EmitEvent(event=launch.events.Shutdown())],
)
)
])
If I start the controller node again and again from a terminal it works every time but here I see that in the ExecuteProcess method whenever I try to run the same process it crashes and raises a runtime error that says "ExecuteProcess action executed more than once".
Another thing is that the ros package is in Python (it cannot be in cpp for now at least) so it is not possible to make it a managed node and use the lifecycle utilities (configure-activate-shutdown etc.) which was my original idea.
I am also open to a better idea to do what I want if it is impossible to re-execute a process.
Originally posted by anastasiaPan on ROS Answers with karma: 123 on 2021-04-14
Post score: 1