Commit ff6b02f0 authored by Moritz Klischat's avatar Moritz Klischat
Browse files

update doc

parent 644f9137
......@@ -17,6 +17,5 @@
<time-to-teleport value="-1"/>
<lanechange-output value="output_lanechange.txt"/>
<lanechange.duration value="20"/>
<lanechange.smooth-change value="1"/>
</processing>
</configuration>
......@@ -17,6 +17,5 @@
<time-to-teleport value="-1"/>
<lanechange-output value="output_lanechange.txt"/>
<lanechange.duration value="15"/>
<lanechange.smooth-change value="1"/>
</processing>
</configuration>
......@@ -49,7 +49,7 @@ setup(
'pytest>=3.8.0',
],
},
long_description_content_type='text/Markdown',
long_description_content_type='text/markdown',
long_description=readme,
classifiers=[
"Programming Language :: Python :: 3.6",
......
......@@ -35,28 +35,68 @@ Plug in a trajectory planner and run:
.. code-block:: python
from sumo2cr.interface.sumo_simulation import SumoSimulation
from sumo2cr.visualization.video import create_video
from example_scenarios.a9.scenario_config import Conf as conf
sumo_sim = SumoSimulation()
sumo_sim.initialize(conf)
output_folder = "/path/to/output_folder"
for t in range(conf.simulation_steps):
ego_vehicles = sumo_sim.ego_vehicles
commonroad_scenario = sumo_sim.commonroad_scenario_at_time_step(sumo_sim.current_time_step)
# plan trajectories for all ego vehicles
for id, ego_vehicle in ego_vehicles.items():
current_state = ego_vehicle.current_state
ego_trajectory = # plug in trajectory planner here
ego_vehicle.set_planned_trajectory(ego_trajectory)
sumo_sim.simulate_step()
sumo_sim.stop()
# obtain the complete scenario
scenario = sumo_sim.commonroad_scenarios_all_time_steps()
import copy
import os
from typing import List
import inspect
from commonroad.scenario.trajectory import State
from commonroad.common.file_reader import CommonRoadFileReader
from commonroad.common.file_writer import CommonRoadFileWriter
from sumocr.interface.sumo_simulation import SumoSimulation
from sumocr.maps.sumo_scenario import ScenarioWrapper
from example_scenarios.a9.scenario_config import Conf
config = Conf()
scenario_path = os.path.dirname(inspect.getfile(Conf))
cr_file = os.path.abspath(
os.path.join(scenario_path,
config.scenario_name + '.cr.xml'))
# Change this as you see fit
output_folder = os.path.dirname(cr_file)
print("Reading file:", cr_file, " Outputing to folder:", output_folder)
scenario, _ = CommonRoadFileReader(cr_file).open()
wrapper = ScenarioWrapper.init_from_scenario(config, scenario_path, cr_map_file=cr_file)
sumo_sim = SumoSimulation()
sumo_sim.initialize(config, wrapper)
for t in range(config.simulation_steps):
ego_vehicles = sumo_sim.ego_vehicles
commonroad_scenario = sumo_sim.commonroad_scenario_at_time_step(
sumo_sim.current_time_step)
# plan trajectories for all ego vehicles
for id, ego_vehicle in ego_vehicles.items():
current_state = ego_vehicle.current_state
# plug in a trajectory planner here, currently staying on initial state
next_state = copy.deepcopy(current_state)
next_state.time_step = 1
ego_trajectory: List[State] = [next_state]
ego_vehicle.set_planned_trajectory(ego_trajectory)
sumo_sim.simulate_step()
sumo_sim.stop()
print("Done simulating")
simulated_scenario = sumo_sim.commonroad_scenarios_all_time_steps()
CommonRoadFileWriter(simulated_scenario,
None,
author=scenario.author,
affiliation=scenario.affiliation,
source=scenario.source,
tags=scenario.tags,
location=scenario.location).write_scenario_to_file(
os.path.join(
output_folder,
config.scenario_name + ".simulated.xml"),
overwrite_existing_file=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment