ユーザ機器UE 4には、航空制御用の無人機シミュレーションプラグイン、AirSimを使用しています.

63588 ワード

UE 4には、アイリスシムを使用します.
1.略述
プロジェクトでは、UE 4を使用して、無人機コントロールのシミュレーションを開発したので、AirSimのメカニズムの一部を理解し、学習しました.マイクロソフトは、無人機飛行をシミュレートするためのツールAirSimをオープンしました.AirSimプラットフォームを通して、自動運転機が実際の世界でどのように走行しているかを理解することができます.同時に、このプラットフォームで深さ学習技術を使用して、これらの輸送工具が様々な環境下でどのように反応しているかを理解することができます.飛行制御ボードやシミュレータによるハードウェア入力ができます.ここでは純粋なソフトウェアシミュレーションを使用しています.マイクロソフトの公式オープンソースのプロジェクトの住所の公式文書の説明
2.簡単な構成は、公式の説明やネットワーク上の他のインストール手順に従って、プロジェクトのcloneをコンパイルし、AirSimを自分のUE 4プロジェクトに適用します.具体的な操作は以下の通りです.
  • Unireal\Pluginsフォルダをコピーします.上の部分から作成した仮想プロジェクトのフォルダのルート
  • までです.
  • ダミープロジェクトの.uplojectファイルにおいて、キーを「Modules」オブジェクトに追加する追加の依存項"AdditionalDependencies": [ "AirSim" ]-Plugins部分"Plugins": [ { "Name": "AirSim", "Enabled": true } ]を追加した後も同様である.
    {
    	"FileVersion": 3,
    	"EngineAssociation": "4.24",
    	"Category": "Samples",
    	"Description": "",
    	"Modules": [
    		{
    			"Name": "LandscapeMountains",
    			"Type": "Runtime",
    			"LoadingPhase": "Default",
    			"AdditionalDependencies": [
    				"AirSim"
    			]
    		}
    	],
    	"TargetPlatforms": [
    		"MacNoEditor",
    		"WindowsNoEditor"
    	],
    	"Plugins": [
    		{
    			"Name": "AirSim",
    			"Enabled": true
    		}
    	]
    }
    
    3.setting.jsonファイルを修正する
    設定ファイルはデフォルトではC:\Users\Admin\Dockments\AirSim\settings.jsonファイルの下で、完全な使い方は以下の通りです.一般的には全部使う必要がなく、必要なものは追加します.
    {
      "SimMode": "",
      "ClockType": "",
      "ClockSpeed": 1,
      "LocalHostIp": "127.0.0.1",
      "RecordUIVisible": true,
      "LogMessagesVisible": true,
      "ViewMode": "",
      "RpcEnabled": true,
      "EngineSound": true,
      "PhysicsEngineName": "",
      "SpeedUnitFactor": 1.0,
        "SpeedUnitLabel": "m/s",
      "Recording": {
        "RecordOnMove": false,
        "RecordInterval": 0.05,
        "Cameras": [
            { "CameraName": "0", "ImageType": 0, "PixelsAsFloat": false, "Compress": true }
        ]
      },
      "CameraDefaults": {
        "CaptureSettings": [
          {
            "ImageType": 0,
            "Width": 256,
            "Height": 144,
            "FOV_Degrees": 90,
            "AutoExposureSpeed": 100,
            "AutoExposureBias": 0,
            "AutoExposureMaxBrightness": 0.64,
            "AutoExposureMinBrightness": 0.03,
            "MotionBlurAmount": 0,
            "TargetGamma": 1.0,
            "ProjectionMode": "",
            "OrthoWidth": 5.12
          }
        ],
        "NoiseSettings": [
          {
            "Enabled": false,
            "ImageType": 0,
    
            "RandContrib": 0.2,
            "RandSpeed": 100000.0,
            "RandSize": 500.0,
            "RandDensity": 2,
    
            "HorzWaveContrib":0.03,         
            "HorzWaveStrength": 0.08,
            "HorzWaveVertSize": 1.0,
            "HorzWaveScreenSize": 1.0,
    
            "HorzNoiseLinesContrib": 1.0,
            "HorzNoiseLinesDensityY": 0.01,
            "HorzNoiseLinesDensityXY": 0.5,
    
            "HorzDistortionContrib": 1.0,
            "HorzDistortionStrength": 0.002
          }
        ],
        "Gimbal": {
          "Stabilization": 0,
          "Pitch": NaN, "Roll": NaN, "Yaw": NaN
        }
        "X": NaN, "Y": NaN, "Z": NaN,
        "Pitch": NaN, "Roll": NaN, "Yaw": NaN    
      },
      "OriginGeopoint": {//               
        "Latitude": 47.641468,
        "Longitude": -122.140165,
        "Altitude": 122
      },
      "TimeOfDay": {
        "Enabled": false,
        "StartDateTime": "",
        "CelestialClockSpeed": 1,
        "StartDateTimeDst": false,
        "UpdateIntervalSecs": 60
      },
      "SubWindows": [//       
        {"WindowID": 0, "CameraName": "0", "ImageType": 3, "Visible": false},
        {"WindowID": 1, "CameraName": "0", "ImageType": 5, "Visible": false},
        {"WindowID": 2, "CameraName": "0", "ImageType": 0, "Visible": false}    
      ],
      "SegmentationSettings": {
        "InitMethod": "",
        "MeshNamingMethod": "",
        "OverrideExisting": false
      },
      "PawnPaths": {
        "BareboneCar": {"PawnBP": "Class'/AirSim/VehicleAdv/Vehicle/VehicleAdvPawn.VehicleAdvPawn_C'"},
        "DefaultCar": {"PawnBP": "Class'/AirSim/VehicleAdv/SUV/SuvCarPawn.SuvCarPawn_C'"},
        "DefaultQuadrotor": {"PawnBP": "Class'/AirSim/Blueprints/BP_FlyingPawn.BP_FlyingPawn_C'"},
        "DefaultComputerVision": {"PawnBP": "Class'/AirSim/Blueprints/BP_ComputerVisionPawn.BP_ComputerVisionPawn_C'"}
      },
      "Vehicles": {//         
        "SimpleFlight": {
          "VehicleType": "SimpleFlight",
          "DefaultVehicleState": "Armed",
          //Armed         ,   Inactive
          "AutoCreate": true,
          "PawnPath": "",
          "EnableCollisionPassthrogh": false,
          "EnableCollisions": true,
          "AllowAPIAlways": true,//  api  ,  
          "RC": {//     switch PX4
            "RemoteControlID": 0,
            "AllowAPIWhenDisconnected": false
          },
          "Cameras": {   
            //     ,             
          },
          "X": NaN, "Y": NaN, "Z": NaN,
          "Pitch": NaN, "Roll": NaN, "Yaw": NaN
        },
        "PhysXCar": {
          "VehicleType": "PhysXCar",
          "DefaultVehicleState": "",
          "AutoCreate": true,
          "PawnPath": "",
          "EnableCollisionPassthrogh": false,
          "EnableCollisions": true,
          "RC": {
            "RemoteControlID": -1
          },
          "Cameras": {   
            "MyCamera1": {
              //     ,             
            },
            "MyCamera2": {
              //     ,             
            },        
          },
          "X": NaN, "Y": NaN, "Z": NaN,
          "Pitch": NaN, "Roll": NaN, "Yaw": NaN      
        }
      }
    }
    
    特に、
       "Lidar1": { 
                 
                 "DrawDebugPoints": true   //      
            }
    
    
    4.開発例はShellDemoをまねて、カスタムクラスを作成し、キーボード入力によって呼び出します.ここで実現する目的は、多機同時飛行、多航路点、陣形などです.だからここでスレッドを使って各飛行機と独立飛行に遅延がないことを保証します.ここでは例として2つのスレッドを開きます.
    	class MultiCommand : public DroneCommand {
    		public:
    			MultiCommand() : DroneCommand("Multi", "Test Muti fly?")
    			{
    			}
    
    			bool execute(const DroneCommandParameters& params)
    			{
    				DWORD dwThreadId1;//  ID
    				DWORD dwThreadId2;
    
    				HANDLE hThread1 = CreateThread(NULL, 0, TakeProc1, NULL, 0, &dwThreadId1);
    				HANDLE hThread2 = CreateThread(NULL, 0, TakeProc2, NULL, 0, &dwThreadId2);
    				
    				params.context->client.enableApiControl(true,"Drone1");
    
    
    				params.context->client.armDisarm(true, "Drone1");
    			  
    				float takeoffTimeout = 5;
    				params.context->client.takeoffAsync(takeoffTimeout,"Drone1")->waitOnLastTask();//  
    			
    				auto position = params.context->client.getMultirotorState("Drone1").getPosition();
    				float z = position.z(); //      (NED coordinate system).
    				const float speed = 3.0f;
    				const float size = 10.0f;// 3 /     10     
    				const float duration = size / speed;//    
    				DrivetrainType driveTrain = DrivetrainType::ForwardOnly;
    				YawMode yaw_mode(true, 0);
    				std::cout << "moveByVelocityZ(" << speed << ", 0, " << z << "," << duration << ")" << std::endl;
    				params.context->client.moveByVelocityZAsync(speed, 0, z, duration, driveTrain, yaw_mode);
    				std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    
    				std::cout << "moveByVelocityZ(0, " << speed << "," << z << "," << duration << ")" << std::endl;
    				params.context->client.moveByVelocityZAsync(0, speed, z, duration, driveTrain, yaw_mode);
    				std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    
    				params.context->client.hoverAsync()->waitOnLastTask();
    				std::this_thread::sleep_for(std::chrono::duration<double>(10));
    
    				CloseHandle(hThread1);
    				printf("  1  
    "
    ); CloseHandle(hThread2); printf(" 2
    "
    ); printf("FINISH-DONE\r
    "
    ); return false; } };
    スレッドの書き方:ここでスレッド2をデモします.四つの点を回って飛行します.
    DWORD WINAPI TakeProc2(LPVOID lpParam)
    {
    	MultirotorRpcLibClient client;
    
    	client.enableApiControl(true, "Drone3");
    	client.armDisarm(true, "Drone3");
    
    	float takeoffTimeout = 5;
    	client.takeoffAsync(takeoffTimeout, "Drone3")->waitOnLastTask();
    
    	auto position = client.getMultirotorState("Drone3").getPosition();
    	float z = position.z(); //    (NED coordinate system).  
    	const float speed = 3.0f;
    	const float size = 10.0f;
    	const float duration = size / speed;
    	DrivetrainType driveTrain = DrivetrainType::ForwardOnly;
    	YawMode yaw_mode(true, 0);
    	std::cout << "Drone3(" << speed << ", 0, " << z << "," << duration << ")" << std::endl;
    	client.moveByVelocityZAsync(speed, 0, z, duration, driveTrain, yaw_mode, "Drone3");
    	std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    	std::cout << "Drone3(0, " << speed << "," << z << "," << duration << ")" << std::endl;
    	client.moveByVelocityZAsync(0, speed, z, duration, driveTrain, yaw_mode, "Drone3");
    	std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    	std::cout << "Drone3(" << -speed << ", 0, " << z << "," << duration << ")" << std::endl;
    	client.moveByVelocityZAsync(-speed, 0, z, duration, driveTrain, yaw_mode, "Drone3");
    	std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    	std::cout << "Drone3(0, " << -speed << "," << z << "," << duration << ")" << std::endl;
    	client.moveByVelocityZAsync(0, -speed, z, duration, driveTrain, yaw_mode, "Drone3");
    	std::this_thread::sleep_for(std::chrono::duration<double>(duration));
    
    	client.hoverAsync()->waitOnLastTask();
    	return 0;
    }
    
    もちろん、settings.jsonの内容を変更することを忘れないでください.マルチマシンの構成例は以下の通りです.
    {
      "SettingsVersion": 1.2,
      "SimMode": "Multirotor",
      "OriginGeopoint": {
        "Latitude": 47.641468,
        "Longitude": -122.140165,
        "Altitude": 122
      },
      "SubWindows": [
        {"WindowID": 0, "ImageType": 0, "CameraName": "3", "Visible": true},
        {"WindowID": 1, "ImageType": 3, "CameraName": "0", "Visible": true},
        {"WindowID": 2, "ImageType": 6, "CameraName": "4", "Visible": true}
      ],
      "SettingsVersion": 1.2,
        "SimMode": "Multirotor",
    
        "Vehicles": {
            "Drone1": {
              "VehicleType": "SimpleFlight",
              "X": 4, "Y": 0, "Z": -2,
          "Yaw": -180
            },
            "Drone2": {
              "VehicleType": "SimpleFlight",
              "AutoCreate": true,
              "X": 8, "Y": 0, "Z": -2
            },
    		 "Drone3": {
              "VehicleType": "SimpleFlight",
              "AutoCreate": true,
              "X": 12, "Y": 0, "Z": 0
            },
             "Drone4": {
              "VehicleType": "SimpleFlight",
              "AutoCreate": true,
              "X": 16, "Y": 0, "Z": 0
            },
         	 "Drone5": {
              "VehicleType": "SimpleFlight",
              "AutoCreate": true,
              "X": 20, "Y": 0, "Z": 0
            }
        
        }
        
    }
    
    
    これで、プラグインの無人機に対する基本的な操作が完了し、バックグラウンドコードの制御によって、所望の効果が達成されました.