public virtual void Do_timestep() { try { conn.Do_timestep(); } catch (Exception ex) { MonoBehaviour.print(ex.GetBaseException()); } }
// Update is called once per frame void Update() { watchdog.Start(); // Simulation step with realtime check if ((unity3DstartTime.ElapsedMilliseconds > stepLengthSeconds * 1000 * simStep) && (simStep < maxSimSteps)) { // Update egoVehicle coordinates for forwarding them to SUMO double xEgo = 0;; double yEgo = 0;; double angleEgo = 0;; if (enableEgoVehicle) { egoVehicle = GameObject.Find("egoVehicle_Peugot_WASD(Clone)"); if (egoVehicle == null) { egoVehicle = GameObject.Find("egoVehicle_Peugot(Clone)"); } xEgo = egoVehicle.transform.position.x; yEgo = egoVehicle.transform.position.z; angleEgo = egoVehicle.transform.rotation.eulerAngles.y; } // Only do next time step if it's necessary (not to fast) conn.Do_timestep(); simStep++; if (enableEgoVehicle) { // Update egoVehicle conn.Do_job_set(Vehicle.MoveToVTD("egoVehicle", "0", 0, xEgo, yEgo, angleEgo, 2)); } // Before updating all vehicles store the vehicles from last step for steering angle approximation (and prob. other interpolations) lastStepVehicles = vehicles.ToDictionary(i => i.Key, i => i.Value); // Get IDs of all vehicles in Simulation SumoStringList vehicleIDs = (SumoStringList)conn.Do_job_get(Vehicle.GetIDList()); vehicles.Clear(); foreach (string id in vehicleIDs.getList()) { SumoPosition3D position = (SumoPosition3D)conn.Do_job_get(Vehicle.GetPosition3D(id)); double yawAngle = (double)conn.Do_job_get(Vehicle.GetAngle(id)); vehicles.Add(id, new SUMOCombinedPositionOrientation(id, position, yawAngle)); } // Update all 3D vehicle models update3DVehiclesInScene(); // Update all traffic lights every refreshTimeTrafficLightsMS miliseconds if (trafficLightsUpdate.ElapsedMilliseconds > refreshTimeTrafficLightsMS) { updateAllTrafficLights(); trafficLightsUpdate.Reset(); trafficLightsUpdate.Start(); } } // Watchdog long stopTime = watchdog.ElapsedMilliseconds; if (stopTime > stepLengthSeconds * 1000) { watchDogCount++; print("Warning: Stepwidth of " + stepLengthSeconds * 1000 + "ms is too short for calculation loop, needed " + stopTime + "ms, Exceeded " + watchDogCount + " times, Current total offset: " + (unity3DstartTime.ElapsedMilliseconds - 1000 * simStep * stepLengthSeconds + stopTime) + " ms"); } watchdog.Reset(); }