Skip to content

Commit 1ea46a0

Browse files
authored
Merge pull request #433 from husarion/ros2-add-rviz-launch
Ros2 add RViz launch
2 parents 552a4c8 + a2a9ee9 commit 1ea46a0

File tree

7 files changed

+233
-114
lines changed

7 files changed

+233
-114
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Launch arguments are largely common to both simulation and physical robot. Howev
108108
||| `safety_bt_project_path` | Path to BehaviorTree project file, responsible for safety and shutdown management. <br/> ***string:*** [`SafetyBT.btproj`](./husarion_ugv_manager/behavior_trees/SafetyBT.btproj) |
109109
||| `shutdown_hosts_config_path` | Path to file with list of hosts to request shutdown. <br/> ***string:*** [`shutdown_hosts.yaml`](./husarion_ugv_manager/config/shutdown_hosts.yaml) |
110110
||| `use_ekf` | Enable or disable EKF. <br/> ***bool:*** `True` |
111+
||| `use_rviz` | Run RViz simultaneously. <br/> ***bool:*** `True` |
111112
||| `use_sim` | Whether simulation is used. <br/> ***bool:*** `False` |
112113
||| `user_led_animations_path` | Path to a YAML file with a description of the user-defined animations. <br/> ***string:*** `''` |
113114
||| `wheel_config_path` | Path to wheel configuration file. <br/> ***string:*** [`{wheel_type}.yaml`](./panther_description/config) |

husarion_ugv_gazebo/launch/simulation.launch.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from launch import LaunchDescription
1818
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
19+
from launch.conditions import IfCondition
1920
from launch.launch_description_sources import PythonLaunchDescriptionSource
2021
from launch.substitutions import (
2122
EnvironmentVariable,
@@ -45,6 +46,14 @@ def generate_launch_description():
4546
description="Add namespace to all launched nodes.",
4647
)
4748

49+
use_rviz = LaunchConfiguration("use_rviz")
50+
declare_use_rviz_arg = DeclareLaunchArgument(
51+
"use_rviz",
52+
default_value="True",
53+
description="Run RViz simultaneously.",
54+
choices=["True", "true", "False", "false"],
55+
)
56+
4857
namespaced_gz_gui = ReplaceString(
4958
source_file=gz_gui,
5059
replacements={"{namespace}": namespace},
@@ -59,6 +68,19 @@ def generate_launch_description():
5968
launch_arguments={"gz_gui": namespaced_gz_gui, "gz_log_level": "1"}.items(),
6069
)
6170

71+
rviz_launch = IncludeLaunchDescription(
72+
PythonLaunchDescriptionSource(
73+
PathJoinSubstitution(
74+
[
75+
FindPackageShare("panther_description"),
76+
"launch",
77+
"rviz.launch.py",
78+
]
79+
)
80+
),
81+
condition=IfCondition(use_rviz),
82+
)
83+
6284
simulate_robots = IncludeLaunchDescription(
6385
PythonLaunchDescriptionSource(
6486
PathJoinSubstitution(
@@ -74,9 +96,11 @@ def generate_launch_description():
7496
actions = [
7597
declare_gz_gui,
7698
declare_namespace_arg,
99+
declare_use_rviz_arg,
77100
# Sets use_sim_time for all nodes started below (doesn't work for nodes started from ignition gazebo)
78101
SetUseSimTime(True),
79102
gz_sim,
103+
rviz_launch,
80104
simulate_robots,
81105
]
82106

lynx_description/urdf/gazebo.urdf.xacro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@
4242
<parameters>${config_file}</parameters>
4343
<ros>
4444
<namespace>${namespace}</namespace>
45+
<remapping>drive_controller/cmd_vel_unstamped:=cmd_vel</remapping>
46+
<remapping>drive_controller/odom:=odometry/wheels</remapping>
47+
<remapping>drive_controller/transition_event:=drive_controller/_transition_event</remapping>
4548
<remapping>gz_ros2_control/e_stop:=hardware/e_stop</remapping>
4649
<remapping>gz_ros2_control/e_stop_reset:=hardware/e_stop_reset</remapping>
4750
<remapping>gz_ros2_control/e_stop_trigger:=hardware/e_stop_trigger</remapping>
4851
<remapping>imu_broadcaster/imu:=imu/data</remapping>
49-
<remapping>drive_controller/cmd_vel_unstamped:=cmd_vel</remapping>
50-
<remapping>drive_controller/odom:=odometry/wheels</remapping>
52+
<remapping>imu_broadcaster/transition_event:=imu_broadcaster/_transition_event</remapping>
53+
<remapping>joint_state_broadcaster/transition_event:=joint_state_broadcaster/_transition_event</remapping>
5154
</ros>
5255
</plugin>
5356
</gazebo>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2020 ros2_control Development Team
4+
# Copyright 2024 Husarion sp. z o.o.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
from launch import LaunchDescription
19+
from launch.actions import DeclareLaunchArgument
20+
from launch.substitutions import (
21+
EnvironmentVariable,
22+
LaunchConfiguration,
23+
PathJoinSubstitution,
24+
PythonExpression,
25+
)
26+
from launch_ros.actions import Node, SetParameter
27+
from launch_ros.substitutions import FindPackageShare
28+
from nav2_common.launch import ReplaceString
29+
30+
31+
def generate_launch_description():
32+
33+
namespace = LaunchConfiguration("namespace")
34+
declare_namespace_arg = DeclareLaunchArgument(
35+
"namespace",
36+
default_value=EnvironmentVariable("ROBOT_NAMESPACE", default_value=""),
37+
description="Add namespace to all launched nodes.",
38+
)
39+
40+
rviz_config = LaunchConfiguration("rviz_config")
41+
declare_rviz_config_arg = DeclareLaunchArgument(
42+
"rviz_config",
43+
default_value=PathJoinSubstitution(
44+
[FindPackageShare("panther_description"), "rviz", "husarion_ugv.rviz"]
45+
),
46+
description="RViz configuration file.",
47+
)
48+
49+
use_sim = LaunchConfiguration("use_sim")
50+
declare_use_sim_arg = DeclareLaunchArgument(
51+
"use_sim",
52+
default_value="False",
53+
description="Whether simulation is used.",
54+
choices=["True", "true", "False", "false"],
55+
)
56+
57+
ns_ext = PythonExpression(["'' if '", namespace, "' else '", namespace, "' + '/'"])
58+
59+
rviz_config = ReplaceString(
60+
source_file=rviz_config,
61+
replacements={"<robot_namespace>/": ns_ext, "<robot_namespace>": namespace},
62+
)
63+
64+
rviz_node = Node(
65+
package="rviz2",
66+
executable="rviz2",
67+
namespace=namespace,
68+
arguments=["-d", rviz_config],
69+
)
70+
71+
actions = [
72+
declare_namespace_arg,
73+
declare_rviz_config_arg,
74+
declare_use_sim_arg,
75+
SetParameter(name="use_sim_time", value=use_sim),
76+
rviz_node,
77+
]
78+
79+
return LaunchDescription(actions)

panther_description/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
<exec_depend>joint_state_publisher</exec_depend>
2121
<exec_depend>launch</exec_depend>
2222
<exec_depend>launch_ros</exec_depend>
23+
<exec_depend>nav2_common</exec_depend>
2324
<exec_depend>robot_state_publisher</exec_depend>
2425
<exec_depend>ros_components_description</exec_depend>
26+
<exec_depend>rviz</exec_depend>
2527
<exec_depend>xacro</exec_depend>
2628

2729
<export>

0 commit comments

Comments
 (0)