]> rtime.felk.cvut.cz Git - hubacji1/py-carla.git/blobdiff - launch.py
Add remote simulation with recording
[hubacji1/py-carla.git] / launch.py
index c3eff64d1463b7308218cfd63bd66f7e06cd45e0..da846ed898ffe6c15eea1261fa6b2bc4569b2bdc 100755 (executable)
--- a/launch.py
+++ b/launch.py
@@ -2,10 +2,22 @@
 """Example of launching world and spawning vehicles."""
 import carla
 
-client = carla.Client("localhost", 2000)
-client.set_timeout(9999)
-world = client.get_world()
-settings = world.get_settings()
+CARLA_SERVER_IP = "10.35.95.3"
+MAX_SIM_TIME = 4.0  # seconds
+
+client = None
+world = None
+settings = None
+
+
+def set_client():
+    global client
+    global world
+    global settings
+    client = carla.Client(CARLA_SERVER_IP, 2000)
+    client.set_timeout(99)
+    world = client.get_world()
+    settings = world.get_settings()
 
 
 def set_world(new_world="Town04"):
@@ -78,7 +90,7 @@ def main_simulation():
     c.throttle = 1
 
     i = 0
-    while i * settings.fixed_delta_seconds < 4:
+    while i * settings.fixed_delta_seconds < MAX_SIM_TIME:
         print("step {} time {} ego speed {} m/s".format(
                 i, i * 0.02, e.get_velocity().length()))
         if i == 10:
@@ -89,8 +101,36 @@ def main_simulation():
     destroy(e, t)
 
 
+def main_remote_simulation_collision():
+    """The default directory to store recordings is::
+
+        ~/.config/Epic/CarlaUE4/Saved/
+
+    """
+    set_world()
+    set_simulation()
+    t = spawn_target()
+    world.tick()
+    e = spawn_ego(t)
+    world.tick()
+    t.set_target_velocity(carla.Vector3D(10, 0, 0))
+
+    c = carla.VehicleControl()
+    c.throttle = 1
+
+    i = 0
+    while i * settings.fixed_delta_seconds < MAX_SIM_TIME:
+        i += 1
+        world.tick()
+
+    destroy(e, t)
+
+
 if __name__ == "__main__":
+    set_client()
     try:
-        main_collision()
+        client.start_recorder("remote-simulation-collision", True)
+        main_remote_simulation_collision()
+        client.stop_recorder()
     except KeyboardInterrupt:
         pass