Flightmatrixbridge

Latest version: v1.7.0

Safety actively analyzes 685525 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 3

15.0

---

**`rotate_roll(self, value)`**

**Description:**
Rotates the drone to a specified roll angle.

**Args:**
- `value (float)`: The roll angle to rotate to.

**Returns:**
None

**Example:**
python
drone_controller.rotate_roll(30.0) Rotate drone to a roll angle of 30 degrees


---

**`rotate_pitch(self, value)`**

**Description:**
Rotates the drone to a specified pitch angle.

**Args:**
- `value (float)`: The pitch angle to rotate to.

**Returns:**
None

**Example:**
python
drone_controller.rotate_pitch(-15.0) Rotate drone to a pitch angle of -15 degrees


---

**`rotate_yaw(self, value)`**

**Description:**
Rotates the drone to a specified yaw angle.

**Args:**
- `value (float)`: The yaw angle to rotate to, in degrees.

**Returns:**
None

**Example:**
python
drone_controller.rotate_yaw(90.0) Rotate drone to a yaw angle of 90 degrees


---

**`ascend(self, value)`**

**Description:**
Ascends the drone by a specified value, increasing the current altitude.

**Args:**
- `value (float)`: The amount to increase the altitude.

**Returns:**
None

**Example:**
python
drone_controller.ascend(5.0) Ascend drone by 5 units


---

**`descend(self, value)`**

**Description:**
Descends the drone by a specified value, decreasing the current altitude.

**Args:**
- `value (float)`: The amount to decrease the altitude.

**Returns:**
None

**Example:**
python
drone_controller.descend(3.0) Descend drone by 3 units


---

**`move_forward(self, value)`**

**Description:**
Moves the drone forward by a specified value (positive y-axis).

**Args:**
- `value (float)`: The amount to move forward.

**Returns:**
None

**Example:**
python
drone_controller.move_forward(10.0) Move drone forward by 10 units


---

**`move_backward(self, value)`**

**Description:**
Moves the drone backward by a specified value (negative y-axis).

**Args:**
- `value (float)`: The amount to move backward.

**Returns:**
None

**Example:**
python
drone_controller.move_backward(8.0) Move drone backward by 8 units


---

**`stop_movement(self)`**

**Description:**
Stops all drone movements on the x, y, and z axes.

**Returns:**
None

**Example:**
python
drone_controller.stop_movement() Stop all drone movements


---

Class: `DataRecorder`
The `DataRecorder` class is designed to record various types of data from a drone or robotic system using the FlightMatrix framework. It can capture visual frames, z-depth images, segmentation frames, and sensor data, all of which are stored in a structured manner for later analysis.

---

**Attributes:**

- `bridge (FlightMatrixBridge)`: The bridge object used to interface with the drone or robot's systems.
- `base_dir (str)`: The base directory where all recorded data will be stored.
- `record_left_frame (bool)`: Flag indicating whether to record the left visual frame (default: `False`).
- `record_right_frame (bool)`: Flag indicating whether to record the right visual frame (default: `False`).
- `record_left_zdepth (bool)`: Flag indicating whether to record the left z-depth frame (default: `False`).
- `record_right_zdepth (bool)`: Flag indicating whether to record the right z-depth frame (default: `False`).
- `record_left_seg (bool)`: Flag indicating whether to record the left segmentation frame (default: `False`).
- `record_right_seg (bool)`: Flag indicating whether to record the right segmentation frame (default: `False`).
- `record_sensor_data (bool)`: Flag indicating whether to record sensor data (default: `False`).
- `sensor_data_interval (float)`: The interval at which sensor data is recorded (default: `0.1` seconds).
- `threads (list)`: List to hold the thread objects for recording data.
- `stop_event (Event)`: Event used to signal the threads to stop.

---

**Methods:**

**`__init__(self, bridge: FlightMatrixBridge, base_dir: str, record_left_frame: bool = False, record_right_frame: bool = False, record_left_zdepth: bool = False, record_right_zdepth: bool = False, record_left_seg: bool = False, record_right_seg: bool = False, record_sensor_data: bool = False, record_sensor_data_interval: float = 0.1)`**

**Description:**
Initializes the `DataRecorder` class with specified options for recording. It sets up directories for storing the recorded data based on user selections.

**Args:**
- `bridge (FlightMatrixBridge)`: An instance of `FlightMatrixBridge` used to interact with the drone/robot.
- `base_dir (str)`: The directory to store recorded files.
- `record_left_frame (bool)`: If `True`, records the left visual frame.
- `record_right_frame (bool)`: If `True`, records the right visual frame.
- `record_left_zdepth (bool)`: If `True`, records the left z-depth frame.
- `record_right_zdepth (bool)`: If `True`, records the right z-depth frame.
- `record_left_seg (bool)`: If `True`, records the left segmentation frame.
- `record_right_seg (bool)`: If `True`, records the right segmentation frame.
- `record_sensor_data (bool)`: If `True`, records sensor data.
- `record_sensor_data_interval (float)`: Time interval for recording sensor data in seconds.

---

**`record_frames(self)`**

**Description:**
Continuously captures and saves visual frames, z-depth frames, and segmentation frames until the recording is stopped. Each frame is saved with a timestamped filename.

---

**`record_sensors(self)`**

**Description:**
Records sensor data at specified intervals, saving the readings to a CSV file. It checks for errors in the sensor data and handles them appropriately.

---

**`start_recording(self)`**

**Description:**
Starts the recording process by launching separate threads for recording frames and sensor data, based on the user’s selections.

---

**`stop_recording(self)`**

**Description:**
Stops the recording process by signaling the threads to finish and waits for them to join back.

---

**Example Usage:**

python
if __name__ == "__main__":
bridge = FlightMatrixBridge()
recorder = DataRecorder(bridge, base_dir="Sample_Recordings",
record_left_frame=True,
record_right_frame=True,
record_left_zdepth=True,
record_right_zdepth=True,
record_left_seg=True,
record_right_seg=True,
record_sensor_data=True,
record_sensor_data_interval=1)

recorder.start_recording()

time.sleep(10) Record for 10 seconds

recorder.stop_recording()

10.5

---

**`move_y(self, value)`**

**Description:**
Moves the drone to a specified y-coordinate (left or right).

**Args:**
- `value (float)`: The y-coordinate to move to.

**Returns:**
None

**Example:**
python

5.2

---

**`move_z(self, value)`**

**Description:**
Moves the drone to a specified z-coordinate (up or down).

**Args:**
- `value (float)`: The z-coordinate to move to.

**Returns:**
None

**Example:**
python

1.7.0

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)

1.6.3

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)

1.5.3

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 system uses the following axis system:
- Y-axis: Forward
- -Y-axis: Backward
- -X-axis: Left
- X-axis: Right
- -Z-axis: Bottom
- Z-axis: Top

Rotation values are in degrees and are labled roll, pitch, and yaw.
- X-axis: Roll
- Y-axis: Pitch
- Z-axis: Yaw

The API and the software system follows this axis system unless otherwise specified.

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)

Page 1 of 3

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.