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

RflySimSDK Module Structure


Core Module Quick Reference

ctrl — Flight Control

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

Interface File Core Class Function
PX4MavCtrlV4 PX4MavCtrler MAVLink control core: arm/takeoff/land/Offboard/waypoint
PX4MavCtrlV4ROS PX4MavCtrlerROS ROS-integrated PX4 controller
DllSimCtrlAPI DllSimModel CopterSim DLL integrated model interaction
DllSimCtrlAPIROS DllSimModelROS DLL model ROS integration
api RflyCtrl High-level simplified API
ReqCopterSim ReqCopterSim CopterSim simulation initialization request
EarthModel EarthModel WGS84/UTM/NED coordinate transformation
IpManager IpManager IP address allocation and management
RflyRosStart RflyRosStart Automatic ROS environment startup

comm — Network Communication

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

Interface File Core Class Function
NetSimAPIV4 NetSimAPI Custom cluster networking simulation
NetUavAPI NetUavAPI Multi-UAV cluster networking communication
RedisUtils RedisUtils Redis publish-subscribe utility

vision — Vision Sensing

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

Interface File Core Class Function
VisionCaptureApi VisionCaptureApi Image/depth/point cloud data acquisition
CameraCtrlApi CameraCtrlApi Camera parameter control (resolution/FOV/pose)
ScreenCapApiV4 ScreenCapApiV4 Screen capture acquisition
Open3DShow Open3DShow Real-time Open3D point cloud visualization
RflyRosCtrlApi RflyRosCtrlApi ROS vision data publishing and control

ue — Engine Control

Interaction and control with RflySim3D/RflySimUE5 3D engines.

Interface File Core Class Function
UE4CtrlAPI UE4CtrlAPI Engine console commands, scene interaction
UEMapServe UEMapServe Map loading and scene switching service
RobotDogStart RobotDogStart Robot dog simulation startup

swarm — Swarm Control

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

Interface File Core Class Function
VehicleApi VehicleApi Single-vehicle state subscription and control encapsulation
distSimCtrlAPI DistSimCtrlAPI Distributed simulation node control
Crazyflie Crazyflie Crazyflie micro-drone adaptation
CrazySwarm CrazySwarm CrazySwarm swarm framework
MavRflyShell MavRflyShell MAVLink command-line tool
RflyADBLib RflyADBLib ADB remote debugging library
RJ45_px6x RJ45_px6x Ethernet-based flight controller communication (Pixhawk 6x)

phm — Health Assessment

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

Interface File Core Class Function
AutoMavCtrl AutoMavCtrl Automated test process management
AutoMavDB AutoMavDB Test case database management
AutoMavCmd AutoMavCmd Standardized control sequence parsing
Ass Ass Safety and reliability assessment
DeBug DeBug Debugging assistance tool
QGCCtrlAPI QGCCtrlAPI QGC ground station control interface
AutoREG AutoREG Automatic registration and discovery
AutoVisConf AutoVisConf Visual configuration automation
MavDataRec MavDataRec MAVLink flight data recording

Quick Start

Minimal Example: Single-Vehicle Takeoff and Landing

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-Vehicle 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)

Vision 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 RflySim's built-in Python environment and can be directly imported.

To 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 Highlights

Feature Description
Full-stack Control Complete flight control chain from low-level MAVLink to high-level API
Multiple Communication Modes Four connection methods: UDP / Serial / Direct / Redis
Real-time Simulation Supports HITL hardware-in-the-loop and SITL software-in-the-loop simulation
Swarm Collaboration Supports large-scale swarm control of hundreds of drones
Visual Perception RGB images, depth maps, LiDAR point clouds, IMU data acquisition
Fault Injection Motor/sensor fault simulation and automated batch testing
ROS Integration Native support for ROS1/ROS2 Topic publishing and subscription
Cross-platform Compatible with Windows, Linux (WSL/Docker) environments