name is not defined in ROS2 python launch file
Hi. Sorry for all mistakes, English is not my native language. I've come from ROS1 and very familiar with ROS2 python launch system so, maybe, for anybody this problem will be obvious, but, unfortunately, not for me. I have the following launch file:
import os
import sys
import xacro
import launch
import launch_ros.actions
from launch.substitutions import LaunchConfiguration
from ament_index_python.packages import get_package_share_directory
from launch.substitutions import PythonExpression
xacro_path = os.path.join(get_package_share_directory('minicar_description'), 'urdf', 'minicar.xacro')
xacro_doc = xacro.parse(open(xacro_path, 'r'))
xacro.process_doc(xacro_doc)
robot_description = xacro_doc.toxml()
def generate_launch_description():
target = LaunchConfiguration("target", default='jetson')
use_sim_time = LaunchConfiguration('use_sim_time', default='true')
minicar_cartographer_prefix = get_package_share_directory('minicar_slam')
cartographer_config_dir = LaunchConfiguration('cartographer_config_dir', default=os.path.join(
minicar_cartographer_prefix, 'config'))
configuration_basename = PythonExpression(["'cartographer_jetson.lua' if ", target, "==jetson else 'cartographer_host.lua'"])
LaunchConfiguration('configuration_basename',default=configuration_basename)
resolution = LaunchConfiguration('resolution', default='0.05')
##publish_period_sec = LaunchConfiguration('publish_period_sec', default='1.0')
##rviz_config_dir = os.path.join(get_package_share_directory('turtlebot3_cartographer'), 'rviz', 'tb3_cartographer.rviz')
ld = launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(
'cartographer_config_dir',
default_value=cartographer_config_dir
),
launch.actions.DeclareLaunchArgument(
'configuration_basename',
default_value=configuration_basename
),
launch.actions.DeclareLaunchArgument(
'use_sim_time',
default_value=use_sim_time
),
launch.actions.DeclareLaunchArgument(
'target',
default_value=target
),
launch.actions.DeclareLaunchArgument(
name='config',
default_value=PythonExpression(["'cartographer_jetson.lua' if ", target, "==jetson else 'cartographer_host.lua'"])
),
launch.actions.DeclareLaunchArgument(
name='odom',
#default_value="$(var '/rs_t265/odom/sample' if (target == 'jetson') else '/minicar/controller/odom')"
default_value=PythonExpression(["'/rs_t265/odom/sample' if ",target, "==jetson else '/minicar/controller/odom'"])
),
launch.actions.DeclareLaunchArgument(
name='scan',
default_value='/minicar/rplidar/scan'
),
launch.actions.DeclareLaunchArgument(
name='map',
default_value='none'
),
launch.actions.DeclareLaunchArgument(
name='bag',
default_value='none'
),
launch_ros.actions.Node(
package='cartographer_ros',
executable='cartographer_node',
name='cartographer_node',
output='screen',
parameters=[
{
'robot_description': robot_description
}
],
condition=launch.conditions.IfCondition("$(var map == 'none')")
),
launch_ros.actions.Node(
package='cartographer_ros',
executable='cartographer_node',
name='cartographer_node',
output='screen',
parameters=[
{
'robot_description': robot_description
}
],
arguments=[
'-configuration_directory', cartographer_config_dir,
'-configuration_basename', configuration_basename
],
condition=launch.conditions.IfCondition("$(var map != 'none')")
),
launch_ros.actions.Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
parameters=[
{
'use_sim_time': use_sim_time,
'robot_description': robot_description
}
],
arguments=[
'-configuration_directory', cartographer_config_dir,
'-configuration_basename', configuration_basename
],
condition=launch.conditions.IfCondition(PythonExpression(["$(var bag != 'none')"]))
),
launch_ros.actions.Node(
package='rosbag2',
executable='play',
name='playbag',
parameters=[
{
'robot_description': robot_description
}
],
condition=launch.conditions.IfCondition(PythonExpression(["$(var bag != 'none')"]))
),
launch_ros.actions.Node(
package='cartographer_ros',
executable='occupancy_grid_node',
name='cartographer_occupancy_grid_node',
arguments=[
'resolution', resolution
],
parameters=[
{
'robot_description': robot_description
}
]
)
])
return ld
if __name__ == '__main__':
generate_launch_description()
That generate this error:
[INFO] [launch]: All log files can be found below /home/mikita/.ros/log/2022-11-17-04-43-30-782618-ubuntu-104998
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=NameError("name 'jetson' is not defined")>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures ...
It would be appreciated if you can minimize the code to review to MRE - if possible, with one argument and one node only