On this page
Nav2 Stack(urdf)
Original guide for reference: https://docs.visualnav2.org/cansetup_guides/urdf/setup_urdf.html
TODO: add rqt graphs for each time we add a node for the Nav2 Stack series
install pkg
creating workspace + package
mkdir -p mbot_ws/src
cd mbot_ws/src
ros2 pkg create --build-type ament_python --license Apache-2.0 mbot_pkg
building
cd ../../ # you should be in the mbot_ws folder after running this
colcon build --symlink-install
source install/setup.bash
Download
create rviz and urdf folder in mbot_pkg
and download the rviz and urdf file:
urdf file:
rviz file:
Core design
TODO: explain map→odom→base_link→sensor…p
Just robot_state_publisher
and joint_state_publisher_gui
run the whole show
(From Articulated Robotics)
creating launch file
make a launch folder called display.launch.py
Nodes we are adding:
- robot_state_publisher_node (reads the URDF and publishes to
/robot_description
all non-fixed joints, static joints and links) - joint_state_publisher_node (finds all of the non-fixed joints and publishes to
/joint_states
) - joint_state_publisher_gui_node (the same as joint_state_publisher_node but with a gui on top)
- rviz_node
launch file
import launch
from launch.substitutions import Command, LaunchConfiguration
import launch_ros
import os
def generate_launch_description():
pkg_share = launch_ros.substitutions.FindPackageShare(package='mbot_pkg').find('mbot_pkg')
default_model_path = os.path.join(pkg_share, 'urdf/mbot_description.urdf')
default_rviz_config_path = os.path.join(pkg_share, 'rviz/urdf_config.rviz')
robot_state_publisher_node = launch_ros.actions.Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{'robot_description': Command(['xacro ', LaunchConfiguration('model')])}]
)
joint_state_publisher_node = launch_ros.actions.Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher',
parameters=[{'robot_description': Command(['xacro ', default_model_path])}],
condition=launch.conditions.UnlessCondition(LaunchConfiguration('gui'))
)
joint_state_publisher_gui_node = launch_ros.actions.Node(
package='joint_state_publisher_gui',
executable='joint_state_publisher_gui',
name='joint_state_publisher_gui',
condition=launch.conditions.IfCondition(LaunchConfiguration('gui'))
)
rviz_node = launch_ros.actions.Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
arguments=['-d', LaunchConfiguration('rvizconfig')],
)
return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(name='gui', default_value='True',
description='Flag to enable joint_state_publisher_gui'),
launch.actions.DeclareLaunchArgument(name='model', default_value=default_model_path,
description='Absolute path to robot urdf file'),
launch.actions.DeclareLaunchArgument(name='rvizconfig', default_value=default_rviz_config_path,
description='Absolute path to rviz config file'),
joint_state_publisher_node,
joint_state_publisher_gui_node,
robot_state_publisher_node,
rviz_node
])
add new files to setup.py
import os
from glob import glob
from setuptools import find_packages, setup
package_name = 'mbot_code'
setup(
name=package_name,
version='0.0.0',
packages=find_packages(exclude=['test']),
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'urdf'), glob('urdf/*.urdf')),
(os.path.join('share', package_name, 'rviz'), glob('rviz/*.rviz*')),
(os.path.join('share', package_name), glob('launch/*launch.[pxy][yma]*')),
],
...
run:
colcon build --symlink-install
ros2 launch mbot_pkg display.launch.py