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 飞行控制
ctrl["<b>ctrl</b><br>Flight Controller Communication · State Acquisition<br>Coordinate Transformation · ROS Integration"]
end
subgraph 网络通信
comm["<b>comm</b><br>Cluster Networking Simulation · Multi-Drone Broadcasting<br>Redis Middleware"]
end
subgraph 视觉传感
vision["<b>vision</b><br>Image Acquisition · Camera Control<br>Point Cloud Visualization · ROS Publishing"]
end
subgraph 引擎控制
ue["<b>ue</b><br>3D Interaction · Map Services<br>Quadruped Robot Initialization"]
end
subgraph 集群控制
swarm["<b>swarm</b><br>Multi-Drone Management · Distributed Simulation<br>Crazyflie · ADB Debugging"]
end
subgraph 健康评估
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¶
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-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)
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)