Proceedings of Insert Conference Abbreviation: Insert Conference Name Insert Conference Date and Location DETC RAPID EMBEDDED PROGRAMMING FOR ROBOTIC SYSTEMS Daniel Burns Thomas G. Sugar Arizona State University Mechanical and Aerospace Engineering Tempe, AZ 85283 ABSTRACT At ASU, new commercially available automatic codegeneration tools are used to progress from controller design, to simulation, and finally to implementation on embedded hardware. Case studies highlighting a force-feedback joystick, a robotic hovercraft, and motor servo-control with encoder feedback are presented. Using these software tools, design iterations and multiple controllers are quickly simulated and downloaded to the actual hardware, providing students an appreciation for rapid embedded system design. INTRODUCTION Educating students in the subject of engineering controls has traditionally been limited to analysis by theory and simulation. Students learn control theory by modeling plants and design controllers with Root Locus methods, Bode plots, and Nyquist plots. Controller analysis is frequently conducted by these methods or through software simulation. However, this is often where limitations in software tools prohibit students from further development: graphical controllers are not easily ported to real hardware; real time controllers and scheduling are difficult to program. To do so, students must be adept at coding software for execution on the hardware, requiring input and output synchronization, and at the same time solving differential equations in real time. (It is one thing for a student to understand how a fourth-order Runge-Kutta differential equation solver operates, it is quite another to implement such a solver for execution in real time.) Students can too easily get lost in coding software and miss out on important concepts in controller design and real-time system operation. Certain software packages have attempted to automatically generate control code for execution on hardware, but these packages have significant limitations. For example, Mathwork s MATLAB has featured Real-Time Workshop for a number of years. This software takes a graphical control block in MATLAB s Simulink and compiles it for execution under various environments such as DOS protected mode or VxWorks. Unfortunately, Real-Time Workshop only includes a few hardware drivers, requiring users to develop most of their own hardware-dependent drivers. While this alleviates the burden of differential equation solvers, it does not allow students to move easily from controller simulation to actual hardware. Additionally, Real-Time Workshop relies on target operating systems for real-time resource allocation and system I/O, providing flexibility, but making concessions to allow for multiple operating system compatibility. However, a new software package, available as a toolbox for MATLAB and Simulink (versions 6.0 and greater) allows users to move from simulation to hardware on Mathworks real-time operating system that includes numerous libraries of supported hardware. This software package, called xpc, allows users to compile graphical Simulink models that include blocks to interface with specific hardware I/O and these models are downloaded to the target hardware running the xpc operating system. xpc's development blocks for Simulink and its realtime operating system allow rapid development of controllers and can be used to educate students on the progression from controller design, to simulation, and then implementation. In general, a rapid code-developing platform should provide a basic set of features for the user. An intuitive graphical interface is required to clearly show signal flows. Additionally, the package should support native simulation and analysis tools (e.g. simulating the response of a model to step commands, plotting the frequency response, etc.) Perhaps most importantly, the package should be directly linked to the operating system (either DOS-protected mode, Linux RT, or some other proprietary OS) so that direct resource management can be achieved. 1 Copyright #### by ASME
Other researchers have created their own prototyping environment for mechatronic systems such as Rutz and Richert (1995), Szymkat et al. (1995), Elmquist and Mattsson (1997) and Burst et al. (1998). Commercial packages such as ControlShell, dspace TargetLink, LabView RT, and ETAS ASCET-SD allow modeling and development of embedded control systems. Some researchers focus on just one part of the problem such as simulation (Gökdere 2000). An excellent state-of-the-art paper providing and overview of modeling and simulation of mechatronic systems was written by researchers at Carnegie Mellon University (Sinha, Liang, Paredis, and Khosla 2001). Professors such as Bradley (2000), Carryer (2000), Meek et al. (2000), and Trumper (2000) have integrated mechatronics and design in the classroom. At ASU, we have focused on tools to progress from controller design, to simulation, and finally to implementation on embedded hardware. ASU S RAPID DEVELOPMENT SYSTEM Software o Simulink graphical Analysis, and Simulation o Real Time Workshop real time code generators, ODE solvers o xpc real time kernel/os, hardware blocks (rapid coding of embedded code) It. manages processor usage, memory allocation, and system I/O in real-time. o FEATURES: Collect data over TCP/IP Recompile code and download over network Online parameter tuning without recompiling Remote execution and data collection from any internet connection via a web browser Different sampling rates in the same model Data is in MATLAB format for post-processing Hardware o VersaLogic VSBC-6 (PC/104+ single board computer) xpc drivers for watchdog timer, analog input, digital I/O, timers, serial port/rs232, parallel port, CAN, and more. AMD K6-400, 64Mb RAM, Compact Flash solidstate hard drives for robust operation o Force-feedback joystick Two brushed DC motors controlling x- and y-axes of joystick handle Potentiometers on shaft pivot point for feedback o RC Hovercraft Radio controlled thrust and rudder position RC transmitter controlled by VSBC-6 parallel port Camera mounted on hovercraft sends visual data back for feedback o Pittman motor Onboard shaft encoder LM629 high speed PID embedded controller LM18201 H-bridge CASE STUDY 1: Force Feedback Joystick Controller To demonstrate the ease with which controller design is accomplished using xpc, a simple linear PID controller is developed, simulated then executed on actual hardware. A force feedback joystick is used as the plant, with one of the two brushed DC motors actuating the joystick's y-axis. For position feedback, a potentiometer is attached to the base of the joystick. To control the motor, a National Semiconductor LM18201 H- bridge chip is interfaced to a single board computer, the Versalogic VSBC-6. The single board computer is often used in process control applications or robotics where numerous digital I/O and analog inputs are required. The potentiometer output is connected to the PC's A/D converter (see Figure 1). Figure 1: A motor actuating a force feedback joystick is interfaced to an H-bridge chip, and the chip is commanded by a single-board target computer (in the black framed case). The target computer runs the xpc operating system, which allows rapid code development, data collection over TCP/IP networks, and advanced parameter updates. The 2 Copyright #### by ASME
host computer on the right runs the MATLAB environment under Windows, and graphical controllers are developed using standard GUI s. The plant is modeled as a linear, second order system with significant inertia due to the mass of the joystick. A Simulink model is created on the host computer and a PID controller block is inserted into the model. During several simulations, PID gains are tuned for good trajectory following of a 1Hz sine wave (see Figure 2). With two simple alterations, a simulation is converted into a real-time controller for a mechanical system. To get the control code onto the target computer, the host computer running MATLAB compiles the graphical model into machine language and transmits the executable to the target using the TCP/IP protocol. (If Ethernet is unavailable, communication between the host and target can be conducted using a serial port). If the client PC has free time, packets of data will be sent to the host PC to be graphically shown to the user. Because all data can be transferred over the Internet, the host and the target could be at separate locations. This opens up the possibility of having centralized hardware at major universities while satellite schools conduct remote experiments and collect data. It is important to note that the variations in Ethernet bandwidth are not a concern because the client PC runs in realtime using its own real-time operating system; thus, delay times and lags are not a concern because the control is done on an embedded processor. An example of data collected from a remote machine is shown in Figure 3. Output from the potentiometer is compared to the desired motor position a 1Hz sine wave. Figure 2: Simulink models showing the simulation (top) and hardware version (bottom). After MATLAB compiles the hardware version, code is downloaded to the target for execution. Once adequate PID gains have been determined, the Simulink model is quickly altered for operation on the target computer. Because the Versalogic single board PC is included in the xpc hardware library, access to digital I/O lines and A/D converters are readily available as graphical blocks in Simulink. The transfer function representing the plant in the simulation is replaced by a hardware block that generates a PWM signal on the Versalogic computer for the H-bridge chip. The sensor in the simulation (assumed to be unity) is replaced by a block that accesses the potentiometer via the Versalogic A/D converter. Figure 3: Data collected remotely using xpc shows the PID controller actuating a force feedback joystick in real-time. All software required to control the joystick s motor was generated using xpc a student could simulate and control hardware in the same day. A second controller is rapidly designed, simulated and tested on this hardware configuration to demonstrate rapid development of controllers for non-linear systems. A model reference adaptive controller is quickly simulated, optimized and downloaded to the real system. Assuming that the joystick system is non-linear, and using a linear reference model, control parameters are dynamically adjusted so that the non-linear system follows the reference model. The user graphically enters the necessary signals for the adaptive controller into Simulink. A non-linear plant is modeled and a linear reference model is inserted in the Model 3 Copyright #### by ASME
Reference block. The input signal is sent to the linear model, and its trajectory is used as the desired trajectory for the adaptive controller. The adaptive controller adjusts the gains to force the plant to follow the desired linear model. In the same way that the simulated plant s transfer function is replaced with xpc s hardware blocks with the PID controller, the nonlinear simulated plant is replaced with the hardware I/O blocks in the Simulink model. Figure 5: The commanded input signal to the system is shown by the blue line. The green line shows the signal from the linear reference model. The red line is the actual motor position measured by the rotary potentiometer. CASE STUDY 2: Robotic Hovercraft Using Mathworks xpc, students are able to rapidly design and test controllers on a radio-controlled (RC) hovercraft (see Figure 6). The hovercraft receives signals that direct the thrust fan s speed and the rudder angle. The hovercraft is outfitted with a standard, commercially available RC receiver, and hobbyist-grade motor control and servopositioning circuitry. In this manner, the hovercraft and its onboard electronics are inexpensive and available off-theshelf. Figure 4: Simulink models showing the simulation (top) and hardware version (bottom). After MATLAB compiles the hardware version, code is downloaded to the target for execution. The controller is compiled and downloaded to the target PC and started. The adaptive controller forces the joystick motor to follow the linear reference model. See Figure 5. Figure 6: A radio-controlled hovercraft is controlled from a single-board PC running Mathworks xpc real-time operating system. A standard RC transmitter is used to send thrust and rudder angle commands to the hovercraft (the same transmitter 4 Copyright #### by ASME
is used to pilot RC airplanes and helicopters). However, instead of a human pilot, a single-board PC is interfaced to the RC transmitter via the Trainer Port (commonly used by novice pilots who wish to have an experienced pilot quickly take control of an RC airplane). See Figure 7. The single-board PC runs the xpc real-time kernel and sends commands to the RC transmitter properly formatted for the Trainer Port. All code necessary to communicate to the RC transmitter (and hence, the hovercraft) is developed graphically in Simulink on a host PC then compiled and downloaded to the target single-board PC. When directed by the host, the target begins execution and sends pre-determined commands to the transmitter s Trainer Port. It should be noted that one Simulink block was created by writing C code for the special purpose of generating a train of PWM signals. Once this block is created, it can be used in all future simulations. A fast and accurate servomotor control system is difficult to program on a PC because the repetitive motor control loop consumes the host computer s resources. To alleviate this problem, the low-level control is shifted to an embedded motor control chip from National Semiconductor, the LM629. The chip is mounted on a custom circuit board with an H-bridge amplifier chip (see Figure 8). In two years, forty students successfully used the motor control board based on the embedded motion control processor. One problem still remained: the code generation for embedded processor is especially difficult. The students use Mathworks xpc toolbox to automatically generate embedded code and control a DC motor. The data is easily collected in MATLAB data files and then analyzed, again using the familiar tools in MATLAB. Using the automatic code generation features of xpc allows students to focus on collecting and analyzing data not writing detailed code. Students without embedded programming experience are able to change PID gains and learn about overshoot and settling time as well as experimentally determine the bandwidth of the motor. Previously, students would spend one semester just writing code to control a motor, and never analyze the data, which is essential for engineers working in industry or performing experimental research. Figure 8: A motor control board with a microprocessor, LM629, and an H-bridge amplifier, 18201. Figure 7: The "Trainer Port" on the RC transmitter typically used to interface two sets of controls for student pilots (top) is interfaced to a single-board PC (bottom) for automatic control of the hovercraft. Using this system, students have been able to quickly get the hovercraft running, and can focus on the controller design using the actual dynamic system. Having access to the hardware at an earlier stage in the design process gives students an opportunity to connect theory with application, and a functioning control system is more quickly realized. CASE STUDY 3: Motor Control with Encoder Feedback A laboratory exercise for the Mechanical System Design course is developed to teach undergraduate and graduate students motor control, data collection, and data analysis. Previously, students had to program a computer for the complicated task of controlling a motor, which over-emphasized programming at the expense of motor control. Figure 9 shows the flow of information in the system. The LM629N-8 gets the digital information of the actual position from the encoder on the motor and modulates the PWM-signal to reach the desired position. The sample time of the chip is 246µs. The xpc-target PC is a Pentium 144Mhz PC with a TCP/IP network connection and a peripheral interface board. The Peripheral Interface CIO-DIO192 board is a digital I/O board designed to operate on computers with ISA bus accessory slots. This board sends and receives data between the target computer and the LM629N-8. This connection has a different sample time compared to the LM629N-8. The sample time depends on the size of the generated C-code, and the time needed by the PC to read the information from each chip, calculate the new target position, and send it back to each chip. The TCP/IP network connection is used to communicate with the host PC, to send a new program to the xpc target PC, or update parameters in the program. Also, this connection is used to send information back to the host PC for analysis. 5 Copyright #### by ASME
Host PC MATLAB development environment and TCP/IP Network connection Data for analyzing New program or update parameters xpc Target PC with TCP/IP Network connection and Peripheral Interface CIO-DIO192 board New target position Actual position LM629N-8 Motion-control Processor Figure 11: 6 Motor control boards wired and connected to the Target PC. An example of actual motor control data is shown in Figure 12. Figure 9: Flow diagram of the system Students are able to change different parameters in the flow diagram of the experiment. For example, the sample time of the target PC was purposely decreased to a low rate so that aliasing could be observed experimentally. The typical structure of the motor control system with the LM629 is shown in a block diagram in Figure 10 and a set of six actual boards for an experiment are shown in Figure 11. Ramp (revolutions) Desired Actual Time (s) Figure 12: The desired ramp trajectory for the DC motor is shown in blue and the actual ramp is shown in green. A very good PID controller can be designed, analyzed, simulated, and implemented. Figure 10. LM629 Based Motor Control System. LM628/LM629 User Guide, National Semiconductor. HIGHLIGHTS Students can develop controllers for real hardware without programming experience focus on the control theory, not the coding details Students focus on understanding and using digital hardware such as A/D and D/A converters, serial ports, parallel ports, and Digital I/O. Real-time operating system, ODE solvers are provided. Remote system execution, data collection, parameter tuning without recompiling. Data analysis in MATLAB (industry/academic standard) 6 Copyright #### by ASME
CONCLUSIONS A rapid prototyping system for mechatronic designers must include tools to analyze and simulate the system as well as tools to rapidly test physical prototypes. At ASU, we have successfully used an environment from The Mathworks that supplies tools for analysis, simulation, and rapid prototyping of control code. We have added our own biscuit PC s and other microprocessors. Case studies demonstrate our ability to use the system in research and in teaching. Other schools are able to remotely design controllers and remotely collect data using ASU s educational laboratory experiment. [10] Trumper, D., Sato, T. (2000.) A Vibration Isolation Platform. Proceedings of the 7 th Mechatronics Forum International Conference 2000. ACKNOWLEDGMENTS We would like to acknowledge the support of ASU, the GRASP laboratory at University of Pennsylvania, and Dr. Gerdes from the Design Center at Stanford University. REFERENCES [1] Bradley, D. (2000) Mechatronics An Established Discipline or a Concept in Need of Direction Proceedings of the 7 th Mechatronics Forum International Conference 2000. [2] Burst, A., Wolff, M., Kühl, M., Müller-Glaser, K. D. (1998) A Rapid Prototyping Environment for the Concurrent Development of Mechatronic Systems. ECEC'98, Erlangen, Germany, April 1998. [3] Carryer, E. (2000) Introducing Mechanical Engineering Students to Embedded Programming. Proceedings of the 7 th Mechatronics Forum International Conference 2000. [4] Elmquist, H., Mattsson, S. (1997) Modelica - The next Generation Modeling Language. Proc. of the 1st world Congress on System Simulation, 1997. [5] Gökdere, L., Brice, C., Dougal, R. (2000) An Advanced Modeling and Simulation Tool for Analysis of Mechatronic Systems. Proceedings of the 7 th Mechatronics Forum International Conference 2000. [6] Meek, S., Devasia, S., Field S. (2000) Mechatronics Education in the Department of Mechanical Engineering at the University of Utah. Proceedings of the 7 th Mechatronics Forum International Conference 2000. [7] Rutz, R. and Richert, J. (1995) CAMeL: An Open CACSD Environment, IEEE Control Systems, Vol. 15, No. 2, April 1995. [8] R. Sinha, V.C. Liang, C.J.J. Paredis, and P.K. Khosla, (2001) Modeling and Simulation Methods for Design of Engineering Systems, to appear in Journal of Computing and Information Science in Engineering, ASME, 2001 [9] Szymkat, M., Ravn, O., Turnau, A., Kolek, K., and Pjetursson, A. (1995). Integrated mechatronic modeling environments. In International Conference on Recent Advances in Mechatronics, 1995. 7 Copyright #### by ASME