-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ComposableNodeContainer and respawn=True #361
Comments
This was probably an oversight in the implementation. I think that the correct thing is happening in that I would suggest that we maybe add a |
@mjcarroll Is there a working solution for the container auto-restart task? I tried to do it through RegisterEventHandler and it didn't work. import launch
from launch_ros.actions import ComposableNodeContainer, LoadComposableNodes
from launch_ros.descriptions import ComposableNode
from launch.event_handlers import (OnExecutionComplete, OnProcessExit,
OnProcessIO, OnProcessStart, OnShutdown)
from launch.actions import RegisterEventHandler, LogInfo
def generate_launch_description():
"""Generate launch description with multiple components."""
comps =[
ComposableNode(
package='composition',
plugin='composition::Talker',
name='talker'),
ComposableNode(
package='composition',
plugin='composition::Listener',
name='listener')
]
container = ComposableNodeContainer(
name='my_container',
namespace='',
package='rclcpp_components',
executable='component_container',
output='screen',
respawn=True
)
event = RegisterEventHandler(
OnProcessStart(
target_action=container,
on_start=[LogInfo(msg='Container start'),LoadComposableNodes(composable_node_descriptions=comps, target_container=container)]
))
return launch.LaunchDescription([container, event]) |
Not that I'm aware of, I will take a look as well. |
@mjcarroll I found a working way for this task import launch
from launch_ros.actions import ComposableNodeContainer, LoadComposableNodes
from launch_ros.descriptions import ComposableNode
from launch.event_handlers import (OnExecutionComplete, OnProcessExit,
OnProcessIO, OnProcessStart, OnShutdown)
from launch.actions import RegisterEventHandler, LogInfo, OpaqueFunction
import time
def func(context, *args, **kwargs):
comps =[
ComposableNode(
package='composition',
plugin='composition::Talker',
name='talker'),
ComposableNode(
package='composition',
plugin='composition::Listener',
name='listener')
]
time.sleep(1) # <--- lmao
return [LoadComposableNodes(composable_node_descriptions=comps, target_container='my_container')]
def generate_launch_description():
container = ComposableNodeContainer(
name='my_container',
namespace='',
package='rclcpp_components',
executable='component_container',
output='screen',
respawn=True
)
event = RegisterEventHandler(
OnProcessStart(
target_action=container,
on_start=[LogInfo(msg='Container start'),OpaqueFunction(function=func)]
))
return launch.LaunchDescription([event, container]) |
Great! Would you like to contribute an example to the documentation so that others may easily reference? |
@mjcarroll The code example above is more of a hack than a reference working example. This solution works, but the LoadComposableNodes class gives a warning "there are now at least 2 nodes with the name ...". It looks like I'm doing something wrong in terms of launch_ros architecture |
I came to create exactly the same issue, glad to see I'm not the only one needing this. I'll try out the hack 😄 |
Some feedback about the proposed workaround, it worked well for me until I ran it for a simulation. Basically I set use_sim_true globally from a parent launch file using |
@mjcarroll I can see how it can get tricky if things are changing at runtime, however do you see a straightforward implementation for respawning the container and loading what was first inputted in |
@mjcarroll any updates/insights here? I'm willing to do the contribution here as I need this pretty urgently but I need some guidance. @clalancette Maybe you have an idea? |
Yeah @tonynajjar sorry to leave you in the lurch here. I think that your initial idea of respawning with the description that was used at launch is generally the safest choice. To prevent any sort of surprise side effects, I think we should make this an opt in flag on the We could consider making that the default further down the road, but it could be surprising right now. |
Sure, can you give me some guidance on how to implement the logic behind As far as I see the respawning logic of the process is in the |
What is a case in which you would want |
Any updates on this? I think |
Bug report
There is a non-working combination of a non-empty parameter "composable_node_descriptions" and "respawn=True" in the ComposableNodeContainer class.
Required Info:
rmw_cyclonedds_cpp
Steps to reproduce issue
ros2 launch ./<launch_name>
Expected behavior
After the container is killed, it respawns with its components
Actual behavior
After the container is killed, it respawns without components.
Additional information
Feature request
Feature description
Implementation considerations
The text was updated successfully, but these errors were encountered: