Skip to content

Commit

Permalink
✨ feat: Add pre-commit configuration for code quality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
LihanChen2004 committed Jan 12, 2025
1 parent d7358ae commit 3a97db6
Show file tree
Hide file tree
Showing 47 changed files with 221 additions and 183 deletions.
119 changes: 119 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
exclude_types: [rst]
- id: fix-byte-order-marker

# Python hooks
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

# CPP hooks
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.3
hooks:
- id: clang-format
args: ['-fallback-style=none', '-i']
types_or: [c++]

- repo: local
hooks:
- id: ament_cppcheck
name: ament_cppcheck
description: Static code analysis of C/C++ files.
entry: env AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1 ament_cppcheck
language: system
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$

- repo: local
hooks:
- id: ament_cpplint
name: ament_cpplint
description: Static code analysis of C/C++ files.
entry: ament_cpplint
language: system
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
args: ["--linelength=100", "--filter=-whitespace/newline"]

# Cmake hooks
- repo: local
hooks:
- id: ament_lint_cmake
name: ament_lint_cmake
description: Check format of CMakeLists.txt files.
entry: ament_lint_cmake
language: system
files: CMakeLists\.txt$

# Docs - RestructuredText hooks
- repo: https://github.com/PyCQA/doc8
rev: v1.1.2
hooks:
- id: doc8
args: ['--max-line-length=100', '--ignore=D001']
exclude: CHANGELOG\.rst$

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
exclude: CHANGELOG\.rst$
- id: rst-directive-colons
- id: rst-inline-touching-normal

# Spellcheck in comments and docs
# skipping of *.svg files is not working...
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ['--write-changes']
exclude: CHANGELOG\.rst|\.(svg|pyc)|\.min.js$

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
hooks:
- id: check-github-workflows
args: ["--verbose"]
- id: check-github-actions
args: ["--verbose"]
- id: check-dependabot
args: ["--verbose"]
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install(DIRECTORY
)

install(PROGRAMS
scripts/referee_system/simple_competition_1v1.py
scripts/referee_system/simple_competition_1v1.py
DESTINATION lib/${PROJECT_NAME})

# environment
Expand Down
2 changes: 1 addition & 1 deletion config/gz_world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ robots:
x_pose: "25.6"
y_pose: "6.45"
z_pose: "0.28"
yaw: "3.14"
yaw: "3.14"
2 changes: 1 addition & 1 deletion config/ros_gz_bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
gz_topic_name: "/world/default/model/<robot_name>/link/front_industrial_camera/sensor/front_industrial_camera/camera_info"
ros_type_name: "sensor_msgs/msg/CameraInfo"
gz_type_name: "ignition.msgs.CameraInfo"
direction: "GZ_TO_ROS"
direction: "GZ_TO_ROS"
2 changes: 1 addition & 1 deletion follow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ign service -s /gui/follow/offset \
-r "x: -0.8, y: 0.0, z: 1.2" \
--reqtype ignition.msgs.Vector3d \
--reptype ignition.msgs.Boolean \
--timeout 1000
--timeout 1000
2 changes: 1 addition & 1 deletion launch/bringup_sim.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def generate_launch_description():
pkg_simulator = get_package_share_directory("rmu_gazebo_simulator")

gz_world_path = os.path.join(pkg_simulator, "config", "gz_world.yaml")
with open(gz_world_path, "r") as file:
with open(gz_world_path) as file:
config = yaml.safe_load(file)
selected_world = config.get("world")

Expand Down
2 changes: 1 addition & 1 deletion launch/spawn_robots.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_launch_description():

# Get spawn robot init pose
gz_world_path = os.path.join(pkg_simulator, "config", "gz_world.yaml")
with open(gz_world_path, "r") as file:
with open(gz_world_path) as file:
config = yaml.safe_load(file)
selected_world = config.get("world")
robots = config["robots"].get(selected_world)
Expand Down
2 changes: 1 addition & 1 deletion resource/ign/gui.config
Original file line number Diff line number Diff line change
Expand Up @@ -1261,4 +1261,4 @@
<property key="pluginToolBarColor" type="string">#03a9f4</property>
<property key="pluginToolBarTextColor" type="string">#fafafa</property>
</ignition-gui>
</plugin>
</plugin>
2 changes: 1 addition & 1 deletion resource/worlds/empty_world.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
</link>
</model>
</world>
</sdf>
</sdf>
2 changes: 1 addition & 1 deletion rviz/visualize.rviz
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ Window Geometry:
collapsed: false
Width: 1504
X: 550
Y: 85
Y: 85
2 changes: 1 addition & 1 deletion scripts/killgazebo.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
ps -ef | grep 'ign gazebo server' | cut -c 9-15 | xargs kill -s 15
ps -ef | grep 'ign gazebo server' | cut -c 9-15 | xargs kill -s 15
24 changes: 12 additions & 12 deletions scripts/player_web/main_no_vision.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
# ==========================================
# ros functions
# ==========================================
from ros_handler import *
from ros_handler import (
publish_chassis_cmd_msg,
publish_gimbal_cmd_msg,
publish_shoot_cmd_msg,
)
from sensor_msgs.msg import Image

from rmoss_interfaces.msg import (
Expand Down Expand Up @@ -127,11 +131,11 @@ def __init__(self, namespace):
def rfid_status_callback(self, message):
for status in message.robot_rfid_status:
if status.robot_name == self.robot_name:
if status.supplier_area_is_triggered == True:
if status.supplier_area_is_triggered is True:
self.rfid_status.supplier_area_is_triggered = True
else:
self.rfid_status.supplier_area_is_triggered = False
if status.center_area_is_triggered == True:
if status.center_area_is_triggered is True:
self.rfid_status.center_area_is_triggered = True
else:
self.rfid_status.center_area_is_triggered = False
Expand All @@ -153,7 +157,7 @@ def exchange_callback(self, future):
else:
print("Failed to exchange ammo: " + response.message)
except Exception as e:
print("Service call failed: %r" % (e,))
print(f"Service call failed: {e!r}")

def on_connect(self):
global info_thread, node, robot_names, chosen_robot_dict
Expand Down Expand Up @@ -183,7 +187,7 @@ def on_control(self, message):
if message["shoot"]:
shoot = True
if message["o"]:
if self.rfid_status.supplier_area_is_triggered == True:
if self.rfid_status.supplier_area_is_triggered is True:
self.supply_active = True
emit("supply", {"value": "active"}, namespace="/" + self.robot_name)

Expand Down Expand Up @@ -257,7 +261,7 @@ def on_default_error_handler(self, e):

# =============================================================================================================================

# ===================================================================== funcitons ==========================================
# ===================================================================== functions ==========================================


# ==========================================
Expand Down Expand Up @@ -335,22 +339,18 @@ def func(message):
def ros_info_thread(node, robot_name):
global BLUE_HP, RED_HP, ATTACK_INFO
for robot_name in robot_names:
img_sub = node.create_subscription(
node.create_subscription(
Image,
"/%s/front_camera/image" % (robot_name),
send_img_callback(robot_name),
45,
)
hp_sub = node.create_subscription(
node.create_subscription(
RobotStatus,
"/referee_system/%s/robot_status" % (robot_name),
send_refere_info_callback(robot_name),
10,
)
# red_hp_sub = node.create_subscription(RobotStatus, '/referee_system/red_standard_robot1/robot_status', send_refere_info_callback(RED_HP, robot_name),
# 10)
# attack_info_sub = node.create_subscription(String, '/referee_system/attack_info', send_refere_info_callback(ATTACK_INFO),
# . 10)
rclpy.spin(node)
node.destroy_node()

Expand Down
24 changes: 12 additions & 12 deletions scripts/player_web/main_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
# ==========================================
# ros functions
# ==========================================
from ros_handler import *
from ros_handler import (
publish_chassis_cmd_msg,
publish_gimbal_cmd_msg,
publish_shoot_cmd_msg,
)
from sensor_msgs.msg import Image
from vision_interfaces.msg import AutoAim

Expand Down Expand Up @@ -137,11 +141,11 @@ def __init__(self, namespace):
def rfid_status_callback(self, message):
for status in message.robot_rfid_status:
if status.robot_name == self.robot_name:
if status.supplier_area_is_triggered == True:
if status.supplier_area_is_triggered is True:
self.rfid_status.supplier_area_is_triggered = True
else:
self.rfid_status.supplier_area_is_triggered = False
if status.center_area_is_triggered == True:
if status.center_area_is_triggered is True:
self.rfid_status.center_area_is_triggered = True
else:
self.rfid_status.center_area_is_triggered = False
Expand All @@ -166,7 +170,7 @@ def exchange_callback(self, future):
else:
print("Failed to exchange ammo: " + response.message)
except Exception as e:
print("Service call failed: %r" % (e,))
print(f"Service call failed: {e!r}")

def on_connect(self):
global info_thread, node, robot_names, chosen_robot_dict
Expand Down Expand Up @@ -199,7 +203,7 @@ def on_control(self, message):
if message["autoAim"]:
autoAim = True
if message["o"]:
if self.rfid_status.supplier_area_is_triggered == True:
if self.rfid_status.supplier_area_is_triggered is True:
self.supply_active = True
emit("supply", {"value": "active"}, namespace="/" + self.robot_name)
print("message['movementX']:", message["movementX"])
Expand Down Expand Up @@ -309,7 +313,7 @@ def on_default_error_handler(self, e):

# =============================================================================================================================

# ===================================================================== funcitons ==========================================
# ===================================================================== functions ==========================================


# ==========================================
Expand Down Expand Up @@ -388,22 +392,18 @@ def func(message):
def ros_info_thread(node, robot_name):
global BLUE_HP, RED_HP, ATTACK_INFO
for robot_name in robot_names:
img_sub = node.create_subscription(
node.create_subscription(
Image,
"/%s/front_camera/image" % (robot_name),
send_img_callback(robot_name),
45,
)
hp_sub = node.create_subscription(
node.create_subscription(
RobotStatus,
"/referee_system/%s/robot_status" % (robot_name),
send_refere_info_callback(robot_name),
10,
)
# red_hp_sub = node.create_subscription(RobotStatus, '/referee_system/red_standard_robot1/robot_status', send_refere_info_callback(RED_HP, robot_name),
# 10)
# attack_info_sub = node.create_subscription(String, '/referee_system/attack_info', send_refere_info_callback(ATTACK_INFO),
# . 10)
rclpy.spin(node)
node.destroy_node()

Expand Down
Binary file modified scripts/player_web/static/css/._bootstrap.min.css
Binary file not shown.
Binary file modified scripts/player_web/static/css/._uikit-rtl.min.css
Binary file not shown.
Binary file modified scripts/player_web/static/css/._uikit.min.css
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/player_web/static/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/player_web/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
}
.selected{
border: 2px solid #2499F3;
}
}
2 changes: 1 addition & 1 deletion scripts/player_web/static/css/uikit-rtl.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/player_web/static/css/uikit.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/player_web/static/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/player_web/static/js/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function select_robot(element, name, can_choose){
if(!can_choose) return
$("#choose_robot_container").children(".selected").removeClass('selected')
my_robot = name
$(element).addClass('selected')
$(element).addClass('selected')
$('#start_btn').removeAttr("disabled");
console.log(my_robot)
$('#start_btn').text("开始游戏");
}
}
Loading

0 comments on commit 3a97db6

Please sign in to comment.