Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Using MATLAB For Calculations in Braiding

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Using MATLAB® for calculations

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.

Braiding Technology for Textiles. http://dx.doi.org/10.1533/9780857099211.4.357


Copyright © 2015 Elsevier Ltd. All rights reserved.
358 Braiding Technology for Textiles

15.2 MATLAB background


15.2.1 Environment
The MATLAB environment has changed in appearance since its first Windows ver-
sion in several respects, but the main features remain the same (Fig. 15.1).
The main window consists of set windows with different purposes. In the
“Command Window” (Fig. 15.1, Position 1) all commands are entered and their out-
put is printed. Figure 15.2 demonstrates the output of the command:
ver
giving the current version of the software and the available licensed toolboxes.
The list of all commands in the current session and former days over long period
of time (adjustable in the settings) has been stored in the “Command History”
(Fig. 15.1 Position 2). This history is especially useful if a sequence of commands
has been tested; it also allows easy cutting and pasting of commands into new files.
(Fig. 15.3).
The scripts and functions are the main elements of the MATLAB libraries, and
these can be edited in the Editor (Fig. 15.1, Position 3).
The example file ch15_1.m consists of one line
x=0:0.5:10;

Figure 15.1 Main window of MATLAB Ver. 2012.


Using MATLAB® for calculations in braiding 359

Figure 15.2 Command window with version information.

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

Figure 15.4 Setting the path to the (own) MATLAB files.

Figure 15.5 Selection of the windows to be shown.

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).

15.2.2 Functions and scripts


As mentioned above, scripts can contain a set of commands, but they do not require
any input variables. Functions are more complex elements; they may have input and
output variables, and all (normal) variables used within functions are accessible only
within the function while the function is in use.
Let us consider the function ch15_2.m (Fig. 15.6).
Using MATLAB® for calculations in braiding 361

Figure 15.6 Function ch15_2.m.

Figure 15.7 Checking the existence of a function with name beta.

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.

15.2.3 Function with global variables and 3D plot


If some variable should remain accessible both within a function and outside a
function, it has to be defined as global. This is shown in Fig. 15.9 within the code
of the function ch15_3, where both variables v (representing takeoff speed) and
EndAngle (denoting the maximal angle for the angular coordinate of the points to
be drawn) are defined as global. This means that the values of these variables have
also to be declared as global in the calling function, which in this case is ch15_4,
presented in Fig. 15.10.
The global variables here are normally constant during calculations assuming
one machine, product or other object. In a practical scenario, there is a large set of
variables that remain global, where it is more convenient to initially specify these as
global. This allows the lists of input variables for the functions to be kept shorter.
362 Braiding Technology for Textiles

Figure 15.8 Running the function and the plotting result.

Figure 15.9 Extended function ch15_3.m for using of global variables v and EndAngle.
Using MATLAB® for calculations in braiding 363

Figure 15.10 Running the function and the plotting result.

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.

15.2.4 Carrier coordinates of spiral braiding machine


The motion of the carrier in the spiral braiding machine is explained in Chapter 11.
The function draw_hopy(k)uses the equations provided there so as to plot the path
364 Braiding Technology for Textiles

Figure 15.11 Example of 3D curve, plotted using the script ch15_4.

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.13 Resulting curve from draw_hypo(4).

function draw_hypo. getcoord calculates the coordinates of a point for given


angular position fi and coefficient lambda, and is called as required for calculation of
all points of the hypocycloid. Figure 15.13 shows the result from the calculation of
the path of carrier with k = 4.

15.2.5 Calculation of the yarn length per repeat depending on


the braiding angle
It is easier to understand the influence of a single variable over some product param-
eter if the relation between the input and output parameters is presented visually. If
the relations become more complex and several equations are used, it is more conven-
ient to draw such relations in MATLAB instead of in MS Excel or OpenOffice Calc.
The calculation sheets can have equations, but they are not directly visible during
the calculation (if the user does not use Visual Basic for Applications), and looking
for errors can take long time. In the MATLAB code, the equations are visible one
after another, and debugging (running the program step by step) allows for errors in
programming to be found more rapidly.
The file lflat.m (Fig. 15.14) presents the code for some of the calculations, pre-
sented in Chapter 14 Productivity calculations in braiding. Here, the variable a stores
the values for the braiding angle – between 20° and 80° – and the variable I is the index
for the single values. The example demonstrates plotting of two curves on the same
figure (Fig. 15.15) with different settings, setting the legend, x- and y-axis, and the
switches to export the figures as jpeg files with no compression (-jdpeg100 means
100% quality) and resolution 300 dpi (-r300), required for the figures in the book.
366 Braiding Technology for Textiles

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.

15.2.6 Yarn force during unwinding


The calculations required to calculate the yarn force necessary to rotate the bobbin
during the braiding process was described in Chapter 8. Figure 15.16 presents the
MATLAB code, where these equations are implemented and can be used for para-
metric analysis of yarn tension.

15.2.7 Horn gear form drawing


For several demonstration and animation processes, it is efficient to have a simplified
representation of the horn gears with their slots. For the purposes of this book, a func-
tion to draw horn gears was written, so that – depending on the machine, and number
of slots of the horn gear – appropriate drawings could be generated automatically.
Figure 15.17 presents the first part of the code, where the function hg=plot_horn_
gear creates a structure hg with all important properties, based on the horn gear
Figure 15.17 Horn gear drawing function, part 1 – initialization and angles of the slots.

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.

15.3 Data Acquisition Toolbox™ and yarn tension


measurement
The Data Acquisition ToolboxTM (DAQ) is a separate library giving MATLAB the abil-
ity to read or write signals from/to external devices. A small set of commands – which
370 Braiding Technology for Textiles

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.

15.3.2 Setting the environment and creating


measuring session
The first step in MATLAB is to check which devices are recognized for
measurement.
Figure 15.21 demonstrates the results of checking the devices on the current com-
puter with the command daq.getDevices. The computer shown has only one
device – ni – with sixteen analogue channels. The device ID is Dev1, the first chan-
nel is named ai0, and they are ready for voltage measurement. These data are required
for the next step, as the other channels are not used in the current example.
The DAQ toolbox has two types of interface – session-based and legacy-based.
These are not supported for all devices and operating systems. The session-based
interface works on “sessions,” for NI devices, multiple devices and measurement
types including temperature, current, and accelerometer, and works as well on the
372 Braiding Technology for Textiles

Figure 15.22 Creating new session.

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.

Double compensation Single compensation


3 3

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

are freely available from the MATLAB Central webpage – at http://www.mathworks.


com/matlabcentral/fileexchange/47310-braiding-technology-fo-textiles--elsevier – as
well as on the author’s homepage www.kyosev.com.

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.

You might also like