Have you ever wanted to bring data directly from hardware into MATLAB or control something via a data acquisition board?
Working with data acquisition hardware was my very first project in MATLAB back in the winter of 2008. I had a miniature load frame, transparent to x-rays, for applying a load to a concrete cylinder. There were three sensor inputs: two displacements, and force, and one output: a voltage to a piezoelectric actuator that applied a force. Here's a figure from my thesis:
I built a user interface in GUIDE to allow me to apply the load while recording and plotting the signals. To complicate matters, the session based interface for the Data Acquisition Toolbox didn't exist yet, so I was also doing everything with timers on my own.
I can only imagine how much easier it would've been with this app. I no longer have access to the load frame, so instead here's an example getting data from an ADALM1000, a low cost data acquisition device.
Let's control it with the app. First, I'll just get connected and pull some data from the attached RC circuit. Note I previously had to install the hardware support package for this board.
Seems to work, great!
Now I want to output some data to it. There are two channels, the first will be a sine wave and the second a cosine wave. The board can take 0-5V so add 1 to the waves keep them positive.
t = linspace(0,8*pi,100000)'; x = [sin(t) cos(t)]+1; %
In order to get them into the output, we simply pick the variable:
And then run the session:
From here, the data can be exported or equivalent code can be generated from the file menu to automate this acquisition session.
My only point of feedback is that error messages are not all exposed via dialogs. For example, the first time I selected x with the range -1:1, it errored at the command line with a useful message that I didn't see because the app was maximized.
Going back to my use case in college, I was trying to control load, with displacement so that the loading rate would be roughly linear. To do this, I ran a bunch of experiments and fit an equation to the load v. displacement curve for many cylinders. At the time, I knew nothing about Simulink or how it could help me. If challenged with the same task today, I would likely use the data acquisition blocks in Simulink R2016b to control the actuator. This would allow me to then use the PID block and its tuning capabilities to accomplish what I was doing much more quickly.
For nostalgia's sake, I put together a quick a model of the system.
Get the MATLAB code
Published with MATLAB® R2016b
Comments are closed.