Azzera filtri
Azzera filtri

Undefined function 'calibrate' for input arguments of type 'serial'.

1 visualizzazione (ultimi 30 giorni)
I receive an error stating:
"Undefined function 'calibrate' for input arguments of type 'serial'.
Error in iMeasureFIG>CalibratePush_Callback (line 55)
handles.calCo = calibrate(handles.accelerometer.s);"
I'm trying to read in data from an accelerometer. I'm able to read the serial port, but when trying to calibrate I read out that error. Here is the entire code to further analyze..
function varargout = iMeasureFIG(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @iMeasureFIG_OpeningFcn, ...
'gui_OutputFcn', @iMeasureFIG_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
% ~~~~~~~~~ OPENING / OUTPUT FUNCTIONS ~~~~~~~~~ %
% --- Executes just before BW2 is made visible.
function iMeasureFIG_OpeningFcn(hObject, eventdata, handles, varargin)
setappdata(handles.text4, 'count', 0);
handles.flag = 0;
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = iMeasureFIG_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% ~~~~~~~~~ SERIALPUSH READPUSH ~~~~~~~~~ %
function SerialPush_Callback(hObject, eventdata, handles)
handles.comPort = 'COM3'; % connect MATLAB to the accelerometer
if (~exist('serialFlag','var'))
[handles.accelerometer.s,handles.serialFlag] = ...
setupSerial(handles.comPort);
end
guidata(hObject, handles);
% ~~~~~~~~~ CALIBRATION ~~~~~~~~~ %
function CalibratePush_Callback(hObject, eventdata, handles)
if(~exist('handles.calCo', 'var'))
handles.calCo = calibrate(handles.accelerometer.s);
end
guidata(hObject, handles);
% ~~~~~~~~~ Clears Serial ~~~~~~~~~ %
function ClosePush_Callback(hObject, eventdata, handles)
% hObject handle to ClosePush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closeSerial
% ~~~~~~~~~ READS DATA ~~~~~~~~~ %
function ReadPush_Callback(hObject, eventdata, handles)
% hObject handle to ReadPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%COMPORT
buf_len = 60;
% create the variables for all three original unfiltered axis and the resultant
handles.gxdata = zeros(buf_len,1);
handles.gydata = zeros(buf_len,1);
handles.gzdata = zeros(buf_len,1);
handles.rdata = zeros(buf_len,1);
% define the initial values of filt data by using alpha
handles.gxFilt=0;
handles.gyFilt=0;
handles.gzFilt=0;
handles.rFilt=0;
% create the variables for all three filtered axis and the resultant by
% using alpha filter
handles.gxFiltdata = zeros(buf_len,1);
handles.gyFiltdata = zeros(buf_len,1);
handles.gzFiltdata = zeros(buf_len,1);
handles.rFiltdata = zeros(buf_len,1);
handles.gxMovingFilt = 0;
handles.gyMovingFilt = 0;
handles.gzMovingFilt = 0;
handles.rMovingFilt = 0;
handles.gxMovingFiltdata = zeros(buf_len,1);
handles.gyMovingFiltdata = zeros(buf_len,1);
handles.gzMovingFiltdata = zeros(buf_len,1);
handles.rMovingFiltdata = zeros(buf_len,1);
handles.index = 1:buf_len;
handles.str = get(handles.ReadPush,'String'); % change the string of the button after a single click.
if strcmp(handles.str,'Read Data')
set(handles.ReadPush,'String','Stop');
else
set(handles.ReadPush,'String','Read Data');
end
while strcmp(get(handles.ReadPush,'String'),'Stop')
alpha=get(handles.alpha,'Value');% update the alpha value
handles.windowSize=str2num(get(handles.movingAverage,'String'));% update the SMA value
[handles.gx handles.gy handles.gz] = readAcc(handles.accelerometer, handles.calCo);% read and store the current original data of axes from the accelerometer
handles.r = sqrt(handles.gx^2 + handles.gy^2 + handles.gz^2);% calculate the magnitude of current original vetor
handles.gxdata = [handles.gxdata(2:end) ; handles.gx];
handles.gydata = [handles.gydata(2:end) ; handles.gy];
handles.gzdata = [handles.gzdata(2:end) ; handles.gz];
handles.rdata= [handles.rdata(2:end);handles.r];
set(handles.edit2,'String',alpha); % show the value of alpha in the edit 2 text which the alpha slider indicates
% If filtering is selected, this data will be graphed into plot 2
if get(handles.popupmenu3,'Value') == 1
handles.gxFilt=(1-alpha)*handles.gxFilt+alpha*handles.gx;% calculate the fixed data by using alpha filter into matrix
handles.gyFilt=(1-alpha)*handles.gyFilt+alpha*handles.gy;
handles.gzFilt=(1-alpha)*handles.gzFilt+alpha*handles.gz;
handles.rFilt=(1-alpha)*handles.rFilt+alpha*handles.r;
handles.gxFiltdata=[handles.gxFiltdata(2:end);handles.gxFilt];%store the current fixed data by using alpha into the matrix
handles.gyFiltdata=[handles.gyFiltdata(2:end);handles.gyFilt];
handles.gzFiltdata=[handles.gzFiltdata(2:end);handles.gzFilt];
handles.rFiltdata=[handles.rFiltdata(2:end);handles.rFilt];
axes(handles.axes2)% plot the graph of using alpha filter
plot(handles.index,handles.rFiltdata,'r');
axis([1 buf_len -5 5]);
xlabel('time');
ylabel('Resultant');
drawnow;
set(handles.movingAverage,'String',handles.rFilt); % set the movingAverage edit text the same value as rFilt
current_value = handles.rFilt;
threshold = get( );
if ( current_value > threshold && handles.flag == 0) %check the current data move from bottom to top -> we need to change the flag status.
count = getappdata(handles.text4, 'count');
count = count + 1;
setappdata(handles.text4, 'count', count)
set(handles.text4,'String',count);
handles.flag=1;
elseif( current_value < threshold && handles.flag == 1 ) % check the current data move from top to bottom -> we need to change the flag back to 0
handles.flag=0;
end;
guidata(hObject, handles);
end
% If moving average is selected, this data will be graphed into plot 2
if get(handles.popupmenu3,'Value') == 2
handles.gxMovingFilt=mean(handles.gxdata(length(handles.gxdata):-1:length(handles.gxdata)-handles.windowSize+1));
handles.gyMovingFilt=mean(handles.gydata(length(handles.gydata):-1:length(handles.gydata)-handles.windowSize+1));
handles.gzMovingFilt=mean(handles.gzdata(length(handles.gzdata):-1:length(handles.gzdata)-handles.windowSize+1));
handles.rMovingFilt=mean(handles.rdata(length(handles.rdata):-1:length(handles.rdata)-handles.windowSize+1));
%calculate the fixed data by using SMA filter into the matrix
handles.gxMovingFiltdata=[handles.gxMovingFiltdata(2:end);handles.gxMovingFilt];%store the current fixed data by using SMA into the matrix
handles.gyMovingFiltdata=[handles.gyMovingFiltdata(2:end);handles.gyMovingFilt];
handles.gzMovingFiltdata=[handles.gzMovingFiltdata(2:end);handles.gzMovingFilt];
handles.rMovingFiltdata=[handles.rMovingFiltdata(2:end);handles.rMovingFilt];
%calculate the rMovingdata by taking the square root of the three axis of MovingFiltdata
rMovingFiltdata = sqrt((handles.gxMovingFiltdata).^2+(handles.gyMovingFiltdata).^2+(handles.gzMovingFiltdata).^2);
% plot the rMovingFiltdata in axes2
axes(handles.axes2)
plot(handles.index,handles.rMovingFiltdata,'r');
axis([1 buf_len -5 5]);
xlabel('time');
ylabel('Resultant');
drawnow;
guidata(hObject, handles);
end
% If no filtering or moving average is selected, this data will be graphed into plot 2
if get(handles.popupmenu3,'Value') == 3
handles.gxdata = [handles.gxdata(2:end) ; handles.gx];
handles.gydata = [handles.gydata(2:end) ; handles.gy];
handles.gzdata = [handles.gzdata(2:end) ; handles.gz];
handles.rdata = [handles.rdata(2:end) ; handles.r];
handles.rdata = sqrt((handles.gxdata).^2+(handles.gydata).^2+(handles.gzdata).^2);
% plot the original rdata
axes(handles.axes2)
plot(handles.index,handles.rdata,'r');
axis([1 buf_len -5 5]);
xlabel('time');
ylabel('Resultant');
drawnow;
guidata(hObject, handles);
end
handles.gxdata = [handles.gxdata(2:end) ; handles.gx];
handles.gydata = [handles.gydata(2:end) ; handles.gy];
handles.gzdata = [handles.gzdata(2:end) ; handles.gz];
handles.rdata = [handles.rdata(2:end) ; handles.r];
axes(handles.axes1)
plot(handles.index,handles.gxdata,'r', handles.index,handles.gydata,'g', handles.index,handles.gzdata,'b');
axis([1 buf_len -5 5]);
xlabel('time');
ylabel('X, Y, Z');
drawnow;
guidata(hObject, handles);
end
% --- Executes on slider movement.
function alpha_Callback(hObject, eventdata, handles)
% hObject handle to alpha (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% set(handles.slidevalue,'String',num2str(get(handles.alpha,'Value')));
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function alpha_CreateFcn(hObject, eventdata, handles)
% hObject handle to alpha (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function movingAverage_Callback(hObject, eventdata, handles)
% hObject handle to movingAverage (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 movingAverage as text
% str2double(get(hObject,'String')) returns contents of movingAverage as a double
% --- Executes during object creation, after setting all properties.
function movingAverage_CreateFcn(hObject, eventdata, handles)
% hObject handle to movingAverage (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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
  3 Commenti
Amed
Amed il 28 Feb 2013
Now i'm receiving the error...
Attempt to execute SCRIPT setupSerial as a function:
C:\Users\Owner\Desktop\MATLABCODE\setupSerial.m
Error in iMeasureFIG>SerialPush_Callback (line 45)
[handles.accelerometer.s,handles.serialFlag] = ...
while trying to run the Serial.. I can't even run the serial now. I didn't change a thing to the code..?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by