-
Notifications
You must be signed in to change notification settings - Fork 76
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
Use node namespace if no other was specified #51
Conversation
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
@@ -340,16 +340,21 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]: | |||
self._perform_substitutions(context) | |||
# Prepare the ros_specific_arguments list and add it to the context so that the | |||
# LocalSubstitution placeholders added to the the cmd can be expanded using the contents. | |||
ros_specific_arguments = [] # type: List[Text] | |||
ros_specific_arguments = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure you'll need type annotations here. Please setup and use mypy to check your code when making changes. We'll likely add a unit test for mypy when this pr is finished: ament/ament_lint#154
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved in 2301294
@ivanpauno thanks for the change, I tested and solves #50. What do you think of the following use case with the modified from launch import LaunchDescription
from launch_ros.actions import PushRosNamespace
from launch.actions import GroupAction
import launch.actions
import launch.substitutions
import launch_ros.actions
def generate_launch_description():
"""Launch a talker and a listener."""
return LaunchDescription([
GroupAction([
PushRosNamespace('launch_ns'),
launch_ros.actions.Node(
package='examples_rclcpp_minimal_timer',
node_executable='timer_member_function',
output='screen')
])
]) The node name is now |
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
I guess |
yes
Not sure if that's the way it worked on ROS1, or if that's the way it's intended for ROS2 or the way it worked before @wjwwood If a namespace is specified at launch, should this overwrite any namespace specified in the node constructor? If so, is there a way we can append the namespaces, i.e. /launch_ns/constructor_ns/node_name |
I don't think there is, I believe the In C++ you can use a "sub-node" to get the effect you want. Launch will set the original node's namespace, but your sub-node will always extend the original node's namespace. |
@wjwwood thanks for the input. One more question, arguments provided in the constructor options |
I had to dig a big to find this, but the arguments in the NodeOptions are called "local arguments" at the C API level, and they are "targeted at the node" where as global arguments are applied to all nodes, and the local ones are checked frist: But to answer your question directly, yes, the arguments given in the NodeOptions will take precedence over the global arguments which are usually coming from the command line. |
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
I've added namespace validation in I finally didn't allow LaunchDescription([
...,
PushRosNamespace('my_ns'),
PushRosNamespace(LaunchConfiguration(variable_name='SOME_NAMESPACE', default=''),
Node(...),
...,
]) If If you delete the first This may be very confusing, specially when combining |
I don't understand the issue with your most recent example @ivanpauno.
I don't understand what's confusing, setting the namespace outside of a launch description (before the include action that included it) is an important feature, and if the |
I will try to explain it in a clearer way. I think that accepting Launch description of launch file 1: LaunchDescription([
...,
PushRosNamespace(LaunchConfiguration(variable_name='SOME_NAMESPACE', default=''),
Node(...),
...,
]) Launch file 2: LaunchDescription([
...,
PushRosNamespace('my_ns')
IncludeLaunchDescription(launch_file_path='<path/to/above/example>'),
...,
]) The node specified in the node source code is in all the cases Results when running launch file 1:
Results when running launch file 2:
With this slightly modified launch file 1: LaunchDescription([
...,
PushRosNamespace(LaunchConfiguration(variable_name='SOME_NAMESPACE', default='node_ns'),
Node(...),
...,
]) The results when running launch file 1 directly are the same.
My original idea was that the first example should work as the second one. |
I don't see any issue with the second example, it is essentially the same as if the "launch file 1" had no |
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please flake8
😆, lgtm
If no namespace is pushed (by
PushRosNamespace
), and the user doesn't usenode_namespace
argument ofNode
action, the default namespace specified by the node should be used.I forgot about that, and in that case
__ns:=/
was being added to the command (which is wrong).I'm doing the corrections to avoid that.
(Edit) I finally didn't allow this
(Original)
If someone uses
PushRosNamespace('')
, and thenode_namespace
argument ofNode
action is the default (''
), the namespace indicated by the node is used.I thought it could by helpful for this case:
In that case, if the variable name doesn't exist, the namespace specified by the node will be used (and there is no need of copying it again in the launch file).
The other option is to raise an error when someone pass
''
toPushRosNamespace
.