-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathrobot_description_publisher.launch.py
executable file
·93 lines (82 loc) · 2.87 KB
/
robot_description_publisher.launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
def generate_launch_description():
# Import the model urdf (load from file, xacro ...)
robot_desc = \
'<?xml version="1.0" ?>'\
'<robot name="will_be_ignored">'\
'<link name="link">'\
'<visual>'\
'<geometry>'\
'<sphere radius="1.0"/>'\
'</geometry>'\
'</visual>'\
'<collision>'\
'<geometry>'\
'<sphere radius="1.0"/>'\
'</geometry>'\
'</collision>'\
'<inertial>'\
'<mass value="1"/>'\
'<inertia ixx="1" ixy="0.0" ixz="0.0" iyy="1" iyz="0.0" izz="1"/>'\
'</inertial>'\
'</link>'\
'</robot>'
# Robot state publisher
params = {'use_sim_time': True, 'robot_description': robot_desc}
robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[params],
arguments=[])
# Gazebo Sim
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')),
launch_arguments={'gz_args': '-r empty.sdf'}.items(),
)
# RViz
pkg_ros_gz_sim_demos = get_package_share_directory('ros_gz_sim_demos')
rviz = Node(
package='rviz2',
executable='rviz2',
arguments=[
'-d',
os.path.join(pkg_ros_gz_sim_demos, 'rviz', 'robot_description_publisher.rviz')
]
)
# Spawn
spawn = Node(package='ros_gz_sim', executable='create',
parameters=[{
'name': 'my_custom_model',
'x': 1.2,
'z': 2.3,
'Y': 3.4,
'topic': '/robot_description'}],
output='screen')
return LaunchDescription([
gazebo,
robot_state_publisher,
rviz,
spawn
])