0% found this document useful (0 votes)
19 views9 pages

Low-Cost Control Education System

This document presents a low-cost system for control education based on free and open-source software (FOSS) and USB communication. The system includes power supplies, a microcontroller, high-speed USB interface, DC motor, encoder, isolation circuitry and an H-bridge power amplifier. It uses Scilab/RTai/Qrtailab FOSS for real-time control and has a graphical interface. The goal is to improve control education by allowing students to implement and test control strategies on real hardware in a portable, low-cost manner.

Uploaded by

Alejandro Mises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Low-Cost Control Education System

This document presents a low-cost system for control education based on free and open-source software (FOSS) and USB communication. The system includes power supplies, a microcontroller, high-speed USB interface, DC motor, encoder, isolation circuitry and an H-bridge power amplifier. It uses Scilab/RTai/Qrtailab FOSS for real-time control and has a graphical interface. The goal is to improve control education by allowing students to implement and test control strategies on real hardware in a portable, low-cost manner.

Uploaded by

Alejandro Mises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MECHATRONICS 00 (2017) 0000-0000

Available online at [Link]

Mechatronics 
Journal homepage: [Link]/locate/mechatronics

A low-cost system for control education based on free software and USB
communication

Juan M. Serna-Ramireza, Carlos Fory-Aguirrea, Alejandro Ojeda-Missesb, Andrés M. González-Vargasc,


Alberto Soria-Lópezb,*
a
Universidad Santiago de Cali, Grupo de investigación GIEIAM, Facultad de Ingeniería Calle 5 Carrera 62, Cali, Valle del Cauca, Colombia.
b
Departamento de Control Automático, Centro de Investigación y de Estudios Avanzados del IPN, Av. IPN 2508, CDMX, México.
c
Departamento de Automática y Electrónica, Grupo G-BIO, Universidad Autónoma de Occidente, Cll 25#115-85, Km 2 Vía Cali-Jamundi, Cali, Colombia.,

ARTICLE INFO ABSTRACT

Article history: This paper presents a portable control education servo laboratory prototype. The main goal is
Received 00 December 00
to improve undergraduate control education by using an integrated prototype including power
Received in revised form 00 January 00
Accepted 00 February 00 supplies, a microcontroller, high speed USB communication interface, 50w direct current
motor, 10,000 pulse incremental encoder, isolation circuitry and an h-bridge as part of the
Keywords: power amplifier that allows tuning the PI low level current loop gains within the graphical
Control education interface. The platform uses Scilab/RTai/Qrtailab free software.
Free software © 2017 Elsevier Ltd. All rights reserved.
Real-time control
RTAI
Rapid Control Prototyping
Scilab

and software without compromising the process itself. HIL


1. Introduction techniques involve real-time simulations of the control system with
the addition of hardware components that simulate the physical
Control systems have become a ubiquitous need that plays an response of the plant. RCP is a variant of HIL, in which controller
important role in the development of devices for industrial, design and tuning is simplified by using graphical interfaces with
biomedical, transportation, communications and entertainment block diagrams and high-level languages. This allows control
purposes, among others [1]. Design of control systems always engineers to quickly test and iterate different control strategies,
requires time and effort, but in previous decades the labor was leaving low-level coding to be automatically generated by compilers
especially tedious and cumbersome since it involved testing directly included in the software. Therefore, more effort can be invested on
on the plant under control, often composed of complex, expensive developing control algorithms in different operating conditions and
and non-flexible machinery [2]. However, the use of techniques such realistic situations.
as hardware-in-the-loop (HIL) and Rapid Control Prototyping (RCP) To develop the full range of skills needed to become control
has greatly shortened the design cycle and reduced development systems designers, students need not only to master theoretical
costs, allowing engineers to validate their model, control algorithm concepts, but also being able to apply them to practical problems [3],

* Corresponding author.
E-mail address: soria@[Link]
Peer review under responsibility of xxxxx.
[Link]
0000-0000/© 2017 Elsevier B.V. All rights reserved.
2 J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000

[4]. Therefore, laboratory experiments become an important factor, developing countries. Also, communication speed between the
allowing abstract concepts to be related to real-world problems, controller and the plant is a key factor to achieve real-time control
providing students with an adequate environment for complete and good sampling frequencies. Another important fact is that
engineering design, from modeling and simulation until experimental graphical interfaces such as Simulink or Scicos simplify the design
verification [5]. However, in many universities the introductory process greatly, allowing the designer to focus on the control strategy
courses of control usually focus on theoretical aspects [2], which can instead of the code. Finally, having a portable platform, which is easy
be difficult to assimilate if they are not accompanied by practical to interface with any computer and be carried home by students,
experiences [6] in which the student constructs knowledge in an opens a new world of possibilities for practical assignments in control
active way [7]. Limiting the control experimentation to advanced courses.
courses misses the opportunity of implementing certain important Development of control engineering educational platforms has
control concepts during the first stages of a student’s career. Several been a very active subject in the last decade. Several works have
authors [8], [9], [6], [10], have presented laboratory setups that make proposed systems that address some of the needs mentioned earlier.
use of real-time RCP systems to control a wide variety of plants, Qian et al. [11], used a Linux/RTAI system with Scicos graphical
allowing students to learn by hands-on experimentation on high order environment to control a frictional testing machine connected via a
nonlinear systems, structurally unstable systems, linear and nonlinear data acquisition card pci-6024e from National Instruments. The
control methods, fuzzy control, artificial neural networks and many results showed Linux/RTAI to be a very powerful real-time platform.
other complex subjects. Grzegorz et al. [10], presented three didactic control systems for
In the last decade, several companies have started to offer RCP servomechanisms using a RCP system based on Scilab/Scicos.
software and hardware solutions. Mathworks’ MATLAB/Simulink Modelling was done in a regular PC while real-time control was
[40] has become the de facto software for signal processing, design carried out by an external embedded ARM-based platform. Meza et
and simulation of control systems. Simulink allows developing al. [12], showed the advantages of using Scilab [45] and RTAI [46]
complex algorithms using a block diagram programming paradigm. for control courses. Using FOSS decreased significantly the cost of
It can compile the block model, translate it into C code and upload it the system. The plant (a rotary inverted pendulum) was connected to
via Ethernet to a xPC target real-time board. National Instruments the computer via the parallel port. Duma et al.[13], presented a RCP
[39] (NI) offers solutions such as CompactRIO and MyRIO, which toolbox using RTAI. The main focus of their work was the software,
are reconfigurable embedded systems oriented towards data and they proved it to work efficiently even in a very slow PC with a
acquisition, control and processing. These systems are programmed CPU speed of 700MHz. The hardware used for testing was an analog
with graphic tools from LabVIEW. One downside of this systems is computer Meda 43Ha, and data was acquired using an AT-MIO-16E-
that they don’t support personalized hardware but only hardware 10 from National Instruments, which had to be connected on the ISA
offered by National Instruments. Another producer of hardware and bus of the PC. Chen et al. [14] presented an economical RCP system
software for control systems is dSPACE [44] . Their products based on MATLAB/Simulink and a real-time target consisting on a
integrate with Matlab/Simulink by specific toolboxes. Their RCP control board based on a Texas Instruments TMS320F2812 DSP.
systems are oriented towards “Processor-in-the-loop” (PIL) and HIL They implemented the system to control a linear motor driven double
simulations. Most of these systems are based on IBM processors. inverted pendulum. Special Simulink blocks were created to add
dSPACE also offers RCP systems called Micro-Autobox that work input/output capability to the control strategy. Their system allowed
without the need of a PC. Another popular option is Quanser’s for symbolic model development, automatic code generation,
QUARC [41] software, which integrates with Matlab/Simulink and variable monitoring, and parameter tuning. Zhong et al. [15],
allows Simulink diagrams to interface hardware and be run in real- proposed a configuration for a low-cost RCP system composed of a
time on local and remote targets. Quanser provides USB Data PC with Matlab/Simulink with an special real-time blockset and an
acquisition devices such as the Q2 and Q8, and offers a wide variety external LabJack U12 DAQ board. The U12 Board uses a USB
of educational plants such as the QUBE Servo 2 and the QNET 2.0 interface. The system did not perform in hard realtime or with high
DC Motor Board. The cost of the tools provided by all these sampling rates and did not consider portability or robustness but
companies is usually quite high, and hardware components plus the offered a low-cost solution for RCP. Bradley et al. [16], developed a
software licenses, including all necessary toolboxes cost thousands of low-cost platform using a PC running GNU/Linux, and LEGO
dollars, sometimes well above US$10000. These costs can be MINDSTORMS NXT as a target system. Real-time control software
restrictive for many education institutions, especially in developing was developed using a mixed paradigm, using Matlab/Simulink for
countries. For undergraduate programs, most of the time it is not cost- controller design and Ada for the NXT real-time code
effective to invest in such sophisticated RCP platforms. implementation. Oftadeh et al. [17] presented a development
In this paper, we present a real-time control system for educational environment consisting of a host PC with Matlab/Simulink connected
purposes. With this system, we seek to address several points that via LAN to an embedded PC with a real-time Linux. They tested the
become important if one wants to achieve a good combination of cost, system on a mobile robot with three degrees of freedom. Lee et al.
performance and portability. Namely, it offers the following features: [18], proposed a cost-effective RCP system based on
low-cost, high-speed communication USB interface, free open source Matlab/Simulink and a DAQ unit with a highspeed USB
software (FOSS), graphical interface modeling, high-performance communication interface. The system showed good maintainability
hardware components and an overall design that favors portability and portability due to the USB interface, low cost, and no necessity
and easiness of use. We have focused on these problems because, as for C-code generation. Bazán and Florez [19] presented a low-cost
mentioned before, the costs associated with facilities and equipment RCP platform with a DC motor. They used free open software such
for practical courses are prohibitive in many universities in as Linux, Scilab/Scicos and RTAI. An external control board based
J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000 3

on a PIC16F877A was in charge of generating the PWM (Pulse servomechanism. The papers ends with some conclusions and ideas
Width Modulation) control signal and digitizing the sensed variables. for future work.
Connection between this board and the host PC was done via parallel
port. Chuang et al. [6] proposed using LEGO Mindstorms NXT kit 2. System Components
and NXC software as a low-cost platform for education in control.
However, the use of NXC as programming language lacked the high Almost all computers available today include a Universal Serial
level language abstraction given by platforms using Simulink or Bus connector, enabling the use of data acquisition devices without
Scicos. Flores [20], developed an advanced RCP system based on the need to insert into a motherboard slot. The experimental
Matlab/Simulink using high-speed USB communication. The real- servomechanism that we present in this paper uses a high-speed 480
time target board used a STM32F4 microcontroller, which eliminates Mb/s USB interface allowing a sampling rate up to 0.5 milliseconds.
the requirement of a real-time operating system and allows direct We designed the control platform so that the hardware components
access to all hardware resources. Multimedia capabilities were also would be ready available in developing countries in Latin America.
added to the control system without compromising its performance. Fig. 1 depicts the overall structure of the system where three main
All the systems mentioned above make some compromise in the parts can be identified: The control platform board which implements
design depending on the particular conditions. Most of them use the servomechanism, the USB2LPT hardware interface to transcript
proprietary software such as Matlab or NI Labview, instead of using data from EPP to the USB standard and the real-time software
FOSS [16], [14], [20], [18], [17] and [15]. In some of them, real-time structure, including RTAI and its interaction with the standard Linux
algorithm must be totally or partially coded directly in C, Ada or kernel, the Scilab/Xcos programmed controller, hardware drivers and
some other non-graphical language [16] and [6]. Other solutions QrtaiLab as visualization and tuning interface.
relied on a real-time target computer [16], [20], [17], [10] and [14].
Another problem was the lack of hard real-time features or low
communication speeds [12], [15] and [19]. For different reasons
(interface, software requirements, plant size), most of them were not
portable [14], [13], [17] and [15]. To the best of our knowledge, none
of these systems or others in literature address the cost, performance
and portability issues better than the one we present. In terms of
performance and portability, a commercial solution that offers similar
features would be a combination of Matlab/Simulink [40], QUARC
[41], a Q2 DAQ and a QNET 2.0 DC Motor board, but the cost would
be many times higher.
The system presented in this paper relies completely on FOSS,
using Lubuntu-Linux operating system in combination with RTAI
extension to provide a lightweight and highly reliable real-time
environment. Modelling and simulation of control systems is done Fig. 1. System structure.
using Scilab/Scicos, which also works as a user interface for soft real-
time applications. A user interface for hard real-time applications is 2.1. Hardware
provided via QRtaiLab [43]. Communication is done via a high-speed
USB interface at 480 Mb/s, allowing sampling rates up to 0.5 The Direct Current (DC) motor servomechanism shown in Fig. 2
milliseconds. The PWM module's carrier frequency of 20.317 KHz includes a direct current (DC) motor [22] , a Peripheral Interface
avoids audible noise in the motor, and the optical incremental encoder Controller (PIC) [23], a high speed USB communication
allows counts 10,000 pulses per revolution. Moreover, the platform microcontroller [24], a digital magnetoresistive isolator [25], an
allows to tune in real-time low-level current loop gains, allowing analog galvanic isolator amplifier[26], an incremental encoder [27] ,
students to understand and be aware that a motor power amplifier an H-bridge [28] and the necessary power supplies for all
used in torque mode should be properly configured assuring proper components. The current power amplifier is implemented within the
higher level control loops operation [21]. The platform measures PIC using the H-Bridge and includes a current loop where the loop
24cmx12cmx10cm and weighs less than 3kg, making it easy to carry gains can be tuned in real time via the Qrtailab window. Fig. 3 shows
in a regular backpack, and the USB interface allows connection to a diagram of on how the components of the platform are
any modern computer. This, and the fact that the operating system interconnected.
and all required software can be directly booted and run from a USB
flash drive makes our platform really portable and easy to transport,
and allows to perform experiments at home or anywhere else,
reducing the need for space and time resources associated with the
use of laboratories.
This paper is organized as follows: Section 2 presents the system
components including the hardware, communication protocol,
firmware implementation and free software details. Section 3
describes the Linux USB driver development. Section 4 introduces
an example of least squares identification of the platform’s
4 J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000

Fig. 2. Direct Current Servomechanism.


The main goals when choosing the system components was to
have as few components as possible, low cost, high performance and
ease to repair. It can be noted that all the Integrated Circuits (IC) have
Fig. 3. Hardware components.
a Dual In Line (DIP) configuration inserted in soldered bases that can
be changed with ease allowing the necessary interconnection. The
2.2. Communication protocol
DSPIC 30f4012 was selected since this PIC has specific modules for
motor control applications such as a Quadrature Encoder Interface
To be able to use the USB interface we adopted hardware signaling
(QEI) and a Pulse Width Modulation (PWM). These modules work
described by the EPP specification. The EPP specification allows
independently consuming small amounts of the PIC processing time.
performing read/write address and data cycles where handshaking is
The QEI module counts the pulses from the incremental encoder performed by the hardware rather than by software. The handshaking
measuring the angular position of the motor shaft. The power signals are the Address Strobe, Data Strobe, Read/Write and Wait.
amplifier includes the PWM module and the LM18200 H-bridge that The Data Strobe that signals a data cycle is connected to the
controls the power delivered to the motor. The PWM carrier dSPIC30f40 INT0 pin. The Address Strobe specifies an address cycle
frequency is 20.317 KHz avoiding audible noise in the motor and is is connected the dSPIC30f40 INT1 pin. The PC will act as a master
determined by the microcontroller. The 10-bit ADC measures a and the dSPic30f4012 as a slave. Thus, a read cycle will transfer
voltage proportional to the current in the H-bridge that is then used information from the dSPIC30f4021 to the PC. A write cycle will
as the feedback signal for a Proportional Integral PI current loop. The transfer information from the PC to the dSPIC30f4012.
isolating digital and analog integrated circuits allow the isolation of The most basic information to be transferred between the
the power amplifier stage from the digital processing stage. The EPP/USB and the servo prototype are the encoder position (4 bytes)
IL711 high speed digital isolator is used isolate the PWM and sign and the PWM control (2 bytes). The data source of the encoder
signals whereas the ISO124 isolating amplifier allows the isolation of position is produced by the dSPic30f40 QEI interface whereas the
the current analog signal coming from the integrated H-bridge. The data source for the PWM control is the PC. To perform data exchange
other available pins are used for a parallel 8-bit data bus, with two a dedicated ordered memory area or data vector is kept within the
handshaking signals. The USB interface USB2LPT uses the Cypress PIC. This vector stores the 4 bytes for the encoder position and 2
CY-68013 EZ-USB high-speed 480mb/s chip [32]. This Cypress chip bytes for the PWM control. This information is ordered in vector
that is encased in a USB-LPT connector allows using the platform memory locations 0,1,2,3 for the encoder position and in vector
with the USB interface. memory location 4,5 for the 2 PWM control bytes.
At each sampling time, the PC will first perform an address write
The optical incremental encoder is the US-Digital E-6 2500 model
cycle followed by 4 data read cycles to retrieve the encoder position
allowing counts 10,000 pulses per revolution. The motor used is a
and by 2 data write cycles in order to send the PWM control. The
dual shaft Dynetic Systems brush DC motor 509051. Therefore, the
address write cycle is used to indicate the starting address memory
proposed system implementation is a reasonable low-cost alternative location for the data vector. When an address write cycle is initiated
having high quality. by the PC the dSPIC30f4012 will enter the External Interrupt 0
service routine where the address byte is read from the data bus
loading an Address Pointer, the address cycle is ended by the
dSPIC30f4012 producing a pulse at the WAIT line. Afterwards when
the PC initiates a data read cycle, the dSPIC30f4012 will enter the
External Interrupt 1 service routine where depending of the
Read/Write line the data byte is read/written from/to the bus and
retrieved/copied to the data vector memory location stored in the
Address Pointer. The Address Pointer is incremented to address the
J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000 5

next data byte. The data cycle is then ended by the PIC producing a quadrature encoder pulse count. The QEI module only has a 16bit
pulse in the WAIT line. Fig. 4 shows the structure of the basic data counter, thus when this counter overflows or underflows the module
exchange. Other address cycles will be performed by the PC and are will produce an interrupt allowing increments or decrements of the
used to synchronize data exchange. In an address cycle, a two most significant bytes of the 32 bit long value. The INT1 is used
synchronization address is sent by the PC. In the INT0 Interrupt to handle address cycles and the INT2 is used to handle data cycles
Service routine the Address Pointer is checked and the using the protocol mentioned above. The ADC interrupt is used to
synchronization action can be performed. The synchronization retrieve from the ADC module the current in the H-bridge.
actions are initiated within the XCos C block corresponding to the Other miscellaneous functions are necessary such as Delay
initialize states function, model output function and model terminate. routines, General function declarations and definitions and the DsPIC
The initialize synchronization action is used to correctly initialize the 30f4012 configuration bits definitions.
encoder pulse counter to zero and the PWM output to 0. The model
output synchronization action is used to set a flag indicating that the 2.4. Free Software
motor block output is required at the sampling period hit, so that in
the main routine in the PIC, an update can be made to the PWM All the software required by the platform is free and open source.
output and the encoder values before this data is retrieved. The model We used the OS Lubuntu 14.04, and RTAI 4.1 with kernel 3.81.6.
terminate synchronization action is used to reset the dsPIC30f4012 to RTAI is a hard real-time extension for Linux, which allows the user
the initial state. to write applications with strict timing constraints. It consists
primarily of a patch to the Linux kernel which introduces a hardware
abstraction layer, and a variety of services to facilitate programming.
Other real-time systems (such as LabVIEW [39] Real-Time or
Matlab Xpc Target[40]) require the use of external processing units
that act like clients, only running the real-time tasks, while the main
computer acts as host, providing the user interface, which is not real-
time. RTAI allows the same computer to run the interface and control
the real-time tasks without risk of incurring in delays that affect
control strategy. The design of the controller is carried out using
Scilab/Xcos. Scilab is an open source numerical computational
package and high-level numerically-oriented programming language.
It provides an interpreted programming environment, with matrices
as the main data type. The language provides a wide range of complex
mathematical operations that simplify tasks as signal processing,
Fig. 4. Basic data exchange between the PC and the dSPIC30f4012. statistical analysis and dynamical systems simulations. Xcos is a
graphical modeler and simulator for dynamical systems that allows
2.3. dSPic30f4012 firmware the possibility of compiling such models into executable code. Xcos-
blocks for the platform are created using the HART Toolbox Version
The firmware is the program within the dSPIC30f4012. I will 3.23 [42], and the user interface utilizes QRtaiLab 2.3 [43], a
perform five tasks: QT-based port of the software scope xrtailab of the RTAI project.
 initialize the dSPIC30f4012 peripherals used to control the DC
motor: the AD converter to measure the current in the H-Bridge, 3. Real-time Linux USB Driver development
the QEI module to read the optical incremental encoders and the
PWM module to drive the H-Bridge; A device driver creates an abstract and simplified model of a
 Perform the PI current loop. physical or virtual device that interacts with an operating system
 Update the encoder position in the Data Vector. through a standard interface operating interface such as POSIX [29],
 Update the PWM output value from the Data Vector. hiding the inherent complexity of the controlled device. Linux
 Transfer data from/to the Data Vector via INT1 and INT2 architecture groups device drivers into three categories: block,
interrupt service routines. character and network drivers. The first ones handle blocks of
The code performing these tasks is organized as follows: information of certain size and are often used to model devices that
Initialization and configuration routines for the QEI, PWM, ADC, host file systems. Character drivers handle information as a string of
modules. These functions will be called upon reset of the arbitrary length and are used to model virtual devices such as
dSPIC30f4012. Each module will have a corresponding initialization terminals or physical devices such as serial ports. Network drivers
routine for the correct configuration. These essentially write the send and receive data packets to and from other hosts handled by the
values for the different dsPIC30f4012 registers to correctly configure network subsystem [30]. Clocks [31] are special devices that do not
each module. fit into the above categories having a dedicated driver.
The main loop routine will execute the PI current loop and the data Designing a Linux driver for a device requires in first place that
update. The data update is executed if the flag indicating that the the communication scheme and type that the driver expects to engage
XCos block output request is set, otherwise only the PI current loop with the operating system be given. It is difficult to identify the best
is executed. The data update will refresh encoder position to the Data driver model (character, block or network) for a device, since there
Vector and the PWM value from the Data Vector. are some driver models that are not clearly associated with employed
QEI, INT1, INT2, ADC interrupt service routines. The QEI hardware technology. For example, if a device is anchored to a USB
interrupt is used to implement a 32bit long integer value for the port, handshaking data allows determining if the device is designed
6 J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000

to store information in blocks (like a pendrive) then a block model


will be preferred. If a device requires a stream of commands of
arbitrary length to operate, (such as a USB to parallel port interface)
then a character driver model is better suited.
The USB2LPT interface (version 1.7) is a character device. Once
anchored to a USB port, it performs communication between the USB
kernel subsystem and the IEEE 1284-1994 standard (parallel port)
implemented using the FX2LP chip (Cypress Semiconductor)
reaching a maximum transfer rate of 480 Mb/s [32].
A sniffer USB filter tool [33],[34] allows the validation of the
transmission format of the data that can be up to 512 bytes wide. This
tool is used in an alternate operating system such as Windows where
the device has a functional driver allowing to intercept USB Request
Blocks (URB) traffic between the Windows driver and the FX2 chip.
URBs are subjected to protocol analysis to identify the content, size,
order and direction of data conveyed (payload). Transfer status can Fig. 5. USB2LPT Linux driver architecture.
be also determined as well as originating transfer request source.
In second place it is important to know the path to the device. Fig. 5 shows the block diagram of the implemented driver for
Many devices like USB2LPT are compound devices, that is, they are USB2LPT. When the driver is loaded into memory, the function
presented to the operating system as multiple devices having sub usb2lpt_init() registers it with the USB kernel subsystem. The
devices with different interfaces and functions. Each subdevice has a function usb2lpt_probe() is executed when the hardware USB2LPT
unique access tuple f(i,a,e) formed by the interface number i, the is anchored to a USB ports on the computer. With it, information
number of alternating interface a and a set of endpoints e. The driver about hardware interfaces and endpoints is obtained and the device
will use path f(i, a, e) in order to access a USB2LPT subdevice. In is registered. The information is then stored in an internal structure
Linux the command, sudo lsusb -v -d VID: PID displays all the that represents the device. The function usb2lpt_open() opens the
information about tuples, where VID and PID are vendor and product USB interface described in the access tuple; usb2lpt_close(), releases
codes; for the USB2LPT device these values are VID=0x16C0 and it; usb2lpt_read() and usb2lpt_write() contains the code for
PID=0x06B3. The above command also displays the type of transfer assembling URBs in order to send, receive and copy information to
(bulk, Isochronous, interrupt or control) supported at each endpoint. and from the user program [36]. These functions have their pointers
The USB2LPT operates in bulk mode for f(0,0,{0x02,0x86}), in the file_operations structure and form the interface with the user.
corresponding to the device whose driver was built. Communication In that sense, user sees the driver as a special file, which is accessed
between the driver and the hardware can be synchronous or from an application using system primitives like open(), close(),
asynchronous. For Linux kernel 3.9 and later versions, for a read() and write() [29]. The usb2lpt_disconnect() function is called
synchronous bulk write the driver performs the following operations: when the device is unanchored from USB. It releases the device
creates a new URB with usb_alloc_urb(), stores it in a new buffer registration done by usb2lpt_probe(). By last, usb2lpt_cleanup()
with usb_alloc_coherent(), copies the user data in the buffer, starts releases the driver registration on the USB kernel subsystem done by
the URB with usb_fill_bulk_urb () and finally sends it to the USB usb2lpt_init() when the module is downloaded from the system [30].
subsystem with usb_submit_urb(). If the URB is processed The driver is implemented as a Linux kernel module. Compilation
successfully, the USB subsystem makes a callback to release the should be done with the same compiler version used for RTAI kernel.
memory used in the process with usb_free_coherent() [35]. Including a Dual BSD / GPL license prevents the kernel to become
Alternatively, when the kernel operates in real time with periodic tainted and avoids warnings in the system log [37]. Module load and
writings and it is desired to minimize the occurrence of changes of unload can be done with insmod and rmmod programs. the load
context; writing cycles should end in the same sampling period where status is checked with lsmod. Once loaded, the driver special file
they started, being more appropriate a bulk synchronous writing [31]. follows the same safety rules as ordinary files and initially only the
In this type of transfer URBs are sent using usb_bulk_msg() and root user has granted access. Normal user and group access is granted
returns when finishes or when the waiting time has ran out. It is a by sudo chmod 777 <file path>. You can also run the application that
blocking transfer. The functions that handle URBs receive as part of uses the driver as root user [38].
their parameters the access tuple to sub device. The interface employed in Scilab to use the driver developed
Many devices with similar features have drivers with similar above is an Xcos function block. The block represents an abstraction
structure. This structure consists of groups of functions that exchange layer composed in its base by the more complex real-time driver
information between the kernel and user address spaces of the application interface to interact at low level with the hardware; a
computer [31]. At the driver level, there are collections of functions computational function written in C allows the management of the
intended to start, read, write and control the hardware of the device. information carried from and to the servomechanism, and an interface
The same driver has control functions for the kernel, whose purpose function written in Scilab language at the top in charge to deal with
is to register and create new instances in case of detecting multiple the appearance and block behavior during simulation. The resulting
compatible devices. From the user address space, the driver appears block (C Block 4 type) has six signal inputs, one activation input and
as a special file in /dev/usb, which can be accessed through standard four signal outputs. Signal inputs allow the PI low level current loop
file operations [36]. to be tuned and turned on or off, and receive the current reference
signal. The activation input allows to synchronize the block with the
real-time simulation. The outputs on the other hand correspond to the
quadrature encoder counts, estimated speed using a high-pass digital
J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000 7

filter, measured current and the PWM signal applied to the DC motor. b  T
The virtualization block can be enclosed in a super block to operate z (t )  1 (t )  2 (t )      (t )
only with the inputs and outputs of interest, for example, the reference a  (11)
where 1 ( s )  L 1 (t ) ; 2 ( s )  L 2 (t ) .
current input signal (tau) and the speed output signal (vel) as shown
in Fig. 6 .
To perform the parameter identification, signals z (t ), 1 (t ), 2 (t )
4. Least squares servomechanism identification
are obtained by the following filters using equations (5), (9) and (11):
As an application example, we propose closed loop identification s
Z (s)  V (s)
of the servomechanisms parameters. We employ a simple first order s (12)
model that considers the main motor dynamics of interest:

( s)   1 ( s)  2 ( s)  U ( s)
1
V ( s)
1 
V (s) b  s   s 
G(S )   (1) (13)
U (s) (s  a) Model parameters a and b are estimated in the Least Squares
To apply a least square identification, it should be noted that the
sense using the Moore-Penrose pseudo inverse with k
above model is of the form:
measurements:
v ( t )  av (t )  bu ( t )  aˆ 
ˆ     2   k  k   k Z k
(2) T 1 T

ˆ
that is not linear in the parameters. It is then necessary to rewrite (2) b (14)
so that parameters a and b appear as:

z (t )  b1 (t )  a2 (t ) (3)

to rewrite (2) we take the Laplace transform of (2):

V ( s )( s  a )  bU ( s ) (4)

were V ( s )  L v (t ) ; U ( s )  L u (t ) .
we then define a stable polynomial:

 (s)  s   (5)

adding  ( s )V ( s ) to (4) gives:

 ( s )V ( s )  bU ( s )   ( s )V ( s )  V ( s )( s  a ) (6) Fig. 6. Identification XCos model.


Fig. 6 shows the XCos model. It should be noted that in this model
using (5) we have: we include a motor model block obtain from a previous identification
run with ˆ  1.16 80.30  .
T

 ( s )V ( s )  bU ( s )  V ( s )  aV ( s ) (7)

dividing by  (s) :
b  a
V (s)  U (s)  V (s)  V ( s) (8)
 (s)  ( s)  (s)
Defining,


Z (s)  V (s)  V (s) (9)
 (s)

we have
U (s) V ( s)
Z ( s)  b  (a) (10) Fig. 7. Model and real motor speed.
 (s)  ( s) Fig. 7 shows the model and the real motor output whereas Fig. 8
U (s) V (s) shows k components. The excitation signal is constructed using a
defining 1 ( s )  ,  2 (s)   we finally that can
 (s)  (s) constant value of 5.7 plus a random value that is changed each 0.300s
rewrite (3) as: in the interval [2.25,5.25] that is afterward filtered using the first
order filter 1 ( s  1) .
8 J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000

[2] J. Apkarian and K. J. Astrom, "A laptop servo for control education,"
in IEEE Control Systems, vol. 24, no. 5, pp. 70-73,
DOI: 10.1109/MCS.2004.1337864, Oct. 2004.
[3] Bristol, “An industrial point of view on control teaching and theory,”
in IEEE Contr. Syst. Mag., vol. 6, no. 1, pp. 24–27, 1986.
[4] N.A. Kheir, K.J. Åström, D. Auslander, K.C. Cheok, G.F. Franklin, M.
Masten, and M. Rabins “Control systems engineering education,” in
Automatica, vol. 32, no. 2, pp. 147–166, 1996.
[5] W. Grega, "Hardware-in-the-loop simulation and its application in
control education," in Frontiers in Education Conference, San Juan,
Puerto Rico, 1999, pp.12B6/7-12B612 vol.2.
DOI:10.1109/FIE.1999.841594, 1999.
Fig. 8. k matrix components. [6] H. S. Chuang, Y. C. Chuang and C. H. Yang, "Development of a low-
cost platform for control engineering education," in 2014 International
Conference on Machine Learning and Cybernetics, Lanzhou, China,
5. Conclusion pp. 444-448. DOI: 10.1109/ICMLC.2014.7009649, 2014.
[7] E. R. Loures, M. R. Silveira, M. A. Busetti and Y. Arda, "Enhancing
The new RCP platform presented in this paper is appealing for control engineering education using a CACSD didactic
several reasons. The use of FOSS reduces significantly the costs environment," in IEEE International Conference on Systems, Man and
Cybernetics 2003, Washington DC, USA. pp. 2205-2212 vol.3.
associated with software licenses. It also ensures that there is a large
DOI: 10.1109/ICSMC.2003.1244211.
community of people working constantly to provide new features and [8] K. Kolek, A. Turnau, K. Hajduk, P. Piatek, M. Pauluk, D. Marchewka,
improved reliability. Using RTAI allows a single PC to run the A. Pilat, M. Rosól and P. Gorczyca, “Laboratory real-time systems to
interface and real-time tasks without needing an external embedded facilitate automatic control education and research,” in International
computer while guaranteeing hard real-time performance. The high Multiconference on Computer Science and Information Technology,
level graphical programming interface based on XCos allows pp. 805-812. Wisla, Poland. 2010.
undergraduate students to focus on the control algorithm rather than [9] P. Ponce Cruz and A. Molina Gutiérrez, "LabVIEW for intelligent
the implementation. Using QRtaiLab offers the possibility to change control research and education," in IEEE 4th International Conference
controller parameters during hard real-time execution, and the on E-Learning in Industrial Electronics, Glendale, AZ, pp. 47-54,
visualization interface has some degree of customization. The most 2010.
[10] S. Grzegorz, Z. Tomasz and B. Andrzej, "Rapid control prototyping
important concepts when learning control theory can be illustrated
with Scilab/Scicos/RTAI for PC-based ARM-based platforms,"
with a servomotor: dynamic system, model, feedback and stability. in 2008 International Multiconference on Computer Science and
Also, servomotors are present in many of the commercial and Information Technology, Wisla, Poland, pp. 739-744.
custom-made educational plants available. Using a DC motor doi: 10.1109/IMCSIT.2008.4747324, 2008.
coupled with an incremental optical decoder allows our platform to [11] D. Qian, D. Zhao, L. Tian, L and Q. Wang, “Linux/RTAI and Scicos in
be used for a wide range of control tutorials and assignments, in a Low Cost High Performance Friction Testing Machine” in 2007
physical setup that is low cost, portable and easy to repair. Portability International Conference on Electronic Measurement and Instruments,
is also reinforced by using a USB interface instead of a data Aug. 16-18, Xian, China. DOI: 10.1109/ICEMI.2007.4350665.
acquisition card inserted into a PC. Future work will be focused on pp. 2252-2254. 2007.
implementing a USB 3.0 interface and developing several plants that [12] C. Meza, J. Andrade-Romero, J. Bucher and S. Balemi , “Free open
source software in control engineering education: a case study in the
can be easily adapted to the current setup, with applications on
analysis and control design of a rotary inverted pendulum,” in 14th
biomedical and mechatronics engineering. The platform has already IEEE international conference on Emerging technologies & factory
been used for several workshops in Mexico and Colombia, presenting automation Sept. 22-25, Mallorca, Spain.
a series of tutorials about some applied aspects of automatic control DOI:10.1109/ETFA.2009.5347162. 2009.
such as obtaining the transfer function of a DC motor, PI current loop [13] R. Duma, R. Dobra, M. Strusca, D. Dumitrache and I. Sista, “Rapid
tuning, DC motor modeling, and speed control using a PI or PD Control Prototyping Educational Toolbox for Scilab/Scicos”, in 2009
controllers. We believe the popularization of this platform will allow European Control Conference. Aug. 23-26, Budapest, Hungary.
students from developing countries to have more access to high pp. 4611-4616. 2009.
quality hands-on modern control education. [14] X. Chen, X. Gong, H. Zhou, Z. Xu, Y. Xu and C. Kang, “An
economical rapid control prototyping system design with
Matlab/Simulink and TMS320F2812 DSP”, in International
Acknowledgments MultiConference of Engineers and Computer Scientists, March 17-19,
Hong Kong, 2010.
Authors would like to thank Jesus Meza for the technical [15] Q. C. Zhong, C. Matthews, P. L. Nguyen and S. Clarke, "Low-cost
assistance for the paper. Authors Carlos Fory-Aguirre and Juan M. Rapid Control Prototyping paradigm," in UKACC International
Serna Ramirez would like to thank the Universidad Santiago de Cali, Conference on Control 2010, Coventry, UK, pp. 1-5.
Colombia, for the financial support on scholar mobility. DOI:10.1049/ic.2010.0463, 2010.
[16] P. J. Bradley, J. A. de la Puente, J. Zamorano and D. Brosnan, “A
platform for real-time control education with LEGO MINDSTROMS”,
References
in 9th IFAC Symposium Advances in Control Education, Nizhny
Russia, Jun. 19-21, 2010.
[1] R.M. Murray, K.J. Åström, S.P. Boyd, R.W. Brockett, and G. Stein, in [17] R. Oftadeh, M. M. Aref, R. Ghabcheloo and J. Mattila, "Unified
“Future directions in control in an information rich world,” IEEE Contr. framework for rapid prototyping of Linux based real-time controllers
Syst. Mag., vol. 23, no. 2, pp. 20–33, 2003. with Matlab and Simulink," in 2012 IEEE/ASME International
J. M. Serna-Ramirez et al./MECHATRONICS 00 (2017) 000–000 9

Conference on Advanced Intelligent Mechatronics, Kachsiung, [44] dSpace Inc. ,50131 Pontiac Trail
Taiwan, pp. 274-279. DOI:10.1109/AIM.2012.6266028, 2012. Wixom, MI, USA 48393-2020.
[18] Y. S. Lee, W. S. Kim and S. Y. Kim, "Development of a rapid control [45] Institut National de Recherche en Informatique et en Automatique
prototyping system based on Matlab and a USB DAQ unit," in 2013 (INRIA). Scilab. [Link].
IEEE 8th Conference on Industrial Electronics and Applications, [46] Dipartimento di scienze e tecnologie aerospaziali del Politecnico di
Melbourne, VIC, pp. 161-166, DOI:10.1109/ICIEA.2013.6566358, Milano. RTAI. [Link].
2013.
[19] C. Bazán-Orobio and J. Flórez-Marulanda, J. “Sistema de Prototipado Carlos Fory was born in Santiago de
Rápido de Control para una Planta Didáctica Motor DC,” in Tecno Cali, Colombia. Bioengineer with honors
Lógicas, No.30, pp. 95–115. 2013. from Universidad Santiago de Cali,
[20] A. Flores, Sistema avanzado de prototipado rápido para control en Colombia, title received in 2017. His
exoesqueletos y dispositivos mecatrónicos. Phd. Dissertation.
principal interest areas include biomedical
Universidad Carlos III de Madrid, Departamento de Ingeniería se
Sistemas y Automática. 309p. 2014
engineering and new biomedical
[21] A. Soria-Lopez and J.C. Martinez-Garcia. “A control laboratory technologies.
prototype for learning power current amplifier PI control loop,”
in 2015 12th International Conference on Electrical Engineering,
Computing Science and Automatic Control, 2015.
[22] Dynetic Systems Co. DM644. Part No. 509051. 115 Main Rd Juan Manuel Serna received his
Montville, New Jersey 07045 USA. [Link]. technical degree in electronics and
[23] Microchip Technology Inc. DSPIC 30f4012. 2355 West Chandler
industrial automation in 2011 and
Blvd. Chandler, Arizona, 85224 USA. [Link].
Bioengineering degree with high honors
[24] Cypress Semiconductor Corp. Cy7C68013A. Champion
Court, San Jose California 95134 USA. [Link]. in 2017 from Universidad Santiago de
[25] NVE Corp. IL711. 11409 Valley Vies Road Eden Prairie, Cali, Colombia. His research interest
Minnesota 55344 USA. [Link]. includes electronic automation, artificial
[26] Texas Instruments. Inc. ISO124. 12500 TI 252125 Blvd. Dallas, intelligence and bioinstrumentation.
Texas 75243 USA. [Link].
[27] US Digital. E6-2500. 1400 NE 136th Ave. Vancouver, Alejandro Ojeda-Misses received a B.
Washington 98684 USA.[Link] Eng. degree in Mechatronics
[28] Texas Instruments. Inc. LM18200. 12500 TI Blvd. Dallas, Texas Engineering from the IPN, México, in
75243 USA. [Link].
2013, and [Link]. Degree in Automatic
[29] D. Lewine, POSIX Programmer’s Guide. Writing Portable UNIX
Programs with the POSIX.1 Standard. O’Reilly &amp Associates:
Control from the CINVESTAV, México, in
Sebastopol, CA 95472 USA, 1994. 2015. He is currently a Ph.D. student at the
[30] Corbet, J., A. Rubini and G. Kroah-Hartman, Linux Device Drivers. Automatic Control Department,
Third Edition. O’Reilly Media: USA, 2005. CINVESTAV, México. His research
[31] A. Tanenbaum, Sistemas Operativos Modernos. Third edition. Pearson interests include robotics
Educación: México, 2009. systems, mechatronic systems, control
[32] Haftman, H.: Converter From USB To Parallel. Germany, 2016. theory and applied electronics.
[Link]
[Link]/~ygu/bastelecke/PC/USB2LPT/[Link]. Andres M. Gonzalez-Vargas received his
[33] Wireshark Foundation, Wireshark, USBcap.
B. Eng. degree in Mechatronics
[Link] [Link] 2016.
Engineering in 2004, followed by an MSc
[34] HHD Sowftware, Device Monitoring Studio. 29 Harley Street,
LONDON, W1G 9QR, UNITED KINGDOM. 2016. in Biomedical Engineering in 2011 and a
[Link] PhD degree in Computer Science,
studio#ixzz49KmLEl97. Electronics and Electrical Engineering in
[35] The Linux Kernel Organization, The Linux-USB Host Side AP. 2015. He is currently an Assistant Professor
California, USA. 2016 at Universidad Autónoma de Occidente,
[36] S. Venkateswaran, Essential Linux Device Drivers. Prentice Hall: Colombia. His research interests include
Upper Saddle River, NJ, 2008. bioinstrumentation, computational biology, rehabilitation devices,
[37] P. Salzman, M. Burian, and O. Pomerantz, Ori, The Linux Kernel medical informatics and clinical engineering.
Module Programming Guide. Salzman, 2007.
[38] W. Mauerer, Professional Linux® Kernel Architecture. Wiley
Alberto Soria-López received a B. Eng.
Publishing: Indianapolis, IN 46256, USA. 2008.
[39] National Instruments, LabView Real-Time, 11500 Mopac Expwy, degree in Electronic Engineering from the
Austin, TX 78759, United States of America. [Link] UAM-I, Mexico, in 1992, and an [Link]. and
[40] The Math Works. Matlab, Simulink, xPC, 1 Apple Hill Drive, Natick, a Ph.D. in Industrial Sciences from the
MA. 01760 USA. [Link] Université de Evry, France, in 1994 and
[41] Quanser Consulting, QUARC. 119 Spy Court, Markham, Ontario, L3R 1999. He is currently an Assistant Professor
5H6 Canada, [Link] at the Automatic Control Department,
[42] Nahrstaed, H: Hart ToolBox. [Link] 2008-2015. CINVESTAV, México. His research
[43] Nahrstaed, H.- QRtaiLab a user interface for RTAI. interests include systems biology, robotics,
[Link] 2008-2009.
fuzzy systems and visual servoing.

You might also like