Free Open Source Software in Control Engineering Education: A Case Study in the Analysis and Control Design of a Rotary Inverted Pendulum Carlos Meza Costa Rica Institute of Technology Electronics Engineering Department Cartago, Costa Rica
[email protected] J. Alexis Andrade-Romero, Roberto Bucher, Silvano Balemi Univ, of App. Sciences of Southern Switzerland Innovative Technology Department Manno, Switzerland {javier.andrade, roberto.bucher, silvano.balemi}@supsi.ch
Abstract The present paper aims to show the advantages of using Free and Open Source Software for control systems in education. Accordingly, this paper presents a control assignment for an introductory control theory course that can be done entirely with FOSS. This assignment consists of the control of a rotary inverted pendulum.
1 Introduction Effectively teaching the basic controller design process (i.e., modeling, analysis, controller design and implementation) cannot be done only through theoretical lectures with little or no practical experience. Engineering students need to experience the design process in order to master it. A complete and more useful training in automatic control requires that, besides learning the theoretical analysis and control techniques, the student also experiences with the same kind of computer-based tools that he or she will be using as an engineer in the industry or as a researcher in the academia. The development of effective strategies and learning resources for control theory courses has called the attention of the control community during the last decades [1]. The advances in software and hardware have made possible to develop more flexible computer-based learning resources with “friendly” man-machine interaction, intuitive graphical user interfaces and high-degree of interactivity (e.g., [2], [3]). The aforementioned software tools are normally oriented towards the study of the most com-
978-1-4244-2728-4/09/$25.00 ©2009 IEEE
mon analytical methods used in automatic control and represent an excellent way of introducing students to theoretical abstract concepts. Nevertheless, these software educational applications lack of the necessary flexibility and capabilities to be used as a tool that supports the entire controller design process (i.e., modeling, analysis, controller design and implementation). Moreover, these control educational support tools won’t be normally used by the student when he or she starts working in the industry as a control engineer. Until a decade ago the only software tools that have had the possibility of supporting effectively the entire controller design process were commercially-based. Consequently, several universities adopted proprietary software for control systems (PSCS) not only as an educational support material for their control and engineering courses but also as a way of teaching a software tool that most likely is used in the industry. In this way, both industry and academia are benefited: on one hand universities have an appropriate computer-based support material to teach effectively automatic control, and on the other hand, the industry will benefit from the fact that universities are graduating students that know how to use computer-based tools for control systems. Even though one can be initially persuaded by the aforementioned statements, the ethical implications and the long term advantages of teaching PSCS in academia are unclear, specially now that several software companies have released their own application for control systems. Some disadvantages of teaching and using proprietary software in academia are listed next: • The relationship between the scientific control com-
munity and PSCS companies is uneven: besides promoting the use of a specific proprietary software tool among its students, the academia often develops applications and toolboxes at no cost. It is questionable if the discounts offered to the academia by PSCS companies for their products are fair. • Universities are set to corporate influence. • The high prices of PSCS make it inaccessible for small universities and both industry and academia of developing countries. Moreover, it is not clear if it is ethical and advantageous for the society that universities teach proprietary software. Questions like • which proprietary software should the academia teach? • why should the academia favor one software company among others? are not easy to answer. A more convenient option that is in line with the purposes of academia is the utilization of free open source software (FOSS). Moreover, it is now possible to find a FOSS equivalent to almost every PCSC: • Scilab/Scicos: It is a very good tool for modeling, simulating, analyzing and designing signal-flow oriented systems. It offers almost all the functionalities provided by Matlab/Simulink. Besides Scilab’s predefined set of features several researchers have also developed new important capabilities for educational purposes [4] and for the design of advanced control systems [5], [6]. Scilab has been used in a wide variety of research applications such as the identification of pollution sources in rivers [7] and on the improvement of friction testing machines [8]. Being a free high sophisticated scientific software it has also been widely used for educational purposes, both in industrially developed countries [9] and in developing countries [10], [11]. • Maxima: ([12]) is a computer software package for the manipulation of symbolical and numerical expressions. It offers the same characteristics of the PSCS Maple or Mathematica. • Modelica/OpenModelica ([13]/[14]): Modelica is an open object-oriented modeling language designed to allow convenient, component-oriented modeling of complex physical systems, e.g., system containing mechanical, electrical, electronic, hydraulic, thermal, control, electro power or process-oriented subcomponents. The Openmodelica ([14]) environment allows to simulate systems using the Modelica modeling language. OpenModelica can simulate the same models used in the PSCS Dymola or MapleSim.
• Scicos/RAI/RTAI-LAB: Scicos is an excellent tool for designing control systems but it cannot interface with the “real world” just by itself, i.e., Scilab/Scicos lacks of software for handling correctly the necessary computer hardware to interface with physical systems (e.g., laboratory setups). Nevertheless, the integration with another open source tool developed at the “Politecnico di Milano” [15], called RTAI [16], allows to get an adequate interaction with physical systems. In this regard, the RTAI-Lab open source project aims to provide a common structure framework for the integration of RTAI into the Scilab environment [17], [18]. With RTAI-Lab and Scilab it is possible to obtain a complete open source environment for designing control systems and test them in real physical systems. This software tool-chain is equivalent to the PSCS Labview or Dspace. It is the authors’ belief that it is now possible to fully integrate such FOSS tools in automatic control related courses both in undergraduate and postgraduate levels. Indeed, FOSS for control systems are now sufficiently friendly and “stable” to be included as support material for control theory courses. In order to validate the aforementioned statement the present paper presents a guided assignment to reinforce the theoretical concepts taught in a typical control theory course. This assignment has been thought such that students gain knowledge of fundamental theories and their application while becoming skilled in using industry-like software tools. By industry-like software tools we refer to the FOSS toolchain: Scilab/Scicos/RTAI.
2 A Guided Assignment for Control Engineering Courses using FOSS The guided assignment presented in this paper is intended to be used as support material for a typical introductory control theory course (i.e., a course teaching linear control techniques). It is a “case study” type of assignment that consists of several related exercises that should be done along the entire elective period (e.g., 4-6 months). The successful fulfilment of these exercises should yield in the design of a linear controller that is able to control a complex plant. The guided assignment has been planed to be done entirely with FOSS. One of the advantage of using FOSS for this kind of assignments is that students can freely acquire and install the software in their home computer. Leaving behind the fact that nowadays students are more comfortable using their own computer, normally universities do not have computer labs large enough to allow students work without a restricted schedule. As mentioned previously there are several useful FOSS tools that can be used to support the control engineering education. In this case we will present an assignment based on the following FOSS software tools: • Scicoslab ([19]): it is a freely distributed software
tool based on Scilab but with a more stable and powerful version of Scicos.
L1 θ1
• Linux with RTAI-Lab: The Linux operating system is patched with RTAI in order to obtain a real-time operating system. The RTAI-Lab set of tools allows to generate code based on the controller designed using Scicos blocks. Depending on the available resources and time for realization of this assignment, it may consist of two phases: • Modeling, analysis and control design: Represents the majority of the assignment. This phase can be done entirely in Scicoslab. Students can solve the assignment exercises of this phase at the university’s computer laboratories or at their own homes. • Experimental validation of the designed controller: using the controller designed in the previous phase the students test it in an experimental setup. This experimental setup can be easily interfaced with the Scicoslab controller using the FOSS RTAI-Lab. It is important to mention that the aforementioned assignment strategy using FOSS tools have been used in the “Mechatronics Laboratory” course of the electronic engineering bachelor’s degree program of the University of Applied Sciences of Southern Switzerland for several years [20]. This type of assignment is part of a 30-hour laboratory course which deals with several modeling, control design and identification techniques. Systems such as a mass and spring [21], an inverted pendulum with cart and pole [22], and, a flexure system [23] have been used as plants for the assignment. The guided assignment presented in this paper is based on the control of a rotary inverted pendulum (a.k.a. “Furuta Pendulum”). 2.1 Rotary Inverted Pendulum An inverted pendulum is a very useful and popular laboratory experiment that can be used to explain many modeling, analysis and control techniques ([24], [25], [26]). The dynamical characteristics of an inverted pendulum can be found in many real control problems such as the vertical acceleration control of high performance aircraft [26] or the stretching folded antennas of a satellite by rotation of the satellite body [27]. The most known inverted pendulums are the so called “cart and pole” systems, where a pendulum attached to a cart needs to be swing up by means of the longitude movements of the cart. A more compact and mechanically robust system is the rotary inverted pendulum, also known as “Furuta Pendulum”. The typical rotary inverted pendulum is composed of two links as it can be seen in Fig. 1. In this case, the first link or “arm”, driven by a motor, rotates in the horizontal plane to balance a pendulum link, which rotates freely in the vertical plane. The goal is to balance the arm to position the pendulum in the upright position using feedback control.
L0
Controller
θ0
θ1 θ0
u Motor
Figure 1: Rotary Inverted Pendulum. The parameters of the system are described in table 1.
Suppose that as general coordinates θ0 , θ1 are used, where θ0 is the angular position of the arm and θ1 is the angular position of the pendulum. Assuming that θ1 = 0 when the pendulum is in the upright position, the dynamic equations of the rotary inverted pendulum depict in Fig.1 can be derived from the Euler-Lagrange method, yielding, J0 + mL1 2 sin2 (θ1 ) + mL0 2 θ¨0 +mL0 L1 cos (θ1 ) θ¨1 + R0 + mL1 2 sin (2 θ1 ) θ˙1 θ˙0
(1)
−mL0 L1 sin (θ1 ) θ˙12 = KM u mL0 L1 cos (θ1 ) θ¨0 + J1 + mL1 2 θ¨1
1 − mL1 2 sin (2 θ1 ) θ˙02 + R1 θ˙1 − mgL1 sin (θ1 ) = 0 2 (2) where the parameters of the system are described in Table 1 and u represents the commanded torque, i.e., the control signal. Table 1: Parameters of the considered rotary inverted pendulum Symbol KM
Description Motor constant
L0
Arm length
L1 m
Distance to the center of mass of the pendulum Pendulum’s mass
R0 R1
Arm’s friction coefficient Pendulum’s friction coefficient
J0 J1
Arm’s rotational moment of inertia Pendulum’s rotational moment of inertia
Notice that the system is non-linear with an infinite numbers of equilibrium points. The set of stable equilibrium points are those where θ1 = π whether the set of unstable equilibrium points have θ1 = 0. The students are asked to design a controller that maintains the pendulum in the upright position (θ1 = 0). The swing up of the pendulum is not considered in this introductory control course. 2.2 Assignment’s tasks The following tasks are asked to the student: • To model the pendulum (nonlinear and linear model) • To design several continuous-time linear controllers: Figure 2: Scicoslab environment.
– Full state-feedback controller – Full-state observer – Reduced-state observer with measurement of the angles
• a list of recommended Scicos blocks necessary for the assignment (see Fig. 3.
• To discretize the reduced-state observer with measurement of the angles.
The superblock with the pendulum non-linear model and the visualization have been created using Scicos native blocks (look at Fig. 4.
• To add quantization and saturation to the model and redesign the controller. As mentioned previously, depending on the time and resources available for this assignment a final task will be to verify the designed controller on a laboratory experimental setup using Scicoslab and RTAI. 2.3 Resources needed for the assignment The resource needed for the assignment is basically Scicoslab 4.3. As depicted in Fig. 2 Scicoslab environment is a very friendly. It consists on a command window and graphical dynamical system modeler and simulator called Scicos. In the command window the user can input a wide variety of commands ranging from mathematical functions (e.g., sine, matrix operations, ect) to linear system representations (e.g., transfer function, statespace representation). Scicos allows the creation of block diagrams to model and simulate the dynamics of hybrid dynamical systems. Fig. 2 shows Scicoslab 4.3 working environment. Even though Scicoslab is quite intuitive, it is recommended that before the students start their assignment a 1 or 2 hour lecture is provided to introduce students with basics usage and commands of Scicoslab. At the beginning of the assignment the students will be provided with • a Scicos superblock containing the non-linear model of the rotary inverted pendulum,
+ +
0 (1)
Demux
(6)
(2)
Mux
(7)
(3)
(4)
(5)
x+=Ax+Bu y=Cx+Du
x+=Ax+Bu y=Cx+Du
(8)
(9)
Figure 3: Basic Scicos blocks needed for the assignment. (1) Nonliner model of the Rotary Inverted Pendulum, (2) Sumation, (3) Step signal, (4) Multiplexor, (5) Linear system, (6) Clock to define the sampling time of the stored variables, (7) To stored variables in the workspace.
In order to illustrate the capabilities of this tools for control theory assignments some aspects of the modeling and controller design stage of the rotary inverted pendulum assignment will be further discussed. 2.4 Modeling It is asked to the students to realize the following tasks related to the modeling: T1. To derive the dynamic equations of the system using Euler-Lagrange. T2. To determine the equilibrium points of the systems.
• a Scilab script with all the parameters of the system, • several visualization blocks such that the students can easily verify the simulations results.
T3. To linearized the Euler-Lagrange model of the system around two equilibrium points (one stable and one unstable).
θ0 (rad)
Index: 1:θ1 3:ω1 2:θ2 4:ω2
Visualization A
20 18 16 14 12 10
Visualization B
8 6 4 1.50
2
0.50
−0.50
θ1 (rad)
Figure 4: Superblocks created for the assignment. From up to bottom: Non-linear model of the Rotary Inverted Pendulum, Visualization A: Displays variables of of the non-linear and linearized model, Visualization B: Displays the angular positions.
time (s)
−1.50 0
Figure 6: Angular Positions: Dynamic response to a short impulse inputted to the non-linear and linearized models.
T5. To compare the impulse response of the non-linear model and the linearized model around a stable equilibrium point. (A sicos block with the non-linear model of the system is provided to the students).
ω0 (rad)
T4. To construct the linearized models of the system in Scicos.
15
Tasks T1 - T3 do not require the use of any computerbased software. Task T4 and T5 are asked to be done in Scicos with the blocks shown in Fig. 3 and fig. 4. For example, the realization of task T5 in Scicos should look like the diagram in Fig. 5. The results obtained with this Scicos block diagram are shown in Fig. 6 and Fig. 7, where it can be seen that the dynamic response to a short impulse of the model linearized around the equilibrium stable point is similar to the nonlinear model. In this way, students are able to verify by themselves their linearized models.
10 5 0
ω1 (rad)
−5 −10 −15 0
2
4
6
8
10
12
14
16
18
20
time (s)
Figure 7: Angular Velocities: Dynamic response to a short impulse inputted to the non-linear and linearized models.
lize the unstable equilibrium point. The controller design stage consists of the following tasks: T6. To design a full state feedback controller.
+ −
T7. Tp design a full state feedback controller with an integral element. Index:
1:θ1 3:ω1 2:θ2 4:ω2
Visualization A
xd=Ax+Bu y=Cx+Du
Figure 5: Scicos block diagram to compare the nonlinear model with the linearized model.
2.5 Controller Design Once the students have validated their linearized models, it is requested to design a linear controller to stabi-
T8. To design a full-state observer. T9. To design a reduced-state observer with measurement of the angles. T10. To add quantization to the model and design a discrete state feedback controller with reduced-state observer with measurement of the angles. T11 To add saturation and an anti-windup scheme to the controller design in task T10. All the aforementioned controllers are requested to be designed using Scicoslab scripts (i.e., lines of code to be
executed in the Scicoslab workspace) and validated with Scicos using the provided nonlinear model of the rotary inverted pendulum. Fig. 8 shows a block diagram made in Scicoslab of the controller asked in Task T11. The simulation results of this controller are shown in Fig. 9.
0
x+=Ax+Bu y=Cx+Du
+ +
Visualization B
Mux
1:θ1 3:ω1 Index: 2:θ2 4:ω2
x+=Ax+Bu y=Cx+Du
Demux
Figure 8: Scicos block diagram of the controller asked in Task T11.
θ0 θ1
0.5
Figure 10: Rotary inverted pendulum constructed at SUPSI.
(rad)
0.4
0.3
0.2
0.1
0.0 0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
Time (s)
Figure 9: Simulation results of the pendulum using the controller of task T11
2.6 Laboratory Setup It is possible that students test their designed controllers on a laboratory set-up, in this case a mechanical construction of the rotary invereted pendulum. The software needed to interface with the electronics of the mechanical plant can be also FOSS. We proposed to use RTAI which adds real-time capabilities to Linux and includes a software tool called RTAI-Lab which generates code from Scicos blocks to be exectued in real-time. In this way, after completing the design stage, just by adding a few input/output blocks into their Scicos diagram, students can compile and test their controller in a laboratory set-up. The input/output Scicos blocks serves as an interface between the Scicos diagram and the hardware used to measured the system’s variables and to output the control signal. More details about RTAI-Lab and Scicos can be found in [18].
For instance, the rotary inverted pendulum constructed at SUPSI (see Fig. 10) makes use of a brushless ECmax 40 motor1 and a EPOS2 driver2 to set the motor current to a desired value. The motor is attached to a digital encoder and the angular position of the pendulum is measured by means of a 3-turn potentiometer. The motor current reference value is set by means of a CAN bus. Also the measured angular position are transmitted via CAN. The CAN Bus has been selected because it offers great flexibility, limited cost, and a large choice of manufacturers [20]. A small interface card has been designed to generate the CAN signals using the computer’s parallel port. A series of specific Scicos blocks have been implemented in order to interconnect the Scicos signals with the CAN Bus; these blocks are shown in Fig. 11. In this way, students will only have to include the blocks shown in Fig 11 into their diagram (See Fig. 12 and Fig. 13), execute a command in Scicos to generate the code for the controller and run a binary file with their controllers to test their controller with the rotary inverted pnedulum laboratory set-up.
3 Final Comments and Conclusion In the present paper a guided assignment to be used as a support material for control theory courses has been 1 EC-max 2 EPOS2
40 is a motor from Maxon Motors. is designed and constructed by Maxon Motors.
replacements Epos canopen sync
Epos Analog 0x08 1
Epos canopen sync
Epos encoder 0x08
Epos Analog 0x08 0
INIT ENC 1s 0
2
1
1/12..
Epos motor I 0x08
Safety block
Figure 11: CANOpen Interface blocks. A description of the blocks can be found in Table 2.
Table 2: CANOpen Interface blocks developed at SUPSI.
Block Name
Description
Epos canopen sync
Synchronization initial routine for the CAN Bus
Epos coder
11
Scope SCOPE
1
Epos motor I 0x08
Epos encoder 0x08
INIT ENC 1s 0
en-
Outputs the measurement of the motor’s encoder
INIT ENC Epos Analog
Initializes the encoder to 0 Outputs the measured analog signal of the multi-turn potentiometer of the pendulum
Epos motor I
Sets the motor’s current
Figure 13: Superblock “Hardware Interfaces” needed to interface with the rotary inverted pendulum constructed at SUPSI.
presented. The assignment consists on the design of a linear controller for a rotary inverted pendulum. As it has been shown this assignment can be entirely done using FOSS. The authors believe that the FOSS for control systems available nowadays are sufficiently stable and mature to be used for educational purposes. The experience at SUPSI indicates that there are clear benefits in using FOSS for control systems, for instance, the costs of the laboratory have been reduced (no need to buy licenses). Moreover, given the user-friendliness and the similarity of the FOSS used with respect with their proprietary counterparts, students will not notice any detrimental change in their education when they switch to FOSS.
References [1] D. S. Bernstein, “Enhancing undergraduate control education,” IEEE Control Systems Magazine, vol. 19, pp. 40–43, 1999. [2] M. Johansson, M. Gfvert, and K. J. Astrm, “Interactive tools for education in automatic control,” IEEE Control Systems Magazine, vol. 18, pp. 33–40, 1998.
1
0
x+=Ax+Bu y=Cx+Du
Hardware Interfaces
+ +
[3] S. Dormido, F. G. S. Dormido-Canto, and J. Aracil, “An interactive tool for introductory nonlinear control system education,” in IFAC 15th Trienial World Congress, 2002.
Mux
x+=Ax+Bu y=Cx+Du
Figure 12: Modified Scicos diagram that interacts with the constructed laboratory set-up. The superblock “Hardware Interfaces”, depicted in Fig. 13 contains the blocks needed to interface with the rotary inverted pendulum constructed at SUPSI.
[4] I. Pendharkar, “Rltool for scilab: A public domain tool for SISO system design,” IEEE Control System Magazine, vol. 25, pp. 23–25, 2005. [5] F. Delebecque, “A slicot based control library for scilab,” in IEEE International Symposium on Computer-Aided Control System Design, 2000. [6] V. Sima, D. Sima, and S. V. Huffel, “Slicot system identification software and applications,” in IEEE International Symposium on Computer Aided Control System Design, 2002.
[7] J. Chancelier, M. Cohen, M. Maldiney, and F. Pacard, “Identification of pollution sources in rivers,” in IEEE International Symposium on Computer-Aided Control System Design, 1996. [8] Q. Dongping, Z. Dongjie, and T. Qiang, “Linux/rtai and scicos in low cost high performance friction testing machine,” in International Conference on Electronic Measurement and Instruments, 2007. [9] P. Tona, “Teaching process control with scilab and scicos,” in American Control Conference, 2006. [10] J. Ramirez and M. Romero, “Scilab as a tool to increase learning in courses of communication systems,” in Electronics, Robotics and Automative Mechanics Conference, 2008. [11] P. Pires and D. Rogers, “Free/open source software: An alternative for engineering students,” in Frontiers in Education, 2002. [12] Maxima Web Site. July 2009. [Online]. Available: http://www.maxima.org [13] Modelica Web Site. July 2009. [Online]. Available: http://www.modelica.org [14] Open Modelica Web Site. July 2009. [Online]. Available: http://www.openmodelica.org [15] L. Dozio and P. Mantegazza, “Linux real time application interface (rtai) in low cos high performance motion control,” in Motion Control Conference, 2003. [16] RTAI web site. July 2009. [Online]. Available: http://www.rtai.org [17] R. Bucher and S. Balemi, “Rapid control prototyping using linux real-time,” in Conference in Control Education, Olulu, Finland, 2003. [18] ——, “Scilab/scicos and linux rtai - an unified approach,” in IEEE Conference on Control Applications, 2005. [19] ScicosLab Web Site. July 2009. [Online]. Available: www.scicoslab.org [20] R. Bucher and S. Balemi, “CAN-bus based rapid control prototyping systems for educational laboratories,” in 18th IFAC World Congress, Seoul, Korea, 2008. [21] S. Balemi. (2008) Mechatronics laboratory: Identification of disks and spring system. [Online]. Available: http://web.dti.supsi.ch/ smt/laboO4.html [22] ——. (2007) Mechatronics laboratory: Control of an inverted pendulum.
[23] ——. (2005) Mechatronics laboratory: Control of a flexible structure. [24] S. Awatar, N. King, T. Allen, I. Bang, M. Hagan, D. Skidmore, and K. Craig, “Inverted pendulum systems: rotary and arm-driven: a mechatronic system design case study,” Mechatronics, vol. 12, pp. 357– 370, 2002. [25] K. Chrisman and J. Vagners, “An alternative inverted pendulum apparatus for education,” in Proceedings of the American Control Conference, 1995. [26] E. Misawa, M. Arrington, and T. Ledgerwood, “Rotational inverted pendulum: A new control experiment,” in American Control Conference, 1995. [27] P. Horacek, “Laboratory experiments for control theory courses: A survey,” Annual Reviews in Control, vol. 24, pp. 151–162, 2000.