Launch cartographer

’m just starting this course and trying to create my launch file.
import os
from ament_index_python.packages import get_package_share_directory
from launch.actions import SetEnvironmentVariable
from launch_ros.actions import Node
from launch import LaunchDescription

cartographer_config_dir = os.path.join(get_package_share_directory(‘cartographer_slam’), ‘config’)
configuration_basename = ‘cartographer’
def generate_launch_description():
return LaunchDescription([
SetEnvironmentVariable(‘RCUTILS_LOGGING_BUFFERED_STREAM’, ‘1’),
parameters=[{‘use_sim_time’: True}],
arguments=[‘-configuration_directory’, cartographer_config_dir,
‘-configuration_basename’, configuration_basename]
parameters=[{‘use_sim_time’: True}],
arguments=[‘-resolution’, ‘0.05’, ‘-publish_period_sec’, ‘1.0’]

Then I run
ros2 launch cartographer_slam

and get:
launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [py]: name ‘configuration_basename’ is not defined

I guessed wrong on the syntax. Can anyone help me define my basename?

i think you need to change the line of : configuration_basename = ‘cartographer’
to configuration_basename = ‘cartographer.lua’

(if you call the file in the folder of config cartographer.lua)

Thanks. Yes, that was one of the assignments I tried also. I get the same error. Curiously enough I deleted the assignment and placed the string directly and still got the same error. Something else is happening somewhere that I can’t see. It’s not complaining about not finding it, just complaining that I didn’t even define it. HUH?

This fails too with the same error—

        package='cartographer_ros', node_executable='cartographer_node', output='screen',
            '-configuration_directory', get_package_share_directory('cartographer_slam') + '/config',
            '-configuration_basename', get_package_share_directory('cartographer_slam') + '/config' + 'cartographer.lua'

Desperate attempt because just putting ‘cartographer.lua’ produces the same error.
So, ultimately it is not recognizing a properly formed argument for configuration_basename. I was hoping to learn about navigation instead of python syntax which I already know. So what’s up with the course material???

Did an entire rebuild and got it to compile. Followed the next few steps successfully until:

h) Move the robot around the Gazebo world using the keyboard teleop to create a full map of the environment.

I have the keyboard teleop in Web Shell #3 but can’t seem to get the focus away from the rviz window to use it to drive the robot around. WOW! I’m missing some other vague instruction. Can’t resize the desktop, can’t focus away, can only minimize it but then I can’t see where I’m driving. WTF?

Hello @jcocovich,

in order to move the robot around and create a map you must first configure Rviz in a way that you see that the map is appearing from the current robot position (the robot cast grey pixel rays straight out from its position). Then you can minimize Rviz and start the keyboard teleop. I would also advice to zoom out in Gazebo (use the mouse wheel) and place the Gazebo view in a top down perspective so that you can see the turtlebot in a way that it is not heavily occluded by the environment. Then keeping the focus on the keyboard teleop shell and keeping an eye on the Gazebo simulation you can move the robot around and see where it is in the environment. After a while switch to Rviz, try to identify the areas that need more mapping and then minimize Rviz an continue the same procedure: keep the focus on the keyboard teleop shell and keeping an eye on the Gazebo simulation you can move the robot around.
I have done this myself and it works. Yes, you have to switch a few times back an forth to Rviz, but that’s it. You will be able to complete the map.

Hope this helps,