function varargout = CruiseControl(varargin)
% CRUISECONTROL MATLAB code for CruiseControl.fig
% CRUISECONTROL, by itself, creates a new CRUISECONTROL or raises the existing
% singleton*.
%
% H = CRUISECONTROL returns the handle to a new CRUISECONTROL or the handle to
% the existing singleton*.
%
% CRUISECONTROL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CRUISECONTROL.M with the given input arguments.
%
% CRUISECONTROL('Property','Value',...) creates a new CRUISECONTROL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before CruiseControl_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to CruiseControl_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help CruiseControl
% Last Modified by GUIDE v2.5 10-Aug-2017 10:11:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @CruiseControl_OpeningFcn, ...
'gui_OutputFcn', @CruiseControl_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
% --- Executes just before CruiseControl is made visible.
function CruiseControl_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to CruiseControl (see VARARGIN)
% Choose default command line output for CruiseControl
handles.output = hObject;
%%初始化参数========================================================
handles.timer = timer('Period',1,'ExecutionMode','FixedRate', 'TimerFcn',...
{@timercallback,handles});%开创一个定时器
start(handles.timer);
Ahead_Picture = importdata('Ahead.jpg');
set(handles.Ahead,'CDATA',Ahead_Picture);
Back_Picture = importdata('Back.jpg');
set(handles.Back,'CDATA',Back_Picture);
Right_Picture = importdata('Right.jpg');
set(handles.Right,'CDATA',Right_Picture);
Left_Picture = importdata('Left.jpg');
set(handles.Left,'CDATA',Left_Picture);
Stop_Picture = importdata('Stop.jpg');
set(handles.Stop,'CDATA',Stop_Picture);
Indicator_Red = imread('indicator_red.jpg')%红色指示灯
axes(handles.indicator);
imshow(Indicator_Red);
vehicle = imread('vehicle_picture.jpg')%导入车辆
axes(handles.vehicle_picture);
imshow(vehicle);
wifi = imread('wifi1.jpg');
axes(handles.wifi);
imshow(wifi);
%=========================================================
%% 初始化参数
hasData = false; %表征网口是否接收到数据
isShow = false; %表征是否正在进行数据显示,即是否正在执行函数dataDisp
isStopDisp = false; %表征是否按下了【停止显示】按钮
isHexDisp = false; %表征是否勾选了【十六进制显示】
isHexSend = false; %表征是否勾选了【十六进制发送】
numRec = 0; %接收字符计数
numSend = 0; %发送字符计数
strRec = ''; %已接收的字符串
%% 将上述参数作为应用数据,存入窗口对象内
setappdata(hObject,'hasData',hasData);
setappdata(hObject,'strRec',strRec);
setappdata(hObject, 'numRec', numRec);
setappdata(hObject, 'numSend', numSend);
setappdata(hObject,'isShow',isShow);
setappdata(hObject,'isStopDisp',isStopDisp);
setappdata(hObject, 'isHexDisp', isHexDisp);
setappdata(hObject, 'isHexSend', isHexSend);
% Update handles structure
guidata(hObject, handles);
function timercallback(obj, event, handles)
time_num = fix(clock);
time_str1 = strcat(num2str(time_num(4)),':',num2str(time_num(5)+2),':',num2str(time_num(6)));
time_str2 = strcat(num2str(time_num(4)),':',num2str(time_num(5)+4),':',num2str(time_num(6)));
set(handles.clock1, 'String', datestr(now, 'HH:MM:SS'),'Fontsize',11);
set(handles.clock2,'String',time_str1,'Fontsize',11);
set(handles.clock3,'String',time_str2,'Fontsize',11);
% --- Outputs from this function are returned to the command line.
function varargout = CruiseControl_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function IP_Address_Callback(hObject, eventdata, handles)
% hObject handle to IP_Address (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of IP_Address as text
% str2double(get(hObject,'String')) returns contents of IP_Address as a double
% --- Executes during object creation, after setting all properties.
function IP_Address_CreateFcn(hObject, eventdata, handles)
% hObject handle to IP_Address (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function PORT_Callback(hObject, eventdata, handles)
% hObject handle to PORT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of PORT as text
% str2double(get(hObject,'String')) returns contents of PORT as a double
% --- Executes during object creation, after setting all properties.
function PORT_CreateFcn(hObject, eventdata, handles)
% hObject handle to PORT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Connect_Button.
function Connect_Button_Callback(hObject, eventdata, handles)
%% 若按下【连接小车】按钮,打开网口
if get (hObject,'value')
set(handles.Status,'String','状态:已连接')
ip = get(handles.IP_Address,'String');
port = str2num(get(handles.PORT,'String'));
global NET ;
NET = tcpip(ip,port);
set(NET,'InputBufferSize',30000);
set(NET,'BytesAvailableFcnMode','byte')
set(NET,'BytesAvailableFcn',{@bytes,handles})
set(NET, 'TimerPeriod',0.05,'timerfcn',{@dataDisp,handles});
%将网口对象的句柄作为用户数据,存入窗口对象
set(handles.figure1,'UserData',NET);
try
fopen(NET);
catch
msgbox('连接失败!请重新连接','警告',10);
set(hObject,'value',0);%弹起本按钮
return;
end
%%打开网口后,允许网口发送数据,同时点亮串口状态指示灯
Indicator_Green = imread('indicator_green.jpg')
axes(handles.indicator);
imshow(Indicator_Green);
else
%%停止并删除定时器
t = timerfind;
if ~isempty(t)
stop(t);
delete(t);
end
%%停止连接对象
fclose(NET);
delete(NET);
APei
- 粉丝: 83
- 资源: 1万+
最新资源
- 基于opencv-dnn和一些超过330 FPS的npu
- 房屋租赁管理系统 java项目ssm框架开发,全套视频教程
- MATLAB代码:计及电转气协同的含碳捕集与垃圾焚烧电厂优化调度 关键词:碳捕集 电厂 需求响应 优化调度 电转气协同调度 参考文档:《计及电转气协同的含碳捕集与垃圾焚烧电厂优化调度》完全复现
- 关键词:微网 优化调度 深度强化学习 A3C 需求响应 编程语言:python平台 主题:基于改进A3C算法的微网优化调度与需求响应管理 内容简介: 代码主要做的是基于深度强化学习的微网
- web网页,三次平时作业+大作业+Acwing笔记
- cruise软件模型,混动仿真模型,IMMD架构混联混动仿真模型,Cruise混动仿真模型,混联混动汽车动力性经济性仿真 关于模型 1.本模型是基于IMMD架构搭载的混联混动仿真模型,关于IMMD架
- C#上位机开发源码 上位机项目源代码 采用基于RS485通讯总线的ModbusRtu协议,支持用户权限管理、sqlite数据库、实时曲线、历史曲线、历史报表、导出Excel、主界面布局可调带记忆等功能
- 基于plc的污水处理,组态王动画仿真,带PLC源代码,组态王源代码,图纸,IO地址分配
- Rhino(犀牛)插件ladybug-tools-1-8-0
- 三相10Kw光伏并网逆变器 包含全套理图 PCB 源代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论1