Skip to content

Commit bc2decd

Browse files
Improve pre commit (#14)
* Added codespell to pre-commit hooks. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Added Pyflakes to the ruff configuration. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Added isort to the ruff configuration. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> * Added Pycodestyle and Pydocstyle checks. Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com> --------- Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com>
1 parent de655fd commit bc2decd

File tree

6 files changed

+252
-193
lines changed

6 files changed

+252
-193
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ repos:
55
- id: end-of-file-fixer
66
- id: mixed-line-ending
77
- id: trailing-whitespace
8+
9+
- repo: https://github.com/codespell-project/codespell
10+
rev: v2.4.1
11+
hooks:
12+
- id: codespell
13+
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.12.5
16+
hooks:
17+
- id: ruff-check
18+
args: [ --fix ]
19+
- id: ruff-format

launch/description/gazebo.launch.py

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,141 @@
11
#! /usr/bin/env python3
2-
"""
3-
Spawn Robot in Gazebo
4-
"""
2+
"""Script to launch Gazebo with RViz support for the Atreus robot."""
3+
54
import os
5+
66
from ament_index_python.packages import get_package_share_directory
7-
from launch import LaunchDescription
8-
from launch.launch_description_sources import PythonLaunchDescriptionSource
9-
from launch.substitutions import LaunchConfiguration, Command, PythonExpression, PathJoinSubstitution
10-
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, AppendEnvironmentVariable
11-
from launch.conditions import IfCondition
127
from launch_ros.actions import Node
138
from launch_ros.substitutions import FindPackageShare
149

10+
from launch import LaunchDescription
11+
from launch.actions import (
12+
AppendEnvironmentVariable,
13+
DeclareLaunchArgument,
14+
IncludeLaunchDescription,
15+
)
16+
from launch.conditions import IfCondition
17+
from launch.launch_description_sources import PythonLaunchDescriptionSource
18+
from launch.substitutions import (
19+
Command,
20+
LaunchConfiguration,
21+
PathJoinSubstitution,
22+
PythonExpression,
23+
)
24+
1525

1626
def generate_launch_description():
17-
"""
18-
Launch Function
19-
"""
20-
pkg_dir = get_package_share_directory('atreus')
21-
22-
rviz_config_path = os.path.join(
23-
pkg_dir, 'config', 'rviz', 'urdf.rviz')
24-
world_path = os.path.join(pkg_dir, 'worlds', 'mapping.sdf')
25-
bridge_params_path = os.path.join(
26-
pkg_dir, 'config', 'ros_gz_bridge.yaml'
27-
)
27+
"""Generate the launch description for Atreus."""
28+
pkg_dir = get_package_share_directory("atreus")
2829

30+
rviz_config_path = os.path.join(pkg_dir, "config", "rviz", "urdf.rviz")
31+
world_path = os.path.join(pkg_dir, "worlds", "mapping.sdf")
32+
bridge_params_path = os.path.join(pkg_dir, "config", "ros_gz_bridge.yaml")
2933

30-
# Create the launch configuration variables
31-
use_sim_time = LaunchConfiguration('use_sim_time')
32-
camera_enabled = LaunchConfiguration('camera_enabled')
33-
two_d_lidar_enabled = LaunchConfiguration('two_d_lidar_enabled')
34-
rviz_enabled = LaunchConfiguration('rviz_enabled')
35-
rviz_config = LaunchConfiguration('rviz_config')
34+
# Create the launch configuration variables
35+
use_sim_time = LaunchConfiguration("use_sim_time")
36+
camera_enabled = LaunchConfiguration("camera_enabled")
37+
two_d_lidar_enabled = LaunchConfiguration("two_d_lidar_enabled")
38+
rviz_enabled = LaunchConfiguration("rviz_enabled")
39+
rviz_config = LaunchConfiguration("rviz_config")
3640

3741
# Declare the append environment variables
3842
append_env_var_gz_sim_resource_path = AppendEnvironmentVariable(
39-
name='GZ_SIM_RESOURCE_PATH',
40-
value=os.path.join(pkg_dir, "worlds") + ':' +
41-
os.path.join(pkg_dir, "models", "warehouse_models")
43+
name="GZ_SIM_RESOURCE_PATH",
44+
value=os.path.join(pkg_dir, "worlds")
45+
+ ":"
46+
+ os.path.join(pkg_dir, "models", "warehouse_models"),
4247
)
4348

4449
# Declare the launch arguments
4550
declare_use_sim_time_arg = DeclareLaunchArgument(
46-
'use_sim_time', default_value='True',
47-
description='Flag to enable use_sim_time'
51+
"use_sim_time", default_value="True", description="Flag to enable use_sim_time"
4852
)
4953
declare_world_name_arg = DeclareLaunchArgument(
50-
'world_name', default_value=world_path,
51-
description='Choice of Gazebo World'
54+
"world_name", default_value=world_path, description="Choice of Gazebo World"
5255
)
5356
declare_camera_enabled_arg = DeclareLaunchArgument(
54-
'camera_enabled', default_value='False',
55-
description='Flag to enable camera'
57+
"camera_enabled", default_value="False", description="Flag to enable camera"
5658
)
5759
declare_two_d_lidar_enabled_arg = DeclareLaunchArgument(
58-
'two_d_lidar_enabled', default_value='False',
59-
description='Flag to enable 2D LiDAR'
60+
"two_d_lidar_enabled",
61+
default_value="False",
62+
description="Flag to enable 2D LiDAR",
6063
)
6164
declare_rviz_enabled_arg = DeclareLaunchArgument(
62-
'rviz_enabled', default_value='False',
63-
description='Flag to enable RViz'
65+
"rviz_enabled", default_value="False", description="Flag to enable RViz"
6466
)
6567
declare_rviz_config_arg = DeclareLaunchArgument(
66-
'rviz_config', default_value=rviz_config_path,
67-
description='Full path to the RViz config file to use'
68+
"rviz_config",
69+
default_value=rviz_config_path,
70+
description="Full path to the RViz config file to use",
6871
)
6972

7073
# Include the Nodes
7174
gz_spawn_entity_node = Node(
7275
package="ros_gz_sim",
7376
executable="create",
7477
arguments=[
75-
"-topic", "/robot_description",
76-
"-name", "atreus",
77-
"-x", "0",
78-
"-y", "0",
79-
"-z", "0.5",
80-
]
78+
"-topic",
79+
"/robot_description",
80+
"-name",
81+
"atreus",
82+
"-x",
83+
"0",
84+
"-y",
85+
"0",
86+
"-z",
87+
"0.5",
88+
],
8189
)
8290
gz_ros2_bridge_node = Node(
83-
package='ros_gz_bridge',
84-
executable='parameter_bridge',
85-
name='bridge_ros_gz',
86-
parameters=[{
87-
'config_file': bridge_params_path,
88-
'use_sim_time': use_sim_time
89-
}],
90-
output='screen',
91+
package="ros_gz_bridge",
92+
executable="parameter_bridge",
93+
name="bridge_ros_gz",
94+
parameters=[{"config_file": bridge_params_path, "use_sim_time": use_sim_time}],
95+
output="screen",
9196
)
9297

9398
robot_state_publisher_node = Node(
94-
package='robot_state_publisher',
95-
executable='robot_state_publisher',
96-
parameters=[{'robot_description': Command(
97-
['xacro ', os.path.join(pkg_dir, 'urdf', 'atreus.xacro'),
98-
' camera_enabled:=', camera_enabled,
99-
' two_d_lidar_enabled:=', two_d_lidar_enabled
100-
])}]
99+
package="robot_state_publisher",
100+
executable="robot_state_publisher",
101+
parameters=[
102+
{
103+
"robot_description": Command(
104+
[
105+
"xacro ",
106+
os.path.join(pkg_dir, "urdf", "atreus.xacro"),
107+
" camera_enabled:=",
108+
camera_enabled,
109+
" two_d_lidar_enabled:=",
110+
two_d_lidar_enabled,
111+
]
112+
)
113+
}
114+
],
101115
)
102116

103117
gz_sim_launch = IncludeLaunchDescription(
104118
PythonLaunchDescriptionSource(
105119
PathJoinSubstitution(
106-
[FindPackageShare('ros_gz_sim'), 'launch', 'gz_sim.launch.py'])),
120+
[FindPackageShare("ros_gz_sim"), "launch", "gz_sim.launch.py"]
121+
)
122+
),
107123
launch_arguments={
108-
"gz_args" : PythonExpression(
109-
["'", world_path, " -r'"])
110-
}.items()
124+
"gz_args": PythonExpression(["'", world_path, " -r'"])
125+
}.items(),
111126
)
112127

113128
rviz_launch = IncludeLaunchDescription(
114129
PythonLaunchDescriptionSource(
115-
os.path.join(pkg_dir, "launch", "description", "rviz.launch.py")),
130+
os.path.join(pkg_dir, "launch", "description", "rviz.launch.py")
131+
),
116132
launch_arguments={
117-
'gazebo_enabled': 'True',
118-
'camera_enabled': camera_enabled,
119-
'two_d_lidar_enabled': two_d_lidar_enabled,
120-
'rviz_config': rviz_config,
121-
}.items(),
122-
condition=IfCondition(rviz_enabled)
133+
"gazebo_enabled": "True",
134+
"camera_enabled": camera_enabled,
135+
"two_d_lidar_enabled": two_d_lidar_enabled,
136+
"rviz_config": rviz_config,
137+
}.items(),
138+
condition=IfCondition(rviz_enabled),
123139
)
124140

125141
ld = LaunchDescription()

launch/description/rviz.launch.py

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,103 @@
1-
#! /usr/bin/env python
2-
"""
3-
Spawn Robot in RViz
4-
"""
1+
#! /usr/bin/env python3
2+
"""Script to launch RViz for the Atreus robot."""
3+
54
import os
5+
66
from ament_index_python.packages import get_package_share_directory
7+
from launch_ros.actions import Node
8+
79
from launch import LaunchDescription
8-
from launch.substitutions import LaunchConfiguration, Command, PythonExpression
910
from launch.actions import DeclareLaunchArgument
1011
from launch.conditions import IfCondition, UnlessCondition
11-
from launch_ros.actions import Node
12-
12+
from launch.substitutions import Command, LaunchConfiguration, PythonExpression
1313

1414

1515
def generate_launch_description():
16-
"""
17-
Launch Function
18-
"""
19-
pkg_dir = get_package_share_directory('atreus')
20-
21-
rviz_config_path = os.path.join(
22-
pkg_dir, 'config', 'rviz', 'urdf.rviz')
16+
"""Generate the launch description for Atreus."""
17+
pkg_dir = get_package_share_directory("atreus")
2318

24-
# Create the launch configuration variables
25-
gazebo_enabled = LaunchConfiguration('gazebo_enabled')
26-
camera_enabled = LaunchConfiguration('camera_enabled')
27-
two_d_lidar_enabled = LaunchConfiguration('two_d_lidar_enabled')
28-
rviz_config = LaunchConfiguration('rviz_config')
29-
gui = LaunchConfiguration('gui')
19+
rviz_config_path = os.path.join(pkg_dir, "config", "rviz", "urdf.rviz")
3020

21+
# Create the launch configuration variables
22+
gazebo_enabled = LaunchConfiguration("gazebo_enabled")
23+
camera_enabled = LaunchConfiguration("camera_enabled")
24+
two_d_lidar_enabled = LaunchConfiguration("two_d_lidar_enabled")
25+
rviz_config = LaunchConfiguration("rviz_config")
26+
gui = LaunchConfiguration("gui")
3127

3228
# Declare the launch arguments
3329
declare_use_sim_time_arg = DeclareLaunchArgument(
34-
'use_sim_time', default_value='True',
35-
description='Flag to enable use_sim_time'
30+
"use_sim_time", default_value="True", description="Flag to enable use_sim_time"
3631
)
3732
declare_gazebo_enabled_arg = DeclareLaunchArgument(
38-
'gazebo_enabled', default_value='False',
39-
description='Flag to indicate if Gazebo is enabled'
33+
"gazebo_enabled",
34+
default_value="False",
35+
description="Flag to indicate if Gazebo is enabled",
4036
)
4137
declare_camera_enabled_arg = DeclareLaunchArgument(
42-
'camera_enabled', default_value='False',
43-
description='Flag to enable camera'
38+
"camera_enabled", default_value="False", description="Flag to enable camera"
4439
)
4540
declare_two_d_lidar_enabled_arg = DeclareLaunchArgument(
46-
'two_d_lidar_enabled', default_value='False',
47-
description='Flag to enable 2D LiDAR'
41+
"two_d_lidar_enabled",
42+
default_value="False",
43+
description="Flag to enable 2D LiDAR",
4844
)
4945
declare_rviz_config_arg = DeclareLaunchArgument(
50-
'rviz_config', default_value=rviz_config_path,
51-
description='Full path to the RViz config file to use'
46+
"rviz_config",
47+
default_value=rviz_config_path,
48+
description="Full path to the RViz config file to use",
5249
)
5350
declare_gui_arg = DeclareLaunchArgument(
54-
'gui', default_value='True',
55-
description='Flag to enable joint_state_publisher_gui'
51+
"gui",
52+
default_value="True",
53+
description="Flag to enable joint_state_publisher_gui",
5654
)
5755

5856
# Include the Nodes
5957
joint_state_publisher_gui_node = Node(
60-
package='joint_state_publisher_gui',
61-
executable='joint_state_publisher_gui',
62-
name='joint_state_publisher_gui',
63-
condition=IfCondition(PythonExpression(
64-
["'", gui, "' == 'True' and '", gazebo_enabled, "' == 'False'"]))
58+
package="joint_state_publisher_gui",
59+
executable="joint_state_publisher_gui",
60+
name="joint_state_publisher_gui",
61+
condition=IfCondition(
62+
PythonExpression(
63+
["'", gui, "' == 'True' and '", gazebo_enabled, "' == 'False'"]
64+
)
65+
),
6566
)
6667
joint_state_publisher_node = Node(
67-
package='joint_state_publisher',
68-
executable='joint_state_publisher',
69-
name='joint_state_publisher',
70-
condition=IfCondition(PythonExpression(
71-
["'", gui, "' == 'False' and '", gazebo_enabled, "' == 'False'"]))
68+
package="joint_state_publisher",
69+
executable="joint_state_publisher",
70+
name="joint_state_publisher",
71+
condition=IfCondition(
72+
PythonExpression(
73+
["'", gui, "' == 'False' and '", gazebo_enabled, "' == 'False'"]
74+
)
75+
),
7276
)
7377
robot_state_publisher_node = Node(
74-
package='robot_state_publisher',
75-
executable='robot_state_publisher',
76-
parameters=[{'robot_description': Command(
77-
['xacro ', os.path.join(pkg_dir, 'urdf', 'atreus.xacro'),
78-
' camera_enabled:=', camera_enabled,
79-
' two_d_lidar_enabled:=', two_d_lidar_enabled
80-
])}],
81-
condition=UnlessCondition(gazebo_enabled)
78+
package="robot_state_publisher",
79+
executable="robot_state_publisher",
80+
parameters=[
81+
{
82+
"robot_description": Command(
83+
[
84+
"xacro ",
85+
os.path.join(pkg_dir, "urdf", "atreus.xacro"),
86+
" camera_enabled:=",
87+
camera_enabled,
88+
" two_d_lidar_enabled:=",
89+
two_d_lidar_enabled,
90+
]
91+
)
92+
}
93+
],
94+
condition=UnlessCondition(gazebo_enabled),
8295
)
8396
rviz_node = Node(
84-
package='rviz2',
85-
executable='rviz2',
86-
output='screen',
87-
arguments=['-d', rviz_config],
97+
package="rviz2",
98+
executable="rviz2",
99+
output="screen",
100+
arguments=["-d", rviz_config],
88101
)
89102

90103
ld = LaunchDescription()

0 commit comments

Comments
 (0)