Skip to content

First hacky implementation of reusing the initial_positions for view_ur #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: ros2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions launch/view_ur.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
#
# Author: Denis Stogl

import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from ament_index_python.packages import get_package_share_directory
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare

import yaml


def generate_launch_description():
declared_arguments = []
Expand Down Expand Up @@ -131,13 +136,24 @@ def generate_launch_description():
)
robot_description = {"robot_description": robot_description_content}

initial_positions_file = os.path.join(
get_package_share_directory("ur_description"), "config", "initial_positions.yaml"
)
print(initial_positions_file)
with open(initial_positions_file, "r") as stream:
try:
initial_positions = yaml.safe_load(stream)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like much this direct dependency on yaml.

Can we do something like in Driver#308

except yaml.YAMLError as exc:
print(exc)

rviz_config_file = PathJoinSubstitution(
[FindPackageShare(description_package), "rviz", "view_robot.rviz"]
)

joint_state_publisher_node = Node(
package="joint_state_publisher_gui",
executable="joint_state_publisher_gui",
parameters=[{"zeros": initial_positions}],
)
robot_state_publisher_node = Node(
package="robot_state_publisher",
Expand All @@ -153,10 +169,6 @@ def generate_launch_description():
arguments=["-d", rviz_config_file],
)

nodes_to_start = [
joint_state_publisher_node,
robot_state_publisher_node,
rviz_node,
]
nodes_to_start = [joint_state_publisher_node, robot_state_publisher_node, rviz_node]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep this "multi-row" because it is easier to read and add nodes if needed. I expect people to copy-paste and extend this file.


return LaunchDescription(declared_arguments + nodes_to_start)