ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Okay, after 3 hours or so I figured it out!
So, the problem seems to be with the shared src variable in the data_processor_all_launch.py. I slightly changed both files to enable launching the data_processor_launch.py with user-defined namespaces and to accept the namespace argument from top-level data_processor_all_launch.py.
This is now the data_processor_all_launch.py :
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.actions import GroupAction
from launch.substitutions import TextSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import PushRosNamespace
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
ld = LaunchDescription()
package_prefix = get_package_share_directory('loading_motor_dt')
load_data_processor = PythonLaunchDescriptionSource([package_prefix,'/launch/data_processor_launch.py'])
traction_data_processor = PythonLaunchDescriptionSource([package_prefix,'/launch/data_processor_launch.py'])
launch_traction = GroupAction(
actions=[
# push-ros-namespace to set namespace of included nodes
#PushRosNamespace('tb_lm_left'),
IncludeLaunchDescription(load_data_processor, launch_arguments = {'namespace':'tb_tm'}.items()),
]
)
launch_loading = GroupAction(
actions=[
# push-ros-namespace to set namespace of included nodes
#PushRosNamespace('tb_tm'),
IncludeLaunchDescription(traction_data_processor, launch_arguments = {'namespace':'tb_tm'}.items()),
]
)
ld.add_action(launch_traction)
ld.add_action(launch_loading)
return ld
This is now the data_processor_launch.py:
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import PushRosNamespace
from launch.actions import GroupAction
def generate_launch_description():
ns = LaunchConfiguration('namespace', default = 'tb_lm_right')
ld = LaunchDescription()
config = os.path.join(
get_package_share_directory('loading_motor_dt'),
'config',
'params.yaml'
)
data_processor=Node(
package = 'loading_motor_dt',
name = 'data_processor',
executable = 'currentVoltageFlow',
parameters = [config]
)
data_processor_with_ns = GroupAction(
actions=[
PushRosNamespace(ns),
data_processor,
]
)
ld.add_action(data_processor_with_ns)
return ld
And finally the result:
sejego@pop-os:~/dev_ws$ ros2 node list
/tb_lm_left/data_processor
/tb_tm/data_processor
2 | No.2 Revision |
Okay, after 3 hours or so I figured it out!
So, the problem seems to be with the shared src variable in the data_processor_all_launch.py. I slightly changed both files to enable launching the data_processor_launch.py with user-defined namespaces and to accept the namespace argument from top-level data_processor_all_launch.py.
This is now the data_processor_all_launch.py :
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.actions import GroupAction
from launch.substitutions import TextSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import PushRosNamespace
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
ld = LaunchDescription()
package_prefix = get_package_share_directory('loading_motor_dt')
load_data_processor = PythonLaunchDescriptionSource([package_prefix,'/launch/data_processor_launch.py'])
traction_data_processor = PythonLaunchDescriptionSource([package_prefix,'/launch/data_processor_launch.py'])
launch_traction = GroupAction(
actions=[
# push-ros-namespace to set namespace of included nodes
#PushRosNamespace('tb_lm_left'),
IncludeLaunchDescription(load_data_processor, launch_arguments = {'namespace':'tb_tm'}.items()),
]
)
launch_loading = GroupAction(
actions=[
# push-ros-namespace to set namespace of included nodes
#PushRosNamespace('tb_tm'),
IncludeLaunchDescription(traction_data_processor, launch_arguments = {'namespace':'tb_tm'}.items()),
]
)
ld.add_action(launch_traction)
ld.add_action(launch_loading)
return ld
This is now the data_processor_launch.py:
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import PushRosNamespace
from launch.actions import GroupAction
def generate_launch_description():
ns = LaunchConfiguration('namespace', default = 'tb_lm_right')
'tb_tm')
ld = LaunchDescription()
config = os.path.join(
get_package_share_directory('loading_motor_dt'),
'config',
'params.yaml'
)
data_processor=Node(
package = 'loading_motor_dt',
name = 'data_processor',
executable = 'currentVoltageFlow',
parameters = [config]
)
data_processor_with_ns = GroupAction(
actions=[
PushRosNamespace(ns),
data_processor,
]
)
ld.add_action(data_processor_with_ns)
return ld
And finally the result:
sejego@pop-os:~/dev_ws$ ros2 node list
/tb_lm_left/data_processor
/tb_tm/data_processor