Create a real-time control in DAQ Matlab
Mostrar comentarios más antiguos
I'm using the Data Acquisition Toolbox for acquiring and generating data with High-Speed Dynamic Signal Analyzers (Modell DT9847 from data translation).
I have a Mini SmartShaker™ with Intergrated Power Amplifier (MODEL K2007E01) connecting to output channel as acutator;
Production link: http://www.synotech.de/produkte/datenblatt/?untergruppe=mod_shaker&h=TMS&m=K2007E01
and one Dynamic Force Sensor (MODEL PCB-288D01) connecting to input channel 0&1 for collecting data.
Production link: http://www.synotech.de/produkte/datenblatt/?untergruppe=mod_impedanz&h=PCB&m=288D01
Now I have built up an open loop which containing one output channel and two input channels. The acquisition and generation rates set to
s.Rate = 100000;
%%Construct the output data
%sweep sine wave source
t = linspace(0, 60, 6000000)';
outputSignal1= chirp(t, 100, t(end), 500)*1/10;
%fixed frequency sine wave source
data = linspace(0,pi*100,s.Rate)';
outputSignal2 = sin(data)*1/10 ;
%%Queue the output data
% Use the |queueOutputData| command to queue the data.
%first queue 60sec of sweep signal(60sec), after that queue fixed frequency signal.
queueOutputData(s,outputSignal1);
queueOutputData(s,outputSignal2);
%Listener fires every 1/10 sec
s.NotifyWhenDataAvailableExceeds = 10000;
s.IsContinuous = true;
s.startBackground;
Then I got the result by calling two listeners;
dataAvailableListener = addlistener(s,'DataAvailable',...
@(src,event)plot(event.TimeStamps, event.Data));
lh = addlistener(s,'DataAvailable',@(src, event)logData(src, event, fid1));
function logData(src, evt, fid)
data = [evt.TimeStamps, evt.Data]' ;
fwrite(fid,data,'double');
end

Figure 1 Plot data during the acquisition (dataAvailableListener )

Figure 2 Plot data of the whole measurement from log file (lh)
In the first 60sec, the result is from the sweep signal outputsignal1. In the 60-70sec the result is from the outputsignal2 with fixed frequency.
You can see from figure 2, the amplitude of the sweep signal changing with fluctuations when the signal frequency increasing from 100Hz to 500Hz.
Now I would like to build a control loop, which could influence the output signal(amplitude) by setting a trigger for the input channel.
hk = addlistener(s,'DataAvailable',...
@inputReceived);
function inputReceived(src,event)
if any(event.Data(:,2) > 0.4)
disp('Too high')
%%control algorithm%%
end
if min(event.Data(:,2) < 0.4)
disp('Too low')
%%control algorithm%%
end
end
I would like to ask you about the possibility to realize the control loop or do you have any experience on building a control loop in matlab? I'm not a professtional in matlab, so could you give me some tools or algorithm to achieve the goal in real-time control? Thank you!
3 comentarios
han xiao
el 31 de Jul. de 2018
Kyle Heintz
el 1 de Ag. de 2018
Each call to the "chirp" function creates a vector which starts at the value of 1 at time of 0. If you inspect the last values in the "outputSignal1" vector, they are different than the beginning values of "outputSignal2". The queued data ultimately has jumps in values at these points which is likely causing the spikes of noise you are seeing at the ends of each buffer.
A better way to handle this would be to call "chirp" only once for the entire range of time, or develop your own frequency sweep function. You could then extract only the points you want to be queued to the output channel, for example:
queueOutputData(s, outputSignalFull(1:1e6))
han xiao
el 6 de Ag. de 2018
Respuestas (1)
Kyle Heintz
el 30 de Jul. de 2018
1 voto
MATLAB and the Data Acquisition Toolbox operate in a non real-time environment, and for this reason true deterministic real-time control is not possible.
If your control loop is not required to be true real-time, you may be able to program the control logic in a loop in MATLAB. It appears that you have already started building the framework for this control loop in MATLAB code. Refer to the following MATLAB Answers post for more information on this workflow:
If you are familiar with Simulink or willing to learn, our products Simulink Real-Time and Simulink Desktop Real-Time are designed for this type of application.
2 comentarios
han xiao
el 31 de Jul. de 2018
hurrch
el 19 de Oct. de 2019
Good day
sorry i have to sneak into this conversation but i really need your expertise Sire.
I am a final year student of an institution in Africa and I have issues with my chosen project cause I do not have prior knowledge of coding or programming.
Please, I really need help with this project of mine as it will be due in 1 weeks’ time (1/11/2019), I don’t mind being assigned to someone good with the matlab DAQ toolbox for an extra fee. This is the crux of my project.
I am to write a code that will read data from two NI 9237 modules (6 channels in total). the modules are to read data from a force balance (strain due to force). The final result should be different plots for different force values against time. I will explain with a diagram and a flow chart, please do correct the flow chart if it is wrong. Some where in the code, there should be a scaling coefficient that will convert strain to force as needed for the equations. The code should plot the data in real time and also at the end of the acquisition. And the plots are individual force values against time. E.g N against time, M against time etc.
This is what I just did playing around with the code but I’m technically stuck afterwards.
daq.getVendors
daq.getDevices
s = daq.createSession ('ni');
ch1 = s.addAnalogInputChannel('Dev1', 'ai0', 'Bridge');
ch2 = s.addAnalogInputChannel('Dev1', 'ai1', 'Bridge');
ch3 = s.addAnalogInputChannel('Dev1', 'ai2', 'Bridge');
ch4 = s.addAnalogInputChannel('Dev2', 'ai0', 'Bridge');
ch5 = s.addAnalogInputChannel('Dev2', 'ai1', 'Bridge');
ch6 = s.addAnalogInputChannel('Dev2', 'ai2', 'Bridge');
ch1.BridgeMode = 'Full';
ch1.ExcitationVoltage = 10;
ch1.NominalBridgeResistance = 350;
ch2.BridgeMode = 'Full';
ch2.ExcitationVoltage = 10;
ch2.NominalBridgeResistance = 350;
ch3.BridgeMode = 'Full';
ch3.ExcitationVoltage = 10;
ch3.NominalBridgeResistance = 350;
ch4.BridgeMode = 'Full';
ch4.ExcitationVoltage = 10;
ch4.NominalBridgeResistance = 350;
ch5.BridgeMode = 'Full';
ch5.ExcitationVoltage = 10;
ch5.NominalBridgeResistance = 350;
ch6.BridgeMode = 'Full';
ch6.ExcitationVoltage = 10;
ch6.NominalBridgeResistance = 350;
attached below is the document to help understand what exactly i am doing and how far i have gone. it also has the flow chart, diagrams and equations.
i really do anticipate your reply.
thank you so much
Categorías
Más información sobre Analog Data Acquisition en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






