fix:新增例程

This commit is contained in:
2025-07-25 17:04:14 +08:00
parent 891627bc06
commit 78481c265e
27 changed files with 980 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import PX4MavCtrlV4ROS as PX4MavCtrl
import time
# 创建一个ROS控制实例针对飞机1
mav = PX4MavCtrl.PX4MavCtrler(CopterID=1)
time.sleep(1)
print('进入offboard并解锁')
mav.initOffboard()
time.sleep(1)
# 飞机起飞到0.1米前0.8米高
print('发送起飞命令')
mav.SendPosNED(0.1,0,-0.8)
time.sleep(10)
print('PosE',mav.uavPosNED)
print('VelE',mav.uavVelNED)
print('Euler',mav.uavAngEular)
print('Quaternion',mav.uavAngQuatern)
print('Rate',mav.uavAngRate)
time.sleep(1)
print('Start control.')
# 下面开始你的控制算法
# mav.SendPosNED(x,y,z,yaw) 发送期望位置点NED地球坐标系
# mav.SendVelNED(vx,vy,vz,yawrate) 发送速度NED地球坐标系
# mav.SendVelFRD(vx,vy,vz,yawrate) 发送速度FRD机体坐标系通常而言设定vx和yawrate即可前进速度和偏航速度。
# mav.SendPosVelNED(PosE=[0,0,0],VelE=[0,0,0],yaw,yawrate) 同时控制飞机位置和速度
# 下面仅展示使用SendVelFRD控制的例子会撞墙为正常现象
print('开始速度控制')
# 向前0.1m/s飞并缓慢调转方向
mav.SendVelFRD(0.1,0,0,0.05)

View File

@@ -0,0 +1,16 @@
@echo off
wsl -d RflySim-20.04 -e bash -lic "echo Current version is ROS$ROS_VERSION"
SET /P ROSVer=New ROS Version 1 or 2:
if %ROSVer% EQU 1 (
ECHO Switch to ROS1
wsl -d RflySim-20.04 ~/ros_switch.sh 1
) ELSE (
ECHO Switch to ROS2
wsl -d RflySim-20.04 ~/ros_switch.sh 2
)
wsl --shutdown
ECHO Successful.
ECHO Press any key to exit.
pause

View File

@@ -0,0 +1,157 @@
@ECHO OFF
REM Run script as administrator
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c ""%~s0"" ::","","runas",1)(window.close)&&exit
REM The text start with 'REM' is annotation, the following options are corresponding to Options on CopterSim
REM This script use UDPSIMMODE=2 for MAVLink FULL control
REM Set the path of the RflySim tools
if not defined PSP_PATH (
SET PSP_PATH=C:\PX4PSP
SET PSP_PATH_LINUX=/mnt/c/PX4PSP
)
REM Start index of vehicle number (should larger than 0)
REM This option is useful for simulation with multi-computers
SET /a START_INDEX=1
REM Total vehicle Number to auto arrange position
REM SET /a TOTOAL_COPTER=8
REM Set the vehicleType/ClassID of vehicle 3D display in RflySim3D
SET /a CLASS_3D_ID=-1
REM Set use DLL model name or not, use number index or name string
REM This option is useful for simulation with other types of vehicles instead of multicopters
set DLLModel=0
REM Check if DLLModel is a name string, if yes, copy the DLL file to CopterSim folder
SET /A DLLModelVal=DLLModel
if %DLLModelVal% NEQ %DLLModel% (
REM Copy the latest dll file to CopterSim folder
copy /Y "%~dp0"\%DLLModel%.dll %PSP_PATH%\CopterSim\external\model\%DLLModel%.dll
)
REM Set the simulation mode on CopterSim, use number index or name string
REM e.g., SimMode=2 equals to SimMode=PX4_SITL_RFLY
set SimMode=2
REM Set the vehicle-model (airframe) of PX4 SITL simulation, the default airframe is a quadcopter: iris
REM Check folder Firmware\ROMFS\px4fmu_common\init.d-posix for supported airframes (Note: You can also create your airframe file here)
REM E.g., fixed-wing aircraft: PX4SitlFrame=plane; small cars: PX4SitlFrame=rover
set PX4SitlFrame=iris
REM Set the map, use index or name of the map on CopterSim
REM e.g., UE4_MAP=1 equals to UE4_MAP=Grasslands
SET UE4_MAP=Grasslands
REM Set the origin x,y position (m) and yaw angle (degree) at the map
SET /a ORIGIN_POS_X=0
SET /a ORIGIN_POS_Y=0
SET /a ORIGIN_YAW=0
REM Set the interval between two vehicle, unit:m
SET /a VEHICLE_INTERVAL=2
REM Set broadcast to other computer; IS_BROADCAST=0: only this computer, IS_BROADCAST=1: broadcast;
REM or use IP address to increase speed, e.g., IS_BROADCAST=192.168.3.1
REM Note: in IP mode, IS_BROADCAST=0 equals to IS_BROADCAST=127.0.0.1, IS_BROADCAST=1 equals to IS_BROADCAST=255.255.255.255
REM You can also use a IP list with seperator "," or ";" to specify IPs to send, e.g., 127.0.0.1,192.168.1.4,192.168.1.5
SET IS_BROADCAST=0
REM Set UDP data mode; 0: UDP_FULL, 1:UDP_Simple, 2: Mavlink_Full, 3: Mavlink_simple. input number or string
REM 4:Mavlink_NoSend, 5:Mavlink_NoGPS, 6:Mavlink_Vision (NoGPS and set PX4 EKF)
SET UDPSIMMODE=2
:Top
ECHO.
ECHO ---------------------------------------
REM Max vehicle number 50
SET /a MAX_VEHICLE=50
SET /a VehicleNum=1
SET /A VehicleTotalNum=%VehicleNum% + %START_INDEX% - 1
if not defined TOTOAL_COPTER (
SET /A TOTOAL_COPTER=%VehicleTotalNum%
)
set /a sqrtNum=1
set /a squareNum=1
:loopSqrt
set /a squareNum=%sqrtNum% * %sqrtNum%
if %squareNum% EQU %TOTOAL_COPTER% (
goto loopSqrtEnd
)
if %squareNum% GTR %TOTOAL_COPTER% (
goto loopSqrtEnd
)
set /a sqrtNum=%sqrtNum%+1
goto loopSqrt
:loopSqrtEnd
REM QGCPath
tasklist|find /i "QGroundControl.exe" || start %PSP_PATH%\QGroundControl\QGroundControl.exe -noComPix
ECHO Start QGroundControl
REM UE4Path
cd /d %PSP_PATH%\RflySim3D
tasklist|find /i "RflySim3D.exe" || start %PSP_PATH%\RflySim3D\RflySim3D.exe
choice /t 5 /d y /n >nul
tasklist|find /i "CopterSim.exe" && taskkill /im "CopterSim.exe"
ECHO Kill all CopterSims
REM CptSmPath
cd /d %PSP_PATH%\CopterSim
set /a cntr=%START_INDEX%
set /a endNum=%VehicleTotalNum%+1
:loopBegin
set /a PosXX=((%cntr%-1) / %sqrtNum%)*%VEHICLE_INTERVAL% + %ORIGIN_POS_X%
set /a PosYY=((%cntr%-1) %% %sqrtNum%)*%VEHICLE_INTERVAL% + %ORIGIN_POS_Y%
start /realtime CopterSim.exe 1 %cntr% %CLASS_3D_ID% %DLLModel% %SimMode% %UE4_MAP% %IS_BROADCAST% %PosXX% %PosYY% %ORIGIN_YAW% 1 %UDPSIMMODE%
choice /t 1 /d y /n >nul
set /a cntr=%cntr%+1
if %cntr% EQU %endNum% goto loopEnd
goto loopBegin
:loopEnd
REM Set ToolChainType 1:Win10WSL 3:Cygwin
SET /a ToolChainType=1
if "%IS_BROADCAST%" == "0" (
SET IS_BROADCAST=0
) else (
SET IS_BROADCAST=1
)
SET WINDOWSPATH=%PATH%
if %ToolChainType% EQU 1 (
wsl -d RflySim-20.04 -e bash -lic "echo Starting PX4 Build; cd %PSP_PATH_LINUX%/Firmware; ./BkFile/EnvOri.sh; make px4_sitl_default; ./Tools/sitl_multiple_run_rfly.sh %VehicleNum% %START_INDEX% %PX4SitlFrame%;~/mavros_run.sh %START_INDEX%,%VehicleNum%; pkill -x px4 || true"
wsl --shutdown
) else (
REM CYGPath
cd /d %PSP_PATH%\CygwinToolchain
CALL setPX4Env.bat
bash -l -i -c 'echo Starting SITL SIMULATION; cd %PSP_PATH_LINUX%/Firmware; ./BkFile/EnvOri.sh; pwd; make px4_sitl_default; ./Tools/sitl_multiple_run_rfly.sh %VehicleNum% %START_INDEX% %PX4SitlFrame%; pkill -x px4 || true;'
)
SET PATH=%WINDOWSPATH%
REM kill all applications when press a key
tasklist|find /i "CopterSim.exe" && taskkill /im "CopterSim.exe"
tasklist|find /i "QGroundControl.exe" && taskkill /f /im "QGroundControl.exe"
tasklist|find /i "RflySim3D.exe" && taskkill /f /im "RflySim3D.exe"
ECHO Start End.

View File

@@ -0,0 +1,12 @@
@echo off
REM Set the path of the RflySim tools
if not defined PSP_PATH (
SET PSP_PATH=C:\PX4PSP
SET PSP_PATH_LINUX=/mnt/c/PX4PSP
)
cd /d %PSP_PATH%\VcXsrv
tasklist|find /i "vcxsrv.exe" >nul || Xlaunch.exe -run config1.xlaunch
cd /d %~dp0
wsl -d RflySim-20.04