From 370ba02e6c95fb8fb5cdedbbf6cb8342852b1b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20D=C3=B6rr?= Date: Tue, 29 Sep 2020 23:00:03 +0200 Subject: [PATCH] Add Flags to Control Simulator (#2246) * Add flags * Update readme old-commit-hash: c13c6ef76b1b3bc9249ba08818f6afef0ee37076 --- tools/sim/README.md | 2 ++ tools/sim/bridge.py | 36 ++++++++++++++++++++--------- tools/sim/start_openpilot_docker.sh | 2 +- tools/sim/tmux_script.sh | 4 ++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/tools/sim/README.md b/tools/sim/README.md index b46150b1bb..9f0077570a 100644 --- a/tools/sim/README.md +++ b/tools/sim/README.md @@ -25,3 +25,5 @@ You can control openpilot driving in the simulation with the following keys | 3 | Cruise cancel | | q | Exit all | +To see the options for changing the environment, such as the town, spawn point or precipitation, you can run `./start_openpilot_docker.sh --help`. +This will print the help output inside the docker container. You need to exit the docker container before running `./start_openpilot_docker.sh` again. diff --git a/tools/sim/bridge.py b/tools/sim/bridge.py index a118df0026..9149ba3b07 100755 --- a/tools/sim/bridge.py +++ b/tools/sim/bridge.py @@ -16,6 +16,15 @@ from selfdrive.test.helpers import set_params_enabled parser = argparse.ArgumentParser(description='Bridge between CARLA and openpilot.') parser.add_argument('--joystick', action='store_true') +parser.add_argument('--town', type=str, default='Town04') +parser.add_argument('--spawn_point', dest='num_selected_spawn_point', + type=int, default=16) +parser.add_argument('--cloudyness', default=0.1, type=float) +parser.add_argument('--precipitation', default=0.0, type=float) +parser.add_argument('--precipitation_deposits', default=0.0, type=float) +parser.add_argument('--wind_intensity', default=0.0, type=float) +parser.add_argument('--sun_azimuth_angle', default=15.0, type=float) +parser.add_argument('--sun_altitude_angle', default=75.0, type=float) args = parser.parse_args() W, H = 1164, 874 @@ -127,23 +136,19 @@ def go(q): # setup CARLA client = carla.Client("127.0.0.1", 2000) client.set_timeout(10.0) - world = client.load_world('Town04') - world.set_weather(carla.WeatherParameters( - cloudyness=0.1, - precipitation=0.0, - precipitation_deposits=0.0, - wind_intensity=0.0, - sun_azimuth_angle=15.0, - sun_altitude_angle=75.0 - )) + world = client.load_world(args.town) blueprint_library = world.get_blueprint_library() world_map = world.get_map() vehicle_bp = blueprint_library.filter('vehicle.tesla.*')[0] - # vehicle = world.spawn_actor(vehicle_bp, world_map.get_spawn_points()[16]) - vehicle = world.spawn_actor(vehicle_bp, world_map.get_spawn_points()[16]) + spawn_points = world_map.get_spawn_points() + assert len(spawn_points) > args.num_selected_spawn_point, \ + f'''No spawn point {args.num_selected_spawn_point}, try a value between 0 and + {len(spawn_points)} for this town.''' + spawn_point = spawn_points[args.num_selected_spawn_point] + vehicle = world.spawn_actor(vehicle_bp, spawn_point) max_steer_angle = vehicle.get_physics_control().wheels[0].max_steer_angle @@ -165,6 +170,15 @@ def go(q): camera = world.spawn_actor(blueprint, transform, attach_to=vehicle) camera.listen(cam_callback) + world.set_weather(carla.WeatherParameters( + cloudyness=args.cloudyness, + precipitation=args.precipitation, + precipitation_deposits=args.precipitation_deposits, + wind_intensity=args.wind_intensity, + sun_azimuth_angle=args.sun_azimuth_angle, + sun_altitude_angle=args.sun_altitude_angle + )) + # reenable IMU imu_bp = blueprint_library.find('sensor.other.imu') imu = world.spawn_actor(imu_bp, transform, attach_to=vehicle) diff --git a/tools/sim/start_openpilot_docker.sh b/tools/sim/start_openpilot_docker.sh index 7db5b5c52a..52bc2ec551 100755 --- a/tools/sim/start_openpilot_docker.sh +++ b/tools/sim/start_openpilot_docker.sh @@ -14,4 +14,4 @@ docker run --net=host\ --shm-size 1G \ -e DISPLAY=$DISPLAY \ commaai/openpilot-sim:latest \ - /bin/bash -c "cd tools && cd sim && sh tmux_script.sh" + /bin/bash -c "cd tools && cd sim && sh tmux_script.sh $*" diff --git a/tools/sim/tmux_script.sh b/tools/sim/tmux_script.sh index cd293d41ee..bb7a4088dc 100755 --- a/tools/sim/tmux_script.sh +++ b/tools/sim/tmux_script.sh @@ -2,5 +2,5 @@ tmux new -d -s htop tmux send-keys "./launch_openpilot.sh" ENTER tmux neww -tmux send-keys "./bridge.py" ENTER -tmux a \ No newline at end of file +tmux send-keys "./bridge.py $*" ENTER +tmux a