Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
real time display

Subject: real time display

From: Attila Kovacs

Date: 26 Apr, 2010 15:59:05

Message: 1 of 4

I am collecting signal from two potentiometers via an NI A/D board. I would like to present real-time feedback by plotting one signal against the other (lissajous figure)always using one pair of datapoints. To this end I use peekdata function and plot the returned values. The problem I run into is that peekdata does not return every single value and therefore the display is jumping between the values returned by peekdata. I would appreciate any suggestions on how to make the display move smoother. This occurs regardless the sampling frequency.

tempairunning=airunning;

if airunning==0;
    start(ai)
    airunning=1;
end

running=1;
set(stop_button,'Visible','On');
set(start_button,'Visible','Off');

% find channels to display
for ii=1:num_channel
    onchannel(ii)=get(channel_check(ii),'Value');
end
goodchannel=find(onchannel==1);% logical operator

pause(1)
%-------------------------------------------
data=peekdata(ai,1)
%-------------------------------------------

hLine=[];
%--------------------------------------------
     for ii=1:length(goodchannel)
        hLine(ii)=line('Parent',haxes,...
            'XData',data(:,1),...
            'YData',data(:,2));
     end
%--------------------------------------------
while running==1
    
    if airunning==0;
        start(ai)
    end
%-------------------------------------------
data=peekdata(ai,1)
%-------------------------------------------
    hLine=[];
%-----------------------------------------------------
     for ii=1:length(goodchannel)
        hLine(ii)=line('Parent',haxes,...
            'XData',data(:,1),...
            'YData',data(:,2),...
     end
%---------------------------------------------------------
plot(data(:,1),data(:,2),'ro','MarkerEdgeColor','r',...
                'MarkerFaceColor',[.49 1 .63],...
                'MarkerSize',10);
xlim([-5 5]);
ylim([-5 5]);
drawnow
    
end

Subject: real time display

From: Sean

Date: 26 Apr, 2010 16:55:21

Message: 2 of 4

"Attila Kovacs" <kovacsek71.removeThis@gmail.com> wrote in message <hr4d89$o3h$1@fred.mathworks.com>...
> I am collecting signal from two potentiometers via an NI A/D board. I would like to present real-time feedback by plotting one signal against the other (lissajous figure)always using one pair of datapoints. To this end I use peekdata function and plot the returned values. The problem I run into is that peekdata does not return every single value and therefore the display is jumping between the values returned by peekdata. I would appreciate any suggestions on how to make the display move smoother. This occurs regardless the sampling frequency.
>
> tempairunning=airunning;
>
> if airunning==0;
> start(ai)
> airunning=1;
> end
>
> running=1;
> set(stop_button,'Visible','On');
> set(start_button,'Visible','Off');
>
> % find channels to display
> for ii=1:num_channel
> onchannel(ii)=get(channel_check(ii),'Value');
> end
> goodchannel=find(onchannel==1);% logical operator
>
> pause(1)
> %-------------------------------------------
> data=peekdata(ai,1)
> %-------------------------------------------
>
> hLine=[];
> %--------------------------------------------
> for ii=1:length(goodchannel)
> hLine(ii)=line('Parent',haxes,...
> 'XData',data(:,1),...
> 'YData',data(:,2));
> end
> %--------------------------------------------
> while running==1
>
> if airunning==0;
> start(ai)
> end
> %-------------------------------------------
> data=peekdata(ai,1)
> %-------------------------------------------
> hLine=[];
> %-----------------------------------------------------
> for ii=1:length(goodchannel)
> hLine(ii)=line('Parent',haxes,...
> 'XData',data(:,1),...
> 'YData',data(:,2),...
> end
> %---------------------------------------------------------
> plot(data(:,1),data(:,2),'ro','MarkerEdgeColor','r',...
> 'MarkerFaceColor',[.49 1 .63],...
> 'MarkerSize',10);
> xlim([-5 5]);
> ylim([-5 5]);
> drawnow
>
> end

Look at the second input argument to peekdata:
you're running:
>>peekdata(obj, 1); %Here ai is your obj
if you want 1000 samples:
>>peekdata(obj, 1000);

Of course this will return an error if there are <1000 samples.
You can ensure available samples with:
obj.SamplesAvailable

Good Luck!

Subject: real time display

From: Attila Kovacs

Date: 26 Apr, 2010 18:03:04

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hr4ghp$253$1@fred.mathworks.com>...
> "Attila Kovacs" <kovacsek71.removeThis@gmail.com> wrote in message <hr4d89$o3h$1@fred.mathworks.com>...
> > I am collecting signal from two potentiometers via an NI A/D board. I would like to present real-time feedback by plotting one signal against the other (lissajous figure)always using one pair of datapoints. To this end I use peekdata function and plot the returned values. The problem I run into is that peekdata does not return every single value and therefore the display is jumping between the values returned by peekdata. I would appreciate any suggestions on how to make the display move smoother. This occurs regardless the sampling frequency.
>
> Look at the second input argument to peekdata:
> you're running:
> >>peekdata(obj, 1); %Here ai is your obj
> if you want 1000 samples:
> >>peekdata(obj, 1000);
>
> Of course this will return an error if there are <1000 samples.
> You can ensure available samples with:
> obj.SamplesAvailable
>
> Good Luck!



Thanks for your input Sean. Unfortunately this doesn't solve my problem as it will plot the number of datapoints I specify in the argument:
> >>peekdata(obj, 1000);
thus creating the effect of leaving a trail.
My goal is to always represent one point in time that continuously is updated by the peekdata function.
Any other ideeas? Thanks.

Subject: real time display

From: Sean

Date: 26 Apr, 2010 19:00:22

Message: 4 of 4

"Attila Kovacs" <kovacsek71.removeThis@gmail.com> wrote in message <hr4kgo$s06$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hr4ghp$253$1@fred.mathworks.com>...
> > "Attila Kovacs" <kovacsek71.removeThis@gmail.com> wrote in message <hr4d89$o3h$1@fred.mathworks.com>...
> > > I am collecting signal from two potentiometers via an NI A/D board. I would like to present real-time feedback by plotting one signal against the other (lissajous figure)always using one pair of datapoints. To this end I use peekdata function and plot the returned values. The problem I run into is that peekdata does not return every single value and therefore the display is jumping between the values returned by peekdata. I would appreciate any suggestions on how to make the display move smoother. This occurs regardless the sampling frequency.
> >
> > Look at the second input argument to peekdata:
> > you're running:
> > >>peekdata(obj, 1); %Here ai is your obj
> > if you want 1000 samples:
> > >>peekdata(obj, 1000);
> >
> > Of course this will return an error if there are <1000 samples.
> > You can ensure available samples with:
> > obj.SamplesAvailable
> >
> > Good Luck!
>
>
>
> Thanks for your input Sean. Unfortunately this doesn't solve my problem as it will plot the number of datapoints I specify in the argument:
> > >>peekdata(obj, 1000);
> thus creating the effect of leaving a trail.
> My goal is to always represent one point in time that continuously is updated by the peekdata function.
> Any other ideeas? Thanks.


Ok gotcha:
This should get close to what you want. It will never be 'true real time' but can approach the limits of the data acquisition toolbox and your machine.
    
%%%%In the main function:
    %Set timer parameters.
    tperiod = 0.2; %It will update every 0.2s. You can make this smaller but you're constrained by the speed of the machine, time to execute this TimerFcn, time to plot, and other overhead. Play with it and see how small you can get! It will never be complete real time.
    set(ai, 'TimerPeriod', tperiod);
    set(ai, 'TimerFcn', @daq_peek);
    set(ai, {'StartFcn', 'StopFcn', 'TriggerFcn'}, {'','',''});

    start(ai);

%%%% daq_peek function
function daq_peek(obj, event)
    data = peekdata(obj, 1); %Preview data in acquisition toolbox buffer.
    figure(1); %assuming you're using a figure and have no others of importance, you'll have to play with axis handles if it's in a gui etc.
    plot(data(1), data(2) 'rs','MarkerSize',5); %data(1)= 1st channel, data(2) = 2nd
    axis([xmin xmax ymin ymax]);%anticipated ranges or you could make them dynamic.
    drawnow;
end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us