Skip to content

Python SDK Overview

RflySim’s Python control interface is uniformly integrated into RflySimSDK, located under [Installation Directory]\RflySimAPIs\RflySimSDK\. This SDK provides comprehensive capabilities for drone simulation control, visual sensing, swarm collaboration, and health management development.


Module Architecture

graph TB
    SDK["<b>RflySimSDK</b>"]

    subgraph Flight Control
        ctrl["<b>ctrl</b><br>Flight Controller Communication · State Acquisition<br>Coordinate Transformation · ROS Integration"]
    end

    subgraph Network Communication
        comm["<b>comm</b><br>Networked Simulation · Multi-Drone Broadcasting<br>Redis Middleware"]
    end

    subgraph Visual Sensing
        vision["<b>vision</b><br>Image Acquisition · Camera Control<br>Point Cloud Visualization · ROS Publishing"]
    end

    subgraph Engine Control
        ue["<b>ue</b><br>3D Interaction · Map Services<br>Quadruped Robot Initialization"]
    end

    subgraph Swarm Control
        swarm["<b>swarm</b><br>Multi-Drone Management · Distributed Simulation<br>Crazyflie · ADB Debugging"]
    end

    subgraph Health Assessment
        phm["<b>phm</b><br>Automated Testing · Fault Injection<br>Data Logging · Safety Evaluation"]
    end

    SDK --> ctrl
    SDK --> comm
    SDK --> vision
    SDK --> ue
    SDK --> swarm
    SDK --> phm

---

## Core Module Quick Reference

### [:octicons-code-16: ctrl — Flight Control](ctrl/index.md)

Core MAVLink communication with PX4/APM flight controllers, supporting single and multi-vehicle control.

| Interface File | Core Class | Function |
|----------|--------|------|
| [PX4MavCtrlV4](ctrl/px4mav.md) | `PX4MavCtrler` | MAVLink control core: arm/takeoff/land/Offboard/waypoint |
| [PX4MavCtrlV4ROS](ctrl/px4mav-ros.md) | `PX4MavCtrlerROS` | ROS-integrated PX4 controller |
| [DllSimCtrlAPI](ctrl/dllsim.md) | `DllSimModel` | CopterSim DLL integrated model interaction |
| [DllSimCtrlAPIROS](ctrl/dllsim-ros.md) | `DllSimModelROS` | DLL model ROS integration |
| [api](ctrl/api.md) | `RflyCtrl` | High-level simplified API |
| [ReqCopterSim](ctrl/reqcopter.md) | `ReqCopterSim` | CopterSim simulation initialization request |
| [EarthModel](ctrl/earth.md) | `EarthModel` | WGS84/UTM/NED coordinate transformation |
| [IpManager](ctrl/ipmgr.md) | `IpManager` | IP address allocation and management |
| [RflyRosStart](ctrl/rosstart.md) | `RflyRosStart` | Automatic ROS environment startup |

---

### [:octicons-broadcast-16: comm — Network Communication](comm/index.md)

Cluster network communication simulation, supporting UDP broadcast/unicast and Redis message middleware.

| Interface File | Core Class | Function |
|----------|--------|------|
| [NetSimAPIV4](comm/netsim.md) | `NetSimAPI` | Custom network simulation |
| [NetUavAPI](comm/netuav.md) | `NetUavAPI` | Multi-UAV network communication |
| [RedisUtils](comm/redis.md) | `RedisUtils` | Redis publish-subscribe utility |

---

### [:octicons-eye-16: vision — Vision Sensing](vision/index.md)

Vision sensor data acquisition and control, supporting RGB images, depth maps, point clouds, and LiDAR.

| Interface File | Core Class | Function |
|----------|--------|------|
| [VisionCaptureApi](vision/viscap.md) | `VisionCaptureApi` | Image/depth/point cloud data acquisition |
| [CameraCtrlApi](vision/cameractrl.md) | `CameraCtrlApi` | Camera parameter control (resolution/FOV/pose) |
| [ScreenCapApiV4](vision/screencap.md) | `ScreenCapApiV4` | Screen capture acquisition |
| [Open3DShow](vision/open3d.md) | `Open3DShow` | Real-time Open3D point cloud visualization |
| [RflyRosCtrlApi](vision/rosctrl.md) | `RflyRosCtrlApi` | ROS vision data publishing and control |

---

### [:octicons-device-desktop-16: ue — Engine Control](ue/index.md)

Interaction and control with RflySim3D/RflySimUE5 3D engines.

| Interface File | Core Class | Function |
|----------|--------|------|
| [UE4CtrlAPI](ue/ue4ctrl.md) | `UE4CtrlAPI` | Engine console commands, scene interaction |
| [UEMapServe](ue/uemap.md) | `UEMapServe` | Map loading and scene switching service |
| [RobotDogStart](ue/dogstart.md) | `RobotDogStart` | Robot dog simulation startup |

---

### [:octicons-people-16: swarm — Swarm Control](swarm/index.md)

Large-scale multi-vehicle swarm management, distributed simulation, and heterogeneous platform adaptation.

| Interface File | Core Class | Function |
|----------|--------|------|
| [VehicleApi](swarm/vehicle.md) | `VehicleApi` | Single-vehicle state subscription and control encapsulation |
| [distSimCtrlAPI](swarm/distsim.md) | `DistSimCtrlAPI` | Distributed simulation node control |
| [Crazyflie](swarm/crazyflie.md) | `Crazyflie` | Crazyflie micro-drone adaptation |
| [CrazySwarm](swarm/crazyswarm.md) | `CrazySwarm` | CrazySwarm swarm framework |
| [MavRflyShell](swarm/rflyshell.md) | `MavRflyShell` | MAVLink command-line tool |
| [RflyADBLib](swarm/adblib.md) | `RflyADBLib` | ADB remote debugging library |
| [RJ45_px6x](swarm/rj45px6x.md) | `RJ45_px6x` | Ethernet-based flight controller communication (Pixhawk 6x) |

---

### [:octicons-shield-check-16: phm — Health Assessment](phm/index.md)

Automated testing, fault injection, flight data logging, and safety evaluation.

| Interface File | Core Class | Function |
|----------------|------------|----------|
| [AutoMavCtrl](phm/mavctrl.md) | `AutoMavCtrl` | Automated test process management |
| [AutoMavDB](phm/mavdb.md) | `AutoMavDB` | Test case database management |
| [AutoMavCmd](phm/mavcmd.md) | `AutoMavCmd` | Standardized control sequence parsing |
| [Ass](phm/ass.md) | `Ass` | Safety and reliability assessment |
| [DeBug](phm/debug.md) | `DeBug` | Debugging assistance tool |
| [QGCCtrlAPI](phm/qgcctrl.md) | `QGCCtrlAPI` | QGC ground station control interface |
| [AutoREG](phm/autoreg.md) | `AutoREG` | Automatic registration and discovery |
| [AutoVisConf](phm/visconf.md) | `AutoVisConf` | Visual configuration automation |
| [MavDataRec](phm/datarec.md) | `MavDataRec` | MAVLink flight data recording |

---

## Quick Start

### Minimal Example: Single-Vehicle Takeoff and Landing

```python
from RflySimSDK.ctrl.PX4MavCtrlV4 import PX4MavCtrler
import time

# Create control instance (connect to vehicle ID=1)
mav = PX4MavCtrler(ID=1)

# Send global start signal
mav.sendStartMsg(copterID=-1)
mav.waitForStartMsg()

# Arm → Takeoff → Hover → Land
mav.SendMavArm(True)
mav.SendMavTakeoff(5)   # Take off to 5m
time.sleep(10)
mav.SendMavLand()

Multi-Machine Cluster Example

from RflySimSDK.ctrl.PX4MavCtrlV4 import PX4MavCtrler

# Create control instances for 3 drones
mavs = [PX4MavCtrler(ID=i+1) for i in range(3)]

# Global startup
mavs[0].sendStartMsg(copterID=-1)
for m in mavs:
    m.waitForStartMsg()

# Individual takeoff
for m in mavs:
    m.SendMavArm(True)
    m.SendMavTakeoff(5)

Visual Sensor Image Capture

from RflySimSDK.vision.VisionCaptureApi import VisionCaptureApi
import cv2

# Initialize visual capture
vis = VisionCaptureApi()
vis.jsonLoad("Config.json")

# Retrieve image
img = vis.getImg(0)
cv2.imshow("Camera", img)
cv2.waitKey(0)

Environment Configuration

The SDK is pre-configured in the Python environment bundled with RflySim and can be used directly via import.

For use in a custom Python environment:

# Method 1: Run the registration script
python RflySimSDK/ReLabPath.py

# Method 2: Manually set environment variables
set PYTHONPATH=%PSP_PATH%\RflySimAPIs;%PYTHONPATH%

# Method 3: Install dependencies via pip
pip install pymavlink numpy opencv-python

Feature Overview

Feature Description
Full-Stack Control Complete flight control chain from low-level MAVLink to high-level APIs
Multiple Communication Modes Four connection methods: UDP, Serial, Direct, and Redis
Real-Time Simulation Supports Hardware-in-the-Loop (HITL) and Software-in-the-Loop (SITL) simulations
Swarm Coordination Supports large-scale swarm control of hundreds of drones
Visual Perception Captures RGB images, depth maps, LiDAR point clouds, and IMU data
Fault Injection Simulates motor/sensor faults and enables automated batch testing
ROS Integration Native support for ROS1/ROS2 topic publishing and subscribing
Cross-Platform Compatibility Compatible with Windows, Linux (WSL/Docker) environments