Acqgen DataAcquisition

From Control Systems Technology Group

Jump to: navigation, search

Acqgen is a piece of software for generating real-time measurement or control software for plain Matlab for EtherCaT devices, such as the E-Box.


Required equipment

To use Acqgen, you need

  1. A Linux computer (tested with Ubuntu 16.04 LTS), with an Ethernet port compatible with the Soem EtherCaT master software (that is, a normal TU/e laptop). Since these laptops usually have the Windows operating system that you want to keep, you can use an USB stick to boot and run a Linux operating system from it, rather than install Linux at the hard disk.
  2. One or more EtherCaT compatible measurement devices, like an E-Box. The software supports several devices, the full list is in the manual, which is included in the software distribution.
  3. An experiment to measure or control.
  4. Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.
  5. A Matlab (tested with R2015a, newer should also work) installed at the Linux system.
  6. Python3 (Likely already installed at the Linux system, try running python3 --version, which should output some lines of text with the version number of the Python interpreter. If you get an error that python3 does not exist, it must be installed in the Linux system first.)
  7. Build software for CMake and C source code (cmake, make, and gcc packages).
  8. The Soem software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.
  9. The Acqgen software installed at the Linux computer (for details see below).

Installing the software

You need to download and install both Soem and Acqgen. The simplest starting point is to download the latter first (see #Releases below for the available versions), and unpack the archive. In it you will find a user manual that explains where to get Soem, and how to build and install everything.

Using Acqgen

The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.

Acqgen generates software that talks with measurement and control devices (for example, an E-box) in real time through EtherCat at one side, and exchanges rows of data in matrices in a Matlab function at the other side. There is no pre-defined connection between both sides, although the normal practice is to send data from Matlab to the actuators of the devices, and to send data from sensors of the devices up to Matlab.

The concept used by Acqgen to define the connection between sides is signals. A signal is a sampled continuously changing data value with a name. Each measurement or control device introduces a number of signals, so you can make connection to it. A single E-Box device gives you 10 signals, 5 input signals (2 analoge inputs, 1 digital input, and two encoder inputs) and 5 output signals (2 analoge outputs, 1 digital output, and 2 pulse with modulator outputs).

 Input signals:
 Output signals:

The ebox[0] here is the device name, a second E-Box will get ebox[1] as device name, etc. If a different type of device is also added, a new device name expressing its type is used (and index numbering starts again at 0 for that type. This means that el5002[0] is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected. For digital input and outputs you can address single bits by appending a bit number, and you can drop the device name entirely if you don't care about the connected devices. For example din[0].1 would be the second bit (bit 1) of the first digital input signal that exists.

Control scenario

In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:

 config(memsize = 32000,
     nic = "eth5", # Modify to the ethernet device connected to EtherCaT
     frequency = 1000, # hz
     buffered = false
 # Matlab gets samples from ain[0] and din[1].2, the first analogue input, and
 # bit 2 (3rd bit) of the second digital input.
 input(ain[0], din[1].2);
 # Matab provides analogue control data to aout[0] and aout[1].
 aout[0], aout[1] = output();

Starting at the bottom of the specification, Acqgen generates a Matlab function that takes a matrix of 2 columns with two output values to be assigned to analogue outputs aout[0] respectively aout[1] (The output() represents a row in the matrix, the statement aout[0], aout[1] = output(); `assigns' the column values to the signals.)

The input(ain[0], din[1].2); statement is the other direction, back to Matlab. It `takes' the value of the first analoge input, and the 3rd bit of the 2nd digital input, and combines them as a row in the matrix to return from the function in Matlab.

The config( ... ) at the top defines the various system parameters. The buffered = false means no buffering of Matlab matrices happens. The frequency gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one row of output with one row of new input from the sensors on each call.

Advanced measurement scenario

By setting buffered = true, Acqgen generates a Matlab function that buffers Matlab matrices. If you give enough buffers, data acquisition and Matlab calls run independently of each other. While the requirements of the data rate must still be met for continuous operation, you can process results or create new data to send to the actuators while the experiment runs, if you so desire. (A simpler and probably more common scenario is that Matlab simply stores all data while the experiment runs, and afterwards performs post-processing on it.)

A second extension is that Acqgen also knows about `blocks', pieces of functionality that take and/or produce signals. There are blocks to generate common signals, filter blocks to apply a filter on a signal, and trigger blocks to construct a on/off signal, which can be used to control storage of signals into Matlab matrices.

That may lead to a specification like

 config(memsize = 32000,
     nic = "eth5", # Modify to the ethernet device connected to EtherCaT
     frequency = 1000, # Frequency in Hz
     buffered = true,
     default_input_buffersize = 100,
     default_input_buffercount = 2,
     default_prewrite = 0.2
 # aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.
 aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);
 # Filter ain[0] by averaging the last 3 samples.
 fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);
 # Trigger on upgoing flank of filter output, passing 1.3. Trigger output is
 # high for 100 samples (= 100/1000 = 0.1 seconds).
 tout = trigger(fout, policy=up, value=1.3, count=100);
 # Save and return raw ain[0] when triggered by tout, with 20% prewriting.
 input(ain[0], index = 1, enable=tout);

The user manual contains many more details than can be explained at this page.

Generating the Matlab function

Generating a Mex-compiled function is as simple as

 acqgen myconfiguration.txt

where myconfiguration.txt is a specification file like above. This call also compiles the code to a Mex function file, that you can immediately use in the Matlab program.


* April 2017
Personal tools