FlightMatrix Bridge • API for Flight Matrix Simulation Software
![FlightMatrix Bridge Cover](https://github.com/Kawai-Senpai/Py-FlightMatrix-Bridge/blob/0d434625dc45a12744eacaa4df21de29f0072612/Assets/FlightMatrix%20Cover.png)
**FlightMatrix Bridge** is a Python-based API designed for controlling and fetching information, frames, and other data from Flight Matrix. This library enables efficient and real-time communication between various processes in a system, primarily designed for interfacing flight simulators, UAV systems, or other robotics platforms. It utilizes the `multiprocessing.shared_memory` module to share data such as frames, sensor data, and movement commands across multiple processes.
Download the software from [Flight Matrix](https://gamejolt.com/games/flightmatrix/933049).
The project is structured around two primary files:
- **`bridge.py`**: Implements the core functionalities of shared memory management, handling frames, sensor data, movement commands, and logging.
- **`utilities.py`**: Provides utility functions to handle timestamps and convert them into human-readable formats. It also includes a `DroneController` class for controlling drones.
Table of Contents
1. [Introduction](introduction)
2. [Features](features)
3. [Controls](controls)
4. [Installation](installation)
5. [Usage](usage)
1. [Initializing the FlightMatrixBridge](initializing-the-flightmatrixbridge)
2. [Units](units)
3. [Axis System](axis-system)
4. [Logging Functions](logging-functions)
5. [Flight Matrix API](flight-matrix-api)
- [Getting Frame Data](getting-frame-data)
- [Fetching Sensor Data](fetching-sensor-data)
- [Sending Movement Commands](sending-movement-commands)
6. [Resolution & Noise Configuration](resolution--noise-configuration)
7. [Timestamp Utilities](timestamp-utilities)
6. [Detailed Functionality](detailed-functionality)
- [Initialization](initialization)
- [Shared Memory Management](shared-memory-management)
- [Frame Handling](frame-handling)
- [Sensor Data Handling](sensor-data-handling)
- [Movement Command Management](movement-command-management)
- [Logging](logging)
- [Noise Application](noise-application)
7. [Examples](examples)
1. [Example 1: Fetching Frames](example-1-fetching-frames)
2. [Example 2: Sending Movement Commands](example-2-sending-movement-commands)
3. [Example 3: Fetching Sensor Data](example-3-fetching-sensor-data)
4. [Example 4: Drone Controller](example-4-drone-controller)
5. [Example 5: Data Recorder](example-5-data-recorder)
8. [Documentation](documentation)
1. [Class: `FlightMatrixBridge`](class-flightmatrixbridge)
- [Attributes](attributes)
- [Methods](methods)
2. [Utilities](utilities)
1. [`timestamp2string`](timestamp2stringtimestamp)
2. [`timestamp2datetime`](timestamp2datetimetimestamp)
3. [`cartesian_to_gps`](cartesian_to_gps)
3. [Class: `DroneController`](class-dronecontroller)
- [Attributes](attributes)
- [Methods](methods)
4. [Class: `DataRecorder`](class-datarecorder)
- [Attributes](attributes)
- [Methods](methods)
5. [Class: `DataStreamer`](data-streaming-with-datastreamer)
9. [Credits](credits)
Introduction
![FlightMatrix Bridge](https://github.com/Kawai-Senpai/Py-FlightMatrix-Bridge/blob/020882b8df9d9452bcb43664452dadc9df753558/Assets/Screenshot%20(4).png)
The **FlightMatrixBridge** system is designed to bridge multiple processes that need to access shared memory for real-time communication. The typical use cases include flight simulators, robotics platforms, autonomous vehicles, and any application where sharing large datasets like frames or sensor readings between processes is essential.
This package provides:
- An interface to retrieve frames and sensor data from shared memory.
- The ability to send movement commands to be processed by another service.
- Real-time noise application to sensor data.
- Utilities to handle timestamps.
Features
![Controllable Features](https://github.com/Kawai-Senpai/Py-FlightMatrix-Bridge/blob/020882b8df9d9452bcb43664452dadc9df753558/Assets/Screenshot%20(3).png)
*Controllable Features*
![Simulation Environments](https://github.com/Kawai-Senpai/Py-FlightMatrix-Bridge/blob/020882b8df9d9452bcb43664452dadc9df753558/Assets/Screenshot%20(1).png)
*Simulation Environments*
![Graphics Presets](https://github.com/Kawai-Senpai/Py-FlightMatrix-Bridge/blob/020882b8df9d9452bcb43664452dadc9df753558/Assets/Screenshot%20(2).png)
*Graphics Presets*
The **FlightMatrix** software offers a range of features to facilitate real-time communication and data sharing between processes. Key features include:
- **Dual Camera Support**: Flight Matrix is equipped with two cameras—left and right—that operate simultaneously. Each camera is capable of outputting high-quality RGB images, depth passes (z-depth), and segmentation maps, providing a comprehensive view of your simulated environment.
- **Independent Camera Control**: Each camera can be controlled independently, allowing you to position them relative to the drone with precision. Adjust the x, y, z coordinates, as well as yaw, pitch, and roll to achieve the desired perspective.
- **Variable Speed Control**: Control the speed of each axis and the rotation speed of the cameras, ensuring you can fine-tune the responsiveness to suit your simulation needs.
- **Customizable Output**: Turn on and off various output maps as required. Control the resolution of the output frames and adjust the Field of View (FOV) to enhance your visual experience.
- **Graphics Presets**: Choose from various graphics presets tailored for different simulation scenarios. Optimize the software’s performance based on your hardware capabilities and desired visual fidelity.
- **Diverse Simulation Environments**: Flight Matrix features a range of realistic maps, including architectural, natural, and ultra-realistic environments for authentic simulations. Navigate through intricate landscapes and urban settings as if you were flying in the real world.
- **Human-like AI Characters**: Enhance your simulations with beautifully animated AI characters that simulate real crowds and human interactions. Observe how they behave and interact within the environment, adding depth to your scenarios.
The **FlightMatrixBridge** API provides a simple and efficient way to interact with the Flight Matrix simulation software, enabling you to access frames, sensor data, and movement commands in real-time. The API is designed to be easy to use and flexible, allowing you to integrate it into your projects seamlessly.
- **Frame Management**: Retrieve left/right frames, z-depth maps, and segmentation frames in real-time.
- **Sensor Data Access**: Retrieve real-time sensor data such as location, orientation, velocity, acceleration, magnetometer readings, and more.
- **Movement Command Handling**: Send movement commands (position and orientation) for external systems to process.
- **Noise Simulation**: Add configurable levels of noise to sensor data for testing robustness.
- **Flexible Resolution Handling**: Easily set and adjust resolution for frames.
- **Timestamp Management**: Convert timestamps into human-readable formats and handle system-wide timing data.
Controls
| Action | Keyboard/Mouse |
|---------------------------------|-------------------------|
| Move Forward | W |
| Move Backward | S |
| Move Left | A |
| Move Right | D |
| Ascend | Space Bar |
| Descend | Left Shift |
| Rotate (Yaw, Pitch, Roll) | Arrow Keys |
| Move Left/Right | Q / E |
| Pause | Escape / Pause / P |
| Exit | Escape / Pause / P |
| Spawn Human AI Character | H |
| Return to Starting Location | R |
Installation
Download the software from [Flight Matrix](https://gamejolt.com/games/flightmatrix/933049).
To install the **FlightMatrixBridge (API)**, simply use pip:
bash
pip install flightmatrixbridge
Make sure your system has Python 3.8+ and supports the `multiprocessing.shared_memory` module.
Usage
Initializing the FlightMatrixBridge
To initialize and start using the **FlightMatrixBridge**, create an instance of the `FlightMatrixBridge` class and specify the resolution of the frames you want to handle:
python
from flightmatrix.bridge import FlightMatrixBridge
bridge = FlightMatrixBridge(resolution=(1226, 370), noise_level=0.01, apply_noise=False) Set frame resolution (width, height), noise level, and noise application
Units
The system uses the following units for sensor data:
- Length: centimeters (cm)
- Angular values: degrees (°)
- Angular velocity/ gyroscope readings: degrees per second (°/s)
- Acceleration/ accelerometer readings: centimeters per second squared (cm/s²)
- Magnetometer readings: unit vector
- LiDAR data: centimeters (cm)
- Collision detection: centimeters (cm)
- Timestamp: milliseconds (ms)
Axis System
The axis system differs slightly between the software interface and the API. Below is a detailed explanation for both.
Inside the Software
When adjusting camera positions or configuring movement multipliers within the software, the following axis system is used:
| Direction | Axis |
|-----------|------|
| Forward | Y |
| Backward | -Y |
| Left | -X |
| Right | X |
| Up | Z |
| Down | -Z |
Rotation values are in degrees and are labeled roll, pitch, and yaw:
| Rotation | Axis |
|----------|------|
| Roll | X |
| Pitch | Y |
| Yaw | Z |
**Axis Orientation:**
Z (Up)
|
|
|
O------ X (Right)
/
/
-Y (Backward)
In the API
The API uses a different axis system for movement commands and sensor data:
| Direction | Axis |
|-----------|------|
| Forward | X |
| Backward | -X |
| Left | -Y |
| Right | X |
| Up | Z |
| Down | -Z |
Rotation values are in degrees and are labeled roll, pitch, and yaw:
| Rotation | Axis |
|----------|------|
| Roll | X |
| Pitch | Y |
| Yaw | Z |
**Axis Orientation:**
Z (Up)
|
|
|
O------ Y (Right)
/
/
-X (Backward)
Logging Functions
You can configure logging based on your needs. The logging system provides flexibility to output logs either to the console or a file, and supports different log levels (`DEBUG`, `INFO`, `WARNING`, `ERROR`, `SUCCESS`).
python
Set log level to 'DEBUG'
bridge.set_log_level('DEBUG')
Enable logging to file
bridge.set_write_to_file(True)
Flight Matrix API
The core functionalities include retrieving frames, fetching sensor data, and sending movement commands.
Getting Frame Data
You can retrieve frames from both the left and right cameras. You also have access to depth and segmentation data.
python
Retrieve right camera frame
right_frame = bridge.get_right_frame()
Retrieve left camera frame
left_frame = bridge.get_left_frame()
Retrieve z-depth for the right camera
right_zdepth = bridge.get_right_zdepth()
Retrieve segmentation frame for the left camera
left_seg = bridge.get_left_seg()
Fetching Sensor Data
The bridge allows real-time access to sensor data from the shared memory block. This data includes location, orientation, velocity, acceleration, and more.
python
sensor_data = bridge.get_sensor_data()
print(sensor_data)
Sending Movement Commands
To send movement commands (position and orientation) to a system, use the `send_movement_command` method.
python
Send movement command (x, y, z, roll, pitch, yaw)