Skip to content

XDongiang/tmt_sonic

Repository files navigation

tmt_sonic

中文文档

A real-time multi-channel acoustic sensor monitoring system built on ROS and Foxglove. It receives multi-channel audio data pushed by sensor devices over TCP, processes and publishes the data as ROS topics, and visualizes waveforms and FFT spectra live in Foxglove Studio.

Architecture

Sensor Device (TCP push)
       |
       v
tcp_to_ros_node.py
  +-- Receive TCP data (32-bit int, multi-channel, 32 kHz)
  +-- Publish raw waveform topics: data_pgc_channel_<i>
  +-- Publish FFT spectrum topics: fft_channel_<i>
  +-- Foxglove Bridge
             |
             v
       Foxglove Studio (live visualization)

Requirements

Dependency Version
Ubuntu 20.04 LTS
ROS Noetic
Python 3.8+
foxglove_bridge latest (ROS package)

Python Dependencies

numpy
scipy
matplotlib
soundfile
pandas
openpyxl

Installation

1. Install ROS Noetic

Follow the official guide: http://wiki.ros.org/noetic/Installation/Ubuntu

2. Install Foxglove Bridge

sudo apt install ros-noetic-foxglove-bridge

3. Clone the Repository

git clone <repo_url> tmt_sonic
cd tmt_sonic

4. Install Python Dependencies

pip install numpy scipy matplotlib soundfile pandas openpyxl

5. Build the ROS Workspace

cd ros_ws
catkin_make

Usage

Configuration

Edit the parameters at the bottom of ros_ws/src/tcp_to_ros/src/tcp_to_ros_node.py:

save_path = "/path/to/save/data/"   # directory for saving recorded data
_ip = '192.168.0.2'                 # local IP to listen on
_port = 9999                        # listening port
sample_rate = 32000                 # sample rate (Hz)
nrChannelsPerFrame = 9              # total hardware channels per frame
channelCount = 6                    # number of channels to publish

Launch

Option 1 - startup script (recommended)

# Load ROS environment
source setup_environment.zsh

# Start all nodes (ROS Master + Foxglove Bridge + tcp_to_ros)
./run.sh

Option 2 - manual launch

source setup_environment.zsh
roslaunch tcp_to_ros main.launch

Visualize in Foxglove Studio

  1. Open Foxglove Studio (desktop app or web)
  2. Connect to ws://localhost:8765 (default Foxglove Bridge port)
  3. Subscribe to the following topics:
    • data_pgc_channel_0 to data_pgc_channel_5 - raw waveform per channel
    • fft_channel_0 to fft_channel_5 - FFT spectrum per channel

Standalone TCP Receiver (debug mode)

Receive and visualize data with matplotlib without ROS:

python readtcp.py

Edit the IP, port, and buffer size at the bottom of the file before running.

Utility Scripts

Offline Data Preprocessing

Convert recorded .c9 binary files to .npy and .wav format:

python preprocess.py

Set file_path and c9_files in preprocess.py to point to your input files. Output is saved to ./mydata/.

Sensor Distance Calculation

Calculate the distance from each sensor node to a reference point using an Excel coordinate file:

python calc.py

Provide a b1-b11.xlsx coordinate file and set the reference point coordinates inside the script.

ROS Message Types

Message File Description
Int32MultiArrayStamped.msg Timestamped int32 array (raw waveform and FFT data)
Int32Stamped.msg Timestamped single int32 value
SensorDataArray.msg Sensor data array with time series

Project Structure

tmt_sonic/
+-- ros_ws/
|   +-- src/
|       +-- tcp_to_ros/
|           +-- CMakeLists.txt
|           +-- package.xml
|           +-- launch/
|           |   +-- main.launch         # launch file
|           +-- msg/                    # custom message types
|           +-- src/
|               +-- tcp_to_ros_node.py  # core ROS node
+-- readtcp.py              # standalone TCP receiver & visualizer (debug)
+-- preprocess.py           # offline .c9 file preprocessing
+-- calc.py                 # sensor coordinate distance calculation
+-- run.sh                  # quick-start script
+-- setup_environment.zsh   # ROS environment setup

License

MIT License

Copyright (c) 2026 sean

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Real-time multi-channel acoustic sensor monitoring system using ROS and Foxglove. Receives 32-bit PCM audio data over TCP, publishes raw waveform and FFT spectrum as ROS topics, and visualizes them live in Foxglove Studio.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors