Skip to content

Commit

Permalink
added factory to view robot
Browse files Browse the repository at this point in the history
  • Loading branch information
mhubii committed Jul 31, 2023
1 parent be6d53b commit 82f5adf
Showing 1 changed file with 50 additions and 66 deletions.
116 changes: 50 additions & 66 deletions lbr_description/launch/view_robot.launch.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,69 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration
import os
from typing import List

from ament_index_python import get_package_share_directory
from launch import LaunchContext, LaunchDescription, LaunchDescriptionEntity
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare

from lbr_description import description_factory

# for reference see
# https://github.com/ros-controls/ros2_control_demos/tree/master/ros2_control_demo_description/rrbot_description
def generate_launch_description():

# Launch arguments
launch_args = []

launch_args.append(DeclareLaunchArgument(
name='description_package',
default_value='lbr_description',
description='Description package.'
))

launch_args.append(DeclareLaunchArgument(
name='description_file',
default_value='urdf/med7/med7.urdf.xacro',
description='Path to URDF file, relative to description_package.'
))

launch_args.append(DeclareLaunchArgument(
name='rviz_pkg',
default_value='lbr_description',
description='Package containing rviz_config.'
))

launch_args.append(DeclareLaunchArgument(
name='rviz_config',
default_value='config/config.rviz',
description='Rviz configuration relative to rviz_pkg.'
))
def launch_setup(context: LaunchContext) -> List[LaunchDescriptionEntity]:
model = LaunchConfiguration("model").perform(context)
robot_name = LaunchConfiguration("robot_name").perform(context)

launch_args.append(DeclareLaunchArgument(
name='robot_name',
default_value='lbr',
description='Set robot name.'
))
robot_description = description_factory(model=model, robot_name=robot_name)

# Load robot description
robot_description_content = Command(
[
FindExecutable(name="xacro"), " ",
PathJoinSubstitution(
[FindPackageShare(LaunchConfiguration('description_package')), LaunchConfiguration('description_file')]
), " ",
"robot_name:=", LaunchConfiguration('robot_name')
]
)

robot_description = {'robot_description': robot_description_content}

# Create required nodes
joint_state_publisher_node = Node(
joint_state_publisher_gui_node = Node(
package="joint_state_publisher_gui",
executable="joint_state_publisher_gui",
)

robot_state_publisher_node = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="both",
parameters=[robot_description],
)
rviz = Node(
package='rviz2',
executable='rviz2',
arguments=['-d', PathJoinSubstitution(
[FindPackageShare(LaunchConfiguration('rviz_pkg')), LaunchConfiguration('rviz_config')]
)]

rviz_node = Node(
package="rviz2",
executable="rviz2",
arguments=[
"-d",
os.path.join(
get_package_share_directory("lbr_description"), "config/config.rviz"
),
],
)

return LaunchDescription(
launch_args +
[
joint_state_publisher_node,
robot_state_publisher_node,
rviz
]
return [
joint_state_publisher_gui_node,
robot_state_publisher_node,
rviz_node,
]


def generate_launch_description():
ld = LaunchDescription()

ld.add_action(
DeclareLaunchArgument(
name="model",
default_value="iiwa7",
description="Set robot model.",
choices=["iiwa7", "iiwa14", "med7", "med14"],
)
)

ld.add_action(
DeclareLaunchArgument(
name="robot_name", default_value="lbr", description="Set robot name."
)
)

ld.add_action(OpaqueFunction(function=launch_setup))

return ld

0 comments on commit 82f5adf

Please sign in to comment.