Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nnmm committed Nov 26, 2020
1 parent 116e505 commit 53623f9
Show file tree
Hide file tree
Showing 21 changed files with 429 additions and 583 deletions.
58 changes: 0 additions & 58 deletions CMakeLists.txt

This file was deleted.

16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See [https://github.com/tier4/AutowareArchitectureProposal#how-to-setup](https:/

## 2. Usage

(2020/07/01 last modified)
(2020/11/23 last modified)

### 2.1 Get Sample Scenario

Expand Down Expand Up @@ -66,22 +66,12 @@ Note that the Map path must be rewritten when sharing a scenario with multiple u

#### (3) Execute

##### (a) Terminal A

``` shell
source /opt/ros/melodic/setup.bash
source /path/to/AutowareArchitectureProposal/install/setup.bash

rosrun planning_simulator_launcher scenario_roslaunch_server.py
```

#### (b) Terminal B

``` shell
source /opt/ros/melodic/setup.bash
source /opt/ros/foxy/setup.bash
source /path/to/AutowareArchitectureProposal/install/setup.bash

rosrun planning_simulator_launcher launch.py --timeout=180 && rosrun planning_simulator_launcher show_result.py ./scenario/generated ./scenario/log
ros2 run planning_simulator_launcher launch.py --timeout=180 && ros2 run planning_simulator_launcher show_result.py ./scenario/generated ./scenario/log
```
Command-line arguments of script `python show_result.py` is depends on the path you written in `scenario_database.json`.
1st argument is path to your directory your scenarios placed on + `/generated`.
Expand Down
4 changes: 2 additions & 2 deletions launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

print('\x1B[1;31mThis script has been deprecated.\x1B[0m')
print('\x1B[1;31mPlease use the following command.\x1B[0m')
print('\x1B[1;32m> rosrun planning_simulator_launcher launch.py\x1B[0m')
print('\x1B[1;32m> ros2 run planning_simulator_launcher launch.py\x1B[0m')

import os
import sys

os.system('rosrun planning_simulator_launcher launch.py ' + ' '.join(sys.argv[1:]))
os.system('ros2 run planning_simulator_launcher launch.py ' + ' '.join(sys.argv[1:]))
9 changes: 3 additions & 6 deletions launch/default.launch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<arg name="vehicle_model" default="lexus"/> <!-- PROJECT REPOSITORY EDIT HERE! -->
<arg name="rviz" default="true"/>

<arg name="log_output_dir"/>
<arg name="scenario_id"/>
<arg name="scenario_path"/>
<arg name="scenario_runner_output" default="screen"/>

<include file="$(find planning_simulator_launcher)/launch/scenario_launcher.launch" pass_all_args="true"/>
<include file="$(find-pkg-share planning_simulator_launcher)/launch/scenario_launcher.launch" pass_all_args="true">
<param from="$eval($(find-pkg-share($var(vehicle_model) + '_description')+'/config/vehicle_info.yaml" />
</include>
</launch>
58 changes: 10 additions & 48 deletions launch/scenario_launcher.launch
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,34 @@
<!-- Parameters for Planning Simulator -->
<arg name="map_path"/>
<arg name="sensor_model"/>
<arg name="vehicle_model"/>
<arg name="vehicle_info_param_path"/>
<arg name="rviz" default="true"/>
<arg name="use_object_recognition" default="true"/>

<!-- Parameters for Scenario Runner -->
<arg name="log_output_dir"/>
<arg name="scenario_id"/>
<arg name="scenario_path"/>
<arg name="scenario_runner_output" default="screen"/>
<arg name="initial_engage_state" />

<!-- Simulation Clock -->
<arg name="use_sim_time" default="false"/>
<param name="/use_sim_time" value="$(arg use_sim_time)"/>

<!-- Planning Simulator -->
<include file="$(find autoware_launch)/launch/planning_simulator.launch">
<include file="$(find-pkg-share autoware_launch)/launch/planning_simulator.launch">
<!-- planning_simulator.launch's essential parameters -->
<arg name="map_path" value="$(arg map_path)"/>
<arg name="sensor_model" value="$(arg sensor_model)"/>
<arg name="vehicle_model" value="$(arg vehicle_model)"/>
<arg name="map_path" value="$(var map_path)"/>
<arg name="sensor_model" value="$(var sensor_model)"/>
<arg name="vehicle_info_param_path" value="$(var vehicle_info_param_path)"/>

<!-- planning_simulator.launch's optional parameters -->
<arg name="rviz" value="$(arg rviz)"/>
<arg name="rviz_args" value="-d $(find scenario_api)/rviz/planning_simulator.rviz"/>
<arg name="rviz" value="$(var rviz)"/>
<arg name="rviz_args" value="-d $(find-pkg-share scenario_api)/rviz/planning_simulator.rviz"/>

<!-- simple_planning_simulator.launch's optional parameters -->
<arg name="initial_engage_state" value="false"/>

<!-- dummy_perception_publisher.launch's optional parameters -->
<arg name="perception/enable_detection_failure" value="false" />
<arg name="perception/enable_object_recognition" value="$(arg use_object_recognition)" />
<arg name="perception/enable_object_recognition" value="$(var use_object_recognition)" />
<arg name="sensing/visible_range" value="1000" />
</include>

<include file="$(find npc_simulator)/launch/npc_simulator.launch">
<arg name="initial_engage_state" value="false"/>
</include>

<!-- Scenario Runner -->
<node pkg="scenario_runner" type="scenario_runner_node" name="scenario_runner_node" output="$(arg scenario_runner_output)">
<param name="camera_frame_id" value="camera5/camera_optical_link"/> <!-- base link of front camera -->
<param name="log_output_path" value="$(arg log_output_dir)/$(arg scenario_id).json"/>
<param name="scenario_id" value="$(arg scenario_id)"/>
<param name="scenario_path" value="$(arg scenario_path)"/>
<remap from="~input/autoware_state" to="/autoware/state"/>
<remap from="~input/pointcloud" to="/sensing/lidar/no_ground/pointcloud"/>
<remap from="~input/route" to="/planning/mission_planning/route"/>
<remap from="~input/signal_command" to="/vehicle/status/turn_signal"/>
<remap from="~input/vectormap" to="/map/vector_map"/>
<remap from="~input/vehicle_twist" to="/vehicle/status/twist"/>
<remap from="~output/autoware_engage" to="/autoware/engage"/>
<remap from="~output/check_point" to="/planning/mission_planning/checkpoint"/>
<remap from="~output/goal_point" to="/planning/mission_planning/goal"/>
<remap from="~output/initial_velocity" to="/initialtwist"/>
<remap from="~output/lane_change_permission" to="/planning/scenario_planning/lane_driving/lane_change_approval"/>
<remap from="~output/limit_velocity" to="/planning/scenario_planning/max_velocity"/>
<remap from="~output/npc_simulator_engage" to="/simulation/npc_simulator/engage"/>
<remap from="~output/object_info" to="/simulation/npc_simulator/object_info"/>
<remap from="~output/simulator_engage" to="/vehicle/engage"/>
<remap from="~output/start_point" to="/initialpose"/>
<remap from="~output/traffic_detection_result" to="/perception/traffic_light_recognition/traffic_light_states"/>
<remap from="~rosparam/add_simulator_noise" to="/simple_planning_simulator/add_measurement_noise"/> <!-- rosparam: add simulator noise or not -->
<remap from="~rosparam/max_velocity" to="/planning/scenario_planning/motion_velocity_optimizer/max_velocity"/> <!-- rosparam: max velocity -->
<remap from="~rosparam/simulator_pos_noise" to="/simple_planning_simulator/pos_noise_stddev"/> <!-- rosparam: std of simulator pos noise -->
</node>

<!-- Recording -->
<node pkg="rosbag" type="record" name="rosbag_recorder" output="screen" respawn="false" respawn_delay="0" args="record --lz4 -a -O $(arg log_output_dir)/$(arg scenario_id).bag"/>
<node pkg="rosbag" exec="record" name="rosbag_recorder" output="screen" respawn="false" respawn_delay="0" args="record --lz4 -a -O $(var log_dir)/$(var scenario_id).bag"/>
</launch>
12 changes: 7 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" ?>
<package format="2">
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>planning_simulator_launcher</name>
<version>0.0.0</version>
<description>The planning_simulator_launcher package</description>
Expand All @@ -9,8 +10,9 @@
<maintainer email="[email protected]">Tatsuya Yamasaki</maintainer>

<license>Apache 2</license>
<exec_depend>scenario_runner</exec_depend>

<buildtool_depend>catkin</buildtool_depend>

<depend>rospy</depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>
153 changes: 153 additions & 0 deletions planning_simulator_launcher/launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import argparse
import json
from pathlib import Path
from typing import Optional, Union

import launch
from planning_simulator_launcher.launch_script import launch_description
from planning_simulator_launcher.scenario_parser import ScenarioParser


# If a base dir is given, resolves relative paths relative to the base dir.
# Otherwise, ensures that the path is absolute.
def absolute_path(path: Union[Path, str], base_dir: Optional[Path] = None):
path = Path(path)
if path.is_absolute():
return path.resolve()
if base_dir:
return (base_dir / path).resolve()
raise ValueError(f"Relative path '{path}' is not allowed.")


class Database:
def __init__(self, database_path: Path, *, base_dir: Optional[Path] = None):
print('Loading Database')
print(f' Opening \x1b[36m{database_path}\x1b[0m => ', end='')
with database_path.open() as file:
database = json.load(file)
print('\x1b[32mSuccess\x1b[0m')

print(f' Validating => ', end='')
self.launch_path = absolute_path(database['launch_path'], base_dir)
# Check if it exists, because the error message if we try to access it
# later is not helpful.
if not self.launch_path.is_file():
raise ValueError(f"launch_path '{self.launch_path}' is not a file")

self.log_output_base_dir = absolute_path(database['log_output_base_dir'], base_dir)

self.map = {name: absolute_path(path, base_dir) for name, path in database['map'].items()}
for path in self.map.values():
if not path.is_file():
raise ValueError(f"map '{path}' is not a file")

self.scenario = [absolute_path(path, base_dir) for path in database['scenario']]
for path in self.scenario:
if not path.is_file():
raise ValueError(f"scenario '{path}' is not a file")
print('\x1b[32mSuccess\x1b[0m')


class Launcher:
def __init__(self, args):
# Only created for validation, doesn't need to be stored
database = Database(args.database)

# Only use database if command line arg is None
self.launch_path = args.launch_path or database.launch_path
self.log_output_base_dir = args.log_output_base_dir or database.log_output_base_dir
# Similar, but wrap it in a list
self.scenarios = [args.scenario] if args.scenario else database.scenario
self.map = database.map
self.timeout = args.timeout
self.log_output_type = args.log_output


# Look up the map name in the scenario in scenario_database.json
def map_path(self, parser: ScenarioParser) -> Path:
scenario_map_path = parser.getMapPath()
print(f' Loading map \x1b[36m{scenario_map_path}\x1b[0m as ', end='')

# If the key is not found, return the key itself
map_path = self.map.get(
parser.getMapPath(),
parser.getMapPath()
)

if map_path == parser.getMapPath():
print('is')
else:
print(f'\x1b[36m{map_path}\x1b[0m')

return absolute_path(map_path)


def run_all_scenarios(self):
# This allows running launch files from this script
ls = launch.LaunchService()

if not self.log_output_base_dir.is_dir():
self.log_output_base_dir.mkdir(parents=True)

for scenario_path in self.scenarios:
print(f'\nRunning scenario \x1b[36m{scenario_path}\x1b[0m')
print(' Parameters')
parser = ScenarioParser(str(scenario_path), generate_mode=True)

n_total = len(parser.scenario_files_path)
for n, scenario_path in enumerate(parser.scenario_files_path, start=1):
scenario_path = Path(scenario_path)
print(f'\nLaunch {n} of {n_total}')
print(f' Scenario \x1b[36m{scenario_path}\x1b[0m')

ld = launch_description(
scenario_path=str(scenario_path),
scenario_id=parser.getScenarioId(),
log_dir=str(self.log_output_base_dir),
map_path=str(self.map_path(parser)),
uuid=scenario_path.stem,
launch_path=str(self.launch_path),
)
ls.include_launch_description(ld)
ls.run() # TODO: Timeout
ls.shutdown()


def main():
parser = argparse.ArgumentParser(description='launch simulator')
parser.add_argument(
'--timeout', type=int, default=180,
help='Specify simulation time limit in seconds. \
The default is 180 seconds.')
parser.add_argument(
'--database',
type=Path,
required=True,
help='Specify path to your scenario_database.json.')
parser.add_argument(
'--launch-path',
type=absolute_path,
help='Overrides the path to your launch file from scenario_database.json')
parser.add_argument(
'--log-output',
choices=['screen', 'log', 'both', 'own_log', 'full'],
default='screen',
help='Specify the type of log output.')
parser.add_argument(
'--log-output-base-dir',
type=absolute_path,
help='Overrides the log directory output from scenario_database.json')
parser.add_argument(
'--scenario',
help='Override the path to the scenario to be executed from scenario_database.json')
parser.add_argument(
'--base-path',
help='Allow relative paths in scenario_database.json and command line arguments, which will be interpreted')
args = parser.parse_args()

launcher = Launcher(args)
launcher.run_all_scenarios()


if __name__ == "__main__":
main()
Loading

0 comments on commit 53623f9

Please sign in to comment.