Skip to content

Commit 35d88bd

Browse files
authored
refactor/build: add Black format check to CI & format codebase (#167)
* chore(ci): reorganise .github and add black format check on PR and push. * MAYBE REMOVE: don't repath. * fix: double steps. * chore(ci): show diff? * refactor: apply black formatting. * refactor: apply black formatting, again
1 parent 62c5f74 commit 35d88bd

File tree

199 files changed

+4618
-2413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+4618
-2413
lines changed

.github/workflows/continuous.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Pull Request
2+
3+
on:
4+
push:
5+
branches:
6+
- [main]
7+
jobs:
8+
QC:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Repository and Submodules
12+
uses: actions/checkout@v4
13+
- name: Build & Deploy Documentation
14+
uses: "./.github/workflows/docs"
15+
- name: Quality Control
16+
uses: "./.github/workflows/qc"

.github/workflows/docs/action.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build & Deploy Documentation
2+
3+
runs:
4+
using: "composite"
5+
steps:
6+
7+
- name: Install ROS Noetic
8+
run: |
9+
sudo add-apt-repository universe
10+
sudo add-apt-repository restricted
11+
sudo add-apt-repository multiverse
12+
13+
sudo apt update
14+
15+
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
16+
17+
sudo apt install curl # if you haven't already installed curl
18+
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
19+
20+
sudo apt update
21+
sudo apt install ros-noetic-ros-base python3-catkin-tools
22+
23+
- name: Build documentation package
24+
run: |
25+
source /opt/ros/noetic/setup.bash
26+
catkin build documentation
27+
28+
- name: Use Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: 20
32+
33+
- name: Build documentation
34+
run: |
35+
source /opt/ros/noetic/setup.bash
36+
source devel/setup.bash
37+
rosrun documentation build.py
38+
39+
- name: Deploy to GitHub Pages
40+
uses: peaceiris/actions-gh-pages@v3
41+
if: github.event_name != 'pull_request' && github.ref_name == 'main'
42+
with:
43+
deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
44+
publish_dir: ./documentation/web/build
45+
external_repository: lasr-at-home/docs

.github/workflows/documentation.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
jobs:
8+
QC:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
- name: Quality Control
14+
uses: "./.github/workflows/qc"

.github/workflows/qc/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Quality Control
2+
3+
runs:
4+
using: "composite"
5+
steps:
6+
7+
- name: Python Formatting
8+
uses: rickstaa/action-black@v1
9+
with:
10+
black_args: ". --check --diff"

common/helpers/cv2_img/setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
from distutils.core import setup
44
from catkin_pkg.python_setup import generate_distutils_setup
55

6-
setup_args = generate_distutils_setup(
7-
packages=['cv2_img'],
8-
package_dir={'': 'src'}
9-
)
6+
setup_args = generate_distutils_setup(packages=["cv2_img"], package_dir={"": "src"})
107

11-
setup(**setup_args)
8+
setup(**setup_args)

common/helpers/cv2_img/src/cv2_img/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def cv2_img_to_msg(img, stamp=None):
2020
msg.header.stamp = rospy.Time.now() if stamp is None else stamp
2121
msg.width = width
2222
msg.height = height
23-
msg.encoding = 'bgr8'
23+
msg.encoding = "bgr8"
2424
msg.is_bigendian = 1
2525
msg.step = 3 * width
2626
msg.data = img.tobytes()
@@ -37,13 +37,13 @@ def msg_to_pillow_img(msg: SensorImage):
3737
"""
3838

3939
size = (msg.width, msg.height)
40-
if msg.encoding in ['bgr8', '8UC3']:
41-
img = Image.frombytes('RGB', size, msg.data, 'raw')
40+
if msg.encoding in ["bgr8", "8UC3"]:
41+
img = Image.frombytes("RGB", size, msg.data, "raw")
4242

4343
# BGR => RGB
4444
img = Image.fromarray(np.array(img)[:, :, ::-1])
45-
elif msg.encoding == 'rgb8':
46-
img = Image.frombytes('RGB', size, msg.data, 'raw')
45+
elif msg.encoding == "rgb8":
46+
img = Image.frombytes("RGB", size, msg.data, "raw")
4747
else:
4848
raise Exception("Unsupported format.")
4949

@@ -80,8 +80,7 @@ def extract_mask_region(frame, mask, expand_x=0.5, expand_y=0.5):
8080
# only requiring cv2 if we need it
8181
import cv2
8282

83-
contours, _ = cv2.findContours(
84-
mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
83+
contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
8584

8685
if contours:
8786
largest_contour = max(contours, key=cv2.contourArea)
@@ -99,6 +98,6 @@ def extract_mask_region(frame, mask, expand_x=0.5, expand_y=0.5):
9998
new_w = min(frame.shape[1] - x, new_w)
10099
new_h = min(frame.shape[0] - y, new_h)
101100

102-
face_region = frame[y:y+int(new_h), x:x+int(new_w)]
101+
face_region = frame[y : y + int(new_h), x : x + int(new_w)]
103102
return face_region
104103
return None

common/helpers/numpy2message/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from catkin_pkg.python_setup import generate_distutils_setup
55

66
setup_args = generate_distutils_setup(
7-
packages=['numpy2message'],
8-
package_dir={'': 'src'}
7+
packages=["numpy2message"], package_dir={"": "src"}
98
)
109

1110
setup(**setup_args)

common/helpers/numpy2message/src/numpy2message/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ def numpy2message(np_array: np.ndarray) -> list:
88
return data, shape, dtype
99

1010

11-
def message2numpy(data:bytes, shape:list, dtype:str) -> np.ndarray:
11+
def message2numpy(data: bytes, shape: list, dtype: str) -> np.ndarray:
1212
array_shape = tuple(shape)
1313
array_dtype = np.dtype(dtype)
1414

1515
deserialized_array = np.frombuffer(data, dtype=array_dtype)
1616
deserialized_array = deserialized_array.reshape(array_shape)
1717

1818
return deserialized_array
19-

common/navigation/tiago_controllers/setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
# fetch values from package.xml
77
setup_args = generate_distutils_setup(
8-
packages=['tiago_controllers'],
9-
package_dir={'': 'src'}
8+
packages=["tiago_controllers"], package_dir={"": "src"}
109
)
1110

12-
setup(**setup_args)
11+
setup(**setup_args)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from .controllers.base_controller import BaseController
22
from .controllers.head_controller import HeadController
3-

common/navigation/tiago_controllers/src/tiago_controllers/base_planner.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import rospy
44
import rosservice
5-
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped, Point, Quaternion, PoseStamped, Vector3
5+
from geometry_msgs.msg import (
6+
Pose,
7+
PoseWithCovarianceStamped,
8+
Point,
9+
Quaternion,
10+
PoseStamped,
11+
Vector3,
12+
)
613
from std_msgs.msg import Header
714
from nav_msgs.srv import GetPlan
815
import numpy as np
@@ -11,17 +18,21 @@
1118

1219

1320
def make_plan(current_pose, x, y, tol=0.01, max_dist=None):
14-
15-
if '/move_base/NavfnROS/make_plan' in rosservice.get_service_list():
16-
make_plan_service = '/move_base/NavfnROS/make_plan'
17-
elif '/move_base/GlobalPlanner/make_plan' in rosservice.get_service_list():
18-
make_plan_service = '/move_base/GlobalPlanner/make_plan'
21+
if "/move_base/NavfnROS/make_plan" in rosservice.get_service_list():
22+
make_plan_service = "/move_base/NavfnROS/make_plan"
23+
elif "/move_base/GlobalPlanner/make_plan" in rosservice.get_service_list():
24+
make_plan_service = "/move_base/GlobalPlanner/make_plan"
1925
else:
20-
rospy.loginfo('Failed to find the make_plan server')
26+
rospy.loginfo("Failed to find the make_plan server")
2127
return False, None, None
22-
23-
start = PoseStamped(header=Header(frame_id="map", stamp=rospy.Time.now()), pose=current_pose)
24-
goal = PoseStamped(header=Header(frame_id="map", stamp=rospy.Time.now()), pose=Pose(position=Point(x, y, 0), orientation=current_pose.orientation))
28+
29+
start = PoseStamped(
30+
header=Header(frame_id="map", stamp=rospy.Time.now()), pose=current_pose
31+
)
32+
goal = PoseStamped(
33+
header=Header(frame_id="map", stamp=rospy.Time.now()),
34+
pose=Pose(position=Point(x, y, 0), orientation=current_pose.orientation),
35+
)
2536
rospy.wait_for_service(make_plan_service, timeout=5)
2637
make_plan_serv = rospy.ServiceProxy(make_plan_service, GetPlan)
2738

@@ -31,9 +42,9 @@ def make_plan(current_pose, x, y, tol=0.01, max_dist=None):
3142
dist = 0
3243
# zips the poses like 1 and 2, 2 and 3, etc
3344
for current, next in zip(mp.poses, mp.poses[1:]):
34-
dist+= euclidian_distance(
45+
dist += euclidian_distance(
3546
(current.pose.position.x, current.pose.position.y),
36-
(next.pose.position.x, next.pose.position.y)
47+
(next.pose.position.x, next.pose.position.y),
3748
)
3849
if dist > max_dist:
3950
return False, None, None
@@ -43,7 +54,9 @@ def make_plan(current_pose, x, y, tol=0.01, max_dist=None):
4354

4455
def draw_points(points):
4556
for x, y in points:
46-
marker_pub = rospy.Publisher.publish("/visualization_marker", Marker, queue_size=2)
57+
marker_pub = rospy.Publisher.publish(
58+
"/visualization_marker", Marker, queue_size=2
59+
)
4760
marker = Marker()
4861
marker.header.stamp = rospy.Time.now()
4962
marker.header.frame_id = "/map"
@@ -77,8 +90,8 @@ def points_on_radius(x1, y1, radius=0.5):
7790
# print( "here is it: ", (x1 + 0.0, y1 - radius), " " ,
7891
# (x1 - radius, y1 + 0.0), " ",
7992
# (x1 + radius, y1 + 0.0), " ",
80-
# (x1 - radius, y1 - radius), " ",
81-
# (x1 + radius, y1 - radius))
93+
# (x1 - radius, y1 - radius), " ",
94+
# (x1 + radius, y1 - radius))
8295
return [
8396
(x1 + 0.0, y1 - radius),
8497
(x1 + 0.0, y1 + radius),
@@ -90,37 +103,43 @@ def points_on_radius(x1, y1, radius=0.5):
90103
(x1 + radius, y1 - radius),
91104
]
92105

106+
93107
def euclidian_distance(p1, p2):
94108
x1, y1 = p1
95109
x2, y2 = p2
96110
a = np.array((x1, y1))
97111
b = np.array((x2, y2))
98-
return np.linalg.norm(a-b)
112+
return np.linalg.norm(a - b)
113+
99114

100115
def plan_to_radius(current_pose, point, radius, tol=0.1):
101116
picked_points = []
102117
points = None
103-
for x,y in points_on_radius(*point, radius=radius):
118+
for x, y in points_on_radius(*point, radius=radius):
104119
# print(f"the points are {x} , and {y}")
105120
success, point, points = make_plan(current_pose, x, y, tol)
106121
if success:
107-
dist = euclidian_distance((current_pose.position.x, current_pose.position.y), (x,y))
122+
dist = euclidian_distance(
123+
(current_pose.position.x, current_pose.position.y), (x, y)
124+
)
108125
picked_points.append([point, dist])
109126

110127
# draw_points(picked_points[0:])
111-
print("-"*30)
128+
print("-" * 30)
112129
# if points:
113-
# print(f"points of journey {points}")
114-
# print(f"middle point of journey {points[round((len(points) - 1) / 2)].pose}")
115-
picked_points = sorted(picked_points, key = lambda x: x[1])
130+
# print(f"points of journey {points}")
131+
# print(f"middle point of journey {points[round((len(points) - 1) / 2)].pose}")
132+
picked_points = sorted(picked_points, key=lambda x: x[1])
116133
return [point[0] for point in picked_points] if picked_points else []
117134

135+
118136
NUMBER = 3
119137

138+
120139
def get_journey_points(current_pose, x, y, tol=0.01):
121140
success, point, points = make_plan(current_pose, x, y, tol)
122141
if len(points) > NUMBER + 2:
123-
mid_points = [points[i] for i in range(points/NUMBER)]
142+
mid_points = [points[i] for i in range(points / NUMBER)]
124143
else:
125144
mid_points = points
126145
return mid_points

0 commit comments

Comments
 (0)