예제 #1
0
    /*    AirSimServer()
        {
        }*/

        void Start()
        {
            vehicleList = new List<Transform>();
            pedestrianList = new List<Transform>();

            comp = new ServerCompanion();
            VehicleCompanion.InitDelegators();
            var settings = AirSimSettings.GetSettings();
                        
            if (IP == "")
                IP = settings.LocalHostIP;
            
            
            if (Port == -1)
                Port = settings.GetPort(AirSimSettings.AgentType.Server);

                // Start server
            bool status = PInvokeWrapper.StartMainServer(Port);
            Debug.LogWarning("Main server started on port " + Port.ToString());
            if(!status)
            {
#if UNITY_EDITOR
                EditorUtility.DisplayDialog("AirSim main failed to start on port " + Port.ToString() + "!!!", "Please check logs for more information.", "Exit");
                EditorApplication.Exit(1);
#else
                Application.Quit();
#endif
            }

        }
예제 #2
0
 //Register the delegate functions to AirLib, based on IVehicleInterface
 private static void InitDelegators()
 {
     PInvokeWrapper.InitVehicleManager(
         Marshal.GetFunctionPointerForDelegate(new Func <AirSimPose, bool, string, bool>(SetPose)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, AirSimPose>(GetPose)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, CollisionInfo>(GetCollisionInfo)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, AirSimRCData>(GetRCData)),
         Marshal.GetFunctionPointerForDelegate(new Func <ImageRequest, string, ImageResponse>(GetSimImages)),
         Marshal.GetFunctionPointerForDelegate(new Func <int, RotorInfo, string, bool>(SetRotorSpeed)),
         Marshal.GetFunctionPointerForDelegate(new Func <bool, string, bool>(SetEnableApi)),
         Marshal.GetFunctionPointerForDelegate(new Func <CarControls, string, bool>(SetCarApiControls)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, CarState>(GetCarState)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, string, CameraInfo>(GetCameraInfo)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, AirSimPose, string, bool>(SetCameraPose)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, float, string, bool>(SetCameraFoV)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, int, bool, bool>(SetSegmentationObjectId)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, int>(GetSegmentationObjectId)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, string, string, int, bool>(PrintLogMessage)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, UnityTransform>(GetTransformFromUnity)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, bool>(Reset)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, AirSimVector>(GetVelocity)),
         Marshal.GetFunctionPointerForDelegate(new Func <AirSimVector, AirSimVector, string, RayCastHitResult>(GetRayCastHit)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, float, bool>(Pause))
         );
 }
 public void StopPedestrianServer()
 {
     if (serverStarted == true)
     {
         PInvokeWrapper.StopPedestrianServer();
         Debug.Log("Pedestrian server halted");
         serverStarted = false;
     }
 }
 public bool StartPedestrianServer(int hostIP)
 {
     if (serverStarted == false)
     {
         serverStarted = PInvokeWrapper.StartPedestrianServer(basePortId);
         Debug.Log("Pedestrian server startedv on port: " + basePortId);
         return(serverStarted);
     }
     return(true);
 }
예제 #5
0
        //Ensure to call this method as the last statement, from derived class `LateUpdate()` method.
        protected void LateUpdate()
        {
            if (isServerStarted)
            {
                if (timeScale_changed)
                {
                    Time.timeScale    = time_scale;
                    timeScale_changed = false;
                }

                if (isSegmentationUpdated)
                {
                    UpdateSegmentationView();
                    isSegmentationUpdated = false;
                }

                if (isCapturingImages)
                {
                    var captureCamera = captureCameras.Find(element => element.GetCameraName() == imageRequest.camera_name);
                    imageResponse = captureCamera.GetImageBasedOnRequest(imageRequest);
                    captureResetEvent.Set(); //Release the GetSimulationImages thread with the image response.
                    isCapturingImages = false;
                }

                if (calculateRayCast)
                {
                    hitResult        = Physics.Linecast(startVec, endVec, out hitInfo);
                    calculateRayCast = false;
                }

                if (Input.GetKeyDown(KeyCode.T))
                {
                    print_log_messages_ = !print_log_messages_;
                }

                if (count > 10)
                {
                    count = 0;
                    foreach (var p in captureCameras)
                    {
                        string camera       = p.GetCameraName();
                        var    imageRequest = new ImageRequest(camera, ImageType.Scene, false, false);

                        imageResponse = p.GetImageBasedOnRequest(imageRequest);
                        PInvokeWrapper.StoreVehicleImage(vehicle_name, camera, imageResponse);
                    }
                }
                count++;
                // Update images



                airsimInterface.InvokeTickInAirSim(Time.deltaTime);     //TODOME check this
            }
        }
 public bool StartVehicleServer(string hostIP)
 {
     if (serverStarted == false)
     {
         Debug.LogWarning("Starting server for " + vehicleType + AirSimSettings.GetSettings().SimMode);
         serverStarted = PInvokeWrapper.StartServer(vehicleType, AirSimSettings.GetSettings().SimMode, basePortId);
         Debug.LogWarning("Server started: " + serverStarted + " - " + basePortId);
         return(serverStarted);
     }
     return(true);
 }
 private static void InitDelegators()
 {
     PInvokeWrapper.InitPedestrianManager(
         Marshal.GetFunctionPointerForDelegate(new Func <AirSimPose, bool, string, bool>(SetPose)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, AirSimPose>(GetPose)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, bool>(Reset)),
         Marshal.GetFunctionPointerForDelegate(new Func <bool, string, bool>(SetEnableApi)),
         Marshal.GetFunctionPointerForDelegate(new Func <PedestrianControls, string, bool>(SetPedestrianApiControls)),
         Marshal.GetFunctionPointerForDelegate(new Func <string, ServerUtils.StringArray>(GetPedestrianCameras))
         );
 }
 public void StopVehicleServer()
 {
     if (serverStarted == true)
     {
         PInvokeWrapper.StopServer(vehicleType);
         Debug.LogWarning("Server halted");
         serverStarted = false;
     }
     else
     {
         Debug.LogWarning("Server already halted");
     }
 }
 private static void InitDelegators()
 {
     PInvokeWrapper.InitServerManager(
        Marshal.GetFunctionPointerForDelegate(new Func<string, bool>(PrintTest)),
        Marshal.GetFunctionPointerForDelegate(new Func<string, string, bool>(AddVehicle)),
        Marshal.GetFunctionPointerForDelegate(new Func<string, bool>(AddPedestrianFunc)),
        Marshal.GetFunctionPointerForDelegate(new Func<string, string, bool>(RemoveVehicle)),
        Marshal.GetFunctionPointerForDelegate(new Func<string, bool>(RemovePedestrian)),
        Marshal.GetFunctionPointerForDelegate(new Func<ServerUtils.StringArray>(GetVehicleTypes)),
        Marshal.GetFunctionPointerForDelegate(new Func<ServerUtils.StringArray>(GetAllVehiclesList)),
        Marshal.GetFunctionPointerForDelegate(new Func<ServerUtils.StringArray>(GetAllPedestriansList))
        // Add functions that can be called from server to Unity
     );
 }
예제 #10
0
        // Start is called before the first frame update
        void Start()
        {
            string simMode         = AirSimSettings.GetSettings().SimMode;
            int    basePortId      = AirSimSettings.GetSettings().GetPortIDForVehicle(simMode == DRONE_MODE);
            bool   isServerStarted = PInvokeWrapper.StartServer(simMode, basePortId);

            if (isServerStarted == false)
            {
#if UNITY_EDITOR
                EditorUtility.DisplayDialog("Problem in starting AirSim server!!!", "Please check logs for more information.", "Exit");
#else
                Application.Quit();
#endif
            }
        }
예제 #11
0
 protected void OnApplicationQuit()
 {
     PInvokeWrapper.StopMainServer();
     Debug.LogWarning("Main server stopped");
     if(PedestrianCompanion.serverStarted)
     {
         PInvokeWrapper.StopPedestrianServer();
         PedestrianCompanion.serverStarted = false;
     }
     if(VehicleCompanion.serverStarted)
     {
         PInvokeWrapper.StopServer("");
         PedestrianCompanion.serverStarted = false;
     }
 }
예제 #12
0
        private void LateUpdate()
        {
            if (count > 5)
            {
                count = 0;
                foreach (var p in captureCameras)
                {
                    string camera       = p.GetCameraName();
                    var    imageRequest = new ImageRequest(camera, ImageType.Scene, false, false);

                    imageResponse = p.GetImageBasedOnRequest(imageRequest);
                    PInvokeWrapper.StorePedestrianImage(pedestrian_name, camera, imageResponse);
                }
            }
            count++;
        }
예제 #13
0
 public bool StartVehicleServer(string hostIP)
 {
     return(PInvokeWrapper.StartServer(vehicleName, AirSimSettings.GetSettings().SimMode, basePortId));
 }
예제 #14
0
 protected void OnApplicationQuit()
 {
     PInvokeWrapper.StopServer();
 }
예제 #15
0
 public KinemticState GetKinematicState()
 {
     return(PInvokeWrapper.GetKinematicState(vehicleName));
 }
예제 #16
0
 public void InvokeCollisionDetectionInAirSim(CollisionInfo collisionInfo)
 {
     PInvokeWrapper.InvokeCollisionDetection(collisionInfo);
 }
예제 #17
0
 public void InvokeTickInAirSim(float deltaSecond)
 {
     PInvokeWrapper.CallTick(deltaSecond);
 }
예제 #18
0
 public void StopVehicleServer()
 {
     PInvokeWrapper.StopServer(vehicleName);
 }
예제 #19
0
 void FixedUpdate()
 {
     PInvokeWrapper.CallTick(Time.fixedDeltaTime);
 }
예제 #20
0
 public void InvokeCollisionDetectionInAirSim(string vehicleName, CollisionInfo collisionInfo)
 {
     PInvokeWrapper.InvokeCollisionDetection(vehicleName, collisionInfo);
 }