目录
- 1.系统效果图
- 2.研究对象
- 3.不定相序模糊控制
- 4.模糊控制器设计思路
- 5.系统开发环境配置
- 6.相序优化模块
- 7.绿灯延时模块
- 8.修正模块
- 9.系统GUI界面设计
1.系统效果图
一来不多说先展示效果图。
2.研究对象
本文选择研究对象为三车道交叉路口,其几何模型示意图如下图所示,本文所设计的基于机器视觉的交通信号灯模糊控制系统共分为主要设计模块交通信号灯配时控制模块,负责根据车流量及道路拥堵状况控制红绿灯时长,进而疏散车流,减缓拥堵。
车辆平均延时等待数学模型,本设计所选取的道路模型为最常见的三车道模型,即每个方向包括了一条左转、一条右转和一条直行总共三个通行选择。另外考虑到在中国实际生活中,右转车辆通常不限行,因此本文中不作考虑。控制示意图如下,图中每个相位中的箭头表示的是拥有通行权的车辆,每个相位时间内车辆依次有序通过路口。
3.不定相序模糊控制
通过查阅相关文献智能控制,我们设计了如下不定相序模糊控制器,其结构主要包括 4个模块:相序优化模块、绿灯延时模块、校正模块及决断模块。其结构示意图如下图所示。不定相序模糊控制的基本思想是:首先定义一个评价指标——各红灯相位绿灯放行需求度,即在当前绿灯相位(用G表示)时间周期中,根据摄像头记录的交叉口实时车流量判断各红灯相位对于绿灯放行的需求度。将需求度最大的一个相作为下一绿灯相位(用NG表示),在当前绿灯相位时间中,通过比对当前绿灯相位车队长度与下一相位绿灯长度,经过各个模块协同作用确定当前绿灯延时时间。
4.模糊控制器设计思路
①确定输入输出变量;
②制定模糊规则,确定隶属度函数;
③通过论域变换,将变量的自然范围映射到论域范围;
④通过重心法进行清晰化处理,得到绿灯时间的模糊控制表。
5.系统开发环境配置
本文设计是利用MATLAB 2017b的图形用户界面(Graphical User Interfaces, GUI)软件平台完成基于机器视觉的交通信号灯自适应模糊控制系统设计。通常在开发一个实际应用的程序时会尽量做到界面友好,最常使用的方法就是使用图形用户界面GUI,建立这样一个界面友好、占用资源少、高性能、便于移植、可配置的GUI界面设计,能够使用户的学习和使用更为方便容易。
6.相序优化模块
相序优化模块的作用为评价当前红灯相位通行需求度,选出下一绿灯相位。该模块的输入量为当前各个红灯相的等候车辆数(Q_r)和红灯已过时长(T_r),输出为红灯相位绿灯放行需求度(U_r),量化因子(K_e)是指在模糊控制中,基本论域中的量为精确量,为了进行模糊化处理,必须将输入变量从基本论域转换到相应的模糊集论域,从而就要引进的概念,隶属度函数图如下。
相序优化模块模糊规则对应表
T_r | Q_r | ||||
VS | S | M | L | VL | |
VS | VF | VF | F | F | M |
S | VF | F | F | M | G |
M | F | F | M | G | VG |
L | F | M | G | VG | VG |
VL | M | G | VG | VG | VG |
7.绿灯延时模块
交通信号灯模糊控制器有两个输入量:当前绿灯周期等待通过交叉路口的车辆数L_g以及下一相位等待车辆数L_e,输出为绿灯相位延长时间T_i,隶属度函数如下。
绿灯延时模糊规则表
L_e | L_g | ||||||
VF | F | CF | M | CH | H | VH | |
VF | VS | CS | M | CL | L | L | VL |
F | VS | S | M | M | L | L | VL |
CF | VS | S | CS | M | CL | L | VL |
M | VS | S | CS | M | CL | L | L |
CH | VS | S | CS | CS | CL | L | L |
H | VS | VS | S | CS | M | CL | L |
VH | VS | VS | VS | S | M | CL | L |
8.修正模块
修正模块实现的功能为:根据当前绿灯和下一绿灯两个相位的车流量数据来修正当前绿灯相位的附加延时∆G。其输入量一个是当前绿灯相位的车辆到达率λ_p一个是下一绿灯相位的车辆到达率λ_n,输出为当前绿灯相位附加延时∆G,隶属度函数如下。
修正模块模糊规则表
λ_n | λ_p | ||||
VS | S | M | G | VG | |
VS | S | M | L | VL | VL |
S | S | S | M | L | VL |
M | VS | S | S | M | L |
G | VS | VS | S | S | M |
VG | VS | VS | VS | S | S |
9.系统GUI界面设计
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237function varargout = sltSystem(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sltSystem_OpeningFcn, ... 'gui_OutputFcn', @sltSystem_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function sltSystem_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; set(gcf, 'name', '基于机器视觉的交通信号灯自适应模糊控制系统设计与实现'); handles.data = show_img(hObject, eventdata, handles); handles.timeShow = {'timeWE', 'timeWN', 'timeNS', 'timeNE'}; handles.Qr = {'Qr_WE', 'Qr_WN', 'Qr_NS', 'Qr_NE'}; handles.Qr_rate = {'Qr_rate_WE', 'Qr_rate_WN', 'Qr_rate_NS', 'Qr_rate_NE'}; handles.reInfo = []; %表格数据 guidata(hObject, handles); function varargout = sltSystem_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function Qr_WE_Callback(hObject, eventdata, handles) function Qr_WE_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_rate_WE_Callback(hObject, eventdata, handles) function Qr_rate_WE_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_WN_Callback(hObject, eventdata, handles) function Qr_WN_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_NS_Callback(hObject, eventdata, handles) function Qr_NS_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_NE_Callback(hObject, eventdata, handles) function Qr_NE_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_rate_WN_Callback(hObject, eventdata, handles) function Qr_rate_WN_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_rate_NS_Callback(hObject, eventdata, handles) function Qr_rate_NS_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Qr_rate_NE_Callback(hObject, eventdata, handles) function Qr_rate_NE_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function control_start_Callback(hObject, eventdata, handles) global finish_status control_start_status(hObject, eventdata, handles, 'off'); [Qr, Qr_rate] = getData(hObject, eventdata, handles); control = readfis('./fuzzyController/control'); psOptimizer = readfis('./fuzzyController/phaseSequenceOptimizer'); correctModule = readfis('./fuzzyController/correctModule'); Kp_Qr = 0.6; Kp_Tr = 0.2; Kp_Ur = 1; Kp_Lg = 0.6; Kp_Le = 0.6; Kp_Ti = 0.6; Kp_lambdap = 1; Kp_lambdan = 1; Kp_deltaG = 1; Tmin = 15; Tmax = 120; KflagG = [1 1 1 1]; Gtime = [0,0,0,0]; Rtime = [0,0,0,0]; [Qr, Qr_rate] = getData(hObject, eventdata, handles); Qr_default = Qr; show_rate = round(handles.show_rate); i = 1;randQr = get_random_seed(Qr_rate); [~, G] = controller(psOptimizer, Qr*Kp_Qr, Rtime); while (true) if finish_status pst = get(handles.control_pause, 'String'); if strcmp(pst, '继续') set(handles.control_pause, 'String', '暂停'); uiresume; % 回复暂停 end break end if rem(i-1,4) == 0 fprintf('-----------------------------n') end G_Qr = Qr(G); Gtime(G) = Tmin; KflagG(G) = 0; [~, NG] = controller(psOptimizer, Qr*Kp_Qr.*KflagG, Rtime*Kp_Tr.*KflagG); [Ti, ~] = controller(control, G_Qr*Kp_Qr, Qr(NG)*Kp_Qr); Ta = 0; if Ti >= 5 [Ta, ~] = controller(correctModule, Qr_rate(G)*Kp_lambdap, Qr_rate(NG)*Kp_lambdan); end Gtime(G) = round(Gtime(G) + Ti/Kp_Ti + Ta/Kp_deltaG); Qr_Rtime = Rtime(G); Rtime = (Rtime + Gtime(G)).*KflagG; [valueT, ~] = max(Rtime); if (valueT > Tmax) Gtime(G) = Gtime(G) - valueT + Tmax; end % 绿灯时间 Qr_Gtime = Gtime(G); [change, Rtime] = limitTime(Rtime, Tmax); fprintf('车辆数: %d, 相位: %d, 绿灯时长: %d. n',Qr(G), G, Gtime(G)); delete(allchild(eval(['handles.' handles.data.names{G}]))); axes(eval(['handles.' handles.data.names{G}])); imshow(handles.data.img.green); while (Gtime(G)>0) if finish_status break end set(eval(['handles.' handles.timeShow{G}]), 'String', num2str(Gtime(G))); set(eval(['handles.' handles.timeShow{NG}]), 'String', num2str(Gtime(G))); pause(1); %这里pause要放在set后面,不然会多一秒 Gtime(G) = Gtime(G) - 1*show_rate; end try delete(allchild(eval(['handles.' handles.data.names{G}]))); end try set(eval(['handles.' handles.timeShow{G}]), 'String', '∞'); end axes(eval(['handles.' handles.data.names{G}])); imshow(handles.data.img.red); handles.reInfo = [handles.reInfo; {G},{G_Qr},{Qr_Gtime},{Qr_Rtime}]; set(handles.reInfoTable, 'Data', handles.reInfo); guidata(hObject, handles); KflagG(G) = 1; Rtime(G) = 0; if (handles.randYes == 1) Qr(G) = randQr(G) + round(rand(1)*8); set(eval(['handles.' handles.Qr{G}]), 'String', num2str(Qr(G))); else Qr(G) = Qr_default(G); end if (change) G = change; else G = NG; end i = i + 1; end finish_status = 0; function control_pause_Callback(hObject, eventdata, handles) pst = get(handles.control_pause, 'String'); if strcmp(pst, '继续') set(handles.control_pause, 'String', '暂停'); uiresume; % 回复暂停 else set(handles.control_pause, 'String', '继续'); uiwait; % 用于暂停 end function showRate_Callback(hObject, eventdata, handles) handles.show_rate = get(handles.showRate, 'Value'); guidata(hObject, handles); function showRate_CreateFcn(hObject, eventdata, handles) handles.show_rate = 1; guidata(hObject, handles); if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function control_finish_Callback(hObject, eventdata, handles) global finish_status button1 = questdlg('是否结束', '信息', '是', '否', '是'); if(button1 == '是') finish_status = 1; control_start_status(hObject, eventdata, handles, 'on'); finish_reset(hObject, eventdata, handles); end function control_exit_Callback(hObject, eventdata, handles) button1 = questdlg('是否退出系统', '退出系统', '是', '否', '是'); if(button1 == '是') delete(gcf); end %退出系统函数 function figure1_CloseRequestFcn(hObject, eventdata, handles) pst = get(handles.control_pause, 'String'); if strcmp(pst, '继续') set(handles.control_pause, 'String', '暂停'); uiresume; % 回复暂停 end button1 = questdlg('是否退出系统', '退出系统', '是', '否', '是'); if(button1 == '是') delete(hObject); end function control_pause_CreateFcn(hObject, eventdata, handles) function control_finish_CreateFcn(hObject, eventdata, handles) global finish_status finish_status = 0; function repeat_random_Callback(hObject, eventdata, handles) handles.randYes = get(handles.repeat_random, 'Value'); guidata(hObject, handles); % --- Executes on button press in random. function random_Callback(hObject, eventdata, handles) [~, Qr_rate] = getData(hObject, eventdata, handles); randQr = get_random_seed(Qr_rate); for i=1:length(randQr) try set(eval(['handles.' handles.Qr{i}]), 'String', num2str(randQr(i)+round(rand(1)*8))); end end function repeat_random_CreateFcn(hObject, eventdata, handles) handles.randYes = 0; guidata(hObject, handles); function exportData_Callback(hObject, eventdata, handles) keepTime = datestr(now,30); [~, ~, ret] = uiputfile('*.xlsx','另存为',['.xlsxData' keepTime '.xlsx']); if ret == 1 rowName = {'相位','车辆数','绿灯时长','等待时间'}; xlswrite(['.xlsxData' keepTime '.xlsx'], [rowName;handles.reInfo], '历史信息表'); msgbox('保存成功','信息'); else msgbox('未保存','信息'); end
最后
以上就是幽默眼睛最近收集整理的关于基于matlab的交通信号模糊控制系统设计1.系统效果图2.研究对象3.不定相序模糊控制4.模糊控制器设计思路5.系统开发环境配置6.相序优化模块7.绿灯延时模块8.修正模块9.系统GUI界面设计的全部内容,更多相关基于matlab内容请搜索靠谱客的其他文章。
发表评论 取消回复