Skip to content

Commit e3ec26d

Browse files
authored
Merge pull request #567 from JdeRobot/car_junction
Car junction
2 parents 944c970 + 1204295 commit e3ec26d

File tree

4 files changed

+139
-89
lines changed

4 files changed

+139
-89
lines changed

Launchers/car_junction.launch.py

Lines changed: 60 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,89 @@
1+
"""
2+
car_junction.launch.py
3+
4+
Entry point for the Car Junction exercise.
5+
"""
6+
17
import os
8+
9+
from ament_index_python.packages import get_package_share_directory
10+
211
from launch import LaunchDescription
3-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
4-
from launch.conditions import IfCondition, UnlessCondition
12+
from launch.actions import (
13+
DeclareLaunchArgument,
14+
IncludeLaunchDescription,
15+
SetEnvironmentVariable,
16+
AppendEnvironmentVariable,
17+
)
518
from launch.launch_description_sources import PythonLaunchDescriptionSource
6-
from launch.substitutions import Command, LaunchConfiguration, PythonExpression
19+
from launch.substitutions import LaunchConfiguration, Command
20+
from launch_ros.actions import Node
21+
from launch.substitutions import LaunchConfiguration
722
from launch_ros.actions import Node
8-
from launch_ros.substitutions import FindPackageShare
923

1024

1125
def generate_launch_description():
1226

13-
# Set the path to the Gazebo ROS package
14-
pkg_gazebo_ros = FindPackageShare(package="gazebo_ros").find("gazebo_ros")
15-
16-
# Set the path to this package.
17-
pkg_share = FindPackageShare(package="custom_robots").find("custom_robots")
18-
19-
# Set the path to the world file
27+
package_dir = get_package_share_directory("custom_robots")
28+
ros_gz_sim = get_package_share_directory("ros_gz_sim")
29+
use_sim_time = LaunchConfiguration("use_sim_time", default="true")
2030
world_file_name = "road_junction.world"
21-
world_path = os.path.join(pkg_share, "worlds", world_file_name)
31+
worlds_dir = "/opt/jderobot/Worlds"
32+
world_path = os.path.join(worlds_dir, world_file_name)
2233

23-
# Set the path to the SDF model files.
24-
gazebo_models_path = os.path.join(pkg_share, "models")
25-
os.environ["GAZEBO_MODEL_PATH"] = (
26-
f"{os.environ.get('GAZEBO_MODEL_PATH', '')}:{':'.join(gazebo_models_path)}"
27-
)
28-
29-
start_ros_gazebo_bridge = (
30-
Node(
31-
package="ros_gz_bridge",
32-
executable="parameter_bridge",
33-
arguments=[
34-
"/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock",
35-
"/cmd_vel@geometry_msgs/msg/Twist]gz.msgs.Twist",
36-
"/odom@nav_msgs/msg/Odometry]gz.msgs.Odometry",
37-
"/waymo/lidar/points@sensor_msgs/msg/PointCloud2[gz.msgs.PointCloudPacked",
38-
"/waymo/camera_info@sensor_msgs/msg/CameraInfo[gz.msgs.CameraInfo",
39-
],
40-
parameters=[{"use_sim_time": True}],
41-
output="screen",
34+
gazebo_server = IncludeLaunchDescription(
35+
PythonLaunchDescriptionSource(
36+
os.path.join(ros_gz_sim, "launch", "gz_sim.launch.py")
4237
),
43-
)
44-
45-
start_ros_gazebo_image_bridge = Node(
46-
package="ros_gz_image",
47-
executable="image_bridge",
48-
arguments=["/waymo/camera_front@sensor_msgs/msg/Image[gz.msgs.Image"],
49-
output="screen",
50-
)
51-
52-
########### YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE ##############
53-
# Launch configuration variables specific to simulation
54-
headless = LaunchConfiguration("headless")
55-
use_sim_time = LaunchConfiguration("use_sim_time")
56-
use_simulator = LaunchConfiguration("use_simulator")
57-
world = LaunchConfiguration("world")
58-
59-
declare_simulator_cmd = DeclareLaunchArgument(
60-
name="headless",
61-
default_value="False",
62-
description="Whether to execute gzclient",
63-
)
64-
65-
declare_use_sim_time_cmd = DeclareLaunchArgument(
66-
name="use_sim_time",
67-
default_value="true",
68-
description="Use simulation (Gazebo) clock if true",
38+
launch_arguments={
39+
"gz_args": ["-r -s -v4 ", world_path],
40+
"on_exit_shutdown": "true",
41+
}.items(),
6942
)
7043

7144
declare_use_simulator_cmd = DeclareLaunchArgument(
7245
name="use_simulator",
7346
default_value="True",
7447
description="Whether to start the simulator",
7548
)
76-
77-
declare_world_cmd = DeclareLaunchArgument(
78-
name="world",
79-
default_value=world_path,
80-
description="Full path to the world model file to load",
49+
world_entity_cmd = Node(
50+
package="ros_gz_sim",
51+
executable="create",
52+
arguments=["-name", "world", "-file", world_path],
53+
output="screen",
8154
)
8255

83-
# Specify the actions
84-
85-
# Start Gazebo server
86-
start_gazebo_server_cmd = IncludeLaunchDescription(
87-
PythonLaunchDescriptionSource(
88-
os.path.join(pkg_gazebo_ros, "launch", "gzserver.launch.py")
89-
),
90-
condition=IfCondition(use_simulator),
91-
launch_arguments={"world": world}.items(),
56+
start_ros_gazebo_bridge = Node(
57+
package="ros_gz_bridge",
58+
executable="parameter_bridge",
59+
arguments=[
60+
"/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock",
61+
"/cmd_vel@geometry_msgs/msg/Twist]gz.msgs.Twist",
62+
"/odom@nav_msgs/msg/Odometry]gz.msgs.Odometry",
63+
"/waymo/lidar/points@sensor_msgs/msg/PointCloud2[gz.msgs.PointCloudPacked",
64+
"/waymo/camera_info@sensor_msgs/msg/CameraInfo[gz.msgs.CameraInfo",
65+
],
66+
parameters=[{'use_sim_time': True}],
67+
output="screen",
68+
)
69+
70+
# Set the path to the SDF model files.
71+
gazebo_models_path = os.path.join(pkg_share, "models")
72+
os.environ["GAZEBO_MODEL_PATH"] = (
73+
f"{os.environ.get('GAZEBO_MODEL_PATH', '')}:{':'.join(gazebo_models_path)}"
9274
)
9375

94-
# Start Gazebo client
95-
start_gazebo_client_cmd = IncludeLaunchDescription(
96-
PythonLaunchDescriptionSource(
97-
os.path.join(pkg_gazebo_ros, "launch", "gzclient.launch.py")
98-
),
99-
condition=IfCondition(PythonExpression([use_simulator, " and not ", headless])),
76+
start_ros_gazebo_image_bridge = Node(
77+
package="ros_gz_image",
78+
executable="image_bridge",
79+
arguments=["/waymo/camera_front@sensor_msgs/msg/Image[gz.msgs.Image"],
80+
output="screen",
10081
)
10182

10283
# Create the launch description and populate
10384
ld = LaunchDescription()
104-
105-
# Declare the launch options
106-
ld.add_action(declare_simulator_cmd)
107-
ld.add_action(declare_use_sim_time_cmd)
108-
ld.add_action(declare_use_simulator_cmd)
109-
ld.add_action(declare_world_cmd)
110-
111-
# Add any actions
112-
ld.add_action(start_gazebo_server_cmd)
113-
ld.add_action(start_gazebo_client_cmd)
85+
ld.add_action(gazebo_server)
86+
ld.add_action(world_entity_cmd)
11487
ld.add_action(start_ros_gazebo_bridge)
11588
ld.add_action(start_ros_gazebo_image_bridge)
11689

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0"?>
2+
<!-- Quick start dialog -->
3+
<dialog name="quick_start" show_again="false"/>
4+
5+
<!-- Window -->
6+
<window>
7+
<width>1024</width>
8+
<height>768</height>
9+
<style material_theme="Light" material_primary="DeepOrange" material_accent="LightBlue" toolbar_color_light="#f3f3f3" toolbar_text_color_light="#111111" toolbar_color_dark="#414141" toolbar_text_color_dark="#f3f3f3" plugin_toolbar_color_light="#bbdefb" plugin_toolbar_text_color_light="#111111" plugin_toolbar_color_dark="#607d8b" plugin_toolbar_text_color_dark="#eeeeee"/>
10+
<menus>
11+
<drawer visible="false">
12+
</drawer>
13+
<plugins visible="false">
14+
</plugins>
15+
</menus>
16+
<dialog_on_exit>false</dialog_on_exit>
17+
</window>
18+
19+
<!-- GUI plugins -->
20+
<!-- 3D scene -->
21+
<plugin filename="MinimalScene" name="3D View">
22+
<gz-gui>
23+
<title>3D View</title>
24+
<property type="bool" key="showTitleBar">false</property>
25+
<property type="string" key="state">docked</property>
26+
</gz-gui>
27+
<engine>ogre2</engine>
28+
<scene>scene</scene>
29+
<ambient_light>0.4 0.4 0.4</ambient_light>
30+
<background_color>0.8 0.8 0.8</background_color>
31+
<camera_pose>0.0 0.0 8 0 1.57 3.14</camera_pose>
32+
</plugin>
33+
34+
<!-- Plugins that add functionality to the scene -->
35+
<plugin filename="GzSceneManager" name="Scene Manager">
36+
<gz-gui>
37+
<property key="resizable" type="bool">false</property>
38+
<property key="width" type="double">5</property>
39+
<property key="height" type="double">5</property>
40+
<property key="state" type="string">floating</property>
41+
<property key="showTitleBar" type="bool">false</property>
42+
</gz-gui>
43+
</plugin>
44+
45+
<plugin filename="InteractiveViewControl" name="Interactive view control">
46+
<gz-gui>
47+
<property key="resizable" type="bool">false</property>
48+
<property key="width" type="double">5</property>
49+
<property key="height" type="double">5</property>
50+
<property key="state" type="string">floating</property>
51+
<property key="showTitleBar" type="bool">false</property>
52+
</gz-gui>
53+
</plugin>
54+
55+
<plugin filename="WorldStats" name="World stats">
56+
<gz-gui>
57+
<title>World stats</title>
58+
<property type="bool" key="showTitleBar">false</property>
59+
<property type="bool" key="resizable">false</property>
60+
<property type="double" key="height">110</property>
61+
<property type="double" key="width">290</property>
62+
<property type="double" key="z">1</property>
63+
64+
<property type="string" key="state">floating</property>
65+
<anchors target="3D View">
66+
<line own="right" target="right"/>
67+
<line own="bottom" target="bottom"/>
68+
</anchors>
69+
</gz-gui>
70+
71+
<sim_time>true</sim_time>
72+
<real_time>true</real_time>
73+
<real_time_factor>true</real_time_factor>
74+
<iterations>true</iterations>
75+
<topic>/world/world_demo/stats</topic>
76+
77+
</plugin>

Worlds/road_junction.world

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,4 @@
704704
</plugin>
705705

706706
</world>
707-
</sdf>
707+
</sdf>

database/universes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ COPY public.worlds (id, name, launch_file_path, tools_config, ros_version, type,
206206
32 Follow Road Harmonic /opt/jderobot/Launchers/follow_road.launch.py {"gzsim":"/opt/jderobot/Launchers/visualization/follow_road.config"} ROS2 gz {0.0,0.0,0.0,0.0,0.0,0.0}
207207
33 Small Laser Mapping Warehouse /opt/jderobot/Launchers/small_laser_mapping.launch.py {"gzsim":"/opt/jderobot/Launchers/visualization/small_laser_mapping.config"} ROS2 gz {0.0,0.0,0.0,0.0,0.0,0.0}
208208
34 Pick And Place Arm /home/dev_ws/src/IndustrialRobots/ros2_SimRealRobotControl/ros2srrc_launch/moveit2/moveit2.launch.py None ROS2 gazebo {0.0,0.0,0.0,0.0,0.0,0.0}
209-
35 Car Junction /opt/jderobot/Launchers/car_junction.launch.py None ROS2 gazebo {0.0,0.0,0.0,0.0,0.0,0.0}
209+
35 Car Junction /opt/jderobot/Launchers/car_junction.launch.py {"gzsim":"/opt/jderobot/Launchers/visualization/car_junction.config"} ROS2 gz {0.0,0.0,0.0,0.0,0.0,0.0}
210210
36 Drone Gymkhana Harmonic /opt/jderobot/Launchers/drone_gymkhana.launch.py None ROS2 gz {0.0,0.0,0.0,0.0,0.0,0.0}
211211
37 Tower Inspection Harmonic /opt/jderobot/Launchers/power_tower_inspection.launch.py None ROS2 gz {0.0,0.0,0.0,0.0,0.0,0.0}
212212
\.

0 commit comments

Comments
 (0)