-
Notifications
You must be signed in to change notification settings - Fork 4
Make the Gazebo GUI work on macOS and keep the robot upright #27
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,10 +13,20 @@ | |
| self_collide on adjacent body meshes (avoids jitter), `gazebo_hand_link` | ||
| enables it with friction tuned for grasping. --> | ||
| <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> | ||
| <!-- Fix entire stand to the world so the robot does not fall (gz-sim may still move root; heavy mass in URDF is fallback). --> | ||
| <gazebo reference="base_node"> | ||
| <static>true</static> | ||
| </gazebo> | ||
| <!-- Anchor the stand to the world so the robot does not fall over. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment too long |
||
| <gazebo reference="..."><static>true</static></gazebo> does not survive | ||
| urdf->sdf conversion: sdformat only honours <static> on the model, not on | ||
| a link, so the stand stayed dynamic and gravity toppled the robot. A fixed | ||
| joint to a `world` link is the conversion-stable way to pin the base, and | ||
| leaves every upper-body joint (torso, neck, arms, fingers) free to move. | ||
| This file is included only under use_gazebo_sim:=true, so the extra link | ||
| never reaches the real/mock-hardware description or its TF tree. --> | ||
| <link name="world"/> | ||
| <joint name="world_to_base_node" type="fixed"> | ||
| <parent link="world"/> | ||
| <child link="base_node"/> | ||
| <origin xyz="0 0 0.02" rpy="0 0 0"/> | ||
| </joint> | ||
| <gazebo reference="stand_link"> | ||
| <static>true</static> | ||
| </gazebo> | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -22,17 +22,20 @@ | |
| # frames without an X server — the ros_gz camera bridge stays functional. | ||
|
|
||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from ament_index_python.packages import get_package_prefix, get_package_share_directory | ||
| from launch import LaunchDescription | ||
| from launch.actions import ( | ||
| DeclareLaunchArgument, | ||
| ExecuteProcess, | ||
| IncludeLaunchDescription, | ||
| OpaqueFunction, | ||
| SetEnvironmentVariable, | ||
| TimerAction, | ||
| ) | ||
| from launch.conditions import UnlessCondition | ||
| from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
| from launch.substitutions import ( | ||
| LaunchConfiguration, | ||
|
|
@@ -43,6 +46,9 @@ | |
| import yaml | ||
|
|
||
|
|
||
| _IS_DARWIN = sys.platform == "darwin" | ||
|
|
||
|
|
||
| def _gz_ros2_control_plugin_path(): | ||
| pkg_share = get_package_prefix("inmoov_urdf") | ||
| plugin_path = os.path.join(pkg_share, "lib", "mock_sensor") | ||
|
|
@@ -270,6 +276,11 @@ def _camera_compressor(topic: str, compressed_topic: str) -> Node: | |
| # When headless: server-only (-s) with EGL rendering (--headless-rendering) | ||
| # so OGRE2 still renders camera sensors without an X display. Otherwise: | ||
| # normal GUI launch. | ||
| # macOS cannot run the gz server and the Qt GUI in one process: Cocoa needs | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment too long |
||
| # the GUI on the main thread, so `gz sim` refuses and exits(-1) unless given | ||
| # -s or -g (gazebosim/gz-sim#44, enforced in the ruby entry point). Run the | ||
| # server with -s here and start `gz sim -g` as a second process below. | ||
| gui_server_args = "-s -r " if _IS_DARWIN else "-r " | ||
| gz_args = PythonExpression( | ||
| [ | ||
| "'-s -r --headless-rendering ", | ||
|
|
@@ -278,7 +289,8 @@ def _camera_compressor(topic: str, compressed_topic: str) -> Node: | |
| " if '", | ||
| LaunchConfiguration("headless"), | ||
| "'.lower() in ('true', '1', 'yes') ", | ||
| "else '-r ", | ||
| "else '", | ||
| gui_server_args, | ||
| default_world, | ||
| "'", | ||
| ] | ||
|
|
@@ -288,13 +300,31 @@ def _camera_compressor(topic: str, compressed_topic: str) -> Node: | |
| launch_arguments={"gz_args": gz_args}.items(), | ||
| ) | ||
|
|
||
| # Second process for the Qt GUI on macOS (see gz_args). Delayed so the | ||
| # server's transport is advertising before the GUI connects to it. | ||
| gazebo_gui_actions = [] | ||
| if _IS_DARWIN: | ||
| gazebo_gui_actions.append( | ||
| TimerAction( | ||
| period=6.0, | ||
| actions=[ | ||
| ExecuteProcess( | ||
| cmd=["gz", "sim", "-g"], | ||
| name="gazebo_gui", | ||
| output="screen", | ||
| condition=UnlessCondition(LaunchConfiguration("headless")), | ||
| ) | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| spawn_robot = TimerAction( | ||
| period=8.0, | ||
| actions=[ | ||
| Node( | ||
| package="ros_gz_sim", | ||
| executable="create", | ||
| arguments=["-name", "lucy", "-topic", "robot_description", "-z", "0.5"], | ||
| arguments=["-name", "lucy", "-topic", "robot_description", "-z", "0.0"], | ||
| output="screen", | ||
| parameters=[{"use_sim_time": True}], | ||
| ) | ||
|
|
@@ -354,6 +384,7 @@ def spawner_actions_from_yaml(context, *args, **kwargs): | |
| supervisor, | ||
| OpaqueFunction(function=spawner_actions_from_yaml), | ||
| gz_sim_launch, | ||
| *gazebo_gui_actions, | ||
| spawn_robot, | ||
| bridge, | ||
| *camera_compressors, | ||
|
|
||
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.
A tester