Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSCENARIO 2.0 supported #1015

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* SignalizedJunctionLeftTurn has been remade. It now has an actor flow on which the ego has to merge into, instead of a single vehicle.
* The BackgroundActivity has been readded to the routes, which the objective of creating the sensation of traffic around the ego
* Add waypoint reached threshold so that the precision of the actor reaching to waypoints can be adjusted based on object types.
* **Supported OpenSCENARIO 2.0 standard.**

### :bug: Bug Fixes
* Fixed bug at OtherLeadingVehicle scenario causing the vehicles to move faster than intended
Expand Down
123 changes: 123 additions & 0 deletions Docs/README_OpenSCENARIO_2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# osc2-runner

We use OpenScenario 2.0 as the scenario description language specification to design and implement the corresponding compilation system, which can automatically convert the test scenario described with OpenScenario 2.0 into a test scenario based on scenario runner, so as to use carla for autonomous driving testing.

## Installation

**1. Install JDK**

```
sudo apt install openjdk-17-jdk
```
Confirm installation:
```
$ java -version
```
Output:
```
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu120.04)
OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu120.04, mixed mode, sharing)
```

**3、Install Antlr 4.10.1**

```
sudo apt install curl
curl -O https://www.antlr.org/download/antlr-4.10.1-complete.jar
```

Put the .jar file into local/lib
```
$ sudo cp antlr-4.10.1-complete.jar /usr/local/lib/
```

The following three steps are used to configure environment variables and create aliases so that antlr4 can be easily used from the command line.
```
$ sudo gedit ~/.bashrc
```
Add the following at the end:
```
export CLASSPATH=".:/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH"
alias antlr4='java -jar /usr/local/lib/antlr-4.10.1-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'
```
And then:
```
source ~/.bashrc
```

Enter antlr4 for verifying in the terminal:
```
$ antlr4
ANTLR Parser Generator Version 4.10.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of grammars, tokens files
-atn generate rule augmented transition network diagrams
-encoding ___ specify grammar file encoding; e.g., euc-jp
-message-format ___ specify output style for messages in antlr, gnu, vs2005
-long-messages show exception details when available for errors and warnings
-listener generate parse tree listener (default)
-no-listener don't generate parse tree listener
-visitor generate parse tree visitor
-no-visitor don't generate parse tree visitor (default)
-package ___ specify a package/namespace for the generated code
-depend generate file dependencies
-D<option>=value set/override a grammar-level option
-Werror treat warnings as errors
-XdbgST launch StringTemplate visualizer on generated code
-XdbgSTWait wait for STViz to close before continuing
-Xforce-atn use the ATN simulator for all predictions
-Xlog dump lots of logging info to antlr-timestamp.log
-Xexact-output-dir all output goes into -o dir regardless of paths/package
```

**4、Install antlr4 runtime**
```
pip install antlr4-python3-runtime==4.10
```

**5、Install python dependency**
```
pip install -r requirements.txt
```

**6.Install graphviz**

```
sudo apt-get install graphviz
```


**7、Configurate carla**

(1) Download [carla release](https://carla-releases.s3.eu-west-3.amazonaws.com/Linux/CARLA_0.9.13.tar.gz)


(2) Extract the carla installation package to a directory.

On Ubuntu systems, the Carla environment variable is configured as follows:
```bash
export CARLA_ROOT=/home/dut-aiid/CARLA_0.9.13
export PYTHONPATH=$PYTHONPATH:${CARLA_ROOT}/PythonAPI/carla/dist/carla-0.9.13-py3.7-linux-x86_64.egg:${CARLA_ROOT}/PythonAPI/carla/agents:${CARLA_ROOT}/PythonAPI/carla/agents/navigation:${CARLA_ROOT}/PythonAPI/carla:${CARLA_ROOT}/PythonAPI/examples:${CARLA_ROOT}/PythonAPI
```

## Quickstart

**1、Run carla**

```bash
cd /home/xxx/CARLA_0.9.13
./CarlaUE4.sh
```

**2、Start manual_control**

```
python manual_control.py -a --rolename=ego_vehicle
```

**3、Run a OpenSCENARIO 2.0 scenario**
```
python scenario_runner.py --sync --openscenario2 srunner/examples/cut_in_and_slow_right.osc --reloadWorld
```
18 changes: 18 additions & 0 deletions Docs/getting_scenariorunner.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ set PYTHONPATH=%PYTHONPATH%;%CARLA_ROOT%\PythonAPI\carla

To permanently set the environment variables, go to *edit the environment variables of this account*. This can be quickly accessed by writing *env* on the Windows' search panel.

If you need to run the scenario based on the OpenSCENARIO 2.0 format, please install graphviz and antlr first:
```
sudo apt-get install -y openjdk-17-jdk graphviz
curl -O https://www.antlr.org/download/antlr-4.10.1-complete.jar
sudo cp antlr-4.10.1-complete.jar /usr/local/lib/
sudo gedit ~/.bashrc
```
Add environment variables into ~/.bashrc:
```
export CLASSPATH=".:/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH"
alias antlr4='java -jar /usr/local/lib/antlr-4.10.1-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'
```
And make the changes into effect:
```
source ~/.bashrc
```

---
## Run a test

Expand Down
13 changes: 13 additions & 0 deletions Docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ python scenario_runner.py --openscenario <path/to/xosc-file>
Please note that the OpenSCENARIO support and the OpenSCENARIO format itself are still work in progress.
More information you can find in [OpenSCENARIO support](openscenario_support.md)

## Running scenarios using the OpenSCENARIO 2.0 format
To run a scenario, which is based on the OpenSCENARIO 2.0 format, please run the ScenarioRunner as follows:
```
python scenario_runner.py --openscenario2 <path/to/osc-file>
```

To control the ego vehicle within the scenario or observe it, open another terminal and run:
```
python manual_control.py -a --rolename=ego_vehicle
```

For more information about how to run a OpenSCENARIO 2.0 scenario, please refer to [README_OpenSCENARIO_2.0](README_OpenSCENARIO_2.0.md)

### Running scenarios using the OpenSCENARIO format with Global ParameterDeclaration overwrite
```
python scenario_runner.py --openscenario <path/to/xosc-file> --openscenarioparams 'param1: value1, param2: value2'
Expand Down
Binary file added Docs/img/metrics_example.jpg~
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ for CARLA. It also allows the execution of a simulation of the CARLA Challenge.
You can use this system to prepare your agent for the CARLA Challenge.

Scenarios can be defined through a Python interface, and with the newest version
the scenario_runner also the upcoming [OpenSCENARIO](http://www.openscenario.org/) standard is supported.
the scenario_runner also the upcoming [OpenSCENARIO](http://www.openscenario.org/) standard and [OpenSCENARIO 2.0](https://www.asam.net/standards/detail/openscenario/v200/) standard is supported.

[![Scenario_Runner for CARLA](Docs/img/scenario_runner_video.png)](https://youtu.be/ChmF8IFagpo?t=68)

Expand Down
8 changes: 4 additions & 4 deletions manual_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ def __init__(self, carla_world, hud, args):
self.imu_sensor = None
self.radar_sensor = None
self.camera_manager = None
self.restart()
self.restart(args)
self.world.on_tick(hud.on_world_tick)
self.recording_enabled = False
self.recording_start = 0

def restart(self):
def restart(self, args):

if self.restarted:
return
Expand All @@ -157,7 +157,7 @@ def restart(self):
time.sleep(1)
possible_vehicles = self.world.get_actors().filter('vehicle.*')
for vehicle in possible_vehicles:
if vehicle.attributes['role_name'] == 'hero':
if vehicle.attributes['role_name'] == args.rolename:
print("Ego vehicle found")
self.player = vehicle
break
Expand Down Expand Up @@ -907,7 +907,7 @@ def game_loop(args):
pygame.display.flip()

hud = HUD(args.width, args.height)
world = World(sim_world, hud, args)
world = World(client.get_world(), hud, args)
controller = KeyboardControl(world, args.autopilot)

sim_world.wait_for_tick()
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ numpy
matplotlib
six
simple-watchdog-timer
antlr4-python3-runtime==4.10
graphviz
39 changes: 37 additions & 2 deletions scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
from srunner.scenarios.route_scenario import RouteScenario
from srunner.tools.scenario_parser import ScenarioConfigurationParser
from srunner.tools.route_parser import RouteParser
from srunner.tools.osc2_helper import OSC2Helper
from srunner.scenarios.osc2_scenario import OSC2Scenario
from srunner.scenarioconfigs.osc2_scenario_configuration import OSC2ScenarioConfiguration

# Version of scenario_runner
VERSION = '0.9.13'
Expand Down Expand Up @@ -89,7 +92,6 @@ def __init__(self, args):
# requests in the localhost at port 2000.
self.client = carla.Client(args.host, int(args.port))
self.client.set_timeout(self.client_timeout)

dist = pkg_resources.get_distribution("carla")
if LooseVersion(dist.version) < LooseVersion('0.9.12'):
raise ImportError("CARLA version 0.9.12 or newer required. CARLA version found: {}".format(dist))
Expand Down Expand Up @@ -133,6 +135,9 @@ def _signal_handler(self, signum, frame):
self._shutdown_requested = True
if self.manager:
self.manager.stop_scenario()
self._cleanup()
if not self.manager.get_running_status():
raise RuntimeError("Timeout occurred during scenario execution")

def _get_scenario_class_or_fail(self, scenario):
"""
Expand Down Expand Up @@ -209,6 +214,7 @@ def _prepare_ego_vehicles(self, ego_vehicles):
self.ego_vehicles.append(CarlaDataProvider.request_new_actor(vehicle.model,
vehicle.transform,
vehicle.rolename,
random_location=vehicle.random_location,
color=vehicle.color,
actor_category=vehicle.category))
else:
Expand Down Expand Up @@ -387,6 +393,12 @@ def _load_and_run_scenario(self, config):
scenario = RouteScenario(world=self.world,
config=config,
debug_mode=self._args.debug)
elif self._args.openscenario2:
scenario = OSC2Scenario(world=self.world,
ego_vehicles=self.ego_vehicles,
config=config,
osc2_file=self._args.openscenario2,
timeout=100000)
else:
scenario_class = self._get_scenario_class_or_fail(config.type)
scenario = scenario_class(self.world,
Expand Down Expand Up @@ -498,6 +510,24 @@ def _run_openscenario(self):
self._cleanup()
return result

def _run_osc2(self):
"""
Run a scenario based on ASAM OpenSCENARIO 2.0.
https://www.asam.net/static_downloads/public/asam-openscenario/2.0.0/welcome.html
"""
# Load the scenario configurations provided in the config file
if not os.path.isfile(self._args.openscenario2):
print("File does not exist")
self._cleanup()
return False

config = OSC2ScenarioConfiguration(self._args.openscenario2, self.client)

result = self._load_and_run_scenario(config)
self._cleanup()

return result

def run(self):
"""
Run all scenarios according to provided commandline args
Expand All @@ -507,6 +537,8 @@ def run(self):
result = self._run_openscenario()
elif self._args.route:
result = self._run_route()
elif self._args.openscenario2:
result = self._run_osc2()
else:
result = self._run_scenarios()

Expand Down Expand Up @@ -543,6 +575,7 @@ def main():
'--scenario', help='Name of the scenario to be executed. Use the preposition \'group:\' to run all scenarios of one class, e.g. ControlLoss or FollowLeadingVehicle')
parser.add_argument('--openscenario', help='Provide an OpenSCENARIO definition')
parser.add_argument('--openscenarioparams', help='Overwrited for OpenSCENARIO ParameterDeclaration')
parser.add_argument('--openscenario2', help='Provide an openscenario2 definition')
parser.add_argument(
'--route', help='Run a route as a scenario (input: (route_file,scenario_file,[route id]))', nargs='+', type=str)

Expand Down Expand Up @@ -571,12 +604,14 @@ def main():
arguments = parser.parse_args()
# pylint: enable=line-too-long

OSC2Helper.wait_for_ego = arguments.waitForEgo

if arguments.list:
print("Currently the following scenarios are supported:")
print(*ScenarioConfigurationParser.get_list_of_scenarios(arguments.configFile), sep='\n')
return 1

if not arguments.scenario and not arguments.openscenario and not arguments.route:
if not arguments.scenario and not arguments.openscenario and not arguments.route and not arguments.openscenario2:
print("Please specify either a scenario or use the route mode\n\n")
parser.print_help(sys.stdout)
return 1
Expand Down
4 changes: 1 addition & 3 deletions srunner/autoagents/npc_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def sensors(self):
return sensors

def run_step(self, input_data, timestamp):
"""
Execute one step of navigation.
"""
# Execute one step of navigation.
if not self._agent:

# Search for the ego actor
Expand Down
34 changes: 34 additions & 0 deletions srunner/examples/acceleration.osc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import basic.osc

type acceleration is SI(m: 1, s: -2)
unit kphps of acceleration is SI(m: 1, s: -1, factor: 0.277777778)

scenario top:
path: Path # A path in the map
path.set_map("Town04") # specify map to use in this test
path.path_min_driving_lanes(2) # Path should have at least two lanes

ego_vehicle: Model3 # ego car
npc: Rubicon # The other car

event start
event end
do serial:
get_ahead: parallel(duration: 15s):
ego_vehicle.drive(path) with:
speed(30kph)
lane(1, at: start) # left to right: [1..n]
npc.drive(path) with:
lane(right_of: ego_vehicle, at: start)
position(15m, behind: ego_vehicle, at: start)
position(20m, ahead_of: ego_vehicle, at: end)

slow: parallel(duration: 10s):
ego_vehicle.drive(path)
npc.drive(path) with:
speed(10kph)

accelerate: parallel(duration: 13s):
ego_vehicle.drive(path)
npc.drive(path) with:
acceleration(15kphps)
Loading