fix:新增例程
This commit is contained in:
46
基础智能/e7.相机取图实验/Config.json
Normal file
46
基础智能/e7.相机取图实验/Config.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"VisionSensors":[
|
||||
{
|
||||
"SeqID":0,
|
||||
"TypeID":1,
|
||||
"TargetCopter":1,
|
||||
"TargetMountType":0,
|
||||
"DataWidth":640,
|
||||
"DataHeight":480,
|
||||
"DataCheckFreq":30,
|
||||
"SendProtocol":[0,127,0,0,1,9999,0,0],
|
||||
"CameraFOV":90,
|
||||
"SensorPosXYZ":[0.3,-0.15,0],
|
||||
"SensorAngEular":[0,0,0],
|
||||
"otherParams":[0,0,0,0,0,0,0,0]
|
||||
},
|
||||
{
|
||||
"SeqID":1,
|
||||
"TypeID":3,
|
||||
"TargetCopter":1,
|
||||
"TargetMountType":0,
|
||||
"DataWidth":640,
|
||||
"DataHeight":480,
|
||||
"DataCheckFreq":30,
|
||||
"SendProtocol":[0,127,0,0,1,1000,0,0],
|
||||
"CameraFOV":90,
|
||||
"SensorPosXYZ":[0.3,0.15,0],
|
||||
"SensorAngEular":[0,0,0],
|
||||
"otherParams":[0,0,0,0,0,0,0,0]
|
||||
},
|
||||
{
|
||||
"SeqID":3,
|
||||
"TypeID":2,
|
||||
"TargetCopter":1,
|
||||
"TargetMountType":0,
|
||||
"DataWidth":640,
|
||||
"DataHeight":480,
|
||||
"DataCheckFreq":30,
|
||||
"SendProtocol":[0,127,0,0,1,1000,0,0],
|
||||
"CameraFOV":90,
|
||||
"SensorPosXYZ":[0.3,0,0],
|
||||
"SensorAngEular":[0,0,0],
|
||||
"otherParams":[0,0,0,0,0,0,0,0]
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
基础智能/e7.相机取图实验/Readme.pdf
Normal file
BIN
基础智能/e7.相机取图实验/Readme.pdf
Normal file
Binary file not shown.
BIN
基础智能/e7.相机取图实验/Readme_EN .pdf
Normal file
BIN
基础智能/e7.相机取图实验/Readme_EN .pdf
Normal file
Binary file not shown.
BIN
基础智能/e7.相机取图实验/SmallFixedWingUAV.dll
Normal file
BIN
基础智能/e7.相机取图实验/SmallFixedWingUAV.dll
Normal file
Binary file not shown.
173
基础智能/e7.相机取图实验/VisionCapAPIDemo.bat
Normal file
173
基础智能/e7.相机取图实验/VisionCapAPIDemo.bat
Normal file
@@ -0,0 +1,173 @@
|
||||
@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 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=SmallFixedWingUAV
|
||||
|
||||
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=standard_plane
|
||||
|
||||
|
||||
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=OldFactory
|
||||
|
||||
REM Set the origin x,y position (m) and yaw angle (degree) at the map
|
||||
SET /a ORIGIN_POS_X=-250
|
||||
SET /a ORIGIN_POS_Y=-119
|
||||
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
|
||||
REM SET /P VehicleNum=Please input UAV swarm number:
|
||||
SET /A VehicleNum=1
|
||||
SET /A Evaluated=VehicleNum
|
||||
if %Evaluated% EQU %VehicleNum% (
|
||||
IF %VehicleNum% GTR 0 (
|
||||
IF %VehicleNum% GTR %MAX_VEHICLE% (
|
||||
ECHO The vehicle number is too large, which may cause a crash
|
||||
pause
|
||||
)
|
||||
GOTO StartSim
|
||||
)
|
||||
ECHO Not a positive integer
|
||||
GOTO Top
|
||||
) ELSE (
|
||||
ECHO Not a integer
|
||||
GOTO Top
|
||||
)
|
||||
:StartSim
|
||||
|
||||
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 echo Starting PX4 Build; cd %PSP_PATH_LINUX%/Firmware; ./BkFile/EnvOri.sh; export PATH=$HOME/ninja:$HOME/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH;make px4_sitl_default; ./Tools/sitl_multiple_run_rfly.sh %VehicleNum% %START_INDEX% %PX4SitlFrame%;echo Press any key to exit; read -n 1
|
||||
) 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%;echo Press any key to exit; read -n 1; 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.
|
||||
91
基础智能/e7.相机取图实验/VisionCapAPIDemo.py
Normal file
91
基础智能/e7.相机取图实验/VisionCapAPIDemo.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import time
|
||||
import math
|
||||
import sys
|
||||
import VisionCaptureApi
|
||||
import PX4MavCtrlV4 as PX4MavCtrl
|
||||
import cv2
|
||||
import UE4CtrlAPI
|
||||
ue = UE4CtrlAPI.UE4CtrlAPI()
|
||||
|
||||
#Create a new MAVLink communication instance, UDP sending port (CopterSim’s receving port) is 20100
|
||||
mav = PX4MavCtrl.PX4MavCtrler(1)
|
||||
|
||||
# The IP should be specified by the other computer
|
||||
vis = VisionCaptureApi.VisionCaptureApi()
|
||||
|
||||
# Send command to UE4 Window 1 to change resolution
|
||||
ue.sendUE4Cmd('r.setres 1280x720',0) # 设置UE4窗口分辨率,注意本窗口仅限于显示,取图分辨率在json中配置,本窗口设置越小,资源需求越少。
|
||||
ue.sendUE4Cmd('t.MaxFPS 30',0) # 设置UE4最大刷新频率,同时也是取图频率
|
||||
time.sleep(2)
|
||||
|
||||
# VisionCaptureApi 中的配置函数
|
||||
vis.jsonLoad() # 加载Config.json中的传感器配置文件
|
||||
|
||||
# vis.RemotSendIP = '192.168.3.80'
|
||||
# 注意,手动修改RemotSendIP的值,可以将图片发送到本地址
|
||||
# 如果不修改这个值,那么发送的IP地址为json文件中SendProtocol[1:4]定义的IP
|
||||
# 图片的发送端口,为json中SendProtocol[5]定义好的。
|
||||
|
||||
isSuss = vis.sendReqToUE4() # 向RflySim3D发送取图请求,并验证
|
||||
if not isSuss: # 如果请求取图失败,则退出
|
||||
sys.exit(0)
|
||||
vis.startImgCap() # 开启取图,并启用共享内存图像转发,转发到填写的目录
|
||||
|
||||
|
||||
#mav.InitMavLoop(UDPMode), where UDPMode=0,1,2,3,4
|
||||
# Use MAVLink_Full Mode to control PX4
|
||||
# In this mode, this script will send MAVLinkOffboard message to PX4 directly
|
||||
# and receive MAVLink data from PX4
|
||||
# Obviously, MAVLink_Full mode is slower than UDP mode, but the functions and data are more comprehensive
|
||||
mav.InitMavLoop() # the same as mav.InitMavLoop() in other PythonVision demos
|
||||
|
||||
time.sleep(1)
|
||||
print('Start Offboard Send!')
|
||||
mav.initOffboard2()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
# Check if the PX4'EKF has correctlly initialized, which is necessary for offboard control
|
||||
if not mav.isPX4Ekf3DFixed:
|
||||
print('CopterSim/PX4 still not 3DFxied, please wait and try again.')
|
||||
sys.exit(0)
|
||||
else:
|
||||
print('CopterSim/PX4 3D Fixed, ready to fly.')
|
||||
|
||||
mav.SendMavArm(True)
|
||||
print('Fly to pos 10, 0,-100!')
|
||||
time.sleep(1)
|
||||
mav.sendMavTakeOff(10,0,-100)
|
||||
|
||||
# 下面的程序非必需,仅用于观察图像用,在电脑性能不足时,请删除
|
||||
lastTime = time.time()
|
||||
num=0
|
||||
lastClock=time.time()
|
||||
while True:
|
||||
lastTime = lastTime + 1/30.0
|
||||
sleepTime = lastTime - time.time()
|
||||
if sleepTime > 0:
|
||||
time.sleep(sleepTime)
|
||||
else:
|
||||
lastTime = time.time()
|
||||
|
||||
for i in range(len(vis.hasData)):
|
||||
if vis.hasData[i]:
|
||||
# Process your image here
|
||||
cv2.imshow('Img'+str(i),vis.Img[i])
|
||||
cv2.waitKey(1)
|
||||
|
||||
if i==0: # 更新0号相机的参数
|
||||
# 以下代码用于实时更新相机参数(位置、焦距、角度、装载飞机和形式)
|
||||
vs = vis.VisSensor[0] #获取第0号相机基本参数
|
||||
# 修改其中的可变部分,只修改需要改变的部分即可
|
||||
vs.TargetCopter=1 #修改视角绑定的飞机ID
|
||||
vs.TargetMountType=0 # 修改视角绑定类型,固连飞机还是地面
|
||||
vs.CameraFOV=90 # 修改视角的视场角(焦距),可以模拟对焦相机
|
||||
vs.SensorPosXYZ=[0,0,0] # 修改相机的位置,可以调整相机初始位置
|
||||
vs.SensorAngEular=[0,0,0] # 修改相机的姿态,可以模拟云台转动
|
||||
vis.sendUpdateUEImage(vs) # 发送更新数据
|
||||
|
||||
|
||||
#mav.endOffboard()
|
||||
#mav.stopRun()
|
||||
0
基础智能/e7.相机取图实验/名称-相机取图实验.txt
Normal file
0
基础智能/e7.相机取图实验/名称-相机取图实验.txt
Normal file
Reference in New Issue
Block a user