Development of a Portable Educational Mechatronics Toolkit by Peter H.J. How S.B., Mechanical Engineering (2000) Massachusetts Institute of Technology Submitted to the Department of Mechanical Engineering in Partial Fulfillment of the Requirements for the Degree of Master of Science in Mechanical Engineering at the Massachusetts Institute of Technology MASSACHUSETTS INSTITUTE OF TECHNOLOGY May 2003 JUL 0 8 2003 LIBRARIES C 2003 Massachusetts Institute of Technology All rights reserved ...... Signature of Author ...............................................,. . . , ... .. .. .. Department of)K echanical Engineering May 9, 2003 y........... Sanjay Sarma Cecil and Ida Green Associate Professor of Mechanical Engineering Thesis Supervisor C ertified by..................................................... A ccepted by.............................. ................. Ain A. Sonin Chairman, Department Committee on Graduate Students BARKER Development of a Portable Educational Mechatronics Toolkit by Peter H.J. How Submitted to the Department of Mechanical Engineering on May 9, 2003 in partial fulfillment of the requirements for the Degree of Master of Science in Mechanical Engineering Abstract A portable educational mechatronics toolkit was developed to aid with the teaching of mechatronics to MIT mechanical engineering undergraduate students. The toolkit was created for use in tlc classroom and laboratory as a teaching aid and outside of the academic environment as a fun, interesting tool. It is hoped that interest in mechatronics will be sparked by "playing" with this toolkit. The hardware for tle toolkit consists of a PCMCIA data acquisition card, a servo motor controller, servo motors, a stepper motor controller, and stepper motors. These components are controlled through the use of MATLAB*, Simulink*, and several miscellaneous toolboxes. The total cost per toolkit for the hardware and software is $1,932. This does not take into account possible educational/bulk discounts or the cost of the required laptop, which the Mechanical Engineering Department already possesses. The toolkit's current state allows for full use of each component individually, but is not fully functional as a whole integrated system. The toolkit may be run in open- loop control but is not at the point where closed- loop control is possible. Thesis Supervisor: Sanjay Sarma Title: Associate Professor of Mechanical Engineering 2 Table of Contents 1.0 Introduction....................................................5 2.0 Background.................................................7 3.0 Design Objectives................................................ 4.0 Academic Contribution..................................................12 5.0 Competing Products................................................ 5.1 Home Automation.................................................. . 10 14 ........ 14 5.2 LEGO®M indStorm s*...............................................................16 5.3 General Purpose M icrocontroller.................................................21 6.0 Toolkit Development..........................................26 6.1 Data Acquisition.......................................... ..... . .......... 26 6.2 Motor Control....................................................28 ...... 34 6.3 Software Interface........................................... 7.0 Toolkit Cost................................................38 8.0 Toolkit Use......................................................39 8.1 Data Acquisition Use............................................... 39 8.2 Servo M otor Control Command Use................................................43 8.3 Stepper Motor Control Command Use..........................................45 8.4 MATLAB Motor Control Interface............................................47 8.5 Simulink M otor Control Interface............................................... 9.0 51 Future Work................................................59 10.0 Conclusions............................................ 3 ........... 61 Appendix A: NI DAQCard-AI-16XE-50 (6012E) Parameters ............................ Appendix B: Servo Motor Controller and Servo Motor Details............................70 Appendix C: Stepper Motor Details..............................................................71 References..................................................................73 4 63 1.0 Introduction The average mechanical engineering student is not accustomed to working with mechatronics outside of the laboratory or classroom environment. Their experience is limited to running experiments in order to prove theories they have learned in class. Educators hope that in addition to proving classroom theories, students will also broaden their general awareness of mechatronics and continue to use mechatronics throughout the rest of their lives. Mechatronics does not currently have a place in the home. It does not stir feelings of amazement that many commercial products do. Yet, in today's technologically advanced society, mechatronics can be utilized in all facets of our lives to enhance our enjoyment of life and ease our curiosity with technology. It can play a prominent role in the day to day activities that we often take for granted, and can be integrated more closely with education to enhance the learning and teaching experience. The proposed solution to this problem is to develop a portable educational mechatronics toolkit for use with a laptop to interface with household appliances/items, classroom/laboratory experiments, power tools, toys, workout equipment, etc. This kit would include a range of sensors/transducers, a data acquisition system, servo motors, stepper motors, and an easy to use software package. It would be versatile enough to allow users to monitor and control almost anything they desired and have software simple enough to use so that prior programming experience would not be necessary. 5 The expected results are to bring mechatronics into the home and to enhance student's academic experience by integrating mechatronics into their everyday classes/labs. Uses for the toolkit would only be limited by the user's imagination and could be used at home for applications ranging from monitoring a hamster's running wheel to controlling a vacuum cleaner to automatically adjust heights depending on tle surface it's currently on. In the classroom, students might have the opportunity to perform desktop experiments during lecture and have their results shared over the network instantly for everyone to analyze. The possibilities are endless. 6 2.0 Background The MIT iCampus project in Mechanical Engineering seeks to bring technology enabled teaching to the Mechanical Engineering undergraduate curriculum. The project was started in October of 1999 as a research alliance between MIT and Microsoft Research to enhance university education through information technology. Through this fund, the MIT School of Engineering, the MIT Department of Mechanical Engineering, a Pappalardo faculty endowment, and a donation by Hewlett-Packard, the department has been able to bring interactive exploration experiments and simulations directly to student's desks through the use of laptop computers. The project initially started with 2.001: Mechanics and Materials I and 2.005: ThermalFluids Engineering I, but has spread to include 2.006: Thermal-Fluids Engineering II, 2.007: Design and Manufacturing I, 2.008: Design and Manufacturing II, and 2.009: The Product Engineering Process. In addition, students have used the laptops in 2.671: Measurement and Instrumentation and several other classes. For 2.001, the staff has developed an extensive interactive online lecture site that teaches the fundamentals of mechanics and materials such as friction, bending, torsion, axial force-deformation, equilibrium, multi-axial stress and strain, truss structures, linear thermo-elasticity, and energy methods. These web-based learning modules maybe accessed in the classroom during lecture in addition to outside of lecture at the student's own convenience. 7 In addition to the web-based learning materials used in 2.001, 12 desktop experiments have been developed that cover the entire spectrum of the material taught in class. These experiments are performed in groups of 3-4 to explore the mechanics concept before it is formally taught in class. In 2.005, the staff has focused on creating a module that teaches conductive and convective heat transfer. This module allows students to develop a sense ofhow temperature distributions develop in solids and liquids throughout time. The staff has also developed "calculators" to determine the values of Bessel and error functions. Laptop use in 2.006 was an extension of its function in 2.005 with the exception of several demonstrations utilizing MathCAD*, an applied mathematical software package developed by Mathsoft . On the other hand, students in 2.007 utilized the laptops primarily for solid modeling. Students used SolidWorks® and PTC®'s ProEngineer® to create three dimensional solid models and mechanical drawings of the radio controlled robots each individual was designing and building for the class. While 2.008 did not use the laptops during lecture, students used the laptops to work on homework and labs. More specifically, spreadsheet analysis for statistical process control and solid modeling of injection molded and thermoformed yoyo parts were extensively performed in the class. 8 The course 2.009 also does not specifically have lectures tailored towards the use of the mechanical engineering laptops. However, as a senior level course, it is an interesting class to study the use of the laptops. Many of the students had previously used the laptops in other semesters and it was intriguing to see the long term effects of laptop use in the department. As it turned out, students mainly used the laptops for presertatiors and solid modeling in the class. Another course not specifically designed for use with the department laptops is 2.671. In this class, students learn techniques to measure physical variables using laboratory experiments. Technical laboratory reports generated due to this class were created by the students on the department laptops. In addition, presentations for the class were also created using the laptops. All these courses utilized the laptops for any combination of online lectures, demonstrations, simulations, spreadsheet analysis, presentations, reports, and solid modeling. While these are all very useful to a mechanical engineering undergraduate, it was also hoped that the laptops would be used to a greater extent. It is for this reason that the mechatronics toolkit of this thesis was proposed. The toolkit is an extension of the iCampus initiative. Its purpose is to create an alternative to the software side of the project. The primary motivation was to expand the scope of the project to include physical hardware in addition to the already developed software educational tools. 9 3.0 Design Objectives There were several major design objectives for the portable educational mechatronics toolkit that were initially set. The hope for the toolkit was that it would be used in the classroom and laboratory, but also beyond at the student's homes. Students would be able to start experiments in lab, pack up their toolkits, and continue the experiment at home. It is also hoped that this toolkit will spark interest in mechatronics beyond what is taught in class. The creators of this toolkit would like students to take the initiative and use this toolkit in their residences to monitor and control anything from appliances to window blinds. The hardware of the toolkit will consist of laptop computer, a data acquisition (DAQ) system, a servo motor controller, servo motors, a stepper motor controller, stepper motors, and several sensors/transducers. The software used to interact with the toolkit's components will require no prior programming experience. In the laboratory, the toolkit will be a partial replacement for existing laboratory equipment. Students will be able to bring their toolkits to lab and connect them directly to existing experimental setups. It will then be possible for the students to log data directly to their own computers and run the ir own motor control and other output device commands. Similarly, desktop demonstrations during lecture could utilize a portion of 10 the student's mechatronics toolkits. These applications demonstrate the necessity for the toolkit to be portable, which is another design objective. The last design objective is for the toolkit is to be inexpensive. The problems that arise with students carrying extremely expensive equipment in their book bags is unimaginable. The less expensive the equipment the better. 11 4.0 Academic Contribution Mechatronics is a little taught subject in the Mechanical Engineering Department. Currently, undergraduate mechanical engineering students are required to take one main course that teaches controls of electro- mechanical devices. This class is called 2.003: Modeling Dynamics and Controls I. Students learn Laplace transforms, traisfer functions, frequency response, Bode plots, modal analysis, open and closed-loop control, instability, time-domain controller design, and cover a brief introduction to frequencydomain control design techniques. The other undergraduate course which teaches mechatronics is an elective course titled 2.737: Mechatronics. This class is laboratory focused and covers such topics as encoder interfacing, quantization, aliasing, digital logic, electronic feedback, power amplifiers, and motor control. The toolkit developed for this thesis is an application of these theories rather than a reteaching. Students do not directly need to design the controllers for the motors but are instead able to directly use the data acquisition system and motors for their purposes. This helps to facilitate a quicker hands-on approach to teach mechatronics. Students will be able to concentrate on the application of mechatronics rather than the theory behind it. This is a less focused on angle taught in MIT's undergraduate curriculum. Hopefully, the results of an attempted/successful mechatronics toolkit project will lead towards an increased interest in the field. 12 The portable educational mechatronics toolkit is the only known toolkit of its kind. Other toolkits that are commercially available are either not portable, too expensive, or not powerful enough to fulfill this toolkit's purpose. This toolkit serves as a versatile educational tool that will teach students the subtleties of data acquisition, the intricacies of motor control, and the importance of the software that ties both together. The software is a very important part of this toolkit. Almost all software packages that are available for existing commercial products are packaged with very limited software in terms of functionality and level of development. The software used for this toolkit, on the other hand, is extremely versatile, and yet not so complicated that a user is required to know a formal programming language. The software packages bundled with the other products limit a user's range of possible activities. For example, one program may only allow a user to control the direction a motor rotates and vary the speed at which it moves. It does not allow precise motor positioning. Other programs, on the flip side, may control motor positioning, but will not allow a user to introduce delays or modify other parameters. 13 5.0 Competing Products There are several products on the market that possess some of the same functionality as the mechatronics toolkit. However, they are not specifically designed to be as versatile or geared for an educational purpose. Several examples of products that perform in some manner similar to the mechatronics toolkit are discussed below. 5.1 Home Automation The first of these products is a category ofproduct rather than a specific item The market for the home automation system contains numerous products which fall into this category. Products of this genre may be used to turn on/off lights, control a user's audio/visual system, monitor a security video system, control a heating, ventilation, and air conditioning (HVAC) system, control pool systems, irrigation, etc. One of the leaders in this category is a company called X10. Many of XIO's products focus on wireless technology and range from wireless video cameras to PC audio/video television transmission Figure 5.0.1, below, shows XIO's ActiveHome Kit which is used to control lights and other appliances. It is initially run from a computer but may be used while the host computer is turned off. 14 Figure 5.1.1: X1O ActiveHome Kit - PC Control of Lights and Appliances The difference between a home automation system like X10 and the portable education mechatronics toolkit is significant. The main difference between the two lies in the autonomy of the two systems. Unlike the many home automation products, the mechatronics toolkit cannot be run autonomously. It requires input from a laptop or a desktop computer at all times. Numerous home automation products, however, are microcontroller based, allowing control without the need for a computer. This is the most significant difference between the two products. The mechatronics toolkit could be used for home automation to turn on/off lights, control a HVAC system, pool system, etc. However, a significant amount of setup and configuration would need to be done to accomplish this goal. Home automation products are already optimized to perform these functions. 15 5.2 LEGO® MindStorms TM Another product that is similar to the portable educational mechatronics toolkit is a product called MindStorms by LEGO. This product is sold as a kid's toy as a simple robotics system. The product includes a microcomputer that acts as the brain of tle product. Sensors and motors can then be attached to the microcomputer and the physical LEGO structure. An autonomous robot can be created by combining this physical hardware with a custom designed control program that is downloaded to the microcomputer. 4f Figure 5.2.1 (L-R): A LEGO MindStorms Autonomous Robot, Microcomputer Module, MindStorms Motor The microcomputer programs are created using a very basic software program that is entirely graphics based. This graphical user interface allows the user to create fairly complex control algorithms without prior software programming or control theory experience. Users are able to take inputs from LEGO MindStorms' sensors and actually create a closed- looped function. The microcomputer can take sensor input, process that 16 information, and output a motor response based on the graphically created microcomputer program. The program used to create the microcomputer code is run on a Windows® based personal computer. The microcomputer program is sent through a USB infrared transmitter to the MindStorms microcomputer. The LEGO MindStorms robot is then able to act autonomously from the personal computer. 17 Figure 5.2.3: USB Infrared Transmission Tower Several aspects of the LEGO MindStorms product are different from the mechatronics toolkit. The first is the limited amount of sensors available for use by the LEGO MindStorms robot The base LEGO MindStorms system only comes with two touch sensors and a light sensor. In addition, the only other sensors available in the entire MindStorms product line are a rotation sensor, a temperature sensor, and a video camera. This video camera contains a built in microphone and will take 30 seconds of video/audio. This allows the robot to respond to changes in light, motion, and color. (a) (b) (c) (d) (e) Figure 5.2.4: a) Touch Sensor b) Light Sensor c) Rotation Sensor d) Temperature Sensor e) Video Camera 18 This limited amount of sensors available in the product line restricts LEGO MindStorms from being an extremely versatile system. Further, the product is handicapped by its ability to only support 3 sensors inputs to the microcomputer at any one time. On the other hand, the mechatronics toolkit is able to use any type of sensor/transducer that emits a voltage and can accommodate numerous inputs far beyond the 3 sensor limit of the LEGO MindStorms product. The output of the entire LEGO MindStorms product line is limited to one type of motor, a light, and one type of pneumatic. In the base MindStorms package, only 2 motors are provided as output devices. Other systems need to be purchased to obtain altermtive output devices. In total, a maximum of three output devices may be connected to the microcomputer at any one time. This severely limits the versatility of the product. Sensor Channels Motor Channels Figure 5.2.5: Sensor and Motor Channel Connections on the Microcomputer 19 (b) (a) Figure 5.2.6: a) Light Output Device b) Pneumatic Output Device Another drawback of the LEGO MindStorms system is the absence in the variety in motors available. Only one type of motor is available for the entire MindStorms product line. If a higher torque application were required, a gear reduction would be needed to obtain the desired torque value. Similarly, if an RPM increase were required, the design of a gear train would be required to have the output perform at the specified speed. Even with a gear box, it is not a guarantee that the desired torque/speed is attainable. The mechatronics toolkit, on the other hand, can control several different types of motors of varying ratings in addition to any device controllable via a digital 1/0 signal. This allows the toolkit to be extremely flexible by allowing the use of any number of motors and output devices. Another advantage of the mechatronics toolkit is its ability to function as a data acquisition system. This allows the user to perform data logging and viewing. The LEGO MindStorms sensors are only able to act as a trigger for the output devices and will not store data. The exception is the video camera which will take 30 seconds of 20 audio/visual input. The mechatronics toolkit, on the other hand, is able to take almost any type of data, view it, and save it for an almost infinite amount of time. 5.3 General Purpose Microcontroller Another way to create a product similar to a mechatronics toolkit is to design and build a circuit board using a microcontroller. Integrated circuits and other components may be added to control motors, perform analog I/0, digital I/O, and other desired functions. One extremely popular microcontroller based circuit board is called the Handy Board (Martin). This board functions as a general robotics controller and was developed based on MIT's 6.270 Autonomous Robot Design Competition board. There are numerous products that are commercially available that are microcontroller based. Many have similar functionality to the Handy Board. It is for this reason that only one microcontroller based product, the Handy Board, will be discussed in this thesis. 21 Figure 5.3.1: Handy Board The Handy Board is based on Motorola's MC68HC 1 microprocessor. It has 32K of RAM, includes 4 DC motor outputs, 7 analog inputs, 9 digital inputs, infrared I/0, an LCD screen, and an integrated rechargeable battery pack. It is extremely useful for robotics but can also serve any number of control applications. 22 (18) piezo beeper OFF (1 power switch ON (16) SPI header (2) computer connector (3) 4 DC motor outputs and indicators expansion (19) power n sion M trck e-charge connector de (4) "Start" button (5) "Stop" button (13) user knob (8) 9 digital (6) low battery indicator inputs T (9) 7 analog inputs (12) analog expansion header T (1R) IR input (10) sensor andt indicator IR out ut (7) power/ready indicator Figure 5.3.2: Labeled Handy Board Layout The Handy Board is able to independently control 2 servo motors. The routines used to drive these motors are very basic, but are a functional interface for controlling the motor's position. To control each servo, a specific pulse train needs to be sent to the control circuit to have the servo motor move to the desired position. The duration of the pulse width modulated signal determines the final position of the servo motor shaft. However, in order to have the servo "sweep", specific C code needs to be generated to iterate values over the global position. Additional servo motors may be controlled with the addition of Handy Board's Expansion Board. This board plugs into the top of the Handy Board and provides the 23 addition of 10 analog inputs, 4 inputs for active LEGO sensors, 9 digital outputs, and 6 servo motor control signals. a 0t% I External Servo Power Polaroid 6500 Sonar Ranging Connector Servo Outputs Digital LEGO Analog Outputs Sensor Sensor Inputs Inputs Figure 5.3.3: Handy Board Expansion Board Stepper motor control with the Handy Board is more difficult. Each time a stepper motor moves a step, the proper step sequence is required to be sent to the motor. This means that each step needs to be programmed in to tfr code used to run the motors. More information specifically about stepper motor control with the Hardy Board maybe found at http://www.cctc.demon.co.uk/stepper.htm (Harrison). While the Handy Board is a very versatile circuit board when it comes to robotics, it is not ideal in terms of teaching motor control and data acquisitionto a mechanical engineering student. The main feature against the Handy Board is the software interface 24 used to program the microcontroller. Users of the board are required to program code using assembly language, C, or Interactive C. Interactive C is a language that was created for the MIT 6.270 LEGO robotic design competition It is a multi- tasking C language based compiler that allows for dynamic expression compilation and evaluation. Although developed for student use, Interactive C still requires students to learn and understand how to program. This is not an ideal software interface for mechanical engineering students who have little or no prior programming experience. The complexity in programming the board makes it difficult for mechanical engineering students to easily control servo and stepper motors, perform data acquisition, and perform other seemingly simple tasks. Another disadvantage of the Handy Board is its limited analog input resolution. The board is only able to handle up to 8 bits of resolution This is not significant enough to perform functions such as strain gauge measurements, a staple in many mechanical engineering applications. This lack of resolution makes the Handy Board inadequate for general use by the MIT Mechanical Engineering Department. 25 6.0 Toolkit Development In the following sections, the development of the portable educational mechatronics toolkit will be discussed. First, the hardware selection of the data acquisition system will be discussed, which will be followed closely by the selection of the servo motor controller and the stepper motor controller. The selection of the software interface will then be explained in detail. 6.1 Data Acquisition The hardware used in the toolkit was initially selected based on the functional requirements of the toolkit; inexpensive, portable, able to perform data acquisition, and control stepper and servo motors. It was very important to include all of these functionalities when choosing the specific hardware that would be included in the toolkit. An additional requirement of having 16 bits of analog input resolution was imposed in order to properly take readings from strain gauges. This is because several strain gauges used in the undergraduate curriculum takes discrete readings of -10 to +10 volts. If the data acquisition portion of the toolkit possessed 16 bits of resolution without a real programmable gain, this would result in 305.2 micro- volts per discrete interval as seen in the calculation below. 26 6 kp 20v 2vx 10 I 'V= 216 lv 33 05.2puv 5 For strains on aluminum, this is acceptable as readings can run in the range of 4000 micro-strain. If the resolution were 12-bits or less, acceptable readings would not be able to be made. The 16-bit resolution requirement for the toolkit limited the possible laptop interface for the data acquisition portion of the toolkit to the PCMCIA slot. This interface also allows the data acquisition system to have greater sample rates than other laptop interfaces. Sample speeds of PCMCIA DAQ cards can range into MHz frequencies. A 16-bit National Instruments (NI) PCMCIA DAQ card was chosen to fulfill the data acquisition requirements of the toolkit. A major portion of this decision was based on the intended software that would be used with the toolkit. It was assumed that National Instrument's LabVIEW and MathWork's MATLAB* would be used extensively in the development of this toolkit. It was therefore decided that a National Instrument's DAQCard would be purchased that was supported by MATLAB's Data Acquisition Toolbox, MATLAB's Real-Time Windows Target, and NI's LabVIEW. The specific NI card that was chosen was based on the cards that the Data Acquisition Toolbox and ReaTime Windows Target supported (see Appendix A). The resulting card was National Instrumert's DAQCardT M -AI- 16XE-50. Basic hardware parameters for this card are shown in Table 6.1.1. Detailed parameters may be seen in Appendix A. 27 Analog Inputs Resolution 16 SE/8 DI 16-bits Sampling Range Digital I/O Counter/ Timers Triggers Input Range 20kS/s; 200kS/s ±0.1 to ±lv 8 2, 24-bit Digital single channel Table 6.1.1: DAQCard-AI- 1 6XE-50 Parameters Figure 6.1.1: NI DAQCard -AI-16XE-50 Using this card, a student will be able to use any sensor/transducer that outputs a signal equal to or less than +10 volts. The DAQ card will then digitize the signal and software will be used to accurately convert the data to the proper engineering units. 6.2 Motor Control The second portion of the toolkit involves the control of motors. From a controls point of view, it was decided that the toolkit would be able to control both servo and stepper motors. Inexpensive, portable servo and stepper motor controllers were researched to 28 determine the best fit for the design goals of the toolkit. Several options presented themselves that initially seemed like viable solutions. One option was to use a general purpose microcontroller based product similar to the Handy Board to perform stepper and servo motor control. Another was to use ready built motor controllers that interface to a laptop through the serial port or parallel port A final option was to purchase a product from Animatics called the SmartMotor ", which has an integrated controller and amplifier within each motor. From the available options on the market, it was determined that a servo motor controller would be bought that interfaced to the laptop through the serial port and that the stepper motor controller would communicate with the laptop through the parallel port. This would allow both servo and stepper motors to run simultaneously without the need to change connections. The primary requirements for the servo motor controller beyond the standard ability to control servo motors were that it needed to be inexpensive, portable, and controllable through the serial port. The chosen servo motor controller is a product called the SV203 from Pontech.com which fulfills these requirements. It is a PIC 16C73 microcontroller based board that accepts RS232 serial data and outputs pulse width modulated signals to control up to 8 servo motors. 29 Candcs o coontrol 5V -12V AD P devices onoff LED Expansionf Re w or Solenaic Port RS -232C RCSE RVCS Co rtrol up to 8 (sold s ep erately) (b) (a) Figure 6.2.1: a) PONTECH SV203 Servo Motor Controller b) SV203 Connection Diagram RS232 is an Electronics Industry Standard that was adopted in the 1960s for serial binary data exchange. Data is transferred one bit at a time from a sender to a receiver through a single line. This is a form of serial communication and is the standard on many personal computers, including the laptop used in this toolkit. For this reason, RS232 communication and serial communication will be considered synonymous for the remainder of this thesis. The SV203 is designed so that multiple SV203s may be connected to the same line. The commands to select individual boards and motors, in addition to the commands sent to position each servo notor, is sent through the computer's serial port in the fbrm of ASCII character strings. The SV203 processes these strings and outputs the appropriate signal. 30 The SV203 is compatible with many radio controlled (RC) hobby servo motors with Futaba J-type connectors. These servo motors contain a built-in potentiometer which accurately tracks the current position of each servo motor. All RC servo motors will not work with the SV203. However, many servos without J-type connectors may be rewired to work properly with the SV203. According to Pontech.com, at the very least, the servos listed in Table 6.2.1 will work correctly with the SV203 servo motor controller. CS-10 CS-20 Cirrus Molecular Micro Ball Bearing Servo Cirrus Sub-Micro Ball Bearing Servo CS-100 1Cirrus High Torque Retract Servo FP-S148 utaba Rugged Low-profile Servo Table 6.2.1: Compatible SV203 Servo Motors In addition to the features mentioned above, the SV203 also includes the following features: . . . . . . Servo control up to 8-bits of resolution (values from 1 to 255) Digital output via a reconfigured servo port Source/sink of 25 mA per pin RS232 serial communication of 2400 to 19200 baud 5 channels of 8-bit A/D input for analog readings of 0-5 volts An SPI port for shifting in/out serial data Similar considerations were taken into account when choosing the parallel port stepper motor controller. Portability, cost, and the obvious ability to control stepper motors was paramount in this decision. After an extensive search, a system by Stepperworld.com called the SP-3/HT was picked to fulfill this purpose. However, after receiving the product, it was found that control of this system is not possible using the current 31 mechanical engineering laptop setup. This is because the mechanical engineering laptops run Windows 2000, which is a Windows NT based operating system. All Windows NT based operating systems do not allow direct digital I/O to the parallel port without the use of a specialized hardware driver. Such a driver was not available from the vendor and third party drivers that were tested with the SP-3/HT system did not work. A decision was made to therefore purchase a stepper motor controller that communicated with the laptop through the serial port instead of the parallel port. The obvious disadvantage of such a decision is the inability to control both servo motors and stepper motors simultaneously. The PONTECH STP 100 stepper motor controller was purchased to fulfill the stepper motor controller role for the toolkit. Each STP 100 board controls one bipolar stepper motor, but has an onboard multiple drop network connection to allow addressing of up to 255 boards. The STPIOO's stepping logic is driven by a SGS Thompson stepper chip with built in current limiting and step logic. This driver chip is able to supply up to 2 amps per stepper motor. In addition, the STP100 tracks step positions to 32-bits and is able to drive bipolar stepper motors in full, half, or wave step modes. Further, four general purpose I/O channels are available for use with the possibility of converting two of the lines to 8-bit A/D converters. Commands to control the stepper motors are sent via a serial cable in the form of ASCII strings, similar to the SV203 servo motor controller. 32 Figure 6.2.2: PONTECH STP100 Stepper Motor Controller * M SEEK 1j t 1 XC1r I Ntwork Terminator [I ~~n.O4*O L 1 I Af E IN " W E9 :Wrn Logic Power *I RS-426 Network NI q INSS ImnA UWIL RS-232A 1;-232 Lim it Swtches Steppe Mdor Figure 6.2.3: PONTECH STP 100 Multi-node Configuration 33 The stepper motor that was initially chosen for use with the toolkit was the Vexta PK26401B. However, just about any bipolar stepper motor may be used with the controller that draws less than 2 amperes of current. In full step mode, the Vexta PK264-O1B rotates at 1.8 degrees per step. In half step mode, this is reduced to 0.9 degrees per step. Parameters of the Vexta PK264-OB are shown in Table 6.2.2 and geometry and torque vs. speed graphs are available in Appendix C. Holding Torque (oz-in) Current per Phase (A/phase) 54. 1 Volts 'Resistance per Phase !Inductance per Phase Rotor Inertia J (oz-in2 ) (mH/phase) (ohm/phase) (V) 5.7 5.7 5.4 0.66 Table 6.2.2: Vexta PK264-O1B Parameters 6.3 Software Interface The software interface for the portable educational mechatronics toolkit is an extremely important aspect of the toolkit. The software needs to be easy enough to use so that prior programming experience is not necessary. It is also beneficial to be able to use all functions of the toolkit with one homogenous program, rather than switching between programs to perform various tasks. The first requirement of the software is that it needs to be able to control the stepper motors and the servo motors of the toolkit. It further needs to be able to take data from the DAQ system, store it, and view. In addition, the software should be able to use tle DAQ system to create a closed- loop system with the motors and other output devices. 34 There are numerous software packages available that are designed to perform data acquisition This includes products such as TestPoint, LabTECH, NI-DAQ, LabVIEW, MATLAB, Personal DaqView, DasyLab, etc. What makes a DAQ software package more useful in the case of the mechatronics toolkit is the ability to control servo/stepper motors and to create a closed- loop system between the DAQ card and the motors. Two software packages distinctly stood out from the rest, not only in terms of the ability to do this, but also in terms of versatility, amount of use in industry and academia, and ease of use. These two programs were LabVIEW by National Instruments and MATLAB by MathWorks. Each package offers certain advantages over the other, but it was MATLAB that was selected in the end. MATLAB is a mathematical computing program that integrates visualization into a powerful language to provide a flexible environment for technical computing. MATLAB can handle numerous science and engineering tasks from data acquisition and analysis to application development. With the addition of Simulink, an add-on to MATLAB, a user is able to build block diagrams, simulate the behavior of a system, evaluate its performance, and refine its design. It is an interactive tool for modeling, simulation, and analysis and is extremely useful for control system design, communications systems design, digital signal processing design, and other simulation applications. One major advantage of Simulink over many competitors is its friendly programming environment. A user works entirely within a graphics based environment where blocks of specific functions are strung together to create a model. This allows users without 35 programming experience to develop highly complex models and simulations. When combined with MATLAB's Data Acquisition Toolbox, Real-Time Windows Target, Real Time Workshop, and a C compiler, a person is able to create a closed- looped system and perform real time control of that model. The Data Acquisition Toolbox for MATLAB is a compiled set of tools for analog input, analog output, and digital I/O from a range of PC-compatible data acquisition hardware devices. The toolbox allows a user to configure external hardware devices, take data for analysis in MATLAB, and output data. Real-Time Windows Target enables a user to run Simulink models in real time. A user is able to create and control a real time execution solely through their Simulink model. This model is converted into C code via Rea Time Workshop, is compiled, and finally executed in real time while interfacing to hardware connected to the computer. Other applications will continue to run and may use all CPU cycles not required by the real time task. MATLAB is an extremely useful package and is used extensively in industry, academia, and the MIT Mechanical Engineering Department. This is a major plus for MATLAB as the department already has a volume license for its use. In addition, undergraduate students in the department are already familiar with MATLAB as many fundamentals of the program are already taught in a sophomore level course entitled 2.670: Mechanical Engineering Tools. In this class, students use MATLAB's mathematical computing 36 power to solve mechanical engineering problems from solving ordinary differential equations to outputting the force to displacement matrix of an air cylinder of a robot built in one of MIT's undergraduate design courses. It is due to this familiarity with the MATLAB computing environment and MIT's already existing association with the program that the MATLAB computing environment was chosen as the software interface for the mechatronics toolkit. 37 7.0 Toolkit Cost The total cost of a basic portable educational mechatronics toolkit is $1,932. This is broken down into individual components in Table 7.0.1. The cost can be reduced significantly by purchasing a less powerful, less expensive PCMCIA DAQ card from National Instruments or by purchasing a similar but cheaper DAQ product from a different vendor. The former option, of course, would reduce the capabilities of the DAQ system of the toolkit. The latter could possibly have issues relating to compatibility. Item Matlab Basic Athena Version Qty Simulink Toolbox Software DAQ Stepper Servo Real-Time Workshop Real-Time Win Target DAQ Toolbox Microsoft Visual C++ .NET Standard (less with license) NI DAQCard-AI-16XE-50 PR68-68F Ribbon Cable CB-68LP 1/O Connector Block STP100 Stepper Motor Controller PP232-485F RS232 to RS485 Signal Conditioner PK264-01 B VEXTA 54.2 oz-in. Stepper Motor SV203 Servo Controller Serial Cable CS-100 Cirrus High Torque Retract Servo _Futaba S148 Total 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 2 Total Price $36 $16 $36 $22 $26 $90 $895 $80 $95 $318 $49 $152 $59 $5 $25 $28 $1,932 Table 7.0.1: Basic Toolkit Cost The total cost of the listed toolkit excludes the cost of any transducers/sensors and cost of the laptop, which the department already has in its possession. Software and hardware prices do not reflect any volume/educational discounts except for MATLAB and its associated toolboxes. 38 8.0 Toolkit Use The following sections will discuss the operation of the toolkit. Details will be explained on how to perform data acquisition, servo motor control, and stepper motor control. The immediately following section will discuss how to perform data acquisition using MATLAB and Simulink. The next two sections will discuss the format of the commands used to control the servo and stepper motors; followed by the last two sections, which will discuss how to perform these commands using the MATLAB and Simulink software interfaces. 8.1 Data Acquisition Use Reading data using MATLAB and the NI DAQCard-AI- 16XE-50 requires the use of MATLAB's Data Acquisition Toolbox. Further, to take data entirely within a graphically based environment, the addition of Simulink is required. The commands below may be used to acquire data directly from MATLAB without the use of Simulink. An M-file may be created to run these commands or entered individually into the MATLAB command prompt. Next to each example command is an explamtion of that command's function. 39 ai = analoginput('nidaq'); addchannel(ai,0, 1); set(ai,'SampleRate', 10) ActualRate = get(ai,'SampleRate'); set(ai,'SamplesPerTrigger', 150) set(ai,'LoggingMode','Disk') set(ai,'LogFileName','datal.daq') start(ai) data = daqread('datal.daq') plot(data) %Creates an analog input %Add channels to object "ai" %Set sample rate to 10 Hz %Retrieve actual sample rate (could be %different from the specified value) %Set the amount of samples taken %Set the data logging mode %Set the data file name %Start the data acquisition %Retrieve the data from the saved file %Plot the data on a graph To learn about other commands and options to take data in MATLAB, please see the Data Acquisition Toolbox website at http://www.mathworks.com/products/daq/ or view the MATLAB help file found within the MATLAB program. To acquire data in Simulink, a model needs to be created which connects the DAQ hardware inputs to the intended outputs. A very basic example Simulink model where an analog input from the DAQCard-AI- 16XE-50 is taken and displayed on the scope is shown in Figure 8.1.1, below. Analog In put Analog Input National Instruments DAQCard-Al-16XE-50 [auto] Scope Figure 8.1.1: Basic DAQ Simulink Model To take data in real time from a DAQ device such as the NI DAQCard, Simulink in addition to MATLAB's Real- Time Windows Target, Real-Time Workshop, and a C compiler (either Microsoft Visual C/C++ or Watcom C/C++) are required. Running an 40 application in real time allows greater flexibility by granting access to parameter tuning and signal tracing in a real time run. A more complex Real-Time Windows Target example application is shown in Figure 8.1.2. Digital Ou t put Digital Output National Instruments DA OCard-AJ-16XE-60 [auto] Analog 10000 2, Input s2+70s+10000 Analog Input National Instruments DAQCard-Al-16XE-50 [auto] Transfer Fcn Scope channell LClock T o Woikspacel To Workspace2 channelO To Woikspace Figure 8.1.2: Example Simulink Data Acquisition Model In this example, one analog input is taken, passed through a transfer function, sent to the scope for viewing, and then sent to a MATLAB workspace. That same analog input is also outputted to a digital out on the DAQCard which is then read by the DAQCard's second analog input. This second analog input is sent simultaneously to the scope for viewing and sent to the workspace. The data from the workspace can then be used after the simulation is paused or stopped by retrieving that data using the "From Workspace" Simulink block. The resulting scope of a randomly pulsed analog input to channel 1 is displayed in Figure 8.1.3, below. The upper graph represents analog channel 1 while the lower graph represents analog channel 2. 41 Figure 8.1.3: Resulting Scope of the Example Simulink Model from Figure 8.1.2 This model is different from a non-real- time simulation in several ways. First, a user is able to capture and display signals from a real time application while it is still running. The data is retrieved from the application and disphyed in a model's scope block in real time. Second, the model parameters may be changed and implemented on the fly. These parameters may be altered in the Simulink block parameters, the block parameters for masked subsystems, and in the MATLAB variables used to represent model parameters. The third difference between this application and a non-real-time application is the ability to take data from the input, immediately process that data, and then use that data to trigger an output to an external hardware device. In this case, that device is the digital out of the National Instruments DAQCard. 42 8.2 Servo Motor Control Command Use The chosen stepper motor controller and servo motor controller accept ASCII string inputs as commands to control their respective motors. Both the SV203 servo motor controller and STP 100 stepper motor controller processes commands one ASCII string at a time. The SV03 servo motor controller accepts ASCII commands in the form ofL n Ln ... <enter>. Each L stands for a letter or letters while the n is a decimal integer. An example of a set of commands that selects a controller board (BDn), selects a servo motor (SVn), and then moves that motor to a specific position (Mn) could be represented with the following commands: BD 1 SV4M 150 <enter> These commands could also be separated by spaces or commas for easier reading. BDI SV3 M85 <enter> BDl,SV3,M85 <enter> BD 1 SV 3 M 85 <enter> A full list of summarized commands for the PONTECH SV203 controller is shown in Figure 8.2.1, below. Most commands are self explanatory. However, it should be noted that a carriage return is required at the end of each string to signal to the controller to process the string just sent. 43 For further details on how to setup the controller board and an explanation of the commands in detail, please see the PONTECH SV203 manual which can be found at http://pontech.com/products/sv200/index.htm. Commands Parameter ,(n) BDn 0 to 255 1 to 8 SVn Mn In Un PSn Description 0 to 255 -128 to 127 Board Select Servo Select Move to an absolute location Move relative to current position 1 to 65535 1 to 8 Delay (ins) Put, set single pin of servo port PCn P'in 1 to 5 ADn b is a number between 1 and 8, which tells what pin on the port is being used. Ifn=0 4 clear Bit n=1 4Set Bit n= 2 4 Toggle Bit Get A/D value, the board will return a value between "0" to "255" followed by ASCII 13 SOn 0 to 255 SI None WRm n m= 0 to 255 n 0 to 255 RRm m= 0 to 255 WEm n n =0 to 8190 V? Shift a byte in form the SPI port Write to internal RAM m is the memory location n is the value to write Read the contain of internal RAM m is the memory location to read None Write to external EEPROM m. is the memory location n is the value to write Read the contents of external EEPROM m is the memory location to read Help, return summary of command listing None Returns the firmware version n= 0 to 255 R.Em which represent a voltage between 0 to 5 Volts. Shift a byte out to the SPI port n = 0 to 8190 Figure 8.2.1: Available Commands from SV203 Manual 44 8.3 Stepper Motor Control Command Use The STP 100 stepper motor controller also accepts ASCII string commands one string at a time. Each string must end with a carriage return or <ASCII 13>. This tells the controller board to process the command string. The command format accepted by the stepper motor controller board has two forms: Ln Ln Ln ... <enter>or L L L... <enter>. The L in this case stands for a letter or letters while the n stands for an integer. An example of a command that selects a board (BDn), sets the step delay (SDn), and moves the stepper motor to an absolute position (MIn) is below. BD 1 <enter> SD1000 <enter> MI320 <enter> Multiple commands up to 20 characters long may also be entered in one command string. These commands may be strung together directly one after another or separated by commas or spaces. BD 1 SD 1 000MI320 <enter> BD 1 SD1000 M1320 <enter> BD1,SD1000,MI320 <enter> It should be noted that once a board is selected, it remains selected until another board is selected or the power is turned off. Also, a minimum delay of three milliseconds should be given between commands to give the controller time to process the command. A summary of all possibly commands for the STP 100 stepper motor controller is shown in Figures 8.3.1 and 8.3.2. For a detailed explanation of each command, board/motor setup, 45 and other information, please see the PONTECH STP 100 manual at http://pontech.com/products/stp100/index.htm Command Parameter Descrlptlon BDn N = 0 to 255 Board Select Min N = -2147483648 Move Immediately to an absolute location to 2147483647 MCni N = -2147483648 Move on Cue to an absolute location (must be lini N = -2147483648 Move Immediately relative to current position ICn N = -2147483648 Move on Cue relative to current position cue CU Pn PSn RPn ADn None N = 3. 5, 6or 8 N = 3, 5, 6, or 8 N = 3, 5, 6, 8 or None N = 1 or 2 Cue a move Pin clear on 10-pin header Pin set on 10-pin header Read Pin on 10-pin header (if n is not specified, a four bit value is retumed representing all pins) Get AD value, the board will return a value betveen "0" to "255" which represents a voltage WRmn n M = 0 to 255 WSS M = 0 to 8190 N = 0 to 255 None Write to internal RAM, m is the memory location n is the value to write Vrite to external EEPROM, m is the memory location n is the value to write Write System Settings to EEPROM (current value of SD. SM. SA, SH, SF, SW, SP SP are RRm M = 0 to 255 Read the contain of internal RAM, m is the REm M = 0 to 8190 RC RD RT None None None Read Current Position Read Destination Position Read delTa Position (DestinationPosition - L_ CurrentPosition) to 2147483647 followed by CU command) to 2147483647 to 2147483647 (must be followed by CU command) between 0 to 5 Volts. N = 0 to 255 WEm n stored to EEPROM) memory location to read Read the contain of external EEPROM, m is the memory location to read Figure 8.3.1: PONTECH STP100 Command Summary 46 Command Parameter HIMn n = -2147483648 Set new home position, current position = HI None to 2147483647 H0 (H - Zero) None Description destination position = n Halt Immediately, set destination position to current position and do not decelerate Halt. Set speed to 0 and decelerate H+ None Move Clockwise forever HSP SO None None None Move Counter-Clockwise forever Stepper Always powered Stepper Off when not moving (Remove power SH SF SW TCn TSn RSA RSD RSM None None None n = 3, 5, 6, or 8 n = 3, 5, 6, or 8 None None None Set Half Step mode Set Ful Step mode Set Wave Step mode Test if pin clear, on clear execute HO Test if pin set, on set execute HO Read Step Acceleration/Deceleration Factor Read Step Delay Read Minimum Step Delay Factor SAii n = 1 - 255 AccelerationiDeceleration Factor SDn SMn n = 6 to 65535 Step Delay (n x 1.6us) n = 0 to (65535 - Minimum Step Delay Factor (Start Step Delay SD) = StepDelay + MinimumStepDelayFactor) if= from stepper, no holding torque) 0 then no acceleration Figure 8.3.2: PONTECH STP 100 Command Summary 8.4 MATLAB Motor Control Interface The servo motor and stepper motor controllers require ASCII string inputs for motor control In order to control the servo motor and stepper motors through MATLAB, it is required that MATLAB be able to send ASCII strings through the serial port. This can be accomplished through the use of the MATLAB command "fprintf'. 47 First, however, an object needs to be created that represents the serial port device. In our case, this is a motor controller. That object then needs to be connected in order to send ASCII string outputs. Only after the object is created and connected will MATLAB properly send ASCII strings through the serial port The commands below serve as an example that will allow a user to control the servo and stepper motors. The string between the quotation marks in the fprintf command line may be substituted with other motor controller commands. Next to each command is a brief description of what that particular command does. These commands may be entered into a MATLAB M- file or entered individually into the MATLAB command prompt. s = serial('COMl'); fopen(s); instrfind %Create a serial device object from COMI of the computer %Connect the serial device object %Return serial port objects from memory (lets you know s is %actually open) fprintf(s,'%s\n\r','BDO SVl') %Writes the string within the quotation marks to s The fprintf command shown above is in the form of fprintf(obj,format','cmd'). The obj in this case is "s", the format is "/os\n\r", and the ASCII command is "BDO SVl "(select board 0, select servo motor 1). The "/os" in the format area designates the notation of the output as an ASCII string. The "\n" symbolizes a new line and the "\r" represents a carriage return. Specifics about the fprintf command and additional options may be seen in the MATLAB help file or online at http://www.mathworks.com/access/helpdesk-rl2pl/help/techdoc/ref/fprintfserial.shtml. The object "s" is required to only be created and connected once. Any further commands may be sent to the motor controllers by sending commands solely through the fprintf 48 MATLAB function. For example, to move servo motor 2 on board 1 to position 200 and then to position 60, the following commands could be used. This assumes that the serial object has not yet been created or connected. s = serial('COM 1'); fopen(s); instrfind %Create a serial device object from COMI of the computer %Connect the serial device object %Return serial port objects from memory (lets you know s is %actually open) fprintf(s,'%s\n\r','BD1 SV2') %Selects board 1 and servo motor 2 fprintf(s,'%s\n\r','M200') %Moves servo motor 2 to position 200 fprintf(s,'%s\n\r','M60') %Moves servo motor 2 to position 60 Note that the M200 and M60 commands could have been sent on the same ASCII string with a delay in between. The board and servo motor select, however, is required to be sent before the initiation of a move operation. This is only true for the SV203 servo motor controller. The STP 100 stepper motor controller allows the board select to be sent in the same command string as a mve command. An example for the STP 100 stepper motor controller may be seen below. It is assumed that the object device has already been created and connected. fprintf(s,'%s\n\r','BD1 MIl00') %Selects board 1 moves the associated motor to position 100 This command will only work after the board IDs are properly associated with the appropriate controller board. When this command is sent to the stepper motor controller immediately after powering up the controller board, not only will motor 1 move to position 100, but so will the other motors. In the case of the 2 stepper motors that are currently part of the toolkit, both motors will move when this command is issued. This is 49 also true if board 2 were selected after initially powering up the controller board instead of board 1. However, if a BD2 command were sent after initially issuing a BD1 command, then that particular motor associated with board 2 will move independently of board 1. This also works when starting with a BD2 command and then sending a BDl command. After sending this second BDn command to the stepper motor controller, issuing a BDI or BD2 command will independently be associated with the correct board for the remained of the time that the power is connected to the controller. Further, once the commands are correctly associated with each board, a BDO command will link together both of the current stepper motor boards causing future move commands associated with a BDO command to control both motors in exactly the same fashion. If a BDO command were initially sent with a move command immediately after powering up the controller boards, the motor associated with board 2 will move, and not the motor associated with board 1. If a BD2 command were then sent followed by a move command, the motor associated with BD2 will move independently of motor 1. Following this, all BDO commands will cause both motors to move together. If a BD 1 command were issued after initially starting with a BDO command, then the motor associated with BDl will move independently of board 2's motor. Similarly, after this, all future move commands will be associated correctly with the appropriate controller board. These are little, but workable, nuances associated with this stepper motor controller. 50 The last nuance about the STP 100 deals with the move on cue (MCn) command. All cue commands for each motor are required to be sent separately. Then when a BDO CU is issued, all the motors will start at the same time. For example, the following move on cue command will not work. This is assuming that board selection is appropriately assigned and that the serial port object has already been created and connected. fprintf(s,'%s\n\r','BD1 MC400 BD2 MC700 CU') Instead, the move on cue command should be sent as follows. fprintf(s,'%s\n\r','BD1 MC400') fprintf(s,'%s\n\r','BD2 MC700') fprintf(s,'%s\n\r','CU') This will cause the stepper motor associated with board 1 to move to absolute position 400 at the same time that motor 2 moves to position 700. 8.5 Simulink Motor Control Interface The purely MATLAB motor control interface presented in section 8.4 is an open- loop process. Commands may be sent to the controllers, but no feedback or external inputs may be used to close the loop or act as a trigger. To be able to have this functionality in MATLAB, it needs to be possible to take real time input from the DAQCard and have that input trigger the export of an ASCII string to the serial port. With Simulink in conjunction withthe Real-Time Windows Target, this is almost possible. A user is able 51 to take data from an analog input and have that trigger an output. However, the problem is that the output cannot be an ASCII string. This is due to the fact that Simulink, including all of its toolboxes, cannot output ASCII strings. The only available data types that can be output ted are listed in Table 8.5.1. Name Description double Double-precision floating point single Single -precision floating point int8 Signed 8-bit integer uint8 Unsigned 8-bit integer int.6 USigned 16-bit integer intl6 Signed 16-bit integer int32 Signed 32-bit integer uint32 Unsigned 32-bit integer Table 8.5. 1: Simulink Built-in Data Types A work around solution to this problem is to program an S-function (system-function). An S-function is a mechanism that allows a user to extend the capabilities of Simulink by adding user defined blocks to a Simulink model. These blocks may be created in MATLAB, C, C++, Fortran, or Ada. Specific algorithms may be implemented by an Sfunction by following a set of rules provided by MathWorks, the creators of MATLAB and Simulink. S-functions are also compatible with Real- Time Windows Target and have customizable user interfaces through the use of masking. Fortunately a free S-function that writes ASCII strings to the serial port has been programmed in C++ by a third party MATLAB user. This package called the "RS232 52 Blockset" (Daga). The RS232 Blockset was initially created to support a project on the avionics of a simulated aircraft. Luckily, this blockset may also be used for general RS232 communication. Unluckily however, the blockset has never worked properly with the portable education mechatronics toolkit. The RS232 Blockset is composed of the 11 blocks seen in Figure 8.5.1. The two important blocks of concern for this mechatronics toolkit are the RS232 Setup block and the RS232 Write String block. The setup block creates a serial device object, connects it, and closes it after the simulation is completed. The RS232 Write String block outputs ASCII strings through the computer's serial port. For each simulation step that the input flag of the RS232 Write String block is a Boolean 1, the designated ASCII string will be sent. Each time a Boolean 0 is inputted to the block, the ASCII string will not be sent. RS232 Blockset Library 1.1 L.Daga. All Rights Reserved Figure 8.5.1: RS232 Blockset Blocks 53 A model to test the functionality of the RS232 Write String block was created. This was used to determine if the RS232 Blockset could indeed control tle servo and stepper motors. This model may be seen in Figure 8.5.2. Terminator Terminator1 I: :Terminator2 Discrete Impulse Figure 8.5.2: RS232 Write String Block Test Model The first output of the RS232 Setup block is used to transmit a handle which tells other RS232 Blockset blocks when the serial port is open for communication. The second output is used to communicate the state of the port. A 0 is not open while a 1 is open. This second output conditions the other RS232 blocks as to the actual status of the port. The first input of the RS232 Write String is specifically for the handle from the RS232 Setup block. The second input is a flag that enables the write execution to the serial port. A Boolean 1 triggers the write while a 0 causes the block to do nothing. The first output of the RS232 Write String block is a replication of the handle from the RS232 Write String block's first input. The second output of the RS232 Write String block is a flag that indicates the completion of the write operation. A 0 is outputted when not completed while a 1 is sent when successful. 54 The string that the RS232 Write String block actually transmits to the serial port is defined as one of the block's parameters (Figure 8.5.3). F Cane H elp A Figure 8.5.3: RS232 Write String Block Parameters The terminator blocks in the model are used to end the unused output signals. This prevents warnings about unconnected output ports. The Discrete Impulse block in the model is used to send a Boolean input as a flag for the second input of RS232 Write String block. When the STP 100 stepper motor is connected to the laptop and the model shown in Figure 8.5.2 is run with the string specified in Figure 8.5.3 and the parameters shown in Figure 8.5.4, the output is "BDl M1300 BDl M1300 BDl M1300 BDl M1300". This results in no movement of the stepper motors. Verification that the ASCII string was received in multiple instances was confirmed by a second computer that was connected to the original laptop via a serial cable and null modem adapter. A terminal program was 55 used on the second computer to view the ASCII command strings being sent through the serial port. j] R ------- Show additional parameters -------Output data type: boolean WK Cace Help Apply I Figure 8.5.4: Discrete Impulse Block Parameters It is unclear why the output of the RS232 Write String block is sent multiple times. If the parameters of the Discrete Impulse block are modified to try to only transmit the string once, the minimum number of time that the string will be sent is 4 times. Increasing the sample time in the parameters box will cause an increase in the amount of instances the string is sent. Decreasing the sample time will not have an effect. The string will still be sent 4 times. Decreasing the samples per frame is not an option. Only natural numbers are accepted by the "Samples per frame" parameter box. Altering the delay does not change the amount of times the string is sent for obvious reasons, and the "Output data 56 type" is required to be Boolean as specified by the input data type of the RS232 Write String block. The Discrete Impulse block is defined by MATLAB's help function as a block that "generates an impulse (the value 1) at output sample D+1, where D is specified by the Delay parameter (D 0). All output samples preceding and following sample D+1 are zero." By this definition, if the RS232 Write String block were programmed correctly to output the specified ASCII string once per sample where a Boolean 1 was inputted to the block, then only one instance of the ASCII string would be transmitted to the serial port, not multiple instances. It is therefore assumed that the RS232 Write String block is not programmed as stated. However, a work-around to this problem looked to be promising. A theory was proposed that sending each command separately through the RS232 Write String block would cause the controllers to react properly. If each command were sent individually, then it might be possible that the ASCII string repetition would not be an issue. To test this theory a terminal program which connects to serial devices through a computer's COM port was used to send strings to the STP 100 stepper motor controller. The following commands were sent to the controller using the terminal program: BDl BD1 BDl BDl <enter> MI500 M1500 MI500 MI500 <enter> 57 The result was that the stepper motor moved to the appropriate position, proving that multiples of the same command may be transmitted to the controller. When this theory was tested with the RS232 Write String block by inputting each command separately, the stepper motor did not move. It was however, confirmed through the second computer and terminal program that the RS232 Write String block was indeed transmitting "BD1 BDl BDl BDl" and "M1500 M1500 M1500 M1500". It is hypothesized that the reason why sending individual commands through the RS232 Write String block does not work is because it is not transmitting a carriage return at the end of each string. Recall that the motor controllers do not process commands until receiving a carriage return. If the ASCII commands are being transmitted to the controller but a carriage return is not included at the end of that string, the motors will not respond. The block would need to be reprogrammed in order to add this functionality. Unfortunately, due to time constraints, a new RS232 Write String S- function block was not programmed for this toolkit. This leaves the toolkit without the ability to create a closed- loop system within the MATLAB/Simulink software environment. 58 9.0 Future Work The most significant improvement to the current state of the portable educational mechatronics toolkit is to program a new S- function block to output compatible ASCII strings. This will link the DAQ system to the motor controllers creating a closed- loop system. Links may be created between inputs and output devices and feedback may be incorporated into a user's applications. This would have the greatest impact of all possible improvements to the toolkit. Another addition to the toolkit that could be incorporated is the addition of a general purpose microcontroller. This would allow toolkit applications to be run autonomously. Students would be able to download programs to their microcontrollers, unplug their laptops, go to lab, return home and still have their applications running. This would create greater flexibility in the possible uses for the toolkit. One of the major issues involved with the addition of a microcontroller, however, is the software interface. It is currently required that a user code programs by hand. A very simple interface would need to be created to simplify this process. This may be a completely graphics based interface or just a simplified programming language. Whatever the outcome, improved usability is a key issue. Another item that could be changed in the future would be to move either the servo or stepper motor controller interface away from the serial port. This would allow simultaneous use of the two types of motors. 59 In the future, a concise manual explaining the toolkit setup and use could also be written. This would include the basics for hardware and software use and could include "cool" example applications beyond normal classroom and laboratory use. Specifics on how to use the toolkit for each demo and lab for a specific class would be provided by the instructors for that class. 60 10.0 Conclusions A portable educational mechatronics toolkit was developed for this thesis. The hardware includes a data acquisition card, a servo motor controller, servo motors, a stepper motor controller, and stepper motors. Specifically, the toolkit is composed of National Instrument's DAQCard-AI- 16XE-50, PONTECH's SV203 servo motor controller, and PONTECH's STP 100 stepper motor controller. The software interface for the toolkit is comprised of MATLAB and Simulink with the addition of the Data Acquisition Toolbox, Real- Time Windows Target, and Real- Time Workshop. This hardware and software combine for a total cost of $1,932 per toolkit. This does not include all possible volume/educational discounts or the cost of the required laptop which the Mechanical Engineering Department already possesses. In its current state the toolkit does not contain all of the functionality that was initially intended for the toolkit. Each hardware component is fully functional with the MATLAB/Simulink software interface as individual components, but is not completely functional as a whole integrated system. It is separately possible to take data using the data acquisition card, control the servo motors, and control the stepper motors. It is not possible to have the data from the DAQ card trigger a response from the servo motors, stepper motors, or other output devices. The portable educational mechatronics toolkit in its current state is only an open-loop system Future work on the toolkit would close this loop and thereby, increase the functionality of the toolkit. 61 All of the design objectives of the toolkit have not been fully realized at this time. Actual implementation of the toolkit into the undergraduate teaching curriculum is required to assess its usefulness in teaching mechatronics and sparking interest in the subject. However, the objectives of keeping the toolkit low cost and portable have been obtained. 62 Appendix A: NI DAQCard-AI-16XE-50 (6012E) Parameters Comments 16-bit PCMCIA DAQCard DAQCard-1200 N IDAQCard-500 N DAQCard-516 Y IDAQCard-6023E N Only 2 16-bit Al J_ N ______________ ? Not available to purchase at current time ? Y vailable to purchase at current time Not supported by Real-Time Windows Target DAQCard-6052E ? Not available to purchase at current time IDAQCard-6062E N IDAQCard-6 FQCard-6034E 024E1 E .A.. ar. 6 fDAQCa rd-6036E J N IDAQCard-6533 N IDAQCard-6715 DAQCard-700 AI I6E-4 N N Y 7 IDAQcard-AI- 6XE-50 DAQCard-DIO-24 I____________ I - N JAlso supported by Real-Time Windows Target I__ Table A. 1: National Instruments MATLAB Data Acquisition Toolbox Compatible PCMCIA Hardware 0to10 .0075 0.009 Sto 5 o to 1 0A225 0.0245 &.0117 X267 B0A67 .D467 591.2 514.6 4. nU5 2T.6 EV R.9 257.3 51 S & 22.9 9,01D II.3 1.8G7 1.56 4,15 DA0M 03 602.7 VI. 60-3 W. 1 6.0 0.0245 .025 1.13 9.6 0.057 MIS 0.7 2 0.044 j of J -angledannei rodinj. f4aurenet aearea are bated fa ruce: Aomuiaies as I1 fc meunurenentsolkirrj an intenal E sene Calibratin. Awad numbers asnume dittenng ad eraye Ar aryat FuL Scae Wtin &IIC of intenrd calibration temperatuna and *10*C deawtrnal or faWry-alibratkn temperature. Oneyear calibration interal reconended. The Absolute calculations. operatbnal tetrerhs IG pt averagrn of data. See oveniew cn p 234 fr emimple calculations were perfoned tot a aemum range input vdtay (for exw e, 10 V kn the 0 V rangl after ore ye, asamr 0 to ft Figure A. 1: Absolute and Relative Accuracy 63 I Input signal ranges Defice 6052E Range Software Serlatable 2DV low +iV 2V I V ki V mV tEl SM mV Dto 5V A2 V+lv kumm MO +11 10 mV 20V 1v 100mV - 50 M*1011 +5v oto ln V 101 5Y 2V Iv t - Il v -o l MV 200 ny 100 Mv n26V 0to 200 mV DtoD 100 mV *kfmV 20V 'icmte - *1011 6 15v 1w Powered Oto 2 V Iv Dto 509 Wi - 200 m4 roen overwmltage Roerae oto 10 V i5 v SM iY Inp-t Maximum ,,vckngvdtatge (gnal + onrmn mc-6-m 0 to 109 snv id 1v Go1k D WO 500 MV D to 200 mV o2EoN *iEo -Mv 61) Mv 200mV 100 my 20V 101 Y4v 2V 6034E 603SE 6036E D to 10 V Dto 5V Dto 2V I ta 1V isV 12.5 V SY 6930E 6031E 6032E 6033E Unipalar islut9aM Bipolar T Rauge I -O 5V to I v -r GO1 my. .. .... DC Eah iptshould remain Athin ground 11 125c'ic Invits -protected ACH<0.15>, AISENSE 6052E MMJE 6332E 8334E 8J35E GE 6331 E I33E FIFO buffer size ACDka6>, AISENSE, AISENSE2 512 samples, 1024 samples for DAQCard; 248 for PCI-MIO-16XE .. Data tranfers DMA irerrupts, programmed VO Interrupts, progammed I/0 PC, PXI, AT. DAQCard. DMA modes PCI, PXI...... Scatter-gether (single transfer, demand transfer) Single transfer, demrd transfer o........... AT .. Configuration memory si3............. 612 wcrds Figure A.2: Input Characteristics 64 Transfer Chorateristics Icuire LU kOMhr; Devim t EUI 2E DNL evicei W12E No rnusaing 2 LSO. U= 42-Mi .l LS2 +15 b 431 LUS . - ... l6 bit! guarant Qd. . ......... om.. AMlifier Characteristics Irput irn paro L[ iaa Md -W Iwrns Normal 7 Gl in Iprdld with 11 pF --- sr 32 0Q i 1 1 kn fkr BADAMrd I lcr kd rd M Input bias and affzUt curafl s Cr Le ia funat unrmt rid 4N M MIA tElOnA CN4R R, DC r. Dowim 1 3H4z flat _ _ ipa_ r _ _ipolr _ 8 dO e 2V 100 IV d8 d 12Dr 211V Figure A.3: Transfer and Amplifier Characteristics Dynaic Characterisic. [ aI nrdiIRun EMkk o2D St12E EE kk 1 t2V M IGO i 203m nN ap Sutdkig tirn oofui-ksca raumay_ Device 9112E R11nn1 *aVII% AM1"t taES I Uil2 ta2iB LSG'1 i 8p5m Ep lomurizi2 Adianenoo EE001-A d@ I LSD swo ps gA OI Figure A.4: Dynamic Characteristics 65 )J E~pnmn EsZwca -ic-psY 1,2J11y bipdat tN4 ;W.OMI :tLR* A0er wne ', -100 dG liming 110 General- Purpose U pfllwn C ou nterdffnu ru Number of channels 2 24 bits (1 in 16, 777, 216) .................. Resolution ..................................... ........ Compatibility .................... 5 V/TTL Digital logic levels Level Input lowd voltage In2ut highvtage Output low voltage (lout =5 mA) mi.imum 0.0 V Max 0.6V 2.0V 43V 5.0V j j 0.4 20 MHz and 100 kHz *±0.01% 20 MHz PFIO..PFI9, RTSIO..RTSI6, analog trigger: software selectable External gate selections..................... PFIO.. PFI9, RTSIO..RTSI6, analog trigger; software selectable Minimum source pulse duration..........10 ns 10 ns, edge-detect mode .... Minimum gate pulse drto. Data transfers PCI, PXI, AT.............................. DMA, interrupts, programmed V(0 Interrupts, programmed I/0 DAOCard .................................. DMVA mod~es PCI, PXI ......................... Scatter-gather (single transfer, demand transfer) AT ............................. Single transfer, demand transfer Base clocks available........................ Base clock accuracy ......................... Maximum source frequency ...........-.. External source selections.................. Frequency Scaler Number of channels.............J........1 Resolution ................................. Co mpatibilIity ............................... 4 bits 5 V/TTL Digital logic levels Level Input low voltage In put high voltage Output low voltage (lout = 5 mA) Output high voltage (lout =3.5 mA)4. M11Inkatu 0.0OV 2.0 V -OAV Base clocks available........................ Base clock acuay........*0.01% Data transfers................................. 10 MHz, 1 00 kHz Programmed I/O Figure A.5: Timing 1/0 66 Max 0.0 V 5.13 V Triggers A=Wig Trggrs Number of triggers 6J52E 1 EI32EE EX131 E933E S3M4E BE3SE GEE No e Purpose Start a-d stop triger, gate, ....................... .A Analog ir Start trigger, gate, clock ........ Anal output General-purpose ciunterAimers........... Source, gate dock Source 6052E 6030E 6032E 6031E A CH&l.15>, PFlTR 11 A-CdL.63>, PH DTR3IG1 Level . Internal scurce, ACH<O..1 E63> External sourc,-, PF KVfTR IG1 ......... Slope tFull-scale . . Rescution Hysteresis .. Bandwidth (,3 dB) Accuracy ... . :k0 V FoAtive r regatie; softwane selecta tie 12 bits, 1 in 4,FB6 Programmable *1% of full-scale range max Internal source > ACH<O.J f " 255 " Devic'a 6852E 60 3 OE, E31E 6032, 6033E Exter na I Source PFIDM 700 kHz A MHz Diital iggr (all devices) 2 Number of triggers Purpose Analog irut Analog output General-purpose omterAlimers. Start a-d stop trigger, gate, dock Start trigger, gate, clock Source, gate Source............................. PFID..PFIa. RTSID..RTSIB Postiec r regative; ftvarve selectabte 6 VTTL Risirg or falling edge 1 D ns minimum Compatibility Response......... PuIsa w idth .......................... Figure A.6: Triggers 67 ExteMnal aIpufOr Dighial or Analog Thgler (PFIOITRIG1) 10 kD DC Impedance. Coupl ......................... ing.... Protection Digital trigger Analog triger -0.5 to Mr.+0.) . V i3S V Calibration Recommended warm-up time. . Calibration Interval 15 minutes; 30 minutes for DAGCard .. 1 yea r Onboard calibrution refererr-e DC Level B[E2E Over full qperating iemperature s lIue stced in EEPRDM mbA 5.000 V 4*1.0 M.I EE EC31 E B032E EM1E ELG3E E3AE 5.000 V 4*3.5 iVW LEE Temperrture coeffi ent E2E kf.BppmPCrax EM& E031 E E032E EO12E i.D ppm PC max BUA4E BEEM DI 1 E 2.DppmC max Long-term stablity BLEE EM Ai.0 pjpmr EMB E EM2E ELD33E_ ESM4E EL3EE __ k15.0 ppjrMaF WME EDI AE Figure A.7: External Input and Calibration 68 Bus Interface PCI, PX .. AT, DASCerd. ....................... Master, slave ................... Slave Power Requirements' Dew ice 6052E 603*E (PD, PXI; 1e apt 603E/603SE 6034E 603SE +5 Vat Ltm 1.3 A 1.5 A PuwarkAailahie at tg Connector +4.65 to +5.25VD1 A +4.65 to +5.25 VD 1 A Q.9 A +4.65 to +5.25 VDE 1 A 1.2 A 1.1 A +4.65to+5.25 VDC, 1 A +4.65 to +5.25 VDC 1 A 6036E 603k-(AT) PAt-M-16XE-') O +4.65 to +5.25 VDC 250 mnA ........ +4.65 to,+5.25 VDK I A 230 mA 7W0 mA 11AUCard-Al-16XE-50 AT-MIO -16XE-90 Physicall DlmESWISm (not ircduding ccrectorsi PCI ................................. PxIl................................. ...... ISA kJngi ISA hort)........ DAOCard......... 17.5 by 10.6 cm (6.P by 4.2 in.) 16.0 by 10.0 cm (6.3 by 39 in.) cm (13.3 by 3.9 in.) B 33 Rq9.. 17.5 by 9.9 cm (6.9 by 4.2 in.) Type I PC Card I1/V OOEDBetDfS 6052E 5030E 6032E 6034E 6035E 603GE 6011 E 6031E 6033E E&pin nale SCS11 tWe 601 2E E& i n fnde PCMCIA [DO-pin feiwe 0O9J D-tye Envirorunent 0 to 66 4C; DAQCrds should not exead GG 7C while in PCMCIA slot -20 to 70 PC 10 to 90%, nonoordensing Operating temper t"re. Storage temperature................ Relative hurnidty...... Figure A.8: Bus Interface, Power Requirements, Physical Parameters 69 Appendix B: Servo Motor Controller and Servo Motor Details Inw - U T~ b.I !~ tjl w II- ~~33 X -L- El 4 ± -2 2 IiH~ IH~~ LLr~ 131-I III. -T-1. I . 9 VVV iJ~ 2 3 3 0 2 2 3 L9Ir El0 - t - -I -t *1* Figure B. 1: SV203 Schematic Diagram 70 2 -I I IVotg odel System Angle (degree) + pulse, 180 :CS-lOO j.52mns I(two ~neutral positions) FPS148 ~+pulse, 180 1.52ms (full neutral rotation)- Curn Output Supply (V) curren Supply orque Ily lip oz-in. 4.8-6.0 pno spcC. Operation iDimension Speed (ich) (sec/60deg) 102.7(4.8V) 050 033.7(4.8V)I !Il1.09(6. V)~ 1 .30.89 9 09 x Wih eight (oz.) 1 11120 1 1(6.OV) 6.OV .8-6.0 f.9x07 8mA (at idle) 42.0 0.22 1.50 14 1.50 Table B. 1: Servo Motor Specifications Futaba S-148: The S-148 servo motor uses an indirect drive potentiometer for feedback to determine shaft positioning. This motor is designed to rotate an approximate total of 90 degrees (45 degrees in each direction). However, when used the SV203, the servo is able to rotate nearly 180 degrees (90 degrees in each direction). CS-100 High Torque Retract Servo: The CS-100 possesses a high torque output for its size. The motor was originally designed to retract landing gear on model air planes, but can easily serve any application where a high torque is required. The only drawback of this motor is that it only has two stationary positions, 180 degrees apart. 71 Appendix C: Stepper Motor Details .63 1.54 .79 .2500 0IA 2495 DIA.4 J 1.856 ~-4 HOLES MX *4r .59 .20 7.98 i 1.5012 DIA 12=- or8I L2EAGS 04 UL Style 32651 AWG 22 Figure C. 1: Vexta PK264-01 B Stepper Motor Mechanical Drawing JL=1 5 gem2 (185xOI kgan) Damper D6CL-6. 0.74 100 -r 0 - O.3 0.1 01 1 10 Speed [kHz] Figure C.2: Vexta PK264-01B Torque vs. Speed Curve 72 References 6.2 70 Autonomous Robot Design Competition. Spring 2003. 9 May 2003 <http://web.mit.edu/6.270/>. Animatics Corporation. IntegratedMotion Control. 2002. 9 May 2003 <http://www.animatics.com/index.html>. Daga, Leonardo. RS232 Blockset. 22 Mar 2003. 9 May 2003 <http://digilander.libero.it/LeoDaga/Simulink/RS232Blockset.htm>. Harrison, Peter. Stepper Motors and the HandyBoard.n.d. 9 May 2003 <http://www.cctc.demon.co.uk/stepper.htn>. The LEGO Group. LEGO MindStorms. 2003. 9 May 2003 <http://mindstorms.lego.com/eng/default.asp?bhcp= 1>. Martin, Fred. HandyBoard.com. 4 Mar 2002. 9 May 2003 <http://handyboard.com/>. The MathWorks, Inc. Data Acquisition Toolbox 2.2. 2003. 9 May 2003 <http://www.mathworks.com/products/daq/>. The MathWorks, Inc. MA TLAB 6.5. 2003. 9 May 2003 <http://www.mathworks.com/products/matlab/>. The MathWorks, Inc. Real-Time Windows Target 2.2. 2003. 9 May 2003 <http://www.mathworks.com/products/rtwt/>. The MathWorks, Inc. Real-Time Workshop 5.0.1. 2003. 9 May 2003 <http://www.mathworks.com/products/rtw/>. The MathWorks, Inc. Simulink 5.0.2. 2003. 9 May 2003 <http://www.mathworks.com/products/simulink/>. MIT iCampus Project. 7 May 2003. 9 May 2003 <http://www.swiss.ai.mit.edu/projects/icampus/index.html>. Motorola, Inc. M68HCJJ Family. 2003. 9 May 2003 < http://ewww.motorola.com/webapp/sps/site/taxonomy.jsp?nodeld=0 1624684498635>. National Instruments Corporation. NI DAQCard-AI-16XE-50. 2003. 9 May 2003 <http://sine.ni.com/apps/we/nioc.vp?cid= 1 070&lang=US>. National Instruments Corporation. NILabVIEW. 2003. 9 May 2003 <http://sine.ni.com/apps/we/nioc.vp?cid=1 381 &lang=US>. 73 PONTECH. PONTECH. 29 Nov 2002. 9 May 2003 <http://www.pontech.com/>. Stepperworld.com. Model SP-3/HT (Hi Torque/Hi Top-speed) Complete 3 Axis Stepper System. n.d. 9 May 2003 <http://www.stepperworld.com/>. XO. 2003. 9 May 2003 <http://www.x10.com/homepage.htm>. 74