MatLab GUI accelerometer reading DATA

Hello, as of right now i'm trying to read in accelerometer data to my MatLab gui thru a pushbutton.. So far here is my code
function pushbutton6_Callback(hObject, eventdata, handles)
%mapping between analog inputs and X,Y,Z axes.
% Xch = 1;
% Ych = 3;
% Zch = 2;
fprintf(out.s,'R');
%read voltages from accelerometer and reorder
reordered(1)= fscanf(out.s,'%u');
reordered(2)= fscanf(out.s,'%u');
reordered(3)= fscanf(out.s,'%u');
%determine what offset and gain values to use
offset = calCo.offset;
gain = calCo.g;
accel = (reordered - offset) ./ gain;
%map analog inputs to axes
handles.gx = accel(1);
handles.gy = accel(2);
handles.gz = accel(3);
guidata(hObject, handles)
This code was partially written for me. I'm trying to understand it since i've only been using matlab for 3 weeks. Can anybody help me what i'm doing wrong? I have a button for calibrating and a button for reading in the serial, but as of right now i'm trying to read actual data and later graph.
THANKS
FIrst problem fixed... scroll down below for the new problem I cannot seem to fix.. THANKS

8 件のコメント

Amed
Amed 2013 年 2 月 8 日
Any suggestions?
Walter Roberson
Walter Roberson 2013 年 2 月 8 日
You have not indicates the problem you are encountering.
Amed
Amed 2013 年 2 月 8 日
I'm sorry, edited with the problem. Nothing happens when the pushbutton is clicked. There are no readouts nor errors.
Walter Roberson
Walter Roberson 2013 年 2 月 8 日
Have you tried putting in a breakpoint at the first executable line of code, and running, and single-stepping to see what happens?
Your code does not display any values or change any gui elements, so it might not be obvious that it is running.
Amed
Amed 2013 年 2 月 8 日
That is not the entire code. Here is the entire written code
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BW2_OpeningFcn, ...
'gui_OutputFcn', @BW2_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
% End initialization code - DO NOT EDIT
% --- Executes just before BW2 is made visible.
function BW2_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 BW2 (see VARARGIN)
% Choose default command line output for BW2
handles.output = hObject;
set(handles.pushbutton1, 'UserData', 0);
% Update handles structure
guidata(hObject, handles);
handles.gx= 0;
handles.gy= 0;
% UIWAIT makes BW2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = BW2_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
counter = get(hObject, 'UserData') + 1;
set(hObject, 'UserData', counter);
set(handles.text1, 'String', sprintf('%d', counter));
Tstart = tic/(1000000000);
set(handles.text8,'String',Tstart);
guidata(hObject, handles);
% SERIAL READ -- PUSHBUTTON 2
function pushbutton2_Callback(hObject, eventdata, handles)
handles.comPort = '/dev/tty.usbmodemfd121';
if (~exist('serialFlag','var'))
[handles.accelerometer.s,handles.serialFlag] = ...
setupSerial(handles.comPort);
end
set(handles.text3,'String','FINISHED');
guidata(hObject, handles);
% --- CALIBRATE -- PUSHBUTTON 3
function pushbutton3_Callback(hObject, eventdata, handles)
if(~exist('handles.calCo', 'var'))
handles.calCo = calibrate(handles.accelerometer.s);
end
set(handles.text6,'String','FINISHED');
guidata(hObject, handles);
% STOP/START -- PUSHBUTTON4
function pushbutton4_Callback(hObject, eventdata, handles)
handles.str = get(handles.pushbutton4,'String');
if strcmp(handles.str,'Start')
set(handles.text5,'String','Starting')
guidata(hObject, handles);
else
set(handles.text5,'String','Starting')
guidata(hObject, handles);
end
% START DATA - PUSHBUTTON6
function pushbutton6_Callback(hObject, eventdata, handles)
[gx, gy gz] = readAcc(accelerometer,calCo);
fprintf(accelerometer.s,'R');
%read voltages from accelerometer and reorder
reordered(1)= fscanf(accelerometer.s,'%u');
reordered(2)= fscanf(accelerometer.s,'%u');
reordered(3)= fscanf(accelerometer.s,'%u');
%determine what offset and gain values to use
offset = calCo.offset;
gain = calCo.g;
accel = (reordered - offset) / gain;
%map analog inputs to axes
handles.gx = accel(1);
handles.gy = accel(2);
handles.gz = accel(3);
guidata(hObject, handles)
handles.gx
handles.gy
handles.gz
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closeSerial
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Pushbutton6 is where i'm trying to read in data. I've updated it if you see above.
Amed
Amed 2013 年 2 月 8 日
OK so I got my accelerometer data to read out, but for some reason my Pushbutton7 won't close serial AS SEEN ABOVE in the code. It worked perfectly before, but now it won't.
I had to manually close it by ctrl+c and then some random graph popped up? How do I delete this graph?
Here is my code to run the data thru pushbutton6 % START DATA - PUSHBUTTON6 function pushbutton6_Callback(hObject, eventdata, handles)
%COMPORT
comPort = '/dev/tty.usbmodemfd121';
%READS SERIAL
if (~exist('serialFlag','var'))
[accelerometer.s,serialFlag] = setupSerial(comPort);
end
%CALIBRATES
if(~exist('calCo', 'var'))
calCo = calibrate(accelerometer.s);
end
%DEFINEING H AND BUTTON VARIABLES
if(~exist('h', 'var') || ~ishandle(h))
h = figure(1);
end
if(~exist('button','var'))
button = uicontrol('Style','pushbutton','String','Stop',...
'pos',[0 0 50 25],'parent',h,...
'Callback','stop_call_vector','UserData',1);
end
%READS DATA
while(get(button, 'UserData'))
[gx gy gz] = readAcc(accelerometer,calCo);
cla;
r = sqrt((gx^2)+(gy^2)+(gy^2));
gx
gy
gz
r
end
Amed
Amed 2013 年 2 月 8 日
any takers on the problem above
Walter Roberson
Walter Roberson 2013 年 2 月 8 日
Note: the lines
guidata(hObject, handles);
handles.gx= 0;
handles.gy= 0;
should have the assignments before the guidata() call.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeUpdate figure-Based Apps についてさらに検索

質問済み:

2013 年 2 月 8 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by