Skip to content

Commit

Permalink
refactor(style): applied formatting and style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kluge7 committed Nov 8, 2024
1 parent 764e54d commit caf99c0
Show file tree
Hide file tree
Showing 41 changed files with 927 additions and 652 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ repos:
"--select=D",
"--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D401",
"--fix",
"--unsafe-fixes"
]
stages: [pre-commit]
pass_filenames: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def __init__(self, ros2_package_directory: str = "") -> None:
]

# Make new .csv file for logging blackbox data ----------
with open(self.data_file_location, mode="w", newline="", encoding="utf-8") as csv_file:
with open(
self.data_file_location, mode="w", newline="", encoding="utf-8"
) as csv_file:
writer = csv.writer(csv_file)
writer.writerow(self.csv_headers)

Expand All @@ -47,8 +49,7 @@ def log_data_to_csv_file(
tdoa: list[float] = [0.0],
position: list[float] = [0.0],
) -> None:
"""
Logs the provided data to a CSV file.
"""Logs the provided data to a CSV file.
Parameters:
self (object): The instance of the class.
Expand All @@ -69,7 +70,9 @@ def log_data_to_csv_file(
current_time = datetime.now().strftime("%H:%M:%S.%f")[:-3]

# Write to .csv file
with open(self.data_file_location, mode="a", newline="", encoding="utf-8") as csv_file:
with open(
self.data_file_location, mode="a", newline="", encoding="utf-8"
) as csv_file:
writer = csv.writer(csv_file)
writer.writerow(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,43 @@
class AcousticsDataRecordNode(Node):
def __init__(self) -> None:
# Variables for setting upp logging correctly
hydrophone_data_size = (2**10) * 3 # 1 hydrophone buffer is 2^10 long, Each hydrophone data has 3 buffers full of this data
hydrophone_data_size = (
(2**10) * 3
) # 1 hydrophone buffer is 2^10 long, Each hydrophone data has 3 buffers full of this data
dsp_data_size = 2**10 # DSP (Digital Signal Processing) has 2^10 long data
tdoa_data_size = 5 # TDOA (Time Difference Of Arrival) has 5 hydrophones it has times for
tdoa_data_size = (
5 # TDOA (Time Difference Of Arrival) has 5 hydrophones it has times for
)
position_data_size = 3 # position only has X, Y, Z basically 3 elements

# Initialize ROS2 node
super().__init__("acoustics_data_record_node")

# Initialize Subscribers ----------
# Start listening to Hydrophone data
self.subscriber_hydrophone1 = self.create_subscription(Int32MultiArray, "/acoustics/hydrophone1", self.hydrophone1_callback, 5)
self.subscriber_hydrophone1 = self.create_subscription(
Int32MultiArray, "/acoustics/hydrophone1", self.hydrophone1_callback, 5
)
self.hydrophone1_data = array.array("i", [0] * hydrophone_data_size)

self.subscriber_hydrophone2 = self.create_subscription(Int32MultiArray, "/acoustics/hydrophone2", self.hydrophone2_callback, 5)
self.subscriber_hydrophone2 = self.create_subscription(
Int32MultiArray, "/acoustics/hydrophone2", self.hydrophone2_callback, 5
)
self.hydrophone2_data = array.array("i", [0] * hydrophone_data_size)

self.subscriber_hydrophone3 = self.create_subscription(Int32MultiArray, "/acoustics/hydrophone3", self.hydrophone3_callback, 5)
self.subscriber_hydrophone3 = self.create_subscription(
Int32MultiArray, "/acoustics/hydrophone3", self.hydrophone3_callback, 5
)
self.hydrophone3_data = array.array("i", [0] * hydrophone_data_size)

self.subscriber_hydrophone4 = self.create_subscription(Int32MultiArray, "/acoustics/hydrophone4", self.hydrophone4_callback, 5)
self.subscriber_hydrophone4 = self.create_subscription(
Int32MultiArray, "/acoustics/hydrophone4", self.hydrophone4_callback, 5
)
self.hydrophone4_data = array.array("i", [0] * hydrophone_data_size)

self.subscriber_hydrophone5 = self.create_subscription(Int32MultiArray, "/acoustics/hydrophone5", self.hydrophone5_callback, 5)
self.subscriber_hydrophone5 = self.create_subscription(
Int32MultiArray, "/acoustics/hydrophone5", self.hydrophone5_callback, 5
)
self.hydrophone5_data = array.array("i", [0] * hydrophone_data_size)

# Start listening to DSP (Digital Signal Processing) data
Expand All @@ -48,10 +62,14 @@ def __init__(self) -> None:
)
self.filter_response_data = array.array("i", [0] * dsp_data_size)

self.subscriber_fft = self.create_subscription(Int32MultiArray, "/acoustics/fft", self.fft_callback, 5)
self.subscriber_fft = self.create_subscription(
Int32MultiArray, "/acoustics/fft", self.fft_callback, 5
)
self.fft_data = array.array("i", [0] * dsp_data_size)

self.subscriber_peaks = self.create_subscription(Int32MultiArray, "/acoustics/peaks", self.peaks_callback, 5)
self.subscriber_peaks = self.create_subscription(
Int32MultiArray, "/acoustics/peaks", self.peaks_callback, 5
)
self.peaks_data = array.array("i", [0] * dsp_data_size)

# Start listening to Multilateration data
Expand All @@ -63,23 +81,38 @@ def __init__(self) -> None:
)
self.tdoa_data = array.array("f", [0.0] * tdoa_data_size)

self.subscriber_position_response = self.create_subscription(Float32MultiArray, "/acoustics/position", self.position_callback, 5)
self.subscriber_position_response = self.create_subscription(
Float32MultiArray, "/acoustics/position", self.position_callback, 5
)
self.position_data = array.array("f", [0.0] * position_data_size)

# Initialize logger ----------
# Get package directory location
ros2_package_directory_location = get_package_share_directory("acoustics_data_record")
ros2_package_directory_location = ros2_package_directory_location + "/../../../../" # go back to workspace
ros2_package_directory_location = get_package_share_directory(
"acoustics_data_record"
)
ros2_package_directory_location = (
ros2_package_directory_location + "src/vortex-auv/acoustics/acoustics_data_record/"
ros2_package_directory_location + "/../../../../"
) # go back to workspace
ros2_package_directory_location = (
ros2_package_directory_location
+ "src/vortex-auv/acoustics/acoustics_data_record/"
) # Navigate to this package

# Make blackbox logging file
self.acoustics_data_record = AcousticsDataRecordLib(ros2_package_directory=ros2_package_directory_location)
self.acoustics_data_record = AcousticsDataRecordLib(
ros2_package_directory=ros2_package_directory_location
)

# Logs all the newest data 1 time(s) per second
self.declare_parameter("acoustics.data_logging_rate", 1.0) # Providing a default value 1.0 => 1 samplings per second, very slow
data_loging_rate = self.get_parameter("acoustics.data_logging_rate").get_parameter_value().double_value
self.declare_parameter(
"acoustics.data_logging_rate", 1.0
) # Providing a default value 1.0 => 1 samplings per second, very slow
data_loging_rate = (
self.get_parameter("acoustics.data_logging_rate")
.get_parameter_value()
.double_value
)
timer_period = 1.0 / data_loging_rate
self.logger_timer = self.create_timer(timer_period, self.logger)

Expand All @@ -100,89 +133,79 @@ def __init__(self) -> None:

# Callback methods for different topics
def hydrophone1_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for hydrophone1 topic.
"""Callback method for hydrophone1 topic.
Args:
msg (Int32MultiArray): Message containing hydrophone1 data.
"""
self.hydrophone1_data = msg.data

def hydrophone2_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for hydrophone2 topic.
"""Callback method for hydrophone2 topic.
Args:
msg (Int32MultiArray): Message containing hydrophone2 data.
"""
self.hydrophone2_data = msg.data

def hydrophone3_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for hydrophone3 topic.
"""Callback method for hydrophone3 topic.
Args:
msg (Int32MultiArray): Message containing hydrophone3 data.
"""
self.hydrophone3_data = msg.data

def hydrophone4_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for hydrophone4 topic.
"""Callback method for hydrophone4 topic.
Args:
msg (Int32MultiArray): Message containing hydrophone4 data.
"""
self.hydrophone4_data = msg.data

def hydrophone5_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for hydrophone5 topic.
"""Callback method for hydrophone5 topic.
Args:
msg (Int32MultiArray): Message containing hydrophone5 data.
"""
self.hydrophone5_data = msg.data

def filter_response_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for filter_response topic.
"""Callback method for filter_response topic.
Args:
msg (Int32MultiArray): Message containing filter response data.
"""
self.filter_response_data = msg.data

def fft_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for fft topic.
"""Callback method for fft topic.
Args:
msg (Int32MultiArray): Message containing FFT data.
"""
self.fft_data = msg.data

def peaks_callback(self, msg: Int32MultiArray) -> None:
"""
Callback method for peaks topic.
"""Callback method for peaks topic.
Args:
msg (Int32MultiArray): Message containing peaks data.
"""
self.peaks_data = msg.data

def tdoa_callback(self, msg: Float32MultiArray) -> None:
"""
Callback method for time_difference_of_arrival topic.
"""Callback method for time_difference_of_arrival topic.
Args:
msg (Float32MultiArray): Message containing TDOA data.
"""
self.tdoa_data = msg.data

def position_callback(self, msg: Float32MultiArray) -> None:
"""
Callback method for position topic.
"""Callback method for position topic.
Args:
msg (Float32MultiArray): Message containing position data.
Expand All @@ -191,8 +214,7 @@ def position_callback(self, msg: Float32MultiArray) -> None:

# The logger that logs all the data
def logger(self) -> None:
"""
Logs all the data to a CSV file using the AcousticsDataRecordLib.
"""Logs all the data to a CSV file using the AcousticsDataRecordLib.
This method is called periodically based on the data logging rate.
"""
Expand All @@ -211,8 +233,7 @@ def logger(self) -> None:


def main() -> None:
"""
Main function to initialize and run the ROS2 node for acoustics data recording.
"""Main function to initialize and run the ROS2 node for acoustics data recording.
This function performs the following steps:
1. Initializes the ROS2 communication.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node

from launch import LaunchDescription


def generate_launch_description() -> LaunchDescription:
"""
Generates a launch description for the acoustics_data_record node.
"""Generates a launch description for the acoustics_data_record node.
This function constructs the path to the YAML configuration file for the
acoustics_interface package and returns a LaunchDescription object that
Expand Down
Loading

0 comments on commit caf99c0

Please sign in to comment.