Skip to content

Commit 115f26e

Browse files
committed
Linting pt 2: sonar_tasks.py, sonar_utils.py, and sonar.py
1 parent d8a9cd5 commit 115f26e

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

onboard/src/sonar/sonar/sonar.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def connect(self) -> None:
108108
self.run()
109109
except StopIteration:
110110
self.get_logger().error(
111-
f'Error in connecting to sonar, trying again in {self.CONNECTION_RETRY_PERIOD} seconds.'
111+
f'Error in connecting to sonar, trying again in {self.CONNECTION_RETRY_PERIOD} seconds.',
112112
)
113113

114114
def init_sonar(self) -> None:
@@ -188,7 +188,7 @@ def get_sweep(self, range_start: int = 100, range_end: int = 300) -> np.ndarray:
188188
return np.vstack(sonar_sweep_data)
189189

190190
def get_xy_of_object_in_sweep(
191-
self, start_angle: int, end_angle: int
191+
self, start_angle: int, end_angle: int,
192192
) -> tuple[Pose | None, np.ndarray, float | None]:
193193
"""
194194
Get the depth of the sweep of a detected object. For now uses mean value.
@@ -245,8 +245,6 @@ def get_xy_of_object_in_sweep(
245245

246246
self.get_logger().info(f'x: {x_index}, y: {y_index}, normal: {normal_angle}')
247247

248-
sonar_angle = (start_angle + end_angle) / 2 # Take the middle of the sweep
249-
250248
return (
251249
sonar_utils.to_robot_position(x_index, y_index, self.sample_period, self.NEGATE_POSE),
252250
color_image,
@@ -282,7 +280,7 @@ def constant_sweep(self) -> None:
282280
rclpy.shutdown()
283281

284282
def perform_sonar_request(
285-
self, request: SonarSweepRequest.Request, response: SonarSweepRequest.Response
283+
self, request: SonarSweepRequest.Request, response: SonarSweepRequest.Response,
286284
) -> SonarSweepRequest.Response:
287285
"""
288286
Perform a sonar request.

onboard/src/sonar/sonar/sonar_utils.py

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

1717

1818
def transform_pose(
19-
buffer: tf2_ros.Buffer, pose: tf2_geometry_msgs.PoseStamped, source_frame_id: str, target_frame_id: str
19+
buffer: tf2_ros.Buffer, pose: tf2_geometry_msgs.PoseStamped, source_frame_id: str, target_frame_id: str,
2020
) -> tf2_geometry_msgs.PoseStamped:
2121
"""
2222
Transform pose from source reference frame to target reference frame.
@@ -47,7 +47,7 @@ def transform_pose(
4747
tf2_ros.ExtrapolationException,
4848
tf2_ros.InvalidArgumentException,
4949
) as e:
50-
error_message = f"Failed to transform pose: {e}"
50+
error_message = f'Failed to transform pose: {e}'
5151
raise RuntimeError(error_message) from e
5252

5353

@@ -208,7 +208,7 @@ def to_robot_position(x_index: int, y_index: int, sample_period: float, negate:
208208

209209

210210
def convert_to_ros_compressed_img(
211-
sonar_sweep: np.ndarray, cv_bridge: CvBridge, compressed_format: str = "jpeg", is_color: bool = False
211+
sonar_sweep: np.ndarray, cv_bridge: CvBridge, compressed_format: str = 'jpeg', is_color: bool = False,
212212
) -> CompressedImage:
213213
"""
214214
Convert any kind of image to ROS Compressed Image.

onboard/src/task_planning/task_planning/tasks/sonar_tasks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from custom_msgs.srv import SonarSweepRequest
1313

1414

15-
logger = get_logger("sonar_tasks")
15+
logger = get_logger('sonar_tasks')
1616

1717
MAX_STEPS = 3
1818

@@ -21,28 +21,28 @@
2121
async def sonar_test(_self: Task, start_angle: float, end_angle: float, scan_distance: float) -> Task[None, None, None]:
2222
"""Repeatedly perform sonar scans."""
2323
while True:
24-
logger.info(f"Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m")
24+
logger.info(f'Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m')
2525
future = Sonar().sweep(
2626
start_angle=start_angle,
2727
end_angle=end_angle,
2828
scan_distance=scan_distance,
2929
)
3030
if future is None:
31-
logger.error("Could not call sonar request service.")
31+
logger.error('Could not call sonar request service.')
3232
else:
33-
service_response = cast("SonarSweepRequest.Response", await future)
34-
logger.info(f"Sonar scan response: {service_response}")
33+
service_response = cast('SonarSweepRequest.Response', await future)
34+
logger.info(f'Sonar scan response: {service_response}')
3535

3636

3737
async def get_normal_angle(start_angle: float, end_angle: float, scan_distance: float) -> float:
3838
"""Get a normal angle from the sonar scan."""
3939
future = Sonar().sweep(start_angle=start_angle, end_angle=end_angle, scan_distance=scan_distance)
4040
response = await future
4141
if not response.is_object:
42-
logger.error("No object detected — cannot rotate")
42+
logger.error('No object detected — cannot rotate')
4343
return np.nan
4444
if response.normal_angle is None:
45-
logger.error("[Sonar] normal_angle was None — cannot rotate")
45+
logger.error('[Sonar] normal_angle was None — cannot rotate')
4646
return np.nan
4747
return response.normal_angle
4848

@@ -56,7 +56,7 @@ async def rotate_to_normal(
5656
yaw_threshold: float,
5757
) -> Task[None, None, None]:
5858
"""Rotates to face a normal angle."""
59-
logger.info(f"Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m")
59+
logger.info(f'Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m')
6060

6161
normal_angle = await get_normal_angle(start_angle, end_angle, scan_distance)
6262
await move_to_pose_local(
@@ -88,7 +88,7 @@ async def rotate_to_angle_from_normal(
8888
rotated_angle: float,
8989
) -> Task[None, None, None]:
9090
"""Rotates to a specified angle using Sonar normal angle."""
91-
logger.info(f"Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m")
91+
logger.info(f'Sonar scan from {start_angle} to {end_angle} degrees, distance: {scan_distance} m')
9292

9393
angle = await get_normal_angle(start_angle, end_angle, scan_distance)
9494
angle = rotated_angle + angle

0 commit comments

Comments
 (0)