Commit 04f028d2 authored by Moritz Klischat's avatar Moritz Klischat

fixed plotting, renamed config folder

parent 7e8db571
......@@ -11,4 +11,4 @@ SUMO_BINARY = '/home/user/sumo/bin/sumo'
TRACI_PORT = 8873
# default files (no adaption required)
DEFAULT_CFG_FILE = 'config/.sumo.cfg'
\ No newline at end of file
DEFAULT_CFG_FILE = 'sumo_config/.sumo.cfg'
\ No newline at end of file
from config.default import SumoCommonRoadConfig
from sumo_config.default import SumoCommonRoadConfig
class Conf(SumoCommonRoadConfig):
verbose = True
......@@ -14,7 +14,7 @@ class Conf(SumoCommonRoadConfig):
video_end = simulation_steps
scenario_name = 'a9'
plot_auto = False #plot_x1,plot_x2, plot_y1, plot_y2 only works if plot_auto is False
focus_ego_vehicle = True
center_ego_vehicle = True # video is centered at ego vehicle
plot_x1 = 50 #plot_x1 and plot_x2 defines the range of plotted scnario in x axis
plot_x2 = 300
plot_y1 = -10 #plot_y1 and plot_y2 defines the range of plotted scnario in y axis
......
from config.default import SumoCommonRoadConfig
from sumo_config.default import SumoCommonRoadConfig
class Conf(SumoCommonRoadConfig):
......@@ -14,7 +14,7 @@ class Conf(SumoCommonRoadConfig):
scenario_name = 'tri_junction'
with_sumo_gui = False
plot_auto = False #plot_x1,plot_x2, plot_y1, plot_y2 only works if plot_auto is False
focus_ego_vehicle = False
center_ego_vehicle = False
plot_x1 = 300 #plot_x1 and plot_x2 defines the range of plotted scnario in x axis
plot_x2 = 360
plot_y1 = 190 #plot_y1 and plot_y2 defines the range of plotted scnario in y axis
......
......@@ -47,10 +47,10 @@ class EgoVehicle:
"""
assert len(planned_state_list) >= self.delta_steps,\
'planned_trajectory must contain at least {} states, but contains {}. (See delta_steps in config file)'\
'planned_trajectory must contain at least {} states, but contains {}. (See delta_steps in sumo_config file)'\
.format(self.delta_steps,len(planned_state_list))
assert 1 == planned_state_list[0].time_step,\
'planned_trajectory must start at next time_step ({}) but starts at time_step {}'\
'planned_trajectory must always start at time_step ({}) but starts at time_step {}'\
.format(1, planned_state_list[0].time_step)
self._planned_trajectories[self.current_time_step] = planned_state_list
self.add_state(planned_state_list[0])
......
......@@ -2,22 +2,7 @@ from collections import defaultdict
import logging
import math
import sys, os
__author__ = "Moritz Klischat, Mostafa Eissa"
__copyright__ = "TUM Cyber-Physical Systems Group"
__credits__ = ["ZIM Projekt ZF4086007BZ8"]
__version__ = "1.0.0"
__maintainer__ = "Moritz Klischat"
__email__ = "commonroad-i06@in.tum.de"
__status__ = "Released"
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME' to point at the path of your SUMO installation.")
import config.default
import sumo_config.default
import traci
import numpy as np
import copy
......@@ -30,11 +15,25 @@ from sumo2cr.interface.ego_vehicle import EgoVehicle
from sumo2cr.maps.sumo_scenario import ScenarioWrapper
from sumo2cr.interface.util import *
from pathConfig import *
from config import plot_params
from config.default import SumoCommonRoadConfig
from sumo_config.plot_params import *
from sumo_config.default import SumoCommonRoadConfig
from sumo2cr.interface.util import initialize_id_dicts
from typing import Dict, List, Union, Type
__author__ = "Moritz Klischat, Mostafa Eissa"
__copyright__ = "TUM Cyber-Physical Systems Group"
__credits__ = ["ZIM Projekt ZF4086007BZ8"]
__version__ = "1.0.0"
__maintainer__ = "Moritz Klischat"
__email__ = "commonroad-i06@in.tum.de"
__status__ = "Released"
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME' to point at the path of your SUMO installation.")
logging.basicConfig(stream=sys.stderr, level=logging.CRITICAL)
......@@ -51,7 +50,7 @@ class SumoSimulation:
self.vehicledomain = traci._vehicle.VehicleDomain()
self.routedomain = traci._route.RouteDomain()
self._current_time_step = 0
self.ids_sumo2cr, self.ids_cr2sumo = initialize_id_dicts(config.default.ID_DICT)
self.ids_sumo2cr, self.ids_cr2sumo = initialize_id_dicts(sumo_config.default.ID_DICT)
self.obstacle_shapes: Dict[int,Rectangle] = {}
self.scenarios = ScenarioWrapper()
self.ego_vehicles: Dict[int, EgoVehicle] = dict()
......@@ -109,9 +108,9 @@ class SumoSimulation:
cr_id = self.cr_scenario.generate_object_id()
sumo_id = self._create_sumo_id()
self.vehicledomain.add(sumo_id,generic_route_id)
self.ids_sumo2cr[config.default.EGO_ID_START][sumo_id] = cr_id
self.ids_sumo2cr[sumo_config.default.EGO_ID_START][sumo_id] = cr_id
self.ids_sumo2cr['all_ids'][sumo_id] = cr_id
self.ids_cr2sumo[config.default.EGO_ID_START][cr_id] = sumo_id
self.ids_cr2sumo[sumo_config.default.EGO_ID_START][cr_id] = sumo_id
self.ids_cr2sumo['all_ids'][cr_id] = sumo_id
self._add_ego_vehicle(
EgoVehicle(cr_id, planning_problem.initial_state, self.conf.delta_steps, width, length, planning_problem))
......@@ -210,9 +209,9 @@ class SumoSimulation:
state = self._get_current_state_from_sumo(veh_id)
if veh_id not in self.ids_sumo2cr['all_ids']:
# initializes new vehicle
if veh_id.startswith(config.default.EGO_ID_START) and not self._silent:
if veh_id.startswith(sumo_config.default.EGO_ID_START) and not self._silent:
# new ego vehicle
cr_id = self._create_cr_id(config.default.EGO_ID_START, veh_id)
cr_id = self._create_cr_id(sumo_config.default.EGO_ID_START, veh_id)
if self._dummy_ego_simulation:
state.time_step = step -1
else:
......@@ -316,7 +315,7 @@ class SumoSimulation:
"""
:return: dictionary with all current ego vehicle ids and corresponding sumo ids
"""
return self.ids_cr2sumo[config.default.EGO_ID_START]
return self.ids_cr2sumo[sumo_config.default.EGO_ID_START]
def _create_sumo_id(self) -> int:
"""
......
......@@ -3,8 +3,8 @@ import xml.etree.ElementTree as et
import warnings
import config.default
from config import plot_params
import sumo_config.default
from sumo_config import plot_params
__author__ = "Moritz Klischat"
__copyright__ = "TUM Cyber-Physical Systems Group"
......@@ -16,8 +16,8 @@ __status__ = "Released"
def get_route_files(config_file):
"""
:param config_file: SUMO config file (.sumocfg)
:return: net-file and route-files specified in the config file
:param config_file: SUMO sumo_config file (.sumocfg)
:return: net-file and route-files specified in the sumo_config file
"""
if not os.path.isfile(config_file):
raise FileNotFoundError(config_file)
......@@ -50,9 +50,9 @@ def initialize_id_dicts(id_convention):
def generate_cr_id(type, sumo_id, ids_sumo2cr):
""" Generates a new commonroad ID without adding it to any ID dictionary."""
if type not in config.default.ID_DICT:
if type not in sumo_config.default.ID_DICT:
raise ValueError(
'{0} is not a valid type of id_convention. Only allowed: {1}'.format(type, config.default.ID_DICT.keys()))
'{0} is not a valid type of id_convention. Only allowed: {1}'.format(type, sumo_config.default.ID_DICT.keys()))
if sumo_id in ids_sumo2cr[type]:
warnings.warn('For this sumo_id there is already a commonroad id. No cr ID is generated')
return ids_sumo2cr[type][sumo_id]
......@@ -62,7 +62,7 @@ def generate_cr_id(type, sumo_id, ids_sumo2cr):
# If this case happens for auto-generated nets, this code will have to be changed. Conversion of SUMO id to
# cr id would have to incorporate type.
cr_id = int(str(config.default.ID_DICT[type]) + str(len(ids_sumo2cr[type])))
cr_id = int(str(sumo_config.default.ID_DICT[type]) + str(len(ids_sumo2cr[type])))
return cr_id
......
......@@ -13,7 +13,7 @@ from commonroad.scenario.lanelet import LaneletNetwork
from commonroad.common.util import Interval
from commonroad.common.file_reader import CommonRoadFileReader
from config.default import SumoCommonRoadConfig as conf
from sumo_config.default import SumoCommonRoadConfig as conf
__author__ = "Moritz Klischat"
__copyright__ = "TUM Cyber-Physical Systems Group"
......@@ -140,8 +140,8 @@ class ScenarioWrapper:
def _get_net_file(self, sumo_cfg_file):
"""
:param sumo_cfg_file: SUMO config file (.sumocfg)
:return: net-file specified in the config file
:param sumo_cfg_file: SUMO sumo_config file (.sumocfg)
:return: net-file specified in the sumo_config file
"""
if not os.path.isfile(sumo_cfg_file):
raise ValueError("File not found: {}. Maybe scenario name is incorrect.".format(sumo_cfg_file))
......
......@@ -13,7 +13,7 @@ from lxml import etree
from opendrive2lanelet.io.extended_file_writer import ExtendedCommonRoadFileWriter
from opendrive2lanelet.network import Network
from opendrive2lanelet.opendriveparser.parser import parse_opendrive
from config.default import EGO_ID_START
from sumo_config.default import EGO_ID_START
__author__ = "Moritz Klischat"
__copyright__ = "TUM Cyber-Physical Systems Group"
......
from commonroad.visualization.draw_dispatch_cr import draw_object
from matplotlib import pyplot as plt, animation as manimation
from config.plot_params import draw_params_obstacle, draw_params_ego
from sumo_config.plot_params import draw_params_obstacle, draw_params_ego
import warnings
import os
import time
from copy import deepcopy
from sumo2cr.interface.sumo_simulation import SumoSimulation
__author__ = "Moritz Klischat"
......@@ -80,9 +81,10 @@ def draw_plot(sumo_sim: SumoSimulation, time_step:int=None, _draw_params_ego=Non
# set plot limits
if (sumo_sim.conf.plot_auto == False):
if sumo_sim.conf.focus_ego_vehicle is True and len(ego_veh) > 0:
if sumo_sim.conf.center_ego_vehicle is True and len(ego_veh) > 0:
scenario = deepcopy(scenario)
pos = ego_veh[0].initial_state.position
ori = sumo_sim.ego_vehicles[ego_veh[0].obstacle_id].initial_state.orientation# - np.deg2rad(90)
ori = sumo_sim.ego_vehicles[ego_veh[0].obstacle_id].initial_state.orientation # - np.deg2rad(90)
# ori=0
plot_limits = [-sumo_sim.conf.window_width / 2 + pos[0], sumo_sim.conf.window_width / 2 + pos[0],
......
......@@ -9,16 +9,17 @@ class SumoCommonRoadConfig():
# simulation
dt = 0.1 # length of simulation step of the interface
delta_steps = 2 # number of sub-steps simulated in SUMO during every dt
presimulation_steps = 10 # number of time steps before simulation with ego vehicle starts
presimulation_steps = 10 # number of time steps before simulation with ego vehicle starts (not plotted)
simulation_steps = 100 # number of simulated (and synchronized) time steps
with_sumo_gui = False
# plotting
video_start = 1
video_start = 1 # start of
video_end = 100
scenario_name = '<scenario_name>'
# autoscale plot limits; plot_x1,plot_x2, plot_y1, plot_y2 only works if plot_auto is False
plot_auto = True
center_ego_vehicle = True # video is centered at ego vehicle
# axis limits of plot
plot_x1 = 450
plot_x2 = 550
......
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