Using Linux in a Control and Robotics Lab
The Mathematics and Engineering program at Queen's University in Kingston, Ontario operates a control and robotics laboratory as part of the course offerings in the control systems area. The lab experiments use our custom-built electro-mechanical setups and require the students to write algorithms in C for controlling the hardware.
The lab began using C under DOS as the software environment for the lab experiments, but not all students had an easy time with the environment. Generally, it was too easy for configuration files to be inadvertently changed with frustrating consequences. Subsequently, an integrated experiment environment known as dlxlab has been developed for simulating and running control lab experiments. It consists of a single program, run as dlxsim for simulations or as dlxrun for controlling hardware experiments. The program was developed using the XView toolkit under Linux (see “Programming with XView” by Michael Hall, LJ, March 1998), and operates in the lab on a variety of PC-compatible hardware running Linux 1.2.13.
The students taking the lab vary widely in computing background and skill. The primary intent of the control labs is to investigate the application of control theory to actual motors, carts, inverted pendula and so on, without having software operation dominate the experience. On the other hand, understanding low-level interfacing code is also a desirable outcome, so the hardware interface has to be “visible”.
In order to design a control algorithm for a physical system, one must have a mathematical model of the system to be controlled in the form of either differential or difference equations, and knowledge of the physical parameters in the model. The user interface to dlxlab was designed so that, as far as possible, this is the only information that must be supplied by the user.
This goal is attained for the case of the program running in simulation mode. For the situation where actual hardware is being controlled, information describing the hardware interface must also be provided, although it can be largely hidden from the user through header files.
The user input to the program takes place through interactive construction of a system file which describes the system under investigation.
To simulate a system, one invokes dlxsim with a system description file as argument.
dlxsim sim.sys &
One of the lab experiments consists of a pair of track-mounted carts, coupled by springs and driven by a servomotor. A simple system file for simulating such a pair of spring-coupled carts is shown in Listing 1. The format of the system file is a sequence of begin ... end delimited blocks. The blocks are of two types:
Definition blocks establishing identifiers for variables (including parameters)
Code blocks containing C code sequences which are executed by the program to initialize variables, as well as numerically integrate the governing differential equations to simulate the system
The main program panel (see Figure 1) contains a “Build” button, which when pressed causes processing of the system file. That is, the user system file is converted into a series of C code files by a parsing process. The files are compiled to a shared object file by gcc, and the contents of the resulting shared object module are dynamically linked into dlxsim as it runs. The linked code contains not just the system differential equations, but also modules for interactively manipulating parameters and plotting results on the basis of the variable names provided in the system file.
Assuming that the system file contains no syntactic errors, the program log window contains only progress messages, and a pop-up panel for controlling simulations appears (Figure 2). As long as only parameter changes are made, a series of simulation runs can be made. Plotting and printing is handled by gnuplot running as a child process.
If the system file contains errors, the error location is reported in the log window, and the pop-up does not appear. The errors are caught either at the parsing level or within the C code segments. In the latter case, the error messages from gcc refer to lines in the user system file, since the generated C files include #line statements referring to the user system file. Since the dlxsim system file edit window is an XView textsw, it inherits the line searching menus associated with XView applications.
Simulations can be run and plotted, as long as the system file contents (such as variable names, equations of motion and so on) are not changed. If such changes are made, the “ReBuild” button must be invoked to cause freeing of resources, recompilation of the dynamic module and relinking of the generated codes.
- New Products
- Android Candy: Google Keep
- A Little GUI for Your CLI
- Readers' Choice Awards 2014
- Handling the workloads of the Future
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- diff -u: What's New in Kernel Development
- Days Between Dates?
- December 2014 Issue of Linux Journal: Readers' Choice
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane