mil_passive_sonar
- Passive Sonar¶
Utility Functions¶
- mil_passive_sonar.algorithms.run(samples: ndarray, sample_rate: int, v_sound: int, dist_h: float, dist_h4: float)[source]¶
The traditional passive sonar algorithm.
- Parameters
samples (np.ndarray) – The samples relevant to the system.
sample_rate (int) – The rate at which samples are recorded, in the number of samples per second.
v_sound (int) – The velocity of sound in the environment, in
m/s
. In fresh water, this should be ~1497 m/s.dist_h (float) –
???
dist_h4 (float) –
???
- mil_passive_sonar.algorithms.zero_mean(samples: ndarray)[source]¶
Zero means data by assuming that the first 32 samples are zeros.
- mil_passive_sonar.algorithms.normalize(samples: ndarray)[source]¶
Rescapes samples so each individual channel lies between -1 and 1.
- mil_passive_sonar.algorithms.compute_freq(samples: ndarray, sample_rate: int, freq_range, plot: bool = False)[source]¶
Checks whether samples are likely a solid ping and returns the frequency.
- mil_passive_sonar.algorithms.bin_to_freq(bin: int, sample_rate: int, fft_length: int) float [source]¶
Converts a bin to a frequency bin.
- mil_passive_sonar.algorithms.freq_to_bin(freq: int, sample_rate: int, fft_length: int) float [source]¶
Converts a frequency pattern to the number of bins in the transform.
- mil_passive_sonar.algorithms.preprocess(samples: ndarray, sample_rate: int, desired_sample_rate: int)[source]¶
Upsamples data to have approx. desired_sample_rate.
- mil_passive_sonar.algorithms.bandpass(samples: ndarray, sample_rate: int)[source]¶
Applies a 20-30khz bandpass FIR filter.
- Parameters
samples (np.ndarray) – The list of samples.
sample_rate (int) – The rate of sampling. The number of samples per second.
- mil_passive_sonar.algorithms.compute_deltas(samples: ndarray, sample_rate: int, max_delay: float, template_duration: float, plot: bool = False)[source]¶
Computes N-1 position deltas for N channels, by making a template for the first channel and matching to all subsequent channels.
- mil_passive_sonar.algorithms.make_template(channel: ndarray, width: int)[source]¶
Returns a template of the specified width, with its 25% position being at where the lower-level driver triggered.
- Parameters
channel (np.ndarray) –
???
width (int) –
???
- mil_passive_sonar.algorithms.match_template(channel: ndarray, start: int, stop: int, template: ndarray)[source]¶
Matches template to channel, returning the point where the start of the template should be placed.
- mil_passive_sonar.algorithms.calculate_error(channel: ndarray, start: int, stop: int, template: ndarray)[source]¶
Slides the template along channel from start to stop, giving the error of the template and channel at each location.
- mil_passive_sonar.algorithms.find_minimum(data: ndarray)[source]¶
Finds the sub-sample position of the minimum in a continuous signal, by first finding the lowest absolute value, then doing quadratic interpolation.
- Parameters
data (np.ndarray) – The relevant signal.
- mil_passive_sonar.algorithms.compute_pos_4hyd(deltas: ndarray, sample_rate: int, v_sound: int, dist_h: float, dist_h4: float)[source]¶
Solves the 4 hydrophone case (3 deltas) for heading, declination, and sph_dist using a bunch of trig. Future work would be to phrase this as a NLLSQ problem or something, and adapt it to more hydrophones.
- Parameters
samples (np.ndarray) – The samples relevant to the system.
sample_rate (int) – The rate at which samples are recorded, in the number of samples per second.
v_sound (int) – The velocity of sound in the environment, in
m/s
. In fresh water, this should be ~1497 m/s.dist_h (float) –
???
dist_h4 (float) –
???
TxHydrophonesClient¶
- defdisable
- defenable
- defget_direction
- defget_last_position
- defget_position
- defheading_cb
- defreset
- defset_callback
- class mil_passive_sonar.TxHydrophonesClient(nh: NodeHandle)[source]¶
TxROS abstraction for interacting with the nodes in this package.
- dir_callback¶
The method that is called when a ping is received.
- Type
Optional[Callable]
Construct a client.
- Parameters
nh (NodeHandle) – The TxROS node handler.
- get_direction() Future [source]¶
Get the next processed direction to the pinger.
- Returns
A Future object which can be used to get the next message of the pinger’s direction.
- Return type
asycio.Future
- get_last_position() PointStamped [source]¶
Get the last processed position of the pinger.
- Returns
A cached value of the last position of the pinger.
- Return type
- get_position() Future [source]¶
Get the next processed position of the pinger.
- Returns
A Future object which can be used to get the next message of the pinger’s position.
- Return type
StreamedBandpass¶
- defconvolve
- defis_ready_to_make_filter
- defmake_filter
- class mil_passive_sonar.streamed_bandpass.StreamedBandpass(lower: float, upper: float, trans_width: float, order: float, rate: Optional[float] = None)[source]¶
- Class for bandpass filtering sequential batches of data. Takes care of the
overlap-adding that needs to be done when filtering sequential batches of data individually.
- h¶
The Remez exchange algorithm, if defined. Constructed when the filter is made.
- Type
Optional[np.ndarray]
Constructs the class using the variables provided. Checks if the class is ready to make a filter, and if so, the filter is constructed.
- Parameters
lower (float) – The lower bound of the desired frequency.
upper (float) – The upper bound of the desired frequency.
trans_width (float) – A magical special filter property!
order (float) – Filter order for the bandpass filter. Higher is better, but slower to compute.
rate (Optional[float]) – The rate at which data is sent.
- convolve(data: ndarray) ndarray [source]¶
Does the filtering.
- Parameters
data (np.ndarray) – Numpy array of shape
(samples, channels)
.- Returns
The resulting filtered data.
- Return type
np.ndarray
HydrophoneTrigger¶
- defenable
- deffilter_response
- defhydrophones_cb
- defreset
- class mil_passive_sonar.scripts.triggering.HydrophoneTrigger[source]¶
ROS Node meant to trigger only when a ping happens in our target frequency range.
Subscribes to raw hydrophone samples on
/samples
.Publishes samples (of gradient) from right around the triggering on
/pings
when a ping is detected and found to be in the target frequency range.Optionally, you can publish a plot of the frequency response of the filter on /filter_debug by service calling /filter_debug_trigger.
- general_lower¶
The lower bound of the frequency range. Set to the frequency of the lowest frequency pinger - 10 kHz.
- Type
- general_upper¶
The upper bound of the frequency range. Set to the frequency of the lowest frequency pinger - 10 kHz.
- Type
- time¶
The amount of time that has passed since recording started, according to the messages received.
- Type
- pub¶
A publisher for the
/pings
topic. PublishesTriggered
messages.- Type
rospy.Publisher
- sub¶
A subscriber to the
/samples
topic. Receives either aPing
orHydrophoneSamplesStamped
message, and sends the message tohydrophones_cb()
.- Type
Optional[rospy.Subscriber]
- trigger_debug¶
A plotter responsible for publishing debug data about the triggering behavior of the system.
- Type
- enable(req: SetBoolRequest) SetBoolResponse [source]¶
Enables the system; can be called through a
SetBoolRequest
request.- Parameters
req (SetBoolRequest) – The service request.
- Returns
The response to the service request.
- Return type
- filter_response(req: TriggerRequest) TriggerResponse [source]¶
Filters the debug service. Serves as a callback to the service.
- Parameters
req (TriggerRequest) – The trigger request.
- Returns
The response to the request.
- Return type
TriggerResponse
PingLocator¶
- class mil_passive_sonar.scripts.ping_locator.PingLocator[source]¶
Subscribers to
/pings
, and publishes vector to the pinger on/direction
. Creates a node namedping_locator
.- enable(req: SetBoolRequest) SetBoolResponse [source]¶
Sets the locator to enabled. Doesn’t immediately do anything.
- Parameters
req (SetBoolRequest) – The service request.
- Returns
The service response.
- Return type
SylphaseSonarToRosNode¶
- funcSylphaseSonarToRosNode
- funcrun
-
class SylphaseSonarToRosNode¶
ROS node which reads in the TCP stream produced by the Sylphase passive sonar board. Publishes the data to a topic as a message.
Public Functions
-
SylphaseSonarToRosNode(ros::NodeHandle nh, ros::NodeHandle private_nh)¶
Constructor with a node handle and private node handle. Upon construction, gets the IP, port, the frame of reference, and the number of seconds to capture.
-
void run()¶
Attempts to read messages forever from the TCP socket. Messages are published as a HydrophoneSamples type.
If an error is encountered, then waits 5 seconds and then tries to connect to the socket again.
-
SylphaseSonarToRosNode(ros::NodeHandle nh, ros::NodeHandle private_nh)¶