Using MATLAB For Calculations in Braiding
Using MATLAB For Calculations in Braiding
Using MATLAB For Calculations in Braiding
in braiding 15
15.1 Introduction
“MATLAB® is a high-level language and interactive environment for numerical
computation, visualization, and programming” (Mathworks, 2014). It is similar to
many modern programming languages, but has a simplified syntax and a large set
of toolboxes with functions for computing different kinds of numerical problems
and visualizing large sets of data types. This chapter gives a short introduction to a
minimal set of MATLAB® commands and toolboxes (MATLAB® is the registered
trademark of The MathWorks, Inc.) which can be useful for speeding up the com-
putation and analysis of braided fabrics, machines, and processes. Large computa-
tional models have revolutionized research since 2000, permitting the consideration
of significantly more process parameters and more accurate modelling.
As textile engineers are seldom familiar with these models, the goal of this chap-
ter is to demonstrate the simplicity of computing with MATLAB and to motivate
the young (and the experienced) researchers and engineers to build their own com-
putational models in the area of braiding. A short introduction of the basics of the
MATLAB environment and language will be followed by an introduction to some
plotting and computing functions, and the chapter ends with an example showing
how yarn tension may be measured using the Data Acquisition ToolboxTM. No prior
knowledge of programming is assumed. Once the first steps are done, the learning
curve using MATLAB is very small, and the extension of the commands and imple-
mentation of code to solve other tasks can be done in a very short time. Detailed
tutorials and examples for all MATLAB toolboxes can be found in the documentation
of the software (Mathworks, 2014), where step-by-step “Getting Started” sections for
each toolbox are available.
While Mathworks provides academic pricing for both students and institutions,
some researchers may still not have access to MATLAB; in this case, some open
source products supporting the MATLAB language – such as FreeMat, Octave,
Scilab – are usable alternatives; they have stable codebases, and contain the most
important features of MATLAB, although they differ slightly in syntax and do
not provide all the functions of MATLAB. As open source products, the quality
of documentation is less detailed than that of MATLAB; while this may be ini-
tially daunting, perseverance will allow MATLAB code to be adjusted for these
products.
Figure 15.3 Commands from the history can be selected (Shift + Arrow) and with right
mouse button a suitable option can be chosen, as for instance creating a script.
and does not require any input variables. This is a script file. All variables defined in
the script remain valid and accessible in the workspace after the script has finished its
work. The workspace is the current “memory” of the program, where variable data
are stored and can be seen – and directly accessed – from the window Workspace
(Position 5, Fig. 15.1). As can be seen, there is the variable x there, because the script
ch15_1.m was executed. The running of single scripts can be done either by clicking
the Run button (Position 6, Fig. 15.1) or entering the name of the script (or function),
without the file ending, on the command line.
360 Braiding Technology for Textiles
The “Current folder” window (Position 4, Fig. 15.1) shows the files in the current
folder (Fig. 15.1, Position 7). All files located in the current folder are accessible
for running. Additionally, all files, located in folders stored in the MATLAB Path,
are also accessible for running. For larger projects, it is sufficient for organizing the
code into several subfolders. In order for all these files to be accessible, the folders
and subfolders have to be stored in the MATLAB Path (Menu -> Home, Set Path,
Fig. 15.4). If some of these windows are not visible, they may be selected from the
layout settings (Fig. 15.5).
The function begins with the keyword function. The variables x_ and y_ are the
local variables in the function, which will be outputted into the workspace after the
function is completed. The function name – here, ch15_2 – has to begin with a char-
acter and be unique, while the file containing the function must be named after the
function. The command which can establish whether a function of the same name
already exists in the MATLAB Path. Figure 15.7 demonstrates how to check if there
is an existing function named beta – as it shows that the function beta already
exists, the name beta should not be used.
The function name in brackets is then given the input variables, in this case, r and
h, representing radius and height. The variable fii defined in the function body will
not be visible in the workspace after the function is executed; this can be checked in
the Workspace window or by typing the command who. Figure 15.8 demonstrates
the common call of the function with inputs r = 10 and h = 20. Before calling the
function, it is recommended that all variables in the workspace are cleared with the
command clear all, and that all open figures are closed with close all.
The function creates a matrix vector named fii, beginning with 0 and ending with
pi (3.1415) in steps of pi/N; the individual elements of fii can be accessed using
fii(k) where k is the index, starting from 1. The row x=r * cos(fii) then cre-
ates a vector x, multiplying each component of fii by the radius, while the function
plot(x,y) takes the output variables from the function to create a 2D plot.
Figure 15.9 Extended function ch15_3.m for using of global variables v and EndAngle.
Using MATLAB® for calculations in braiding 363
The next new code in the function ch15_3 is in the last lines; if a third coordinate
z_ has to be defined that increases at every step with value v, then one possible way
is to set the single values within for –cycle and direct access to the elements (there
are shorter ways to achieve this as well, for instance using z_=0:v:v*length(fii),
but commands are more complicated), The command length(fii) returns the
number of the elements in fii, required in order to specify the same number of
elements for z_.
Figure 15.10 lists the code of the function ch15_4, where the global variables are
defined again as global and their values are set. The variables r and N are assigned
values (r = 10 and N = 20), but these values are not global. After the calculation
the returned values from the function ch15_3 will be stored in the variables x, y
and z, which are used to plot a line with the function plot3. The characters after
the three vector ro- define the colour (r = red), the marker (o – means circle) and
the line type (– means solid line) of the line. All options for plotting can be seen
using the “build it” help function, or by invoking help plot in the command
window.
The resulting plot is shown in Fig. 15.11. For 3D rotation to be switched on, the
corresponding button shown on the picture has to be clicked, after which the figure
can be rotated with the mouse.
Figure 15.12 Function for drawing hypocycloid for spiral drawing machine.
of one carrier during the work of the machine. Figure 15.12 presents the code of the
function. This code demonstrates the nesting of functions within other functions; the
function getcoord is a local function that is accessible only for the code inside the
Using MATLAB® for calculations in braiding 365
Figure 15.14 Code for visualization of the yarn length per repeat for flat braids.
30
Yarn per repeat
Repeat length
25
Yarn length per repeat (mm)
20
15
10
0
20 30 40 50 60 70 80
Braiding angle (degree)
Figure 15.15 The figure shows the yarn length per repeat and repeat length for different
braiding angles, created with the program given in Fig. 15.14.
Using MATLAB® for calculations in braiding 367
Figure 15.16 Calculation of the yarn tension, required to rotate the bobbin.
Figure 15.18 Horn gear drawing function, part 2 – drawing the arc of the slots.
Using MATLAB® for calculations in braiding 369
Figure 15.19 Horn gear drawing function, part 2 – drawing the arc between the slots.
diameter D, the centre with coordinates (xc, yc), number of slots nsec and starting
angle alfa. It is not necessary to add parameters structure hg in the form:
hg.xc;
hg.yc;
but to do so would allow these data to be used and stored after finishing the draw-
ing; for instance, in an array for all horn gears, this can be useful for simulation of
the braiding process. This is how it is used in the software TexMind Braider Geo3D,
albeit implemented in C++.
The variable dr is the difference between the radius of the track and the radius
of the horn gear. Normally, these are almost equal, but here the horn gears are drawn
with a smaller radius for better visibility and clarity of the pictures.
After initialization of all the data, the second part of the code (Fig. 15.18) plots
the arcs for the carrier feet – the slots. Some vector operations are used for the
right orientation to be found; an arc, consisting of a set of short lines between the
points, is then drawn around the slot centre. Finally, the curves between the slots
are drawn as presented in Fig. 15.19, and the results from these single steps lead to
the final drawing in Fig. 15.20. Using this function, any braiding machine can be
drawn within a parametric cycle, or step by step in adding single drawings to the
same figure.
Figure 15.20 Steps of drawing horn gear (a) slot arcs (b) arcs between slots (c) final results.
can be used for measurement of yarn tension – will be demonstrated. The yarn ten-
sion is not measured during machine activity, as such a device would require both an
electricity source and data transmission or storage abilities on the carrier. Here, the
yarn tension was measured on a stopped machine, in order to analyse the state of the
carrier using the most important characteristic for braiding – yarn tension. Another
direct application could be the measurement and control of tension during yarn wind-
ing. The principle can be applied to any kind of measurement where the investigated
value is received in some electric signal.
15.3.1 Equipment
The equipment mentioned here is given only to ensure the integrity of the informa-
tion. The measurements can be performed with any other device compatible with
the available software. For measuring tensile force, the measurement element manu-
factured by BTSR (BTSR Yarn feeding control, 2013) for 500 cN is currently used.
This is an analogue device, which gives an output voltage between 0 and 10 V. This
voltage can be transferred to the computer using an analogue digital converter (ADC).
Currently used is one of the analogue inputs of the National Instruments device NI
USB-6211 (National Instruments, 2013). Before attempting measurement, the driver
for the ADC has to be installed on the computer; it should be determined whether the
Using MATLAB® for calculations in braiding 371
Figure 15.21 Getting the devices plugged into the computer and recognized by DAQ of
MATLAB.
device drivers are compatible with both the operating system on the computer and
the MATLAB toolbox.
Figure 15.23 Adding Analog Session for the channel ai0, device Dev1 and type Voltage.
64 bit MATLAB system. The legacy interface can be used for all other types of
devices, but was at this time (MATLAB 2012b, Year 2013) not available on 64 bit
MATLAB.
For the session interface, a new session has to be created with the command
s=daq.createSession(‘ni’), where s is the session object, and ni is the
device name, taken from the previous result (Fig. 15.22).
The channel that receives the signal is currently the first one (ai0)– this is deter-
mined from the place, where the cable from the sensor is plugged into the ADC. This
channel has to be added to the session with the command daq.addAnalogIn-
putChannel where the device ID, the channel name and the type of the signal have
to be specified (Fig. 15.23).
Additionally, the type of sensor connection (single-ended or double-ended) and the
time for the recording has to be set, as presented in Fig. 15.24.
If some other properties have to be changed, as for instance sampling rate, etc., the
properties of the sessions can be set in the same manner as the DurationInSeconds
in Fig. 15.24.
15.3.3 Measurement
In the current examples, the following command set was used for the measurement:
clear data; data=s.startForeground(); plot(data);
Using MATLAB® for calculations in braiding 373
Figure 15.24 Setting the single-ended type of the sensor connection and 10 s for the
measuring time.
2.5
2.5
2
2
1.5
Voltage (V)
Voltage (V)
1 1.5
0.5
1
0
0.5
–0.5
–1 0
0 5000 10000 0 0.2 0.4 0.6 0.8 0.1 1.2 1.4 1.6 1.8 2
Time (ms) Time (ms) ⫻ 104
Figure 15.25 Measured yarn tension for double and single compensated carrier.
The first command clears any variable data still present from previous measure-
ments. Normally, the data will be overwritten, but the clean start ensures that the
variable data will be reinitialized to null values. The second command begins meas-
urement in the foreground, and stores all data in the vector. The third command plots
all single values on the current figure.
15.3.4 Examples
Figure 15.25 shows the measurement of yarn tension on one carrier in cases of double
and single compensation (see Chapter 7 Carriers for braiding machines), where the
yarn was taken up and down slowly so that the lever swung around its middle posi-
tion. This corresponds to the situation where the carrier is “dancing” around the horn
gears, and compensates for the distance differences between the carrier and braiding
point. The measurement shows that, in the case of double compensation, there were
374 Braiding Technology for Textiles
Bobbin unwinding
3 Bobbin brake released
2.5
2
Voltage (V)
1.5
0.5
0
0 5000 10000 15000
Time (ms)
Figure 15.26 Yarn tension during two motion cycles of the lever and bobbin unwinding.
more fluctuations in yarn tension around the upper and lower tension values com-
pared to single compensation. This is because the yarn goes through two more guides
in double compensation than in single compensation; because of this, there are more
places where the stick–slip effect from the friction between the yarn and guide influ-
ences the yarn tension.
In both cases, the yarn tension swings between two values: the higher one during
the tension period, where the lever is travelling up and more yarn has to be given;
and the lower one – nearly zero – where the available yarn length is greater than the
distance between the carrier and braiding point, and the superfluous length is moving
back into the compensation area. The yarn tension can be recalculated using the prin-
ciple that the sensor gives 10 V for 500 cN; however, more exact calculation requires
calibration of the device with some known weight(s).
Figure 15.26 illustrates the yarn tension after two cycles of bidirectional lever
swinging; it is pulled further, so that the bobbin starts to rotate and unwind more
yarn. It can be seen that the maximal yarn tension is reached at the moment before
the bobbin starts rotating and, after that, during the unwinding, where the yarn tension
fluctuates around values identical to these during the loading cycle during the normal
braiding process.
15.4 Conclusions
The given examples demonstrate the power of the MATLAB environment; with a
few lines of code, it is possible to measure and plot the signal for the yarn tension
to be measured and plotted, or draw a 3D path. The code samples from this chapter
Using MATLAB® for calculations in braiding 375
References
BTSR Yarn feeding control (2013). Constant Tension Feeders [online], www.btsr.com. Available
from: http://www.texgilles.de/fournisseure_btsr.html (Accessed 2013).
Mathworks (2014). MATLAB, www.mathworks.com [online]. Available from: www.math-
works.com.
National Instruments (2013). National Instruments [online]. Available from: www.ni.com.