-
Notifications
You must be signed in to change notification settings - Fork 66
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
Standalone launch file for rviz #161
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ddaa11
add arguments to configure publishing pointcloud and depth_registered…
jschornak-bdai 3ef4e7c
fix line lengths
jschornak-bdai a4c5e77
Standalone launch file for rviz
jbarry-bdai 34d0d27
Update spot_driver/launch/spot_driver.launch.py
jbarry-bdai 844fbdd
has_arm is no longer a launch argument
abaker-bdai e183496
pre-commit
abaker-bdai 85c3940
pre-commit one more time
abaker-bdai 37c0311
Merge branch 'main' into jlb/rviz_launch
abaker-bdai 46c1656
Merge branch 'main' into jlb/rviz_launch
abaker-bdai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright [2023] Boston Dynamics AI Institute, Inc. | ||
|
||
import os | ||
|
||
import launch | ||
import launch_ros | ||
import yaml | ||
from ament_index_python.packages import get_package_share_directory | ||
from launch import LaunchContext, LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, OpaqueFunction | ||
from launch.substitutions import ( | ||
LaunchConfiguration, | ||
PathJoinSubstitution, | ||
) | ||
from launch_ros.substitutions import FindPackageShare | ||
|
||
THIS_PACKAGE = "spot_driver" | ||
|
||
|
||
def create_rviz_config(robot_name: str) -> None: | ||
"""Writes a configuration file for rviz to visualize a single spot robot""" | ||
|
||
RVIZ_TEMPLATE_FILENAME = os.path.join(get_package_share_directory(THIS_PACKAGE), "rviz", "spot_template.yaml") | ||
RVIZ_OUTPUT_FILENAME = os.path.join(get_package_share_directory(THIS_PACKAGE), "rviz", "spot.rviz") | ||
|
||
with open(RVIZ_TEMPLATE_FILENAME, "r") as template_file: | ||
config = yaml.safe_load(template_file) | ||
|
||
if robot_name: | ||
# replace fixed frame with robot body frame | ||
config["Visualization Manager"]["Global Options"]["Fixed Frame"] = f"{robot_name}/vision" | ||
# Add robot models for each robot | ||
for display in config["Visualization Manager"]["Displays"]: | ||
if "RobotModel" in display["Class"]: | ||
display["Description Topic"]["Value"] = f"/{robot_name}/robot_description" | ||
|
||
if "Image" in display["Class"]: | ||
topic_name = display["Topic"]["Value"] | ||
display["Topic"]["Value"] = f"/{robot_name}{topic_name}" | ||
|
||
with open(RVIZ_OUTPUT_FILENAME, "w") as out_file: | ||
yaml.dump(config, out_file) | ||
|
||
|
||
def launch_setup(context: LaunchContext, ld: LaunchDescription) -> None: | ||
rviz_config_file = LaunchConfiguration("rviz_config_file").perform(context) | ||
spot_name = LaunchConfiguration("spot_name").perform(context) | ||
|
||
# It looks like passing an optional of value "None" gets converted to a string of value "None" | ||
if not rviz_config_file or rviz_config_file == "None": | ||
create_rviz_config(spot_name) | ||
rviz_config_file = PathJoinSubstitution([FindPackageShare(THIS_PACKAGE), "rviz", "spot.rviz"]).perform(context) | ||
|
||
rviz = launch_ros.actions.Node( | ||
package="rviz2", | ||
executable="rviz2", | ||
name="rviz2", | ||
arguments=["-d", rviz_config_file], | ||
output="screen", | ||
) | ||
|
||
ld.add_action(rviz) | ||
|
||
|
||
def generate_launch_description() -> launch.LaunchDescription: | ||
launch_args = [] | ||
|
||
launch_args.append( | ||
DeclareLaunchArgument( | ||
"rviz_config_file", | ||
default_value="", | ||
description="RViz config file", | ||
) | ||
) | ||
launch_args.append(DeclareLaunchArgument("spot_name", default_value="", description="Name of Spot")) | ||
|
||
ld = launch.LaunchDescription(launch_args) | ||
|
||
ld.add_action(OpaqueFunction(function=launch_setup, args=[ld])) | ||
|
||
return ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Quality of Service needs to be set to "best effort" in Rviz if you want to visualize the PointCloud2 under
Reliability Policy
. Is there a way to set that automatically in this config?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a way to have that default to the right setting, but I think you need to provide that in the config YAML file. Here's the full entry for a PointCloud display, for example. We set
Topic -> Reliability Policy
toBest Effort
instead ofReliable
.