├── Allclass2bar_contrast.m
├── README.md
├── class2_15_testplot.m
├── class2_18_testplot.m
├── class2_21_testplot.m
├── class2_24_testplot.m
├── class2_27_testplot.m
├── contrast15.m
├── image
├── 1.png
├── 2.png
└── 3.png
├── intersection.m
├── intersection.net.xml
├── intersection.rou.xml
├── intersection.settings.xml
├── intersection.sumocfg
├── intersection_energy.m
├── threshold_15s_all.m
├── threshold_18s_all.m
└── threshold_21s_all.m
/Allclass2bar_contrast.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/Allclass2bar_contrast.m
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Intersection-simulation
2 | Trying to build a trafic intersection assistant driving system simulation based on SUMO and TraCI4Matlab
3 |
4 | Sorry for all the notations are in Chinese, have't got the time to do the translation.
5 |
6 | To run this simple simulation, you need to install the following software:
7 |
8 | * Matlab2016a;
9 | * SUMO 0.32.0;
10 | * traci4matlab-API;
11 |
12 | You can have the following results:
13 |
14 | * A realtime Speed-time graph;
15 | * A realtime Speed-Distance graph;
16 | * A realtime Fuelconsumption-Distance graph;
17 |
18 | Here are some example of the figure:
19 |
20 |
21 |
22 |
23 |
24 | Here are some useful websites.
25 | * [SUMO Official Document](http://sumo.dlr.de/wiki/Simulation_of_Urban_MObility_-_Wiki)
26 | * [TraCI4Matlab](https://ww2.mathworks.cn/matlabcentral/fileexchange/44805-traci4matlab)
27 |
28 | run **intersection.m** to start.
29 |
30 | You can consider this as a tutorial of Traci4Matlab ^ ^
31 |
32 |
--------------------------------------------------------------------------------
/class2_15_testplot.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/class2_15_testplot.m
--------------------------------------------------------------------------------
/class2_18_testplot.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/class2_18_testplot.m
--------------------------------------------------------------------------------
/class2_21_testplot.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/class2_21_testplot.m
--------------------------------------------------------------------------------
/class2_24_testplot.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/class2_24_testplot.m
--------------------------------------------------------------------------------
/class2_27_testplot.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/class2_27_testplot.m
--------------------------------------------------------------------------------
/contrast15.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/contrast15.m
--------------------------------------------------------------------------------
/image/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/image/1.png
--------------------------------------------------------------------------------
/image/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/image/2.png
--------------------------------------------------------------------------------
/image/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/image/3.png
--------------------------------------------------------------------------------
/intersection.m:
--------------------------------------------------------------------------------
1 | clear
2 | close all
3 | clc
4 | import traci.constants
5 | system(['sumo-gui -c ' './intersection.sumocfg &']);%将m文件放至sumocfg文件同文件夹下
6 |
7 | unitchange = @(x) x*3600/1000; %变单位从m/s到km/h
8 | clock = 0; %计时器
9 | a=0;
10 | traci.init();%初始化接口
11 | Tidb = [];
12 | s = [];
13 | f = [];%接收累加的油耗参数
14 | d = [];%接收距离参数
15 | while traci.simulation.getMinExpectedNumber()>0 %无车辆时结束
16 | traci.simulationStep();
17 |
18 | ID = traci.vehicle.getIDList();
19 | if ismember('veh0',ID); %车辆列表中有veh0时开始
20 | % if ~isempty(strfind(ID, 'veh0'));
21 |
22 | % idb_arrived = traci.vehicle.getDistance('veh0');
23 | % if idb_arrived >= 400
24 | % a=1;
25 | % Tidb = clock;
26 | % end
27 | fuel = [f,traci.vehicle.getFuelConsumption('veh0')];%把每step油耗加入数组
28 | f = fuel;
29 | Distance = [d,traci.vehicle.getDistance('veh0')];%把每step距离加入数组
30 | d = Distance;
31 | current_speed_veh0 = traci.vehicle.getSpeed('veh0');
32 |
33 | current_speed_veh0 = unitchange(current_speed_veh0);
34 | Speed = [ s,current_speed_veh0];%把每step速度加入数组
35 | s = Speed;
36 | else
37 | end
38 | clock = clock +1;
39 | end
40 |
41 | traci.close()%关闭接口
42 |
43 | figure(1);
44 | plot(Speed,'r','LineWidth',1);ylim([0 60]);grid on;
45 | xlabel('时间');
46 | ylabel('速度km/h');
47 | legend('速度');
48 |
49 | figure(2);
50 | plot(Distance,fuel,'r','LineWidth',1);xlim([0 700]);ylim([0 7]);grid on;
51 | xlabel('距离');
52 | ylabel('瞬时油耗/ml');
53 | legend('油耗');
54 |
55 | figure(3);
56 | plot(Distance,Speed,'r','LineWidth',1);ylim([0 60]);grid on;
57 | xlabel('距离');
58 | ylabel('速度km/h');
59 | legend('速度');
60 |
61 | % Time = 2:clock;
62 | % figure(4);
63 | % plot(Time,Distance,'r','LineWidth',1);ylim([0 100]);grid on;
64 | % xlabel('距离');
65 | % ylabel('速度km/h');
66 | % legend('速度');
67 |
68 | Sumfuel = sum(fuel)
69 |
--------------------------------------------------------------------------------
/intersection.net.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/intersection.rou.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/intersection.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/intersection.sumocfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/intersection_energy.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/intersection_energy.m
--------------------------------------------------------------------------------
/threshold_15s_all.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/threshold_15s_all.m
--------------------------------------------------------------------------------
/threshold_18s_all.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/threshold_18s_all.m
--------------------------------------------------------------------------------
/threshold_21s_all.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MartinQingM/Intersection-simulation/4cf98717b23a23670a025dbbb626ef36dd37fdf1/threshold_21s_all.m
--------------------------------------------------------------------------------