Skip to content
Snippets Groups Projects
Commit 7a0d3ef7 authored by keyis2's avatar keyis2
Browse files

modify CarAgent, update doc

parent 6071de79
No related branches found
No related tags found
2 merge requests!14Merge gearbox example to main,!12AEB example, plotter doc, CarAgent brake mode
......@@ -4,6 +4,7 @@ from verse import Scenario
from verse.scenario import ScenarioConfig
# from noisy_sensor import NoisyVehicleSensor
from verse.plotter.plotter2D import *
import os
from enum import Enum, auto
import time
......@@ -48,9 +49,10 @@ class State:
if __name__ == "__main__":
input_code_name = './demo/AEB/controller1.py'
# note: I modify file path assuming the controller is under the same directory -- Keyi
parent_dir=os.path.dirname(__file__)
input_code_name = parent_dir+'/controller1.py'
scenario = Scenario(ScenarioConfig(init_seg_length=5))
car = CarAgent('car1', file_name=input_code_name)
scenario.add_agent(car)
car = NPCAgent('car2')
......@@ -58,8 +60,9 @@ if __name__ == "__main__":
# car = NPCAgent('car3')
# scenario.add_agent(car)
# Q. Why do we need the tmp_map name?
# A. Not necessary. We can replace all tmp_map by M1() in this case.
tmp_map = M1()
scenario.set_map(M1())
scenario.set_map(tmp_map)
scenario.set_init(
[
[[5, -0.5, 0, 1.0], [5.5, 0.5, 0, 1.0]],
......@@ -77,7 +80,7 @@ if __name__ == "__main__":
# traces = scenario.verify(40, 0.1, params={"bloating_method": 'GLOBAL'})
traces = scenario.simulate(100,0.1)
run_time = time.time()-start_time
traces.dump('./demo/AEB/sim_straight.json')
traces.dump(parent_dir+'/sim_straight.json')
print({
"#A": len(scenario.agent_dict),
......@@ -90,7 +93,7 @@ if __name__ == "__main__":
})
fig = go.Figure()
fig = simulation_tree(traces, tmp_map, fig, 1, 2,None, 'lines', 'trace')
fig = simulation_tree(traces, tmp_map, fig, 1, 2, None, 'lines', 'trace')
# fig = simulation_anime(traces, tmp_map, fig, 1, 2,None, 'lines', 'trace', time_step=0.1)
# fig = reachtube_anime(traces, tmp_map, fig, 1, 2, None,'lines', 'trace', combine_rect=1)
fig.show()
\ No newline at end of file
This diff is collapsed.
......@@ -16,6 +16,11 @@ simulation_tree
----------------------
It statically shows simulation traces, possibly with multiple brances.
Note: Since the plotter functions have similar APIs,
in this document, we treat this function as a base function.
Its parameters are general and occurred in all remaining functions.
We will omit them in the remaining functions and only list some specific parameters.
Usage::
simulation_tree(root: Union[AnalysisTree, AnalysisTreeNode], map=None, fig=go.Figure(), x_dim: int = 1, y_dim: int = 2, print_dim_list=None, map_type='lines', scale_type='trace', label_mode='None', sample_rate=1)
......@@ -76,37 +81,6 @@ Parameters not occurred in ``simulation_tree``:
* if it's ``False``, then the full trace will not be displayed.
* Otherwise, the full trace will be displayed.
Parameters shown in ``simulation_tree``:
* ``root``: root node of a simulation trace. Typically, return value of ``Scenario.simulate()``.
* ``map``: the map of the scenario plotted as a background.
* ``fig``: figure object of type ``plotly.graph_objects.Figure()``.
* ``x_dim:`` the dimension of x coordinate in the trace list of every time step. The default value is ``1``.
* ``y_dim:`` the dimension of y coordinate in the trace list of every time step. The default value is ``2``.
* ``print_dim_list`` the list containing the dimensions of data which will be shown directly or indirectly when the mouse hovers on the point. The default value is ``None``. And then all dimensions will be shown.
* ``map_type`` the way to draw the map. It should be ``'lines'`` or ``'fill'`` or ``'detailed'``. The default value is ``'lines'``.
* For the ``'lines'`` mode, map is only drawn by margins of lanes.
* For the ``'fill'`` mode, the lanes will be filled with semitransparent colors.
* For the ``'detailed'`` mode, the lanes will be filled some colors according to the speed limits of lanes(if the information is given). Otherwise, it is the same as the 'lines' mode.
* ``scale_type`` the way to scale the coordinate axises. It should be ``'trace'`` or ``'map'``. The default value is ``'trace'``.
* For the ``'trace'`` mode, the traces will be in the center of the plot with an appropriate scale.
* For the ``'map'`` mode, the map will be in the center of the plot with an appropriate scale.
* ``label_mode`` the mode to display labels which indicate mode transitions or not. The default value is ``'None'``.
* If it is ``'None'``, then labels will not be displayed.
* Otherwise, labels will be displayed.
* ``sample_rate`` it determines the points used in the plot. It is useful when the points are too much and the response of the plot is slow. The default value is ``1``.
* If ``sample_rate = n`` where ``n`` is a positive integer, then the plotter samples one point for every ``n`` points.
----------------------
reachtube_tree
----------------------
......@@ -120,37 +94,6 @@ Parameters not occurred in ``simulation_tree``:
* ``combine_rect`` it determines the way of displaying reachtube. Specifically, it can combine specified number of reachtubes as a rectangle. The default value is ``1`` here.
Parameters shown in ``simulation_tree``:
* ``root``: root node of a simulation trace. Typically, return value of ``Scenario.simulate()``.
* ``map``: the map of the scenario plotted as a background.
* ``fig``: figure object of type ``plotly.graph_objects.Figure()``.
* ``x_dim:`` the dimension of x coordinate in the trace list of every time step. The default value is ``1``.
* ``y_dim:`` the dimension of y coordinate in the trace list of every time step. The default value is ``2``.
* ``print_dim_list`` the list containing the dimensions of data which will be shown directly or indirectly when the mouse hovers on the point. The default value is ``None``. And then all dimensions will be shown.
* ``map_type`` the way to draw the map. It should be ``'lines'`` or ``'fill'`` or ``'detailed'``. The default value is ``'lines'``.
* For the ``'lines'`` mode, map is only drawn by margins of lanes.
* For the ``'fill'`` mode, the lanes will be filled with semitransparent colors.
* For the ``'detailed'`` mode, the lanes will be filled some colors according to the speed limits of lanes(if the information is given). Otherwise, it is the same as the 'lines' mode.
* ``scale_type`` the way to scale the coordinate axises. It should be ``'trace'`` or ``'map'``. The default value is ``'trace'``.
* For the ``'trace'`` mode, the traces will be in the center of the plot with an appropriate scale.
* For the ``'map'`` mode, the map will be in the center of the plot with an appropriate scale.
* ``label_mode`` the mode to display labels which indicate mode transitions or not. The default value is ``'None'``.
* If it is ``'None'``, then labels will not be displayed.
* Otherwise, labels will be displayed.
* ``sample_rate`` it determines the points used in the plot. It is useful when the points are too much and the response of the plot is slow. The default value is ``1``.
* If ``sample_rate = n`` where ``n`` is a positive integer, then the plotter samples one point for every ``n`` points.
----------------------
reachtube_anime
----------------------
......@@ -170,36 +113,6 @@ Parameters not occurred in ``simulation_tree``:
* ``combine_rect`` it determines the way of displaying reachtube. Specifically, it can combine specified number of reachtubes as a rectangle. The default value is ``None`` here, which means no combination.
Parameters shown in ``simulation_tree``:
* ``root``: root node of a simulation trace. Typically, return value of ``Scenario.simulate()``.
* ``map``: the map of the scenario plotted as a background.
* ``fig``: figure object of type ``plotly.graph_objects.Figure()``.
* ``x_dim:`` the dimension of x coordinate in the trace list of every time step. The default value is ``1``.
* ``y_dim:`` the dimension of y coordinate in the trace list of every time step. The default value is ``2``.
* ``print_dim_list`` the list containing the dimensions of data which will be shown directly or indirectly when the mouse hovers on the point. The default value is ``None``. And then all dimensions will be shown.
* ``map_type`` the way to draw the map. It should be ``'lines'`` or ``'fill'`` or ``'detailed'``. The default value is ``'lines'``.
* For the ``'lines'`` mode, map is only drawn by margins of lanes.
* For the ``'fill'`` mode, the lanes will be filled with semitransparent colors.
* For the ``'detailed'`` mode, the lanes will be filled some colors according to the speed limits of lanes(if the information is given). Otherwise, it is the same as the 'lines' mode.
* ``scale_type`` the way to scale the coordinate axises. It should be ``'trace'`` or ``'map'``. The default value is ``'trace'``.
* For the ``'trace'`` mode, the traces will be in the center of the plot with an appropriate scale.
* For the ``'map'`` mode, the map will be in the center of the plot with an appropriate scale.
* ``label_mode`` the mode to display labels which indicate mode transitions or not. The default value is ``'None'``.
* If it is ``'None'``, then labels will not be displayed.
* Otherwise, labels will be displayed.
* ``sample_rate`` it determines the points used in the plot. It is useful when the points are too much and the response of the plot is slow. The default value is ``1``.
* If ``sample_rate = n`` where ``n`` is a positive integer, then the plotter samples one point for every ``n`` points.
===================
3D Visualization
===================
......@@ -90,7 +90,7 @@ class CarAgent(BaseAgent):
self.switch_duration += 0.1
elif vehicle_mode == "Brake":
d = -lane_map.get_lateral_distance(vehicle_lane, vehicle_pos)
a = -1
a = max(-1,-v)
self.switch_duration = 0
elif vehicle_mode == "Accel":
d = -lane_map.get_lateral_distance(vehicle_lane, vehicle_pos)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment