Skip to content
Snippets Groups Projects
Commit 794d02fe authored by keyis2's avatar keyis2
Browse files

general Cont.

parent 82cf3799
No related branches found
No related tags found
No related merge requests found
from dryvr_plus_plus.example.example_agent.car_agent import CarAgent, NPCAgent
from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario
from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap5, SimpleMap6
from dryvr_plus_plus.plotter.plotter2D import *
from dryvr_plus_plus.plotter.plotter2D_new import *
from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor2
import matplotlib.pyplot as plt
......@@ -75,6 +75,6 @@ if __name__ == "__main__":
fig = go.Figure()
for traces in res_list:
# plotly_map(tmp_map, 'g', fig)
fig = plotly_simulation_tree(traces, 'car2', 1, [2], 'r', fig)
fig = test_simu_anime(traces, tmp_map, fig, 1, 2, 'lines')
# fig = plotly_simulation_anime(traces, tmp_map, fig)
fig.show()
......@@ -2,6 +2,7 @@ from dryvr_plus_plus.example.example_agent.car_agent import CarAgent
from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario
from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap5, SimpleMap6
from dryvr_plus_plus.plotter.plotter2D import *
from dryvr_plus_plus.plotter.plotter2D_new import *
from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor2
import plotly.graph_objects as go
import matplotlib.pyplot as plt
......@@ -82,9 +83,9 @@ if __name__ == "__main__":
# fig = plotly_reachtube_tree_v2(traces, 'car1', 1, [2], 'blue', fig)
# fig = plotly_reachtube_tree_v2(traces, 'car2', 1, [2], 'red', fig)
# fig.show()
traces = scenario.verify(20)
traces = scenario.simulate(20)
fig = go.Figure()
fig = generate_reachtube_anime(traces, tmp_map, fig)
fig = test_simu_anime(traces, tmp_map, fig, 1, 2, 'lines')
# fig = plotly_simulation_anime(traces, tmp_map, fig)
# # fig = plotly_reachtube_tree_v2(traces, 'car2', 1, [2], 'red', fig)
fig.show()
......@@ -55,7 +55,7 @@ def controller(ego: State, other: State, sign: State, lane_map: LaneMap):
# output.vehicle_mode = VehicleMode.Accelerate
# if lane_map.get_longitudinal_position(other.lane_mode, [other.x, other.y]) - lane_map.get_longitudinal_position(ego.lane_mode, [ego.x, ego.y]) > 5:
# output.vehicle_mode = VehicleMode.Accelerate
if lane_map.get_speed_limit(ego.lane_mode, [ego.x, ego.y]) > 1:
if lane_map.get_speed_limit(ego.lane_mode) > 1:
output.vehicle_mode = VehicleMode.Accelerate
if ego.vehicle_mode == VehicleMode.SwitchLeft:
......
This diff is collapsed.
# Plotly-based Plotter Notes
# Plotly-based Plotter Development Notes
Now the latest version is placed in plotter2D_new.py. All functions in the plotter2D.py still work. Every function are in developemnt and might change.
## Current work & Todo
- **Animation with trails** supported in test_simu_anime() and will be tested further.
- **Modified accelerating mode** modified, will be tested
- **new quadrotor agent**
- **different color for segments of trace** ongoing. Color choice ?
## Functions
Belows are the functions currently used. Some of the functions in the file are deprecated.
......@@ -29,11 +35,11 @@ The original version is implemented with rectangle and very inefficient.
- **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.
- **color_id:** a int indicating the color. Now 10 kinds of colors are supported. If it is None, the colors of segments will be auto-assigned. The default value is None.
- **map_type** the way to draw the map. It should be 'lines' or 'fill'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors.
- **map_type** the way to draw the map. It should be 'lines' or 'fill' or 'detailed'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors. For the 'detailed' mode, it will vistualize the speed limit information (if exists) by fill the lanes with different colors. The Default value is 'lines'.
#### draw_map(map, color, fig, fill_type)
The genernal static plotter for map. It is called in many functions drawing traces.
The genernal static plotter for map. It is called in many functions drawing traces, so it is often unnecessary to call it separately.
**parameters:**
- **map:** the map of the scenario, templates are in dryvr_plus_plus.example.example_map.simple_map2.py.
......@@ -50,10 +56,22 @@ The old ungenernal static plotter for map which support visualization of speed l
- **color** the color of the margin of the lanes, should be a string like 'black' or in rgb/rgba format, like 'rgb(0,0,0)' or 'rgba(0,0,0,1)'. The default value is 'rgba(0,0,0,1)' which is non-transparent black.
- **fig:** the object of the figure, its type should be plotly.graph_objects.Figure().
#### draw_simulation_tree(root, agent_id, x_dim, y_dim, color, fig):
#### draw_simulation_tree(root, map, fig, x_dim, y_dim, map_type, scale_type):
The genernal static plotter for reachtube tree. It draws the all traces of reachtubes and the map.
The original version is implemented with rectangle and very inefficient.
The genernal static plotter for simulation trees. It draws the traces of agents and map.
**parameters:**
- **root:** the root node of the trace, should be the return value of Scenario.simulate().
- **map:** the map of the scenario, templates are in dryvr_plus_plus.example.example_map.simple_map2.py.
- **fig:** the object of the figure, its type should be 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.
- **map_type** the way to draw the map. It should be 'lines' or 'fill'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors.
- **scale_type** the way to draw the map. It should be 'trace' or 'map'. For the 'trace' mode, the plot will be scaled to show all traces. For the 'map' mode, the plot will be scaled to show the whole map. The Default value is 'trace'.
#### draw_simulation_tree_single(root, agent_id, x_dim, y_dim, color_id, fig):
The genernal static plotter for simulation tree. It draws the traces of one specific agent.
**parameters:**
- **root:** the root node of the trace, should be the return value of Scenario.simulate().
......@@ -62,7 +80,6 @@ The original version is implemented with rectangle and very inefficient.
- **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.
- **color_id:** a int indicating the color. Now 10 kinds of colors are supported. If it is None, the colors of segments will be auto-assigned. The default value is None.
- **map_type** the way to draw the map. It should be 'lines' or 'fill'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors.
#### draw_simulation_anime(root, map, fig)
......@@ -73,7 +90,7 @@ The old ungenernal plotter for simulation animation. It draws the all traces and
- **map:** the map of the scenario, templates are in dryvr_plus_plus.example.example_map.simple_map2.py. It doesn't handle the map with wrong format. Only SimpleMap3_v2() class is supported now.
- **fig:** the object of the figure, its type should be plotly.graph_objects.Figure().
#### general_simu_anime(root, map, fig, x_dim, y_dim, map_type):
#### general_simu_anime(root, map, fig, x_dim, y_dim, map_type, scale_type):
The genernal plotter for simulation animation. It draws the all traces and the map. Animation is implemented as points. Since arrow is hard to generalize.
......@@ -83,5 +100,6 @@ The genernal plotter for simulation animation. It draws the all traces and the m
- **fig:** the object of the figure, its type should be 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.
- **map_type** the way to draw the map. It should be 'lines' or 'fill'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors.
- **map_type** the way to draw the map. It should be 'lines' or 'fill'. For the 'lines' mode, map is only drawn by margins of lanes. For the 'fill' mode, the lanes will be filled semitransparent colors. The Default value is 'lines'.
- **scale_type** the way to draw the map. It should be 'trace' or 'map'. For the 'trace' mode, the plot will be scaled to show all traces. For the 'map' mode, the plot will be scaled to show the whole map. The Default value is 'trace'.
......@@ -8,9 +8,10 @@ from dryvr_plus_plus.scene_verifier.map.lane_segment import AbstractLane
class Lane():
COMPENSATE = 3
def __init__(self, id, seg_list: List[AbstractLane]):
def __init__(self, id, seg_list: List[AbstractLane], speed_limit=None):
self.id = id
self.segment_list: List[AbstractLane] = seg_list
self.speed_limit = speed_limit
self._set_longitudinal_start()
def _set_longitudinal_start(self):
......@@ -46,8 +47,10 @@ class Lane():
longitudinal, lateral = segment.local_coordinates(position)
return lateral
def get_speed_limit(self, position: np.ndarray) -> float:
def get_speed_limit_old(self, position: np.ndarray) -> float:
seg_idx, segment = self.get_lane_segment(position)
longitudinal, lateral = segment.local_coordinates(position)
return segment.speed_limit_at(longitudinal)
def get_speed_limit(self):
return self.speed_limit
......@@ -95,11 +95,23 @@ class LaneMap:
seg_idx, segment = lane.get_lane_segment(position)
return segment
def get_speed_limit(self, lane_idx: str, position: np.ndarray) -> AbstractLane:
def get_speed_limit_old(self, lane_idx: str, position: np.ndarray) -> float:
if not isinstance(position, np.ndarray):
position = np.array(position)
lane = self.lane_dict[lane_idx]
limit = lane.get_speed_limit(position)
limit = lane.get_speed_limit_old(position)
# print(limit)
# print(position)
return limit
def get_speed_limit(self, lane_idx: str) -> float:
lane = self.lane_dict[lane_idx]
print(lane.get_speed_limit())
return lane.get_speed_limit()
def get_all_speed_limit(self) -> Dict[str, float]:
ret_dict = {}
for lane_idx, lane in self.lane_dict.items():
ret_dict[lane_idx] = lane.get_speed_limit()
print(ret_dict)
return ret_dict
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