https://cstwiki.wtb.tue.nl/api.php?action=feedcontributions&user=Ahofkamp&feedformat=atomControl Systems Technology Group - User contributions [en]2024-03-29T15:19:41ZUser contributionsMediaWiki 1.39.5https://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=48869Acqgen DataAcquisition2018-03-08T09:14:12Z<p>Ahofkamp: Nicer name for the download link</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
to_matlab(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = from_matlab();<br />
<br />
Acqgen generates a Matlab mex function that takes a column matrix with values that are forwarded to the signals at the left hand side of the <code>aout[0], aout[1] = from_matlab()</code> statement, and it returns a column matrix with values obtained from the signals in <code>to_matlab(ain[0], din[1].2)</code>. In this example, there are 2 output signals, so the matrix passed into the Matlab function has 1 column and 2 rows. The configuration also reads two signal values, so the returned matrix is also a 2 row, 1 column matrix. (The simplest way to think about this is that a row represents a signal, while a column represents a point in time.)<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens, your matrix data is directly passed on to the signals (or rather to the EtherCaT connection). The <code>nic = "eth5"</code> defines which ethernet port to use ("eth5" likely does not exist at your computer, so change it!). The <code>frequency</code> gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one column of output and one column of new input from the sensors on each call.<br />
<br />
During the experiment, errors are not reported, since reporting them might take enough additional time to miss the deadline, and destroy the experiment. Instead, they are collected, and printed when you close down the experiment by calling the generated Matlab function with the single argument <code>'report'</code>.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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, since you exchange many data values at the same time, there is time to process results or to create new data 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.)<br />
<br />
A second extension is that Acqgen also knows about other `blocks', additional 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 with a custom filter, and trigger blocks to construct a on/off signal. A common use of the latter is to control storage of measured signals into Matlab matrices, for example if you are interested in only a part of the periodic behavior.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting (due to the "default_prewrite=0.2" configuration).<br />
to_matlab(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Using the Matlab function ==<br />
The common usage pattern of a generated Matlab function is something like<br />
<br />
% prepare data that should be sent away, if needed.<br />
for i = 1:20<br />
result = mymex(input);<br />
% store result<br />
end<br />
mymex('report'); % Report any errors that may have occurred.<br />
<br />
With <code>buffered = false</code>, <code>input</code> and <code>result</code> are simple 1 column matrices.<br />
<br />
With <code>buffered = true</code>, the <code>input</code> and <code>result</code> are cell matrices where the indices match the <code>index</code> parameter of the <code>to_matlab</code> and <code>from_matlab</code> blocks. In this way you can have several independent input or output streams. Be prepared for the case that there is no data to return from a <code>to_matlab</code> block. This trivially holds when you deliver the first output matrix, but it may also happen if you control output with the <code>enable</code> parameter.<br />
<br />
== Other configurations ==<br />
The above configuration files are just two examples, where <code>from_matlab</code> data was coupled directly to output, and measurements where coupled to <code>to_matlab</code> blocks. However, you can make any configuration with blocks that you like, and connect them with signals, as long as a signal does not use itself to derive its value. If you do not use a signal, it is removed automatically (no point in wasting time to compute a value that is never used).<br />
It is also perfectly fine to have a configuration without <code>from_matlab</code> or <code>to_matlab</code> if that is useful, or use the same signal at several places. For the <code>buffered = false</code> case has some more restrictions, you can at most have one <code>from_matlab</code> and one <code>to_matlab</code> block, and you cannot use the <code>enable=</code> parameter, since Matlab does not support empty matrices.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-V1.zip | Acqgen-release-V1]] March 2018</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=File:Acqgen-release-V1.zip&diff=48868File:Acqgen-release-V1.zip2018-03-08T09:12:05Z<p>Ahofkamp: </p>
<hr />
<div></div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=48866Acqgen DataAcquisition2018-03-08T09:11:24Z<p>Ahofkamp: V1 release!</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
to_matlab(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = from_matlab();<br />
<br />
Acqgen generates a Matlab mex function that takes a column matrix with values that are forwarded to the signals at the left hand side of the <code>aout[0], aout[1] = from_matlab()</code> statement, and it returns a column matrix with values obtained from the signals in <code>to_matlab(ain[0], din[1].2)</code>. In this example, there are 2 output signals, so the matrix passed into the Matlab function has 1 column and 2 rows. The configuration also reads two signal values, so the returned matrix is also a 2 row, 1 column matrix. (The simplest way to think about this is that a row represents a signal, while a column represents a point in time.)<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens, your matrix data is directly passed on to the signals (or rather to the EtherCaT connection). The <code>nic = "eth5"</code> defines which ethernet port to use ("eth5" likely does not exist at your computer, so change it!). The <code>frequency</code> gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one column of output and one column of new input from the sensors on each call.<br />
<br />
During the experiment, errors are not reported, since reporting them might take enough additional time to miss the deadline, and destroy the experiment. Instead, they are collected, and printed when you close down the experiment by calling the generated Matlab function with the single argument <code>'report'</code>.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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, since you exchange many data values at the same time, there is time to process results or to create new data 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.)<br />
<br />
A second extension is that Acqgen also knows about other `blocks', additional 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 with a custom filter, and trigger blocks to construct a on/off signal. A common use of the latter is to control storage of measured signals into Matlab matrices, for example if you are interested in only a part of the periodic behavior.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting (due to the "default_prewrite=0.2" configuration).<br />
to_matlab(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Using the Matlab function ==<br />
The common usage pattern of a generated Matlab function is something like<br />
<br />
% prepare data that should be sent away, if needed.<br />
for i = 1:20<br />
result = mymex(input);<br />
% store result<br />
end<br />
mymex('report'); % Report any errors that may have occurred.<br />
<br />
With <code>buffered = false</code>, <code>input</code> and <code>result</code> are simple 1 column matrices.<br />
<br />
With <code>buffered = true</code>, the <code>input</code> and <code>result</code> are cell matrices where the indices match the <code>index</code> parameter of the <code>to_matlab</code> and <code>from_matlab</code> blocks. In this way you can have several independent input or output streams. Be prepared for the case that there is no data to return from a <code>to_matlab</code> block. This trivially holds when you deliver the first output matrix, but it may also happen if you control output with the <code>enable</code> parameter.<br />
<br />
== Other configurations ==<br />
The above configuration files are just two examples, where <code>from_matlab</code> data was coupled directly to output, and measurements where coupled to <code>to_matlab</code> blocks. However, you can make any configuration with blocks that you like, and connect them with signals, as long as a signal does not use itself to derive its value. If you do not use a signal, it is removed automatically (no point in wasting time to compute a value that is never used).<br />
It is also perfectly fine to have a configuration without <code>from_matlab</code> or <code>to_matlab</code> if that is useful, or use the same signal at several places. For the <code>buffered = false</code> case has some more restrictions, you can at most have one <code>from_matlab</code> and one <code>to_matlab</code> block, and you cannot use the <code>enable=</code> parameter, since Matlab does not support empty matrices.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-V1.zip]] March 2018</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=48863Acqgen DataAcquisition2018-03-08T09:09:32Z<p>Ahofkamp: Elaborated a bit on further use.</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
to_matlab(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = from_matlab();<br />
<br />
Acqgen generates a Matlab mex function that takes a column matrix with values that are forwarded to the signals at the left hand side of the <code>aout[0], aout[1] = from_matlab()</code> statement, and it returns a column matrix with values obtained from the signals in <code>to_matlab(ain[0], din[1].2)</code>. In this example, there are 2 output signals, so the matrix passed into the Matlab function has 1 column and 2 rows. The configuration also reads two signal values, so the returned matrix is also a 2 row, 1 column matrix. (The simplest way to think about this is that a row represents a signal, while a column represents a point in time.)<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens, your matrix data is directly passed on to the signals (or rather to the EtherCaT connection). The <code>nic = "eth5"</code> defines which ethernet port to use ("eth5" likely does not exist at your computer, so change it!). The <code>frequency</code> gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one column of output and one column of new input from the sensors on each call.<br />
<br />
During the experiment, errors are not reported, since reporting them might take enough additional time to miss the deadline, and destroy the experiment. Instead, they are collected, and printed when you close down the experiment by calling the generated Matlab function with the single argument <code>'report'</code>.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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, since you exchange many data values at the same time, there is time to process results or to create new data 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.)<br />
<br />
A second extension is that Acqgen also knows about other `blocks', additional 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 with a custom filter, and trigger blocks to construct a on/off signal. A common use of the latter is to control storage of measured signals into Matlab matrices, for example if you are interested in only a part of the periodic behavior.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting (due to the "default_prewrite=0.2" configuration).<br />
to_matlab(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Using the Matlab function ==<br />
The common usage pattern of a generated Matlab function is something like<br />
<br />
% prepare data that should be sent away, if needed.<br />
for i = 1:20<br />
result = mymex(input);<br />
% store result<br />
end<br />
mymex('report'); % Report any errors that may have occurred.<br />
<br />
With <code>buffered = false</code>, <code>input</code> and <code>result</code> are simple 1 column matrices.<br />
<br />
With <code>buffered = true</code>, the <code>input</code> and <code>result</code> are cell matrices where the indices match the <code>index</code> parameter of the <code>to_matlab</code> and <code>from_matlab</code> blocks. In this way you can have several independent input or output streams. Be prepared for the case that there is no data to return from a <code>to_matlab</code> block. This trivially holds when you deliver the first output matrix, but it may also happen if you control output with the <code>enable</code> parameter.<br />
<br />
== Other configurations ==<br />
The above configuration files are just two examples, where <code>from_matlab</code> data was coupled directly to output, and measurements where coupled to <code>to_matlab</code> blocks. However, you can make any configuration with blocks that you like, and connect them with signals, as long as a signal does not use itself to derive its value. If you do not use a signal, it is removed automatically (no point in wasting time to compute a value that is never used).<br />
It is also perfectly fine to have a configuration without <code>from_matlab</code> or <code>to_matlab</code> if that is useful, or use the same signal at several places. For the <code>buffered = false</code> case has some more restrictions, you can at most have one <code>from_matlab</code> and one <code>to_matlab</code> block, and you cannot use the <code>enable=</code> parameter, since Matlab does not support empty matrices.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017<br />
* [[Media:Acqgen-release-v1-RC3.zip]] November 2017 (fixes E-Box driver crashes)</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=48861Acqgen DataAcquisition2018-03-08T08:41:47Z<p>Ahofkamp: Minor fixes</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
to_matlab(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = from_matlab();<br />
<br />
Acqgen generates a Matlab mex function that takes a column matrix with values that are forwarded to the signals at the left hand side of the <code>aout[0], aout[1] = from_matlab()</code> statement, and it returns a column matrix with values obtained from the signals in <code>to_matlab(ain[0], din[1].2)</code>. In this example, there are 2 output signals, so the matrix passed into the Matlab function has 1 column and 2 rows. The configuration also reads two signal values, so the returned matrix is also a 2 row, 1 column matrix. (The simplest way to think about this is that a row represents a signal, while a column represents a point in time.)<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens, your matrix data is directly passed on to the signals (or rather to the EtherCaT connection). The <code>nic = "eth5"</code> defines which ethernet port to use ("eth5" likely does not exist at your computer, so change it!). The <code>frequency</code> gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one column of output and one column of new input from the sensors on each call.<br />
<br />
During the experiment, errors are not reported, since reporting them might take enough additional time to miss the deadline, and destroy the experiment. Instead, they are collected, and printed when you close down the experiment by calling the generated Matlab function with the single argument <code>'report'</code>.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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, since you exchange many data values at the same time, there is time to process results or to create new data 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.)<br />
<br />
A second extension is that Acqgen also knows about other `blocks', additional 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 with a custom filter, and trigger blocks to construct a on/off signal. A common use of the latter is to control storage of measured signals into Matlab matrices, for example if you are interested in only a part of the periodic behavior.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting (due to the "default_prewrite=0.2" configuration).<br />
to_matlab(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017<br />
* [[Media:Acqgen-release-v1-RC3.zip]] November 2017 (fixes E-Box driver crashes)</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=48858Acqgen DataAcquisition2018-03-08T08:13:26Z<p>Ahofkamp: Updated the explanation for V1, corrected a few errors as well.</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
to_matlab(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = from_matlab();<br />
<br />
Acqgen generates a Matlab mex function that takes a column matrix with values that are forwarded to the signals at the left hand side of the <code>aout[0], aout[1] = from_matlab()</code> statement, and it returns a column matrix with values obtained from the signals in <code>to_matlab(ain[0], din[1].2)</code>. In this example, there are 2 output signals, so the matrix passed into the Matlab function has 1 column and 2 rows. The configuration also reads two signal values, so the returned matrix is also a 2 row, 1 column matrix. (The simplest way to think about this is that a row represents a signal, while a column represents a point in time.)<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens, your matrix data is directly passed on to the signals (or rather to the EtherCaT connection). The <code>nic = "eth5"</code> defines which ethernet port to use ("eth5" likely does not exist at your computer, so change it!). The <code>frequency</code> gives the data rate. Obviously, this means that you must call the generated Matlab function at least 1000 times each second, exchanging one column of output and one column of new input from the sensors on each call.<br />
<br />
During the experiment, errors are not reported, since reporting them might take enough additional time to miss the deadline, and destroy the experiment. Instead, they are collected, and printed when you close down the experiment by calling the generated Matlab function with the single argument <code>'report'</code>.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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.)<br />
<br />
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.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting.<br />
input(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017<br />
* [[Media:Acqgen-release-v1-RC3.zip]] November 2017 (fixes E-Box driver crashes)</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=46254Acqgen DataAcquisition2017-11-01T10:15:58Z<p>Ahofkamp: Added v1-RC3 acqgen release</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
input(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = output();<br />
<br />
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 <code>aout[0]</code> respectively <code>aout[1]</code> (The <code>output()</code> represents a row in the matrix, the statement <code>aout[0], aout[1] = output();</code> `assigns' the column values to the signals.)<br />
<br />
The <code>input(ain[0], din[1].2);</code> 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.<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens. The <code>frequency</code> 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.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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.)<br />
<br />
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.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting.<br />
input(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017<br />
* [[Media:Acqgen-release-v1-RC3.zip]] November 2017 (fixes E-Box driver crashes)</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=File:Acqgen-release-v1-RC3.zip&diff=46253File:Acqgen-release-v1-RC3.zip2017-11-01T10:14:22Z<p>Ahofkamp: </p>
<hr />
<div></div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44970Acqgen DataAcquisition2017-07-12T12:18:53Z<p>Ahofkamp: row and column are different things</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
input(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = output();<br />
<br />
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 <code>aout[0]</code> respectively <code>aout[1]</code> (The <code>output()</code> represents a row in the matrix, the statement <code>aout[0], aout[1] = output();</code> `assigns' the column values to the signals.)<br />
<br />
The <code>input(ain[0], din[1].2);</code> 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.<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens. The <code>frequency</code> 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.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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.)<br />
<br />
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.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting.<br />
input(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Projects/Courses&diff=44969Projects/Courses2017-07-12T10:51:20Z<p>Ahofkamp: Added link to acqgen</p>
<hr />
<div>*[http://servicerobot.cstwiki.wtb.tue.nl AMIGO]<br />
*[http://www.techunited.nl/wiki/index.php?title=Main_Page Tech United]<br />
*[http://www.techunited.nl/wiki/index.php?title=Humanoid TUlip]<br />
*[[viotar|Viotar]]<br />
*[[Matlab tools|Matlab/Simulink Tools]]<br />
*[[Home_of_ShapeIt|ShapeIt controller design tool]]<br />
<br />
*[[FMBS tool|FMBS tool; bilateral controller design tool]]<br />
*[[E-box|E-box]] and [[Acqgen DataAcquisition|Acqgen DataAcquisition]]<br />
*[[EDrive|EDrive]]<br />
*[[Football Table|Football Table]]<br />
*[[PITON steerable needle|PITON steerable needle]]<br />
*[[RoPod_Project|RoPod Project]]<br />
----<br />
*[[Embedded Motion Control|Embedded Motion Control]]<br />
*[[Printer_Casus|Printer Casus (4G031)]]<br />
*[[Printer_Casus_Ebox|Printer Casus (4G031) 2012/2013]]<br />
*[[Pick_Place|Pick en Place Casus (?????) 2013/2014]]<br />
*[[Integration Project Systems and Control|Integration Project Systems and Control (4SC00)]]<br />
*[[Project Robots Everywhere (0LAUK0)]]<br />
*[[Robotic Drone Referee]]<br />
*[[Autonomous Referee System]]<br />
----<br />
*[[Robotics Lab|Robotics Lab]]</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44968Acqgen DataAcquisition2017-07-12T10:40:20Z<p>Ahofkamp: typo fix</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
input(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = output();<br />
<br />
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 <code>aout[0]</code> respectively <code>aout[1]</code> (The <code>output()</code> represents a row in the matrix, the statement <code>aout[0], aout[1] = output();</code> `assigns' the column values to the signals.)<br />
<br />
The <code>input(ain[0], din[1].2);</code> 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 column in the matrix to return from the function in Matlab.<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens. The <code>frequency</code> 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.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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.)<br />
<br />
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.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting.<br />
input(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
<br />
== Generating the Matlab function ==<br />
Generating a Mex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44967Acqgen DataAcquisition2017-07-12T10:34:25Z<p>Ahofkamp: Always nice if the system logs you out while you're editing</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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.<br />
# 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.<br />
# An '''experiment to measure or control'''.<br />
# '''Cables, power, etc''' to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A '''Matlab''' (tested with R2015a, newer should also work) installed at the Linux system.<br />
# '''Python3''' (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# Build software for CMake and C source code (<code>cmake</code>, <code>make</code>, and <code>gcc</code> packages).<br />
# The '''Soem''' software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The '''Acqgen''' software installed at the Linux computer (for details see below).<br />
<br />
== Installing the software ==<br />
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.<br />
<br />
== Using Acqgen ==<br />
The user manual also explains the Acqgen software in full detail, but a brief explanation and illustration is likely useful.<br />
<br />
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.<br />
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.<br />
<br />
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).<br />
<br />
Input signals:<br />
ebox[0]:ain0<br />
ebox[0]:ain1<br />
ebox[0]:din0<br />
ebox[0]:enc0<br />
ebox[0]:enc1<br />
<br />
Output signals:<br />
ebox[0]:aout0<br />
ebox[0]:aout1<br />
ebox[0]:dout0<br />
ebox[0]:pwm0<br />
ebox[0]:pwm1<br />
<br />
The <code>ebox[0]</code> here is the device name, a second E-Box will get <code>ebox[1]</code> 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 <code>el5002[0]</code> is always the first EL5002 device, no matter where it is connected in the EtherCaT chain, or which other device types are connected.<br />
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 <code>din[0].1</code> would be the second bit (bit 1) of the first digital input signal that exists.<br />
<br />
=== Control scenario ===<br />
In the simplest case, you connect the device signals directly to Matlab, leading to a real-time control scenario:<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # hz<br />
buffered = false<br />
);<br />
<br />
# Matlab gets samples from ain[0] and din[1].2, the first analogue input, and<br />
# bit 2 (3rd bit) of the second digital input.<br />
input(ain[0], din[1].2);<br />
<br />
# Matab provides analogue control data to aout[0] and aout[1].<br />
aout[0], aout[1] = output();<br />
<br />
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 <code>aout[0]</code> respectively <code>aout[1]</code> (The <code>output()</code> represents a row in the matrix, the statement <code>aout[0], aout[1] = output();</code> `assigns' the column values to the signals.)<br />
<br />
The <code>input(ain[0], din[1].2);</code> 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 column in the matrix to return from the function in Matlab.<br />
<br />
The <code>config( ... )</code> at the top defines the various system parameters. The <code>buffered = false</code> means no buffering of Matlab matrices happens. The <code>frequency</code> 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.<br />
<br />
=== Advanced measurement scenario ===<br />
By setting <code>buffered = true</code>, 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.)<br />
<br />
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.<br />
<br />
That may lead to a specification like<br />
<br />
config(memsize = 32000,<br />
nic = "eth5", # Modify to the ethernet device connected to EtherCaT<br />
frequency = 1000, # Frequency in Hz<br />
buffered = true,<br />
default_input_buffersize = 100,<br />
default_input_buffercount = 2,<br />
default_prewrite = 0.2<br />
);<br />
<br />
# aout[0] provides 100Hz sine wave at sample frequency 1000Hz, between -4 and 4.<br />
aout[0] = function(shape=sine, frequency=100, base=0.0, amplitude=4.0);<br />
<br />
# Filter ain[0] by averaging the last 3 samples.<br />
fout = filter(ain[0], weights=[0.33, 0.33, 0.33]);<br />
<br />
# Trigger on upgoing flank of filter output, passing 1.3. Trigger output is<br />
# high for 100 samples (= 100/1000 = 0.1 seconds).<br />
tout = trigger(fout, policy=up, value=1.3, count=100);<br />
<br />
# Save and return raw ain[0] when triggered by tout, with 20% prewriting.<br />
input(ain[0], index = 1, enable=tout);<br />
<br />
The user manual contains many more details than can be explained at this page.<br />
<br />
<br />
== Generating the Matlab function ==<br />
Generating a Maex-compiled function is as simple as<br />
<br />
acqgen myconfiguration.txt<br />
<br />
where <code>myconfiguration.txt</code> 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.<br />
<br />
== Releases ==<br />
* [[Media:Acqgen-release-v1-RC2.zip]] April 2017</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=File:Acqgen-release-v1-RC2.zip&diff=44966File:Acqgen-release-v1-RC2.zip2017-07-12T08:51:24Z<p>Ahofkamp: </p>
<hr />
<div></div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44965Acqgen DataAcquisition2017-07-12T08:10:48Z<p>Ahofkamp: Typo fix</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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 Windows 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.<br />
# 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.<br />
# An experiment to measure or control.<br />
# Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A Matlab (tested with R2015a, newer should also work) installed at the Linux system. The software generates a C module that must be compiled, which means the Linux system must have a working C compiler compatible with Matlab Mex (that is, the normal gcc program).<br />
# Python3 (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# The Soem software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The Acqgen software distribution at the Linux computer (for details see below).<br />
<br />
== Installing the Soem software ==<br />
# Soem is available from Github, at https://github.com/OpenEtherCATsociety/SOEM Clone or download a copy (acqgen was tested with revision <code>fb975cbc70bde723a178936ddb8c3b1c8c192c39</code>, committed at March 31, 2017).<br />
# Unpack the archive.<br />
# Install the software.<br />
<br />
Installing it can be done anywhere, for simplicity, it is assumed that it should be installed in directory <code>installed_soem</code>, right next to the unpacked archive directory named <code>SOEM</code>.<br />
The software uses CMake, which works best if it has a directory by itself for building. That means you need the following directory structure.<br />
<br />
... / SOEM # the unpacked archive, a file .../SOEM/CMakeLists.txt should exist<br />
/ installed_soem # empty directory, will contain the installed result<br />
/ build_dir # empty directory, used for building and installing SOEM, should be deleted afterwards<br />
<br />
Building and installing is then<br />
<br />
mkdir installed_soem # Create 'installed_soem' (use <code>rm -rf installed_soem</code> if the directory already exists,<br />
# this removes the directory and everything inside it)<br />
mkdir build_dir # Make some room for CMake too<br />
#<br />
gcc --version # Verify that the C compiler is installed. If it is, this command should output a version number,<br />
# else you get an error that the command cannot be found. In the latter case, install gcc in the Linux system first.<br />
#<br />
#<br />
cd build_dir # Enter Cmake build directory<br />
#<br />
# Tell CMake where to install the result, which C compiler to use, which additional compiler flags to use,<br />
# and where to find the source.<br />
cmake -DCMAKE_INSTALL_PREFIX=../installed_soem -DCMAKE_C_COMPILER:FILEPATH=gcc -DCMAKE_C_FLAGS:STRING=-fPIC ../SOEM<br />
#<br />
# CMake should find everything it needs, else additional software needs to be installed at the Linux system first.<br />
#<br />
make # Compile the SOEM source code, and put the results into build_dir (the current directory)<br />
make install # Install the compiled results ready for use in ../installed_soem.<br />
<br />
Afterwards, the <code>installed_soem</code> directory should have a <code>bin</code>, <code>include</code>, and <code>lib</code> directories, each containing some files.<br />
<br />
== Installing the Acqgen software ==<br />
Installing Acqgen is pretty much the same procedure, except it doesn't have a nifty CMake script, it uses a simple Python script<br />
1. Download the software archive (see Releases below for a link.<br />
2. Unpack the archive.<br />
3. Install it somewhere<br />
2. If your archive is named <code>acqgen-release-v1-RC2.tar.gz</code>, run a command like<br />
<br />
tar xzf acqgen-release-v1-RC2.tar.gz<br />
<br />
(extract while decompressing, the file <code>acqgen-release-v1-RC2.tar.gz</code>)<br />
<br />
Extracting gives you a directory named like the archive but without extensions, that is, something like <code>acqgen-release-v1-RC2</code>.</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44964Acqgen DataAcquisition2017-07-12T08:09:51Z<p>Ahofkamp: fixing markup</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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 Windows 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.<br />
# 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.<br />
# An experiment to measure or control.<br />
# Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A Matlab (tested with R2015a, newer should also work) installed at the Linux system. The software generates a C module that must be compiled, which means the Linux system must have a working C compiler compatible with Matlab Mex (that is, the normal gcc program).<br />
# Python3 (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# The Soem software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The Acqgen software distribution at the Linux computer (for details see below).<br />
<br />
== Installing the Soem software ==<br />
# Soem is available from Github, at https://github.com/OpenEtherCATsociety/SOEM Clone or download a copy (acqgen was tested with revision <code>fb975cbc70bde723a178936ddb8c3b1c8c192c39</code>, committed at March 31, 2017).<br />
# Unpack the archive.<br />
# Install the software.<br />
<br />
Installing it can be done anywhere, for simplicity, it is assumed that it should be installed in directory <code>installed_soem</code>, right next to the unpacked archive directory named <code>SOEM</code>.<br />
The software uses CMake, which works best if it has a directory by itself for building. That means you need the following directory structure.<br />
<br />
... / SOEM # the unpacked archive, a file .../SOEM/CMakeLists.txt should exist<br />
/ installed_soem # empty directory, will contain the installed result<br />
/ build_dir # empty directory, used for building and installing SOEM, should be deleted afterwards<br />
<br />
Building and installing is then<br />
<br />
mkdir installed_soem # Create 'installed_soem' (use <code>rm -rf installed_soem</code> if the directory already exists,<br />
# this removes the directory and everything inside it)<br />
mkdir build_dir # Make some room for CMake too<br />
#<br />
gcc --version # Verify that the C compiler is installed. If it is, this command should output a version number,<br />
# else you get an error that the command cannot be found. In the latter case, install gcc in the Linux system first.<br />
#<br />
#<br />
cd build_dir # Enter Cmake build directory<br />
#<br />
# Tell CMake where to install the result, which C compiler to use, which additional compiler flags to use,<br />
# and where to find the source.<br />
cmake -DCMAKE_INSTALL_PREFIX=../installed_soem -DCMAKE_C_COMPILER:FILEPATH=gcc -DCMAKE_C_FLAGS:STRING=-fPIC ../SOEM<br />
#<br />
# CMake should find everything it needs, else additional software needs to be install at the Linux system first.<br />
#<br />
make # Compile the SOEM source code, and put the results into build_dir (the current directory)<br />
make install # Install the compiled results ready for use in ../installed_soem.<br />
<br />
Afterwards, the <code>installed_soem</code> directory should have a <code>bin</code>, <code>include</code>, and <code>lib</code> directories, each containing some files.<br />
<br />
== Installing the Acqgen software ==<br />
Installing Acqgen is pretty much the same procedure, except it doesn't have a nifty CMake script, it uses a simple Python script<br />
1. Download the software archive (see Releases below for a link.<br />
2. Unpack the archive.<br />
3. Install it somewhere<br />
2. If your archive is named <code>acqgen-release-v1-RC2.tar.gz</code>, run a command like<br />
<br />
tar xzf acqgen-release-v1-RC2.tar.gz<br />
<br />
(extract while decompressing, the file <code>acqgen-release-v1-RC2.tar.gz</code>)<br />
<br />
Extracting gives you a directory named like the archive but without extensions, that is, something like <code>acqgen-release-v1-RC2</code>.</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44963Acqgen DataAcquisition2017-07-12T08:03:48Z<p>Ahofkamp: added more install details</p>
<hr />
<div>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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
# 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 Windows 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.<br />
# 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.<br />
# An experiment to measure or control.<br />
# Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
# A Matlab (tested with R2015a, newer should also work) installed at the Linux system. The software generates a C module that must be compiled, which means the Linux system must have a working C compiler compatible with Matlab Mex (that is, the normal gcc program).<br />
# Python3 (Likely already installed at the Linux system, try running <code>python3 --version</code>, which should output some lines of text with the version number of the Python interpreter. If you get an error that <code>python3</code> does not exist, it must be installed in the Linux system first.)<br />
# The Soem software installed at the Linux computer (for details, see below). Installing this software needs the same C compiler as above.<br />
# The Acqgen software distribution at the Linux computer (for details see below).<br />
<br />
== Installing the Soem software ==<br />
# Soem is available from Github, at https://github.com/OpenEtherCATsociety/SOEM Clone or download a copy (acqgen was tested with revision <code>fb975cbc70bde723a178936ddb8c3b1c8c192c39</code>, committed at March 31, 2017).<br />
# Unpack the archive.<br />
# Install the software.<br />
<br />
Installing it can be done anywhere, for simplicity, it is assumed that it should be installed in directory <code>installed_soem</code>, right next to the unpacked archive directory named <code>SOEM</code>.<br />
The software uses CMake, which works best if it has a directory by itself for building. That means you need the following directory structure.<br />
<br />
... / SOEM # the unpacked archive, a file .../SOEM/CMakeLists.txt should exist<br />
/ installed_soem # empty directory, will contain the installed result<br />
/ build_dir # empty directory, used for building and installing SOEM, should be deleted afterwards<br />
<br />
Building and installing is then<br />
<br />
mkdir installed_soem # Create 'installed_soem' (use <code>rm -rf installed_soem</code> if the directory already exists,<br />
# this removes the directory and everything inside it)<br />
mkdir build_dir # Make some room for CMake too<br />
<br />
gcc --version # Verify that the C compiler is installed. If it is, this command should output a version number,<br />
# else you get an error that the command cannot be found. In the latter case, install gcc in the Linux system first.<br />
<br />
<br />
cd build_dir # Enter Cmake build directory<br />
<br />
# Tell CMake where to install the result, which C compiler to use, which additional compiler flags to use, and where to find the source.<br />
cmake -DCMAKE_INSTALL_PREFIX=../installed_soem -DCMAKE_C_COMPILER:FILEPATH=gcc -DCMAKE_C_FLAGS:STRING=-fPIC ../SOEM<br />
<br />
# CMake should find everything it needs, else additional software needs to be install at the Linux system first.<br />
<br />
make # Compile the SOEM source code, and put the results into build_dir (the current directory)<br />
make install # Install the compiled results ready for use in ../installed_soem.<br />
<br />
Afterwards, the <code>installed_soem</code> directory should have a <code>bin</code>, <code>include</code>, and <code>lib</code> directories, each containing some files.<br />
<br />
== Installing the Acqgen software ==<br />
Installing Acqgen is pretty much the same procedure, except it doesn't have a nifty CMake script, it uses a simple Python script<br />
1. Download the software archive (see Releases below for a link.<br />
2. Unpack the archive.<br />
3. Install it somewhere<br />
2. If your archive is named <code>acqgen-release-v1-RC2.tar.gz</code>, run a command like<br />
<br />
tar xzf acqgen-release-v1-RC2.tar.gz<br />
<br />
(extract while decompressing, the file <code>acqgen-release-v1-RC2.tar.gz</code>)<br />
<br />
Extracting gives you a directory named like the archive but without extensions, that is, something like <code>acqgen-release-v1-RC2</code>.</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44962Acqgen DataAcquisition2017-07-12T06:59:59Z<p>Ahofkamp: some fixes in markup, and added extraction process</p>
<hr />
<div>= AcqGen Data acquisition or control =<br />
<br />
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.<br />
<br />
== Required equipment ==<br />
To use Acqgen, you need<br />
<br />
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 Windows 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.<br />
<br />
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.<br />
<br />
3. A Matlab (tested with R2015a, newer should also work) installed at the Linux system. The software generates a C module that must be compiled, which means the Linux system must have a working C compiler compatible with Matlab Mex (that is, the normal gcc program).<br />
<br />
3. The Acqgen software distribution at the Linux computer (for details see below).<br />
<br />
4. An experiment to measure or control.<br />
<br />
5. Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
<br />
== Using the Acqgen software ==<br />
If the software is not yet available at the Linux system, download it (see Releases below for a link), and unpack the archive.<br />
If your archive is named <code>acqgen-release-v1-RC2.tar.gz</code>, run a command like<br />
<br />
tar xzf acqgen-release-v1-RC2.tar.gz<br />
<br />
(extract while decompressing, the file <code>acqgen-release-v1-RC2.tar.gz</code>)<br />
<br />
Extracting gives you a directory named like the archive but without extensions, that is, something like <code>acqgen-release-v1-RC2</code>.</div>Ahofkamphttps://cstwiki.wtb.tue.nl/index.php?title=Acqgen_DataAcquisition&diff=44961Acqgen DataAcquisition2017-07-12T06:54:00Z<p>Ahofkamp: test-save</p>
<hr />
<div>= AcqGen Data acquisition or control<br />
<br />
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.<br />
<br />
== Required equipment<br />
To use Acqgen, you need<br />
<br />
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).<br />
Since these laptops usually have Windows 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.<br />
<br />
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.<br />
<br />
3. A Matlab (tested with R2015a, newer should also work) installed at the Linux system. The software generates a C module that must be compiled, which means the Linux system must have a working C compiler compatible with Matlab Mex (that is, the normal gcc program).<br />
<br />
3. The Acqgen software distribution at the Linux computer (for details see below).<br />
<br />
4. An experiment to measure or control.<br />
<br />
5. Cables, power, etc to hook the EtherCaT measurement device(s) to the experiment, and to connect the EtherCaT devices to the computer.<br />
<br />
== Using the Acqgen software</div>Ahofkamp