8.8 KiB
IMU System Integration Tests
This document describes integration tests for the IMU data pipeline (IMU reader ESP32, Lifecycle MITM node, Database writer node). These tests will verify end-to-end functionality from ESP32 sensor data to database storage.
Test Overview
The integration tests validate the complete flow through the main components:
- ESP32 MPU6886 Sensor - Data fetching and transmission (MQTT or Serial)
- ROS2 Lifecycle Node - Message reception from ESP and forwarding to database writer
- IMU Database Writer Node - Database storage
Test Environment Setup
Prerequisites
- ESP32 with MPU6886 sensor configured and flashed
- PostgreSQL database running (can be ran using dockerfile documented in the README)
- ROS2 workspace built and sourced
- if testing MQTT mode, MQTT broker running
- if testing Serial mode, Serial port access
Configuration Files
src/config.toml- Database connection parametersIMU/sdkconfig- Serial/MQTT mode selection and network settings
Integration Test Cases
Test 1: Database Writer Persistence Verification
Verify that the Database Writer node correctly saves data to the PostgreSQL database when IMU messages are received.
Test Setup
- Start PostgreSQL database (docker compose up)
- Verify database connection, if incorrect change settings settings in
src/config.toml - Clear or note the current state of the IMU data table
- Launch the Database Writer node:
ros2 run g2_2025_imu_reader_pkg g2_2025_imu_database_writer_node
Test Procedure
-
Query the database for initial row count
SELECT COUNT(*) FROM imu_data; -
Use ROS2 CLI to publish IMU data
ros2 topic pub --once /imu_data sensor_msgs/msg/Imu "{ linear_acceleration: {x: 0.5, y: 0.6, z: 9.8}, angular_velocity: {x: 0.1, y: 0.2, z: 0.3} }" -
Query the database for new entries
SELECT * FROM imu_data ORDER BY timestamp DESC LIMIT 1; -
Send 10 messages with varying data
for i in {1..10}; do ros2 topic pub --once /imu_data sensor_msgs/msg/Imu "{ linear_acceleration: {x: $(echo "scale=2; $i * 0.1" | bc), y: 0.0, z: 9.8}, angular_velocity: {x: 0.0, y: 0.0, z: 0.0} }" sleep 0.5 done -
Confirm all 10 messages were persisted
SELECT COUNT(*) FROM imu_data WHERE timestamp > (NOW() - INTERVAL '1 minute');
Expected Results
- Each published message creates one database row
- Linear acceleration values (x, y, z) match published data
- Angular velocity values (x, y, z) match published data
- Timestamps are automatically generated and sequential
- No data loss occurs
Test 2: Lifecycle Node Message Forwarding
Verify that the Lifecycle Node correctly receives IMU data from either Serial or MQTT sources and forwards it to the
imu_datatopic for consumption by the Database Writer.
Test Setup
- Ensure ROS2 environment is sourced
- Launch the Lifecycle Node and Database Writer Node:
ros2 run g2_2025_imu_reader_pkg g2_2025_lifecycle_node ros2 run g2_2025_imu_reader_pkg g2_2025_imu_database_writer_node - Monitor the
imu_datatopic:ros2 topic echo /imu_data
Test Procedure - Serial Mode
-
Configure ESP32 for Serial Output:
- Ensure
CONFIG_ENV_MQTT_ENABLEDis not defined in ESP32 sdkconfig - Flash ESP32 with serial configuration
- Ensure
-
Connect ESP32 via Serial:
- Connect ESP32 to computer via USB
- Identify serial port (e.g.,
/dev/ttyUSB0on Linux) - Configure lifecycle node to read from this serial port
-
Verify Data Flow:
- Observe lifecycle node logs for incoming serial data
- Confirm
ros2 topic echo /imu_datadisplays messages - Verify message fields match ESP32 output:
linear_acceleration.x/y/zmatchesaccel.x/y/zangular_velocity.x/y/zmatchesgyro.x/y/z
-
Verify Database storage:
- Check database for new entries
- Confirm values match ESP32 sensor readings
Test Procedure - MQTT Mode
-
Start MQTT Broker:
mosquitto -v -
Configure ESP32 for MQTT Output:
- Enable
CONFIG_ENV_MQTT_ENABLEDin ESP32 sdkconfig - Configure MQTT broker URI (
mqtt://192.168.1.100:1883) - Set MQTT topic (
CONFIG_MQTT_TOPIC = "imu/data") - Configure WiFi credentials
- Flash ESP32 with MQTT configuration
- Enable
-
Verify MQTT Publishing:
- Subscribe to MQTT topic to confirm ESP32 is publishing:
mosquitto_sub -h localhost -t "imu/data" -v - Expected MQTT payload format:
{"accel":{"x":0.123,"y":0.456,"z":9.800},"gyro":{"x":0.012,"y":0.023,"z":0.034},"Temp":25.50}
- Subscribe to MQTT topic to confirm ESP32 is publishing:
-
Configure Lifecycle Node for MQTT:
- Set lifecycle node to subscribe to MQTT broker and topic
- Restart lifecycle node with MQTT configuration
-
Verify Data Flow:
- Observe lifecycle node logs for incoming MQTT messages
- Confirm
ros2 topic echo /imu_datadisplays messages
-
Verify Database storage:
- Check database for continuously arriving data
- Confirm timestamps are recent and sequential
Expected Results
Serial Mode:
- Lifecycle node successfully reads JSON-formatted messages from serial port
- Messages are parsed and converted to
sensor_msgs/msg/Imuformat - All IMU data fields are correctly mapped
- Messages are published to
/imu_datatopic - Database writer receives and persists data
MQTT Mode:
- Lifecycle node successfully subscribes to MQTT broker
- MQTT messages are received and parsed
- Messages are converted to
sensor_msgs/msg/Imuformat - All IMU data fields are correctly mapped
- Messages are published to
/imu_data - Database writer receives and persists data
Test 3: ESP32 Data Format Validation
Verify that the ESP32 correctly formats and transmits IMU data in both Serial and MQTT modes according to the expected JSON schema.
Test Setup
- ESP32 with MPU6886 sensor properly wired and powered
- IMU sensor calibrated (100 samples for gyro and accel)
- Serial terminal or MQTT subscriber ready to capture output
Data Quality Checks
- Accelerometer Z-axis reads ~9.8 (m/s)^2 when device is stationary and level
- Gyroscope values near zero when device is stationary
- Temperature reading is within expected range
- No NaN or Inf values in output
- Calibration offsets are properly applied
End-to-End Integration Test
Objective: Validate complete system integration from ESP32 sensor to database persistence.
Test Setup
- Clean database state (truncate IMU data table)
- Start PostgreSQL database
- Start MQTT broker (for MQTT test variant)
- Launch all ROS2 nodes:
- Lifecycle node
- Database writer node
- Power on and connect ESP32
Test Procedure
-
System Initialization:
- Verify all nodes are running and healthy
- Check lifecycle node is connected to data source (Serial/MQTT)
- Confirm database writer node is subscribed to
/imu_data
-
Data Flow Verification:
- Let system run for 2 minutes
- Monitor ROS2 topics:
ros2 topic hz /imu_data ros2 topic bw /imu_data
-
Database Query:
SELECT COUNT(*) FROM imu_data WHERE timestamp > (NOW() - INTERVAL '2 minutes'); SELECT AVG(linear_accel_z) as avg_accel_z, AVG(angular_vel_x) as avg_gyro_x, MIN(timestamp) as first_sample, MAX(timestamp) as last_sample FROM imu_data WHERE timestamp > (NOW() - INTERVAL '2 minutes'); -
Physical Movement Test:
- Pick up ESP32 and rotate it
- Observe changes in database values
- Verify accelerometer and gyroscope values change
-
Stress Test:
- Let system run for 30 minutes
- Check for memory leaks or connection drops
- Verify continuous data storage
Expected Results
- Data flows from ESP32 -> Lifecycle Node -> Database Writer -> PostgreSQL
- Publishing rate at
/imu_data - Database receives ~240 rows in 2 minutes
- Average Z-axis acceleration is ~9.8 (m/s)^2 during stationary periods
- Physical movements are reflected in database values
- No data loss over extended operation (30 minutes)
- All components remain stable without crashes
Test Execution Checklist
Pre-Test Verification
- PostgreSQL database is running and accessible
- Database schema is created (IMU data table exists)
- ROS2 workspace is built and sourced
- ESP32 firmware is flashed with correct configuration
- MQTT broker is running
- Serial port permissions are correct
During Test
- Monitor node logs for errors or warnings
- Check ROS2 topic publishing rates
- Verify database connection remains active
- Observe IMU data values
Post-Test Analysis
- Review test results and logs
- Document any failures or anomalies
- Clean up test data if necessary