A comprehensive motion tracking system using Qualisys Track Manager (QTM) for real-time 6DOF tracking with monitoring and logging capabilities.
motion-tracking/
βββ config/ # Configuration files
β βββ qtm_config.py # Main configuration settings
βββ data/ # Output data directory
β βββ new.csv # Main tracking data output
β βββ qtm_config.json # Saved configuration (auto-generated)
β βββ qtm_system_info.json # QTM system information (auto-generated)
β βββ qtm_parameters.xml # QTM parameters (auto-generated)
β βββ monitoring_logs.json # Monitoring data (auto-generated)
β βββ monitoring_summary.txt # Human-readable monitoring summary (auto-generated)
βββ src/ # Source code
β βββ qtm_data_export.py # Main data collection script
β βββ test_qtm_connection.py # QTM connection test script
β βββ test_file_saving.py # File saving functionality test
β βββ test_monitoring_events.py # Monitoring events test
βββ utils/ # Utility modules
β βββ qtm_handlers.py # QTM data handling functions
β βββ qtm_settings.py # QTM system information utilities
β βββ savers.py # File saving utilities
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Python 3.8+ installed
- QTM Server running and accessible
- Network access to QTM server
-
Clone or download:
git clone https://github.com/sensint/motion-tracking.git
-
Install dependencies:
pip install -r requirements.txt
-
Configure QTM connection in
config/qtm_config.py:QTM_HOST = '139.19.40.134' # Your QTM server IP
or for local host:
QTM_HOST = '127.0.0.1'
-
Test QTM connection:
python src/test_qtm_connection.py
-
Run data collection:
python src/qtm_data_export.py
The system supports real-time UDP streaming of QTM tracking data. This allows you to broadcast or multicast tracking data to other applications or devices on your network in real time.
- Data is streamed as CSV-formatted rows, matching the CSV output.
- UDP streaming is controlled by the
STREAMandLOGflags inconfig/qtm_config.py. - By default, data is sent to the multicast address
224.1.1.1:5005, but you can set any IP/port. - Both
src/qtm_data_export.pyandsrc/qtm_data_export_stream.pysupport UDP streaming.
In config/qtm_config.py:
STREAM = True # Enable UDP streaming
LOG = False # Disable file logging (set True to log to CSV as well)
UDP_IP = '224.1.1.1' # Multicast address (or use a specific IP or broadcast address)
UDP_PORT = 5005 # UDP portTo stream QTM data over UDP:
python src/qtm_data_export.py
# or
python src/qtm_data_export_stream.pyA reference UDP receiver is provided:
python src/udp_receiver.pyThis will print all received tracking data to the console. You can adapt this script to process or save the data as needed.
QTM_HOST = '139.19.40.134' # QTM server IP address
QTM_CONNECTION_TIMEOUT = 10 # Connection timeout (seconds)
WARMUP_TIME = 2 # Warmup period (seconds)
MONITORING_WARMUP_EXTRA = 0.5 # Extra monitoring warmup (seconds)TRACKING_COMPONENT = ['6d'] # Tracking type: '3d', '6d', or both
DURATION_SECONDS = 10 # Recording duration (seconds)
TARGET_BODY_NAME = 'pen_27_06' # Specific body to track (None = all)
rotation_type = 'matrix' # Rotation format: 'matrix' or 'quaternion'SAMPLE = True # Enable/disable sampling
SAMPLE_FREQ = 100 # Sampling frequency (Hz)
RATE_CHECK_INTERVAL = 1.0 # Rate monitoring interval (seconds)
NAN_CHECK_INTERVAL = 5.0 # NaN monitoring interval (seconds)
RATE_DROP_SOFT_THRESHOLD = 90 # Soft rate drop warning (%)
RATE_DROP_HARD_THRESHOLD = 50 # Hard rate drop error (%)
NAN_THRESHOLD = 10 # NaN rate warning threshold (%)OUTPUT_FOLDER = '../data/' # Output directory
FILE_NAME = 'new.csv' # Main data file name
CSV_HEADER = ['time_python(ms)', 'qtm_x', 'qtm_y', 'qtm_z', 'qtm_rot'] # CSV headers
STREAM = True # Enable UDP streaming
LOG = False # Enable/disable file logging
UDP_IP = '224.1.1.1' # UDP target IP (multicast/broadcast/unicast)
UDP_PORT = 5005 # UDP target portThis is the primary data collection script that:
- Connects to QTM and retrieves system information
- Saves configuration and system parameters to files
- Streams tracking data in real-time (to file and/or UDP, depending on config)
- Monitors performance and logs events
- Saves comprehensive logs including:
- Real-time monitoring events
- Performance statistics
- System configuration
- QTM parameters
After running data collection, the following files are created in the data/ directory:
time_python(ms),qtm_x,qtm_y,qtm_z,qtm_rot
0.0,123.456,789.012,345.678,"(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)"
10.0,123.457,789.013,345.679,"(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)"
...
{
"connection_settings": {
"qtm_host": "139.19.40.134",
"connection_timeout": 10,
"warmup_time": 2
},
"capture_settings": {
"tracking_component": ["6d"],
"duration_seconds": 10,
"target_body_name": "pen_27_06"
},
"sampling_settings": {
"sample": true,
"sample_freq": 100
},
"timestamp": "2024-01-15T10:30:00.123456"
}=== QTM Data Collection Monitoring Summary ===
Collection Date: 2024-01-15 10:30:00
Duration: 10 seconds
Expected Sampling Frequency: 100 Hz
Total Samples Logged: 950
Total NaN Samples: 5 (0.5%)
Actual Logging Rate: 95.0 Hz (95.0% of expected 100 Hz)
QTM Capture Frequency: 1400 Hz
=== Real-Time Monitoring Logs ===
[2024-01-15 10:30:03.123] Rate Check: 95 samples in 1.0s = 95.0 Hz (95.0% of expected 100 Hz)
WARNING: Logging rate is 95.0% of expected rate!
[2024-01-15 10:30:08.456] NaN Check: 2/475 samples are NaN (0.4%)
=== Final Performance Assessment ===
β Final logging rate is within acceptable range
β Final NaN rate is within acceptable range
python src/test_qtm_connection.pyTests QTM connectivity and basic communication.
python src/test_file_saving.pyTests file saving functionality without QTM connection.
python src/test_monitoring_events.pyTests monitoring event capture functionality.
The system continuously monitors:
- Logging Rate: Compares actual vs expected sampling rate
- Data Quality: Tracks NaN values and data integrity
- System Performance: Monitors QTM capture frequency
The system can retrieve the actual QTM capture frequency using multiple methods:
- Direct API Method:
await conn.get_capture_frequency() - XML Parameters: Parses QTM XML parameters for frequency
- Packet Timing: Estimates frequency from packet arrival times
- Real-Time Monitoring: Tracks actual logging rates vs expected rates
The system automatically detects frequency mismatches and provides warnings when:
- Configured sampling frequency > QTM capture frequency
- Configured sampling frequency < QTM capture frequency (downsampling)
- Soft Warning: < 90% of expected rate
- Hard Error: < 50% of expected rate
- NaN Warning: > 10% NaN values
Each monitoring check creates an event with:
- Timestamp
- Event type (rate_check, nan_check)
- Performance metrics
- Warnings/errors
Note: Monitoring events are captured in real-time and stored in the monitoring_logs.json file. The system uses a global variable to ensure events are not lost when the monitoring task is cancelled.
-
Connection Timeout
- Check QTM server is running
- Verify IP address in config
- Check network connectivity
- Ensure QTM allows remote connections
-
No Data Received
- Verify cameras are in preview mode
- Check tracking components are enabled
- Ensure target body exists in QTM
-
Low Sampling Rate
- Check QTM capture frequency vs configured rate
- Verify network bandwidth
- Check system resources
-
High NaN Rate
- Check marker visibility
- Verify camera calibration
- Check tracking settings
-
Empty Monitoring Events
- This issue has been fixed in recent updates
- Monitoring events are now captured using a global variable
- Events are preserved even when tasks are cancelled
- Check
monitoring_logs.jsonfor captured events
The system provides extensive debug information:
- Connection status and QTM version
- System parameters and available components
- Real-time monitoring with timestamps
- Performance statistics and warnings
- Comprehensive logs saved to files
qtm-rt # QTM real-time client
asyncio # Asynchronous I/O (Python standard library)
csv # CSV file handling (Python standard library)
json # JSON handling (Python standard library)
xml.etree.ElementTree # XML parsing (Python standard library)
pip install qtm-rt- Setup: Configure QTM server and tracking setup
- Configure: Adjust settings in
config/qtm_config.py - Test: Run connection and functionality tests
- Collect: Run main data collection script
- Analyze: Review monitoring logs and performance data
- Process: Use collected data for analysis
config/qtm_config.py: Main configuration settingsconfig/params.xml: QTM system parameters (auto-generated)
src/qtm_data_export.py: Main data collection script (supports UDP streaming)src/qtm_data_export_stream.py: Alternative data collection script (also supports UDP streaming)src/udp_receiver.py: Example UDP receiver for streamed datasrc/test_qtm_connection.py: Connection testingsrc/test_file_saving.py: File saving testssrc/test_monitoring_events.py: Monitoring tests
utils/qtm_handlers.py: Data processing functionsutils/qtm_settings.py: System information utilitiesutils/savers.py: File saving utilities
data/new.csv: Main tracking datadata/qtm_config.json: Configuration snapshotdata/qtm_system_info.json: System informationdata/qtm_parameters.xml: QTM parametersdata/monitoring_logs.json: Monitoring datadata/monitoring_summary.txt: Human-readable summary
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
For issues and questions:
- Check QTM documentation
- Their Python API repository
- Create an issue with detailed information
- Or contact me at: [email protected]