Real-time Simulation
Real-time simulation following the Ego vehicle is the fundamental feature of LimSim. To experience it, run the following command:
Interface Layout¶
If the above command runs successfully, the following interface will be displayed:
The entire graphical interface is divided into five areas. Area A shows the global view of the road network, with a blue circle representing the Area of Interest (AoI) that follows the movement of the Ego vehicle. It displays the real-time position of the Ego vehicle within the entire road network. Area B shows the follow view of the Ego vehicle, with a blue translucent circle representing the AoI, consistent with the circle in Area A. The purple curve in front of the vehicle represents the trajectory provided by the trajectory planning algorithm. Area C is the status display area of the Ego vehicle, showing its real-time speed and acceleration. Note the X-axis coordinates; the zero point is in the middle of the X-axis, representing the current moment. The left half of the zero point shows historical speed and acceleration, while the right half shows future speed and acceleration (i.e., the speed and acceleration provided by the planning algorithm). Additionally, the speed axis's range depends on the road's speed limit. Area D is the simulation information display area, showing the simulation mode, simulation time, the lane where the Ego vehicle is located, and its position on the lane. Area E is the scene evaluation area, which displays real-time evaluations of the scene. For the specific meanings of each indicator, please refer to ๅบๆฏ่ฏไปทใ
AoI (Area of Interest)
The AoI can be considered as the perception area of the Ego vehicle. It is a compromise solution made by LimSim to conduct long-duration simulations. Long-duration simulation involves a large road network and a large number of traffic flows, making it impossible to perform trajectory planning for all vehicles. Therefore, the behavior of vehicles inside the AoI is controlled by the decision-planning model, creating diverse and realistic driving environments around the Ego vehicle. Vehicles outside the AoI are controlled by SUMO, following basic traffic rules.
Example Analysis¶
This simulation example has the following structure:
-
On Windows systems, make sure that all model-related code is within the
if __name__ == '__main__':
scope; otherwise, the program may crash. The main reason for this is that SUMO uses Python's multiprocessing module, and the methods for creating processes differ between Windows and Linux. For more details, please refer to the contexts-and-start-methods in the Python documentation. -
If you are no longer controlling the Ego, remember to hand control back to SUMO.
The program's 8th line initializes the model with several main parameters, including egoID
, which specifies the ID of the Ego car. In this case, we use SUMO for traffic flow management, and the path information for all vehicles in the network is defined in Town05.rou.xml
. Therefore, you can check this file to select a specific car as the Ego car, or you can follow Customizing Vehicles and Routes to generate vehicles with specific paths for simulation and algorithm testing. The netFile
and rouFile
represent the network and route files used for simulation, and their generation and definition can be found in the SUMO documentation. dataBase
is a string specifying the database for recording simulation data.
The 15th line initializes the trajectory planning algorithm, which includes trajectory prediction, decision-making, planning, and other modules. Here, the basic version of LimSim (default parameters) is used to control the vehicles in the AoI. You can replace any part of it with your own algorithm. For details on customizing algorithms.
The main part of the program runs starting from line 17. model.tpEnd
is a boolean variable that indicates whether the Ego has reached the destination, i.e., whether the program has ended. model.moveStep()
and model.updateVeh()
are used for the simulation update process. The former is used to get information about all traffic participants, and the latter is used to update (control) information about all traffic participants. Thus, between the two functions, the trajectory planning algorithm can control the vehicles in the AoI.
Since trajectory planning algorithms are typically time-consuming and can provide trajectories for multiple frames in a single planning step, we perform trajectory planning every 5 frames, i.e., if model.timeStep % 5 == 0:
. Then, roadgraph, vehicles = model.exportSce()
provides information about the current scene around the Ego. roadgraph
contains the road network information around the Ego, and vehicles
contains information about the surrounding vehicles. The trajectories returned by the trajectory planning algorithm are then passed back to the simulation through model.setTrajectories()
.
After running the simulation above, all the data during the simulation will be stored in egoTrackingTest.db
, which can be used for replay and analysis. For more information about the database, please refer to Database.