WinCon Manual
WinCon Manual
1
Hard Real-time Performance at your Fingertips
User's Guide
Version 1.2 July 22nd, 2003
How to contact Quanser Consulting: (905) 940-3575 (905) 940-3576 80 Esna Park Drive Markham, ON Canada L3R 2K8 http://www.quanser.com http://www.wincon.quanser.com mailto://[email protected] mailto://[email protected] All Rights Reserved
2003 Quanser Consulting Inc. All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the copyright holder, except under the terms of the associated software license agreement. No part of this manual may be photocopied or reproduced in any form. The use of general descriptive names, trade names, trademarks, etc. in this publication, even if the former are not especially identified, is not to be taken as a sign that such names as understood by the Trade Marks and Merchandise Marks Act, may accordingly be used freely by anyone. Printed in Canada.
Disclaimer
While every effort has been made to ensure the accuracy and completeness of all information in this document, Quanser, Inc. assumes no liability to any party for any loss or damage caused by errors or omissions or by statements of any kind in this document, its updates, supplements, or special editions. Quanser, Inc. further assumes no liability arising out of the application or use of any product or system described herein; nor any liability for incidental or consequential damages arising from the use of this document. Quanser, Inc. disclaims all warranties regarding the information contained herein, whether expressed, implied or statutory, including implied warranties of merchandability or fitness for a particular purpose. Quanser Inc. reserves the right to make changes to this document or to the products described herein without further notice. Trademarks WinCon is a trademark of Quanser Consulting, Inc. MATLAB, Simulink and Real-Time Workshop are registered trademarks and Target Language Compiler is a trademark of The MathWorks, Inc. Windows and Visual C++ are registered trademarks of Microsoft Corporation. RTX is a registered trademark of VenturCom, Inc. Intel and Pentium are registered trademarks of Intel Corporation. Other brands and their products are trademarks or registered trademarks of their respective holders and should be noted as such.
Licensing Rules
Licensing Rules
You must acquire and dedicate a license for WinCon for each computer on which WinCon is used. Each WinCon package consists of one copy of WinCon Server and one copy of WinCon Client. If you want to run configurations that require more than one PC, you will need as many copies of WinCon. One WinCon license is required per PC on which a WinCon component is installed, whether it is WinCon Server, WinCon Client, or both. For complete details, please consult the End-User License Agreement (EULA) provided with the WinCon software.
Table of Contents
Table of Contents
Licensing Rules........................................................................................................2 About WinCon 4.1.................................................................................................13 New Features and Updates...................................................................................15 Local and Remote Configurations.......................................................................17 Local Configuration................................................................................17 Remote Configurations...........................................................................18 Installing WinCon.................................................................................................21 Uninstalling or Upgrading WinCon....................................................................23 Upgrading or Repairing WinCon..........................................................23 Uninstalling WinCon..............................................................................23 WinCon Principles of Operation.........................................................................25 WinCon Server........................................................................................25 WinCon Client.........................................................................................25 WinCon Server's Graphical Interface................................................................27 WinCon Server's File Menu Options....................................................27 WinCon Server's Client Menu Options................................................28 WinCon Server's Model Menu Options................................................28 WinCon Server's Plot Menu Options....................................................30 WinCon Server's Window Menu Options............................................30 WinCon Server's View Menu Options..................................................31 WinCon Server's Help Menu Options..................................................31 WinCon Server's Toolbar Buttons........................................................32 WinCon Server's Keyboard Shortcuts.................................................32 File Extensions Generated and Used by WinCon Server....................33 WinCon Client's Graphical Interface.................................................................35 WinCon Client's File Menu Options.....................................................36 WinCon Client's Control Menu Options..............................................36 WinCon Client's View Menu Options...................................................37 WinCon Client's Help Menu Options...................................................38 WinCon Client's Keyboard Shortcuts..................................................38 WinCon Client's Displayed Statistics....................................................38 Discrete Time Considerations..............................................................................41 Timing of Real-Time Events..................................................................41 i
Table of Contents
Choice of Sampling Period.....................................................................42 Choice of Threshold................................................................................43 Choice of Time Base...............................................................................43 Generating Real-Time Code................................................................................45 WinCon Link and WinCon Menu.........................................................45 Setting Real-Time Workshop Options .................................................47 Setting Simulink Options.......................................................................49 Real-Time Code Generation..................................................................49 Restrictions on Real-Time Code............................................................50 Calling Win32 Functions in Real-Time Code..........................50 Calling Standard C Library Functions in Real-Time Code. . .53 Using Dynamic Link Libraries in Real-Time Code.................54 Matlab Scripts.............................................................................55 The Matlab Compiler.................................................................55 Running the Real-Time Code...............................................................................57 Connecting to WinCon Client................................................................57 Connecting to the Local Client..................................................57 Connecting to a Remote Client..................................................58 Downloading the Real-Time Code.........................................................59 Running WinCon Client.........................................................................59 The Active Client....................................................................................59 The Active Model....................................................................................61 The Start/Stop All Commands...............................................................62 WinCon Task Manager..........................................................................63 WinCon Service.......................................................................................64 Plotting On-Line Data..........................................................................................65 WinCon Scope.........................................................................................65 WinCon X-Y Graph................................................................................71 WinCon Digital Meter............................................................................71 WinCon Thermometer...........................................................................73 Performance Monitoring........................................................................74 Saving On-Line Data............................................................................................75 Changing Parameters On-Line............................................................................77 WinCon Control Panel...........................................................................78 Building WinCon Control Panels..........................................................79
ii
Table of Contents
WinCon Projects...................................................................................................83 The WinCon Toolbox............................................................................................85 The Quanser Toolbox.............................................................................86 Extra Sinks..............................................................................................86 Thermometer...............................................................................87 X-Y Graph...................................................................................88 Interfacing to Hardware: The Quanser Toolbox...............................................89 Quanser Consulting MQ3 Series...........................................................90 Analog Input................................................................................90 Analog Output.............................................................................92 Digital Input................................................................................94 Digital Output.............................................................................94 Time Base....................................................................................95 Encoder Input.............................................................................96 Encoder Extras............................................................................97
Encoder Reset (level-sensitive) ..............................................97 Encoder Reset (edge-triggered)..............................................98 Encoder Reset (edge-triggered with enable).........................99
Quanser Consulting MultiQ-PCI Series.............................................100 Analog Input .............................................................................100 Analog Output...........................................................................102 Digital Input..............................................................................104 Digital Output...........................................................................105 Watchdog Timer.......................................................................106 Encoder Input...........................................................................107 Encoder Extras..........................................................................109 Quanser Consulting Q8 Series.............................................................110 Analog Input..............................................................................110 Analog Output...........................................................................112 Digital Input..............................................................................115 Digital Output...........................................................................116 Encoder Input...........................................................................117 Counter Output.........................................................................119 PWM Output.............................................................................120 Watchdog...................................................................................121 Additional Q8 Blocks................................................................122 Encoder Extras..........................................................................122 Time Bases.................................................................................123 Asynchronous Interrupts.........................................................123 Polling Interrupts......................................................................124 Status..........................................................................................124 National Instruments E-Series.............................................................126 Analog Input .............................................................................126 iii
Table of Contents
Analog Output...........................................................................130 Digital Input..............................................................................132 Digital Output...........................................................................133 Time Base..................................................................................134 Encoder Input...........................................................................135 Encoder Extras..........................................................................137 Serial Drivers.........................................................................................138 Serial Initialization ..................................................................138 Serial Output.............................................................................139 Serial Input................................................................................140 Serial Error...............................................................................142 Extra Sources........................................................................................143 Is Simulation?............................................................................143 Smooth Sine Wave....................................................................143 Sequences...................................................................................144
Enabled Sequence..................................................................145 Triggered Sequence...............................................................145 Triggered-Enabled Sequence...............................................145 Sigmoid...................................................................................146 Sigmoid (with limits).............................................................147 Triggered Sigmoid.................................................................148 Triggered Sigmoid (with limits)...........................................149 Continuous Sigmoid..............................................................149 Continuous Sigmoid (with limits)........................................150
Sigmoids.....................................................................................146
Extra Sinks............................................................................................151 Stop With Error........................................................................152 PC Speaker................................................................................152 Transformations....................................................................................154 Discretized Transfer Function ................................................154 Discretized Zero-Pole...............................................................155 Discretized State Space.............................................................155 System Transfer Function........................................................156 System Zero-Pole......................................................................156 System State-Space...................................................................157 Double to PIC Float..................................................................157 PIC Float to Double..................................................................157 To Bytes.....................................................................................157 From Bytes................................................................................158 CRS ROBOTS.......................................................................................159 CRS A465 Blocks......................................................................159
A465 Motor Pulses to Joint Angles......................................160 A465 Joint to World..............................................................160 A465 Forward Kinematics....................................................160 A465 Stance............................................................................161 A465 Inverse Kinematics......................................................161
iv
Table of Contents
A465 World to Joint..............................................................161 A465 Joint Angles to Motor Pulses......................................162
CAT5 Motor Pulses to Joint Angles....................................163 CAT5 Joint to World............................................................163 CAT5 Forward Kinematics..................................................163 CAT5 Inverse Kinematics....................................................163 CAT5 World to Joint............................................................164 CAT5 Joint Angles to Motor Pulses....................................164
Interfacing to Other Hardware...........................................................165 WinCon Scripting Commands in MATLAB....................................................167 wc_build.................................................................................................167 wc_clean.................................................................................................168 wc_close..................................................................................................168 wc_disconnect........................................................................................169 wc_download.........................................................................................169 wc_examples..........................................................................................170 wc_isrunning.........................................................................................170 wc_newplot............................................................................................171 wc_open..................................................................................................171 wc_openplot...........................................................................................172 wc_path..................................................................................................172 wc_refresh..............................................................................................173 wc_run....................................................................................................174 wc_save..................................................................................................174 wc_saveplot............................................................................................174 wc_select................................................................................................175 wc_setoptions.........................................................................................176 wc_start..................................................................................................177 wc_stop...................................................................................................177 wc_update..............................................................................................178 Additional Plot Scripting Commands.................................................178 Model Examples..................................................................................................181 WinCon Demonstrations Window......................................................181 Analog Loopback Example: q_a_lpbk.mdl........................................184 Proportional Control Example: q_p.mdl............................................188 Script Example: script_q_p.m.............................................................193
Table of Contents
Troubleshooting..................................................................................................197 Scope Disappears When Stopping Controller....................................197 Problems Using Visual C++ 6.0 SP4-SP5 and RTX 4.3.2.1...............197 Controller Fails to Load.......................................................................197 WinCon Menu Missing from Simulink Diagram...............................199 Simulink Diagram Fails to Compile....................................................199 Scope Fails to Plot Signal.....................................................................199 MultiQ-3 Time-Base Block Doesn't Work..........................................199 Time-Base Block Doesn't Work...........................................................200 Cannot Achieve 10kHz Sampling Rate...............................................202 WinCon Stops Responding..................................................................202 Obtaining Support................................................................................203 Index.....................................................................................................................204
vi
List of Figures
Table of Figures
Figure 1 Local configuration: 1 PC................................................................................17 Figure 2 Remote configuration #1: 2 PC's.....................................................................18 Figure 3 Remote configuration # 2: N PC's...................................................................19 Figure 4 Remove Shared File? Window........................................................................24 Figure 5 WinCon Server Graphical Interface...............................................................27 Figure 6 WinCon Client Graphical Interface...............................................................35 Figure 7 Timing of Real-Time Events............................................................................42 Figure 8 WinCon Link Icon............................................................................................45 Figure 9 WinCon Menu in Simulink..............................................................................45 Figure 10 Real-Time Workshop Settings Dialog Box...................................................47 Figure 11 Real-Time Workshop's Solver Tab Options................................................48 Figure 12 External Target Interface..............................................................................49 Figure 13 Generating the Real-Time Code....................................................................50 Figure 14 Connect to the Local WinCon Client............................................................57 Figure 15 WinCon Server Hierarchy.............................................................................60 Figure 16 WinCon Task Manager..................................................................................63 Figure 17 WinCon Scope.................................................................................................66 Figure 18 WinCon Scope in Fixed Mode.......................................................................70 Figure 19 WinCon X-Y Graph with Trail Effect..........................................................71 Figure 20 WinCon Digital Meter....................................................................................72 Figure 21 WinCon Thermometer...................................................................................73 Figure 22 Monitoring of the Actual Sampling Time.....................................................74 Figure 23 WinCon Control Panel...................................................................................78 Figure 24 The WinCon Toolbox.....................................................................................85 Figure 25 The WinCon and Quanser Toolboxes within the Simulink Library.........86 Figure 26 The WinCon Toolbox's Extra Sinks.............................................................87 Figure 27 Thermometer Input Parameters...................................................................87 Figure 28 X-Y Graph Input Parameters.......................................................................88 Figure 29 The Quanser Toolbox.....................................................................................89 Figure 30 MultiQ-3 Library............................................................................................90 Figure 31 Analog Input parameters for MQ3...............................................................91 Figure 32 Analog Output parameters for MQ3............................................................93 Figure 33 Time Base parameters for MQ3....................................................................95 vii
List of Figures
Figure 34 Encoder Input parameters for MQ3.............................................................96 Figure 35 Encoder Extras for MQ3...............................................................................97 Figure 36 Encoder Reset (level-sensitive) parameters for MQ3..................................98 Figure 37 Encoder Reset (edge-triggered) parameters for MQ3................................99 Figure 38 MultiQ-PCI Library.....................................................................................100 Figure 39 Analog Input parameters for MultiQ-PCI.................................................101 Figure 40 Analog Output parameters for MultiQ-PCI..............................................103 Figure 41 Digital Input parameters for MultiQ-PCI..................................................105 Figure 42 Digital Output parameters for MultiQ-PCI...............................................106 Figure 43 Watchdog Timer parameters for MultiQ-PCI..........................................107 Figure 44 Encoder Input parameters for MultiQ-PCI...............................................108 Figure 45 Q8 Library....................................................................................................110 Figure 46 Q8 Analog Input parameters......................................................................111 Figure 47 Q8 Analog Output parameters...................................................................114 Figure 48 Q8 Digital Input parameters......................................................................115 Figure 49 Q8 Digital Output parameters....................................................................116 Figure 50 Q8 Encoder Input parameters....................................................................118 Figure 51 - Q8 Counter Output parameters................................................................119 Figure 52 - Q8 PWM Output parameters....................................................................120 Figure 53 - Q8 Watchdog parameters..........................................................................121 Figure 54 National Instruments PCI E-Series Library..............................................126 Figure 55 Analog Input parameters for E-Series........................................................127 Figure 56 Analog Output parameters for E-Series.....................................................131 Figure 57 Digital Input parameters for E-Series........................................................133 Figure 58 Digital Output parameters for E-Series.....................................................134 Figure 59 Time Base parameters for E-Series............................................................135 Figure 60 Encoder Input parameters for E-Series.....................................................136 Figure 61 Serial Drivers................................................................................................138 Figure 62 Serial Initialization parameters...................................................................138 Figure 63 Serial Output parameters............................................................................139 Figure 64 Serial Input parameters...............................................................................140 Figure 65 Serial Error parameters...............................................................................142 Figure 66 Extra Sources blocks....................................................................................143 viii
List of Figures
Figure 67 Smooth Sine Wave Parameters...................................................................144 Figure 68 Sequences blocks...........................................................................................144 Figure 69 Enabled Sequence Parameters....................................................................145 Figure 70 Triggered Sequence Parameters.................................................................145 Figure 71 Triggered-Enabled Sequence Parameters..................................................145 Figure 72 Sigmoid blocks..............................................................................................146 Figure 73 Sigmoid Parameters.....................................................................................147 Figure 74 Sigmoid (with limits) Block Parameters.....................................................148 Figure 75 Triggered Sigmoid Parameters...................................................................148 Figure 76 Triggered Sigmoid (with limits) Block Parameters...................................149 Figure 77 Continuous Sigmoid Block Parameters......................................................150 Figure 78 Continuous Sigmoid (with limits) Block Parameters................................151 Figure 79 Extra Sinks....................................................................................................151 Figure 80 Stop With Error parameters.......................................................................152 Figure 81 PC Speaker parameters...............................................................................152 Figure 82 Transformations Library.............................................................................154 Figure 83 Discretized Transfer Function parameters................................................154 Figure 84 Discretized Zero-Pole Block parameters....................................................155 Figure 85 Discretized State Space Block parameters.................................................156 Figure 86 System Transfer Block parameters............................................................156 Figure 87 System Zero-Pole Block parameters...........................................................156 Figure 88 System State-Space Block parameters........................................................157 Figure 89 To Bytes parameters.....................................................................................157 Figure 90 From Bytes parameters................................................................................158 Figure 91 CRS Robots Libraries..................................................................................159 Figure 92 CRS A465 Blocks..........................................................................................159 Figure 93 CRS Catalyst-5 Blocks.................................................................................163 Figure 94 WinCon Demonstrations Window..............................................................181 Figure 95 Library of Demonstrations for Quanser's MultiQ-PCI board.................182 Figure 96 Loopback Wiring Configuration.................................................................184 Figure 97 Analog Loopback Model..............................................................................185 Figure 98 Setting the default WinCon options............................................................185 Figure 99 Building the Real-Time Code......................................................................186 ix
List of Figures
Figure 100 WinCon Server...........................................................................................186 Figure 101 Clipped Sinosoid.........................................................................................187 Figure 102 WinCon Scope Data Saved and Plotted in MATLAB.............................188 Figure 103 SRV02-E Connections................................................................................189 Figure 104 Proportional Controller Model in Simulink............................................190 Figure 105 SRV02-E Sub-block....................................................................................190 Figure 106 SRV02 Position Response with Two Different Kp's................................191 Figure 107 WinCon Control Panel...............................................................................192 Figure 108 Proportional Controller Model used by the WinCon Script..................193 Figure 109 SRV02 Position Response To Incremental Changes of Kp.....................196 Figure 110 Converting Windows drivers to RTX.......................................................201
List of Tables
List of Tables
Table 1 WinCon Server's File Menu Options...............................................................27 Table 2 WinCon Server's Client Menu Options...........................................................28 Table 3 WinCon Server's Model Menu Options...........................................................29 Table 4 WinCon Server's Plot Menu Options...............................................................30 Table 5 WinCon Server's Window Menu Options.......................................................30 Table 6 WinCon Server's View Menu Options.............................................................31 Table 7 WinCon Server's Help Menu Options.............................................................31 Table 8 WinCon Server's Interface Icons.....................................................................32 Table 9 WinCon Server's Keyboard Shortcuts.............................................................33 Table 10 File Extensions used by WinCon Server........................................................33 Table 11 WinCon Client's File Menu Options..............................................................36 Table 12 WinCon Client's Control Menu Options.......................................................37 Table 13 WinCon Client's View Menu Options............................................................37 Table 14 WinCon Client's Help Menu Options............................................................38 Table 15 WinCon Client's Keyboard Shortcuts............................................................38 Table 16 WinCon Client's Displayed Statistics.............................................................39 Table 17 WinCon Menu Options....................................................................................46 Table 18 Real-Time Workshop Settings........................................................................48 Table 19 Win32 functions supported on 2000/XP.........................................................52 Table 20 Standard C library functions supported under 2000/XP.............................54 Table 21 WinCon Scope's File Menu Options...............................................................67 Table 22 WinCon Scope's Update Menu Options.........................................................67 Table 23 WinCon Scope's Axis Menu Options.............................................................69 Table 24 WinCon Scope's Window Menu Options.......................................................70 Table 25 WinCon Digital Meter's Number Menu Options..........................................72 Table 26 WinCon Digital Meter's Window Menu Options..........................................72 Table 27 WinCon Thermometer's Settings Menu Options..........................................73 Table 28 Non-Realtime Simulink Blocks and WinCon Equivalents...........................75 Table 29 WinCon Scope and X-Y Graph Data Saving Capabilities...........................76 Table 30 Control Panel's Window Menu Options........................................................79 Table 31 Control Panel's Control Menu Options.........................................................80 Table 32 Control Panel's Available Controls................................................................81 xi
List of Tables
Table 33 Control Panel's Tools Menu Options.............................................................82 Table 34 E-Series Differential Analog Input Channels..............................................128 Table 35 Serial Input errors.........................................................................................142 Table 36 Representation of the CRS A465 Stance......................................................161 Table 37 WinCon plot scripting commands................................................................179 Table 38 Hardware-Specific Example Directories.....................................................182
xii
13
15
16
Local Configuration
The local configuration is shown below in Figure 1. The data acquisition and control board (DACB) is used to interface the real-time code to the plant to be controlled. The user interacts with the real-time code via either WinCon Server or the Simulink diagram. Data from the running controller may be plotted in real-time on the WinCon scopes and changing values on the Simulink diagram automatically changes the corresponding parameters in the real-time code. The real-time code, i.e. WinCon Client, runs on the same PC. However, the real-time code takes precedence over everything else, so hard real-time performance is still achieved!
17
The advantage of these configurations is that PC's #2 to #(N-1) are not burdened by any other tasks. Thus, you can achieve the fastest possible performance in these configurations. You could, of course, get similar performance in the local configuration because the realtime code takes precedence over everything else but for very fast sampling rates the controller would consume all the CPU time, leaving no time left for plotting or changing parameters! The remote configuration avoids this problem by moving the user interface portion to another machine.
18
Remote Configurations
These configurations are also convenient for remote monitoring and tuning of the plants. For example, WinCon Server could be running in a remote office while the WinCon Clients are located in a factory or laboratory setting.
19
WinCon Installation
A comprehensive Installation Guide has been provided to you. The Installation Guide covers Local Configuration installation. Please locate either the hard copy or the digital copy on the WinCon CD. Please follow ALL the instructions.
21
Uninstalling WinCon
Full Administrator privileges are required to uninstall (and re-install) WinCon. To uninstall all the different components of the WinCon software, follow the steps described below: Step 1. Exit WinCon Link. On the PC running WinCon Server, the WinCon Link icon is found in the system tray (near the clock). To terminate WinCon Link, either left-click on the icon to open its window and select Exit, or right-click on it and choose Exit from the context menu that appears. Close all open applications. Step 2. Uninstalling WinCon Server. On the PC running WinCon Server, open the Start | Settings | Control Panel | Add/Remove Programs window. Select, for example, WinCon Server 3.2, and click on the Change/Remove button to remove it from that computer. Click Yes to the Confirm File Deletion window to proceed with the removal of WinCon Server. If a warning message appears indicating that WinCon Link is still running, abort the WinCon Server uninstall, close the Add/Remove Programs window and Control Panel and return to Step 1, to first shut down WinCon Link, before proceeding any further. Step 3. Uninstalling WinCon Controls. On the PC running WinCon Controls, (the same PC as WinCon Server), open the Start | Settings | Control Panel | Add/Remove Programs window. Select, for example, WinCon Controls 3.2, and click on the Change/Remove button to remove it from that computer. Click Yes to the Confirm File Deletion window to proceed with the removal of WinCon Controls. Click Yes To All in the Remove Shared File? warning window, as shown in Figure 4, to remove all of files corresponding to Control Panel widgets, namely: QVSlider.ocx, QEdit.ocx, QKnob.ocx, QSelect.ocx, QSlider.ocx,
23
Uninstalling WinCon
QButton.ocx, QText.ocx, and QPicture.ocx. Also click Yes to the Remove Shared File? confirmation window. The uninstall will then complete automatically. Step 4. Reboot. To finish the WinCon Server uninstall, it is recommended that the computer be restarted. If the uninstaller indicates that not all files could be removed, then the computer must be rebooted prior to installing another version of WinCon Server. Otherwise, the new installation may be corrupted because the uninstaller removes problematic files the first time the computer is restarted. Step 5. Uninstalling WinCon Client. On the PC running WinCon Client (possibly the same PC as WinCon Server), open the Start | Settings | Control Panel | Add/Remove Programs window. Select, for example, WinCon Client 3.2, and click on the Change/Remove button to remove it from the computer. Click Yes to the Confirm File Deletion window to proceed with the removal of WinCon Client.
24
WinCon Client
WinCon Client is the real-time software component that runs the code generated from the Simulink diagram at the sampling rate specified. It can perform the following tasks: Reception of the controller code in the form of a WinCon Controller Library file (.wcl) from WinCon Server. Running the controller in real-time. Maintaining communications with any connected WinCon Servers. Streaming real-time data to any WinCon Server(s) requesting it. Management of a user-defined threshold setting to control the maximum amount of CPU time allotted to the real-time code.
25
27
WinCon Server's Client Menu Options WinCon Server's Client Menu Options
The WinCon Client information relevant to the Server is managed by using WinCon Server's Client menu options, which are enumerated in Table 2. Client Menu Option Connect... Disconnect Close on Exit Threshold... Network... [Clients List] Description Connect to a desired client. Enter the name of the remote machine or its IP address and remote port. Disconnect from the primary WinCon Client. Close the local Client upon exit from the Server. (A local Client is run automatically by the Server when needed.) Set the CPU time Threshold for the current Client. Launches Microsoft Windows' Network dialog interface in order to obtain information about the network. List of Clients that are currently connected to this Server. A check mark (i.e. ) at the beginning of the Client's address indicates that this Client is the currently active Client. All operations act upon the currently active Client only, with the exception of the Start All and Stop All commands. A star (i.e. *) at the end of the name indicates that this is a Secondary Server for that Client. A secondary server cannot change controller parameters.
Recent Clients List of the last three Clients to which the Server was connected.
28
Reload Build
[Models List] List controllers which are loaded into Clients. A controller has a check mark (i.e. ) if it is the currently active model. All operations refer to the currently active model, on the currently active Client, with the exception of the Start All and Stop All commands.
Table 3 WinCon Server's Model Menu Options
29
WinCon Server's Plot Menu Options WinCon Server's Plot Menu Options
The WinCon real-time plots are managed through use of the WinCon Server's Plot menu, whose commands are enumerated in Table 4. For detailed information on the plotting capabilities of WinCon, refer to section Plotting On-Line Data. Plot Menu Option New Description Open a new plot. Possible types are: Scope, X-Y Graph, Digital Meter, and Thermometer. The display does not need to be defined in the Simulink diagram. Open an existing Scope, Digital Meter, or Thermometer defined in the Simulink diagram. Open the Plot Properties dialog for setting the default properties of the Scope, X-Y Graph, Digital Meter and Thermometer. Close all open plots.
External Interface Open the External Interface Window (EIW) to allow other Window applications to connect to WinCon, and for external sinks and sources. [Displays List] Navigate through the different open displays.
Table 5 WinCon Server's Window Menu Options
30
WinCon Server's View Menu Options WinCon Server's View Menu Options
The appearance of the WinCon Server window is controlled through using the WinCon Server's View menu options, which are listed and described in Table 6. View Menu Option Toolbar
Table 6 WinCon Server's View Menu Options
31
Launch Simulink. Open the Simulink diagram associated with the current model, if any. Launch MATLAB. If a model is currently opened, start MATLAB in that model's directory. Open a Plot which is defined directly in the current (Simulink) model, through the use of a Scope, Display, Thermometer or X-Y Graph block.
32
33
35
WinCon Client's File Menu Options WinCon Client's File Menu Options
The WinCon Client's File menu options are listed and described in Table 11. File Menu Option Open... Close Servers... Network... Description Open a WinCon controller (i.e. a .wcl file). Close the current WinCon controller. The controller is stopped prior to unloading it from the real-time kernel. Display a list of the WinCon Servers connected. Obtain network information for the computer on which WinCon Client is running. It launches Microsoft Windows' Network dialog interface. Set the TCP/IP port used for Client-Server communications. The default port is 17255. Only change the port number if you are running other software that interferes with the default port. Display the model's 128-bit checksum. It is used to verify that the loaded WinCon controller matches its associated Simulink diagram. Exit the WinCon Client. The controller is stopped, if necessary, prior to exit.
Port...
Checksum
[Recent Controllers List] List of recently loaded real-time controllers (i.e. .wcl files). Exit
36
WinCon Client's Control Menu Options WinCon Client's Control Menu Options
The WinCon Client's Control menu options are listed and described below, in Table 12. Control Menu Option Threshold... Description Set the Threshold, which is the minimum processor time allotted to foreground tasks. If the running controller uses too much CPU time, WinCon Client stops the controller. The threshold value is saved whenever the Client is exited. It is not saved with the project. Note that device drivers also steal processor time from foreground tasks. Hence, the threshold does not always reflect the processor time used up the controller alone, and it may be necessary to disable threshold checking by setting the threshold to zero on some systems. Frame rate for streaming data to WinCon Server [Hz]. WinCon Client streams data in "frames" to make data streaming more efficient over a network. This rate is different from the sampling rate at which data is collected, which is dependent on the sampling rate of the controller.
Frame Rate...
Measure Performance... Toggles a WinCon option that is used to Measure Performance of the real-time controller. With this option left on (default), the WinCon client will display real-time data such as Sampling Interval, Average Period, Max. Computation Time and Min. Foreground Time. With this option not selected, the latency of your real-time controller will improve as it will reduce the amount of computational overhead. Start Stop Start the real-time controller. Stop the real-time controller.
37
Description
38
Sample time
Max. Computation Time Maximum computation time, TC_max, observed during the controller run. This gives a measure of the worst case computation delay. Min. Foreground Time Minimum foreground time, TF_min, observed during the running of the controller.
39
41
42
43
44
45
Open Plot...
Options...
46
The following Real-Time Workshop settings, shown in Table 18, must be set (and saved) in the Simulink diagram for which you wish to generate real-time code. Improper settings will result in the failure of WinCon to generate real-time code.
47
System target file Select the Target Language Compiler file to be wincon.tlc, (Real-Time Workshop Tab) as shown in Figure 10. The wincon.tlc file can be found, for example, under: C:\MATLAB6p1\rtw\c\Wincon\. Template makefile To generate code for a WinCon Client running under (Real-Time Workshop Tab) Windows 2000/XP, choose: nt_msvc.tmf, as shown in Figure 10. Make command Choose make_wc, as shown in Figure 10. (Real-Time Workshop Tab) Solver Fixed-Step Size (Solver Tab) Solver options (Solver Tab) Solver Mode (Solver tab)
Table 18 Real-Time Workshop Settings
Set to the desired sampling period TS (in seconds), as shown in Figure 11. Note that the real-time code will have to be rebuilt if the sampling period is changed. The choice of integration method depends, in some cases, on the controller. Only fixed step integration methods are supported. The ode1 (Euler) method is typically used. Set to Single-tasking.
48
49
The Build procedure generates a WinCon Controller Library (i.e. .wcl) file. When code generation and compilation is complete, a message appears in the MATLAB window indicating that a wcl file has been successfully created. For example, for the q_sine model, the message that appears is:
### Created executable: q_sine.wcl ### Successful completion of Real-Time Workshop build procedure for model: q_sine
After successful completion of the Build procedure, WinCon Server automatically downloads the generated controller file (i.e. .wcl) to WinCon Client, where it can be executed. If required, please refer to section Connecting to WinCon Client for instructions on how to connect WinCon Server to different WinCon Clients.
50
51
52
53
Det. Function Y Y Y Y Y Y Y Y Y Y Y N Y Y Y Y sscanf strcat strchr strcmp strcpy* strcspn strerror strlen strncat strncmp* strncpy* strpbrk strrchr strspn strstr strtod
Det. N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Function wcslen wcsncat wcsncmp wcspbrk wcsrchr wcsspn wcsstr wcstod wcstol wcstoul wprintf wtof wtoi _controlfp _fpreset
*
Det. Y Y Y Y Y Y Y Y Y Y Y N Y Y N N
wcsncpy*
memmove*
54
Matlab Scripts
While MATLAB scripts may be used to control WinCon, they cannot be used in real-time code. MATLAB is an interpretive language and cannot run in real-time. Furthermore, the MATLAB engine and numerical libraries have not been compiled for the real-time environment, so neither is not possible to call MATLAB from real-time code. Thus, do not use the MATLAB Fcn block from Functions & Tables in a Simulink diagram that will be used to generate real-time code.
55
If WinCon Server does not already have a Client connection, opening a model in WinCon Server or generating real-time code from the Simulink diagram (i.e. using the WinCon | Build command) will automatically launch and connect to the local WinCon Client.
57
58
59
Plot #1 Client #1 Server Client #2* Model #1 Plot #2 Plot #3 Plot #4 Plot #5
Each WinCon Server may connect to more than one WinCon Client. Each Client may also connect to several Servers, but, in this example, a single Server is connected to two Clients, Client #1 and Client #2. Client #2 has a check mark beside it indicating that it is the active Client. The WinCon Server interface consists of a single toolbar and menu bar. The interface would get cumbersome quite quickly if a toolbar and menu were provided for each model, on each Client. In this case, there would be six separate toolbars! Instead, WinCon Server utilizes the notion of an active Client and active model. In Figure 15, the Server is connected to two Clients. Client #2 is the active Client. There is only one active Client at a time. The term "active" does not imply that Client #1 is not running or is somehow "asleep". Controllers may be running simultaneously on both Clients, streaming data to different plots at the same time. The active Client is the Client to which commands from the Server refer. For example, selecting the Threshold menu item in WinCon Server will change the threshold setting of Client #2, since Client #2 is the active Client. Similarly, choosing Client | Disconnect from the Server's menu will disconnect from Client #2. To change the active Client, simply select another Client from the list of Clients under the Server's Client menu. The selected Client will become the active Client. Changing the active Client does not change the status of the real-time code loaded into other connected Clients. It simply changes the Client to which commands from the Client menu refer.
60
61
62
63
64
WinCon Scope
A typical WinCon Scope is depicted in Figure 28. It displays the data collected from the running code in real-time. Refer to section Plotting On-Line Data to see how to open, or create, a WinCon Scope.
65
WinCon Scope
As seen in Figure 28, the default plot background is black. However, to preserve ink, plots printed from WinCon Scopes (as well as WinCon X-Y Graphs) always have a white background with black text and lines. Table 21 describes how to print the content of a WinCon Scope. The Scope legend, corresponding to the different signals being plotted, is always displayed in a separate window, as illustrated in Figure 28. Select Window | Legend from the WinCon Scope menu bar to show the legend window, as explained in Table 24. To avoid having an excessively wide legend, the variable/signal names, from the Simulink model, are intelligently truncated to fit within the legend window. In many cases, ellipses indicate what part of the name was removed (typically, parts of the intervening subsystem name). Only in the case in which the variable/block name itself (i.e. without the hierarchy) is extremely long, will the name itself be truncated. The WinCon Scope colour and font toolbar uses the standard Microsoft Windows colour chooser and font chooser dialogs, respectively, so that they can be set by the user. A quick and easy way to include the content of a WinCon Scope into a document is to use the Edit | Copy item from the Scope menu bar. This operation copies a bitmap of the current plot to the clipboard, for subsequent pasting.
66
WinCon Scope
For plotting on a Scope, you can choose the output(s) of any block(s) of the Simulink diagram (corresponding to the running code) by selecting File | Variables... from the WinCon Scope menu bar. Table 21, below, gives a description of all the WinCon Scope's File menu options. File Menu Option Save Variables... Print... Close Description Open a submenu to save the acquired data, as explained in Section Saving On-Line Data. Open a selection list from which to choose the block(s) (from the Simulink diagram) whose output(s) you desire to plot. Print the WinCon Scope content, with a white background and black text and lines. Close the WinCon Scope.
The WinCon Scope's Update menu options are listed and described below, in Table 22. Update Menu Option Real-Time Freeze Plot Description When checked, this option makes the plot return to Time 0 at the end of a trace and restart drawing the new data. If selected when the real-time plot is running, this option makes the plot trace immediately stop (freeze). The full extent of the sampled data is plotted. This mode is referred to as fixed mode. If selected when the real-time plot is not running, the plot enters fixed sweep mode or one-shot mode. In this case, the plot will collect one buffer full of data when the controller is started, and then freeze. Freeze All Plots When checked, this option applies the "Freeze Plot" command (described above) to all plots at the same time. Frequency ... Open a dialog box to select the plot sampling frequency (or period). The plot sampling frequency is the frequency at which data is decimated for real-time display only. It is used for efficient plotting and does not affect the data displayed when the plot is frozen or saved. When a plot is frozen or saved, the data is not decimated, but reflects data collected at the controller sampling frequency (different from the plot frequency). Duration of time for which data is buffered for each plot.
Buffer ...
67
WinCon Scope
It is important to note that the plotting on WinCon Scopes is decimated, but only in realtime mode. In other words, the collected data is automatically displayed at a rate that minimizes the number of pixels to be drawn. This rate is known as the plot sampling frequency, or decimation frequency. This decimation is done deliberately in order to ensure that the plots can keep up with the real-time data stream and to maximize the number of plots that can be opened at any instant. However, this decimation may result in plot aliasing during real-time display. Therefore, you must be careful in selecting the time scale of the data that is displayed in real-time mode, so that the plots are not misinterpreted. When WinCon Client is decimating the data and streaming it to the WinCon Scopes, it also collects data for the save variable at the controller sampling frequency. For example, suppose the controller sampling frequency is 1kHz and the plot sampling frequency is 200Hz. WinCon Client will collect data every 1 millisecond, but only send every fifth data point to the WinCon Scope during real-time plotting. However, as soon as the plot is frozen and its data saved, WinCon Client transmits all the data, collected at 1kHz, to the Scope. Thus, as soon as a plot is frozen, it redraws its display with all the available data and the effects of plot aliasing at the plot sampling frequency, if any, disappear. The same process occurs when the plot buffer is saved. All the available data is saved to disk, collected at the 1kHz sampling frequency. Hence, no data is lost due to the temporary decimation during real-time plotting. Since the amount of data displayed on a plot can be quite large (hundreds of thousands of points), WinCon Scopes perform on-the-fly data compression when plotting, so that (very) large numbers of data points are handled quickly and efficiently. The WinCon Scope's Axis menu options are listed and described below, in Table 23. They allow the user to change the plot axes. Axis Menu Option Auto-Scaled Description When checked, this option automatically scales the vertical (i.e. Y) axis of the plot at the end of each sweep, according to the data collected during the previous sweep. When checked, this option fixes the scale of the vertical (i.e. Y) axis of the plot. Auto-scaling is not performed at the end of each sweep.
Fixed
Auto-Scale Range... Open a dialog box to set the minimum Y range used during autoscaling, so that the Y range does not go to zero for constant signals. Fixed Range... Open a dialog box to set the range of the fixed Y axis.
68
WinCon Scope
Axis Menu Option Time... Description Open a dialog box to set the time interval for the time axis. This Time frame cannot exceed the Buffer duration defined in Table 22. In fixed mode or fixed sweep mode, a Time interval less than the Buffer length enables a scroll bar which allows the user to examine the data more closely, as shown in Figure 18. When checked, it adds major grid lines to the axes.
Grid
In both fixed modes (namely the fixed sweep mode and the fixed mode, as defined in Table 22), the data plotted on the Scope is not decimated and every point that was collected (at the sampling frequency of the real-time code) is drawn. In fixed sweep mode, one buffer's worth of data is collected from WinCon Client (i.e. real-time code) and displayed on the plot. To examine that data closely, the timescale on the plot can be changed by using the Axis | Time... item from the Scope menu bar, as mentioned in Table 23. A time frame strictly smaller than the buffer length results in the plot being magnified for the time axis. A scroll bar also appears at the top of the Scope to allow the entire buffer of collected data to be navigated, as pictured in Figure 18. By dragging the slider on the top of the graph, the user may examine the collected data in detail.
69
WinCon Scope
The WinCon Scope's Window menu options are listed and described below, in Table 24. Window Menu Option Always on top Legend Description Select whether you want the WinCon Scope plot window to stay on top of all other windows. Open a window containing the legend information. You can change line colors, used to trace signals, by clicking on the corresponding legend name.
70
In real-time mode, the x-y plot erases itself at the end of the buffer of collected data, unless the Axis | Trail item from the WinCon X-Y Graph menu bar is selected. In this case, the XY plot leaves a trail, as depicated in Figure 19. The WinCon X-Y Graph interface and functionality are very similar to the operation of the WinCon Scope, described in section WinCon Scope.
71
The WinCon Digital Meter's Number menu options are enumerate in Table 25 below. Number Menu Option Decimal Places... Use Segments Description Open a dialog box to select, automatically or manually, the number of decimal places. This option sets the accuracy of the display. If checked, print each digit using 7 segments. Otherwise, each digit is printed according to the selected Text Font from the toolbar. If checked, use decimal format instead of scientific notation.
Scientific Notation If checked, use scientific notation instead of decimal format. Decimal Format
Table 25 WinCon Digital Meter's Number Menu Options
The value displayed within the WinCon Digital Meter window can also be displaced. To do so, move the mouse cursor over the displayed number. When the mouse cursor changes to a horizontal double arrow (similar to ), left click on the display and drag the mouse left or right. The digits will move also. The WinCon Digital Meter's Window menu options are listed in Table 26 below. Window Menu Option Always On Top Hide Menu Hide Toolbar Description Select whether you want the WinCon Digital Meter window to stay on top of all other windows or not. Show or hide the Digital Meter's menu bar. Show or hide the Digital Meter's toollbar.
72
The WinCon Thermometer's Settings menu options are explained below in Table 27. Settings Menu Option Range... Description Open a dialog window to set the thermometer range (i.e. minimum and maximum values).
Thermometer Colours... Open the standard Microsoft Windows Color selection window to choose the thermometer colour.
Table 27 WinCon Thermometer's Settings Menu Options
73
Another important performance parameter is the computation delay (i.e. TC). It shows how long it takes the PC to execute the real-time controller code at every sample. Knowing the maximum value for TC allows the user to determine the fastest sampling frequency possible for that particular controller on that particular PC. Specifically, knowing the maximum computation delay Max(TC) and wishing to keep a minimum time Min(TF) for foreground tasks results in the following fastest sampling rate possible: FMAX = 1 / ( Min(TF) + Max(Tc) ) This maximum computation delay, Max(TC), can also be monitored in real-time on a WinCon display and is labelled Maximum Computation Time under the .performance node of the variable list in, for example, the WinCon Client window.
74
The on-line data being saved from a WinCon Scope or a WinCon X-Y Graph is not decimated. The sampling frequency for the real-time code is also the frequency at which the selected data is acquired by the WinCon Scope or X-Y Graph buffer. Therefore, you should ensure that the buffer duration of your WinCon Scope or X-Y Graph is long enough to accommodate your data acquisition needs. The buffer duration can be accessed through the Update | Buffer... option from the WinCon Scope or X-Y Graph menu bar, as specified in Table 22. WinCon Scopes are optimized for handling large quantities of data and thus are the preferred option for saving data. WinCon Scope and X-Y Graph offer three different ways to save on-line data. These saving options are described below, in Table 29. They are listed in a sub-menu of the File | Save item from the WinCon Scope or X-Y Graph menu bar.
75
Save As MAT-file... This command saves the buffered data to a MAT-file (i.e. a binary file with a .mat extension) of the user-selected name. That MATfile can then be loaded into the MATLAB workspace by using the MATLAB load command. The variable names of the saved data are constructed from the model name and the name of the block outputs that you had selected (e.g. q_sine_Scope). Save To Workspace The result of this is equivalent to saving the desired data to a MATfile first, and then loading it into the MATLAB workspace.
Table 29 WinCon Scope and X-Y Graph Data Saving Capabilities
76
77
WinCon Control Panels accept ActiveX controls. The controls, like WinCon displays, are saved as part of a WinCon Project, as described in section WinCon Projects, below, together with an ActiveX file (having a .ocp extension). Like WinCon displays, WinCon Control Panels also re-associate their variables/parameters by name when loading a WinCon project or when the real-time code is reloaded (e.g. because of a rebuild). Hence, it is possible to change the Simulink model and have the Control Panel(s), as well as the display(s), work when you reload a previous WinCon project and/or newly-generated real-time code (i.e. .wcl file), as long as the associated variable names remain unchanged. WinCon Server 4.1 also has Control Panels that write their current variable values to the controller when a project is loaded or the model is rebuilt. Therefore, WinCon Control Panels set the initial parameter values in the controller when loaded, instead of the other way around. CAUTION: The drawback to this approach can appear in the case of a single WinCon Client (e.g. unique experiment) / multiple WinCon Server (e.g. multiple student) configuration. In this remote configuration, WinCon Projects with different Control Panels
78
Use the menu option Control | Insert Control to start the insertion process, as explained in Table 31 below, whichs enumerates the Control Panel's Control menu options. Note that these menu options are only available if the WinCon Control Panel is in Design Mode. The WinCon Control Panel's Control menu allows the user to configure the behaviour (e.g. associated variable, default value) and the appearance (e.g. label, colour) of the supplied control widgets (listed in Table 32).
79
Delete
About... Properties...
Associate Variable... Open the Model Parameters selection window, in which the variable to (re-)associate with the selected control is chosen. This variable must be a scalar, i.e. of size (1,1). To do this, ensure that the proper control, for which you wish to create or change the variable association, has been selected. To select a control, click on it when the Control Panel is in Design Mode.
Table 31 Control Panel's Control Menu Options
The ActiveX controls currently available to WinCon Control Panels are described below, in Table 32.
80
Once all the desired controls have been inserted and configured in the Control Panel, their size and location still needs to be set. To move an individual control, select it (by left-clicking on it) and drag it to the desired location on the Control Panel, and release the mouse button. To move a group of controls, select the desired multiple controls, drag them to their desired new location on the Control Panel, and release the mouse button. To select multiple controls, hold the Ctrl key and click on the desired controls to select, when the Control Panel is in Design Mode. To size an individual control, select it and move your mouse cursor to one of its corners or edges so that the resize cursor appears. Left click on the corner or edge and drag the mouse to modify the size of the control. Release the mouse when the control is the desired size. To size and align multiple controls relatively to each other, the WinCon Control Panel's Tools menu items should be used. Note that these menu options are only available if the WinCon Control Panel is in Design Mode and multiple controls have been selected. The control selected first acts as the reference. The Control Panel's Tools menu options are listed and described in Table 33 below.
81
If you wish to to start over and clear the Control Panel of all of its controls, select File | Clear from the Control Panel menu bar. Right-clicking on a WinCon Control Panel gives you quick access to the most useful menu options for inserting and/or modifying controls, otherwise only available though the Control Panel's menu bar. Once you are satisfied with your newly designed Control Panel, exit the Design Mode by de-selecting the Window | Design Mode item from the Control Panel menu bar, as described in Table 30. The WinCon Control Panel now allows you to interact on-the-fly with the selected parameters of your real-time code (e.g. controller). Depending on your requirements, you may then re-iterate the control insertion/editing process as many times as necessary.
82
83
85
Figure 25 The WinCon and Quanser Toolboxes within the Simulink Library
Extra Sinks
Sinks are Simulink blocks, like Scopes, that take an input but generally do not have output ports. Quanser Consulting provides additional sinks to enhance the Simulink environment.
86
Extra Sinks
Double-click on the Extra Sinks icon in the WinCon Toolbox, wctools, to access these sinks. The extra sinks are illustrated in Figure 26. Two sinks are currently provided: the Thermometer and the X-Y Graph blocks.
Thermometer
The Thermometer block defines a thermometer display for WinCon, similar to that described in section WinCon Thermometer. The dialog box of the Thermometer block is shown in Figure 27. It lets the user set the maximum and minimum thermometer values to be used when the Thermometer is opened in WinCon Server. The Thermometer will appear in the plot list when the Plot button is pressed on the WinCon Server toolbar.
87
Extra Sinks
X-Y Graph
The X-Y Graph block defines an X-Y Graph display for WinCon, similar to that described in section WinCon X-Y Graph. The dialog box of the X-Y Graph block is shown in Figure 94. It lets the user set the range of the X and Y axes when the X-Y Graph is opened in WinCon Server. The X-Y Graph will appear in the plot list when the Plot button is pressed on the WinCon Server toolbar.
88
Interfacing to Hardware: The Quanser Toolbox Interfacing to Hardware: The Quanser Toolbox
A real-time package finds its real use when it can be interfaced with hardware. Fortunately, WinCon may be used with a variety of data acquisition cards, including, of course, Quanser Consulting's own MultiQ-2, MultiQ-3, MultiQ-PCI and Q8 data acquisition cards. Accessing hardware becomes as simple as placing blocks into your Simulink diagram. The blocks for the Quanser products, as well as some additional blocks, are available in the Simulink-integrated Quanser Toolbox library, described in this section. There are two ways to access the Quanser Toolbox library. The first way is to type the following command at the MATLAB prompt: qctools This command opens up the Quanser Toolbox as shown in Figure 26. The other way to access the Quanser Toolbox is through the standard Simulink Library Browser, as depicted in Figure 25. You can get to it by clicking on the Library Browser button in the Simulink window, and then clicking on the Quanser Toolbox icon.
As briefly mentioned previously, the Quanser Toolbox library contains all the Simulink blocks you need to use Quanser Consulting's MultiQ-2, MultiQ-3, MultiQ-PCI and Q8 data acquisition cards. There are also additional blocks to increase functionality, such as extra sources (e.g. sigmoids, sequences), extra sinks, serial drivers, data conversion blocks, and convenient discretizing transfer function blocks. Be sure to see what is available it can save you time!
89
Analog Input
The Analog Input block is used to interface with the analog-to-digital converters on the MultiQ. The analog input block may be used to read more than one analog input at a time. In this case, the output from the analog input block will be a vector with one entry for each analog input read. You may put more than one analog input block into your diagram, if you prefer. The only restriction is that no two analog input blocks can read the same channels. However, they can read different channels on the same I/O card. To change the analog input parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 31 below will appear.
90
The first field allows you to specify the base address of the MultiQ I/O card. The MultiQ card is an I/O mapped ISA card. If there is more than one MultiQ card in your system, simply specify the base address of the card you want. All the MultiQ blocks have a Base I/O Address parameter. The second field identifies the analog input channel, or channels, you wish to read. Specify a scalar number from 0 to 7 to read one of the eight analog input channels. To read more than one channel, specify a vector. The channels will be read in the order that they appear in the vector. For example, entering [5 2] will cause the Analog Input block to read analog channel 5 first and then to read analog channel 2. The output from the Analog Input block will be a vector, where the first element corresponds to analog channel 5, and the second element corresponds to analog channel number 2. The output units are volts. In most cases, you will probably want to specify the channels in ascending order. You can do this using the convenient ':' vector shorthand notation of MATLAB. For example, to read analog channels 2 through 4, simply enter 2:4 into the Channel(s) to Use field. The third parameter is the sample time. All the MultiQ blocks include a sample time parameter so that they may be used in discrete-time systems. The default sample time is set to the base sampling rate of your system. You will not have to change this default unless you are developing a multi-rate system. The expression simget(bdroot,'FixedStep') returns the base sampling period as a real number, so you can multiply this expression by an integer to get a multiple of the base sampling period. Alternatively, you can simply enter
91
Analog Output
The Analog Output block is used to interface with the digital-to-analog converters on the MultiQ data acquisition card. The analog output block may be used to write to more than one analog output at a time. In this case, the input to the analog output block must be a vector with one entry for each analog output written. You may put more than one analog output block into your diagram, if you prefer.
92
To change the analog output parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 32 below will appear. Like the Analog Input block, there are fields for the Base I/O Address and Sample Time. See the Analog Input section for a discussion of the Base I/O Address parameter. The Channel(s) to Use field identifies the analog output channels that will be written by this block. Specify a scalar number from 0 to 7 to write to one of the eight analog output channels. To write more than one channel, specify a vector. The channels will be written in the order that they appear in the vector. For example, entering [5 2] will cause the Analog Output block to write to analog channel 5 first and then to write analog channel 2. The input to the Analog Output block must be a vector, where the first element corresponds to analog channel 5, and the second element corresponds to analog channel number 2. The input units are volts. In most cases, you will probably want to specify the channels in ascending order. You can do this using the convenient ':' vector shorthand notation of MATLAB. For example, to write to analog channels 2 through 4, simply enter 2:4 into the Channel(s) to Use field.
93
Digital Input
The digital input block is used for reading the digital inputs on the MultiQ card. It has the same parameters as the Analog Input block. The only difference between the two blocks is that the Digital Input block reads the digital inputs, of which there are eight, instead of the analog inputs. See the Analog Input section for a discussion of its parameters. Note however that the output of the Digital Input block is zero or one, not a voltage.
Digital Output
The Digital Output block is used to write to the digital outputs of the MultiQ data acquisition card. There are eight digital outputs. The Digital Output block has the same
94
Time Base
The Time Base block allows a hardware timer to be used to generate the sampling rate for the system. When no Time Base block is present in the diagram, the system timer is used. The system timer under Linux is fast and accurate, supporting sub-millisecond sampling rates, so this block is not strictly necessary, but it is available for those users wanting to use the hardware time-base on their data acquisition card. In Windows, the Time Base block is necessary for sampling rates beyond 10kHz on Windows 2000/XP. The parameters for the MultiQ Time Base block are shown in Figure 33. See the Analog Input section for a discussion of the Base I/O Address parameter.
The IRQ Level parameter must be set to the interrupt level selected on the MultiQ card. The MultiQ-3 card does not support software programmable interrupt levels, so this setting must match the jumper setting on the MultiQ card. The Clock Source parameter determines which clock on the MultiQ card will be used for the hardware time-base. This setting is also determined by a jumper on the MultiQ card, so this parameter must match the hardware setting for this block to work.
95
Encoder Input
The Encoder Input block is used to read the counter values of the MultiQ encoder inputs. The number of encoder inputs available depends on the model of MultiQ card purchased. The output of the encoder block is the 24-bit encoder count(s). More than one encoder channel may be read at the same time and more than one Encoder Input block may be present in your Simulink diagram. Indeed, the Encoder Input block is analogous to the Analog Input block except that it reads the encoders and outputs counter values instead of processing analog inputs.
The parameters of the Encoder Input block are illustrated in Figure 34. Refer to the Analog Input section for details on the parameters to the Encoder Input block. If the Simulation
96
Encoder Extras
It is often convenient to calibrate the encoders in the real-time code in response to some event, such as a limit switch being hit or at a certain time. The Encoder Extras library provides a set of Encoder Reset blocks for performing such calibration. One block resets the encoder value based on a level-sensitive input. Two others reset the encoder value based on an edge-triggered input. Since the Encoder Input block sets the initial value of the encoder count, the Encoder Reset blocks are not necessary to set the initial count value. However, they are very useful for calibration. The Encoder Extras library is depicted in Figure 35 below.
Encoder Reset (level-sensitive) The level-sensitive Encoder Reset block resets the encoder value when its input is nonzero. Like the Encoder Input block, the Encoder Reset (level-sensitive) block has parameters for the base I/O address and encoder channels to use. Refer to the Encoder Input block, as shown in Figure 36, for a discussion of these parameters.
97
The Reset Value(s) parameter operates in the same way as the Initial Value(s) parameter of the Encoder Input block except that it specifies the values to which the encoder counts are reset when the input to the block is non-zero. Since the input is level-sensitive, the encoder counts are reset every sample time instant until the input returns to zero. This block may be used to reset the encoder counts until a certain amount of time has transpired for example. For example, with Quanser's inverted pendulum experiment, it could be used to give the user a few seconds to hold the pendulum upright before the controller kicks in. It can also be used in triggered subsystems so that all your calibration may be performed in response to a single trigger. The Sample Time parameter is used to set the sampling time for the block. The default value is -1, indicating that the sample time is inherited from the input signal driving the block. The sample time must be inherited to use the block in a triggered subsystem. The sample time can be set to a positive real scalar outside of a triggered subsystem. Encoder Reset (edge-triggered) The edge-triggered Encoder Reset block resets the encoder counts in response to a rising edge at its input. The encoder value is reset only at each rising edge. The block will not continue to reset the encoder counts after the rising edge. This block is useful for resetting the encoder counts at a particular instant in time (but not before) or when a particular event occurs.
98
For example, a controller designed to find the limits of the workspace could use velocity control to slowly move the apparatus around its workspace. When a limit switch was hit, the Encoder Reset (edge-triggered) block could be used to reset the encoder count to calibrate it. The controller could then switch to position control. The parameters for the block are illustrated in Figure 37. The parameters are identical to the Encoder Reset (level-sensitive) block with one exception: the Sample Time parameter is missing because the block is event-based. It always derives its sample time from the trigger signal input. Encoder Reset (edge-triggered with enable) The Encoder Reset (edge-triggered with enable) block is identical to the Encoder Reset (edge-triggered) block except that it has an enable input as well. The encoder counts will only be reset when the trigger occurs and the enable input is non-zero. See the Encoder Reset (edge-triggered) block for a discussion of the block parameters.
99
Analog Input
The Analog Input block is used to interface with the analog-to-digital converters on the MultiQ-PCI. The Analog Input block is also used to read more than one analog input at a time. In this case, the output from the analog input block will be a vector with one entry for each analog input read. Note that there can only be one MultiQ-PCI Analog Input block (per card) in a Simulink diagram. To change the analog input parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 39 below will appear.
100
The first field allows you to specify which MultiQ-PCI I/O card to use. The MultiQ-PCI card is a memory-mapped PCI card. The first card is referred to as board number 0 by WinCon. The next card is referred to as board number 1, etc. Hence, if there is more than one MultiQ-PCI card in your system, simply specify the board number of the card you want. Since the correspondence between the board number and the slot in which the I/O cards are placed depends on the computer manufacturer, the easiest way to determine which card is board number 0, and which card is board number 1, etc. is to output different constant voltages on each board. Which card is which may then be determined easily using a voltmeter. All the MultiQ-PCI blocks have a Board Number parameter. The second field identifies the analog input channel, or channels, you wish to read. If a MultiQ terminal board is being used, then specify a scalar number from 0 to 7 to read one of the eight single-ended analog input channels. Otherwise, specify a scalar number from 0 to 15 to read one of the sixteen differential analog inputs. To read more than one channel, specify a vector. The channels will be read in the order that they appear in the vector. For example, entering [5 2] will cause the Analog Input block to read analog channel 5 first and then to read analog channel 2. The output from the Analog Input block will be a vector, where the first element corresponds to analog channel 5, and the second element corresponds to analog channel number 2. The output units are volts.
101
Analog Output
The Analog Output block is used to interface with the digital-to-analog converters on the MultiQ-PCI data acquisition card. The analog output block may be used to write to more than one analog output at a time. In this case, the input to the analog output block must be a vector with one entry for each analog output written. You may put more than one analog output block into your diagram, if you prefer. To change the analog output parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 40 will appear. Like the Analog Input block, there is a field for the Board Number. See the Analog Input section for a discussion of this parameter.
102
The Channel(s) to Use field identifies the analog output channels that will be written by this block. Specify a scalar number from 0 to 3 to write to one of the four analog output channels. To write more than one channel, specify a vector. The channels will be written in the order that they appear in the vector. For example, entering [5 2] will cause the Analog Output block to write to analog channel 5 first and then to write analog channel 2. The input to the Analog Output block must be a vector, where the first element corresponds to analog channel 5, and the second element corresponds to analog channel number 2. The input units are volts. In most cases, you will probably want to specify the channels in ascending order. You can do this using the convenient ':' vector shorthand notation of MATLAB. For example, to write to analog channels 2 through 4, simply enter 2:4 into the Channel(s) to Use field. The Initial Output(s) field specifies the value(s) that will be written to the analog output channels when the real-time code is initialized, before it starts running. If you specify a scalar, then all analog output channels in the Channel(s) to Use field will be initialized to the same value. To initialize each channel to a different value, specify a vector containing the initial values for each channel.
103
Digital Input
The digital input block is used for reading the digital inputs on the MultiQ card. The dialog box of the Digital Input block is shown in Figure 41. Like the Analog Input block, there are fields for the Board Number, Sample Time and Simulation Input. See the Analog Input section for a discussion of these parameters. The output of the Digital Input block is zero or one, not a voltage. The digital input channels to read are specified in the Channel(s) to Use parameter, much like the Analog Input block. A vector may be used to specify more than one input channel. The Digital Input block supports up to 48 digital inputs. However, in this case, the digital input channels are shared with the Digital Output block. Thus, a Digital Input block and a Digital Output block cannot share the same channel numbers because the common channels would be using the same digital I/O pin. For example, if a Digital Input block was reading channel 0 then a Digital Output block could not be writing to channel 0.
104
Digital Output
The Digital Output block is used to write to the digital outputs of the MultiQ-PCI data acquisition card. The dialog box of the Digital Input block is shown in Figure 42. Like the Analog Output block, there are fields for the Board Number, Initial Output(s), Final Output(s), Sample Time and Simulation Input. See the Analog Output section for a discussion of these parameters. The Digital Output block takes inputs that are zero or one, not a voltage, and sends them to the digital outputs of the MultiQ-PCI. The digital output channels to write are specified in the Channel(s) to Use parameter, much like the Analog Output block. A vector may be used to specify more than one output channel. The Digital Output block supports up to 48 digital outputs. However, in this case, the digital output channels are shared with the Digital Input block. Thus, a Digital Output block and a Digital Input block cannot share the same channel numbers because the common channels would be using the same digital I/O pin. For example, if a Digital Output block was writing to channel 0 then a Digital Input block could not be reading from channel 0.
105
Watchdog Timer
The Watchdog Timer block is used to program the watchdog timer on the MultiQ-PCI card. If the watchdog timer expires before the next sampling instant then the MultiQ-PCI card is reset and the model is stopped. An error message will be issued in this case indicating that the watchdog timer expired. Note that resetting of the MultiQ-PCI card is done in hardware. Hence, even if the system has crashed, the card will still be reset when the watchdog timer expires. This block provides a useful safety feature. However, Quanser strongly recommends that other safety features also be implemented in your Simulink diagrams. An unstable controller would continue to reset the watchdog timer (because it hasn't crashed) yet would drive the hardware out of control! Thus, other safety features should also be incorporated. For example, limit switches may be polled using a Digital Input block and fed to a Stop Simulation block to halt the real-time code in the event of a limit switch being hit. The parameters of the Watchdog Timer block are illustrated in Figure 43. See the Analog Input section for a discussion of the Board Number and Sample Time parameters.
106
The Period Selection parameter determines the period of the watchdog timer. There is a choice of four periods: 0.125 seconds, 0.5 seconds, 1 second and 10 seconds. The period should always be longer than the base sampling period of the system, yet as small as possible. Thus, in the event of a crash, the watchdog timer will reset the card as soon as possible, but it will not interfere with the normal operation of the controller. For example, if the controller sampling period is 0.010 seconds, then the watchdog period should be set to 0.125.
Encoder Input
The Encoder Input block is used to read the counter values of the MultiQ-PCI encoder inputs. Up to six encoder inputs are supported, numbered 0 through 5. Note that with the MultiQ terminal board, encoder channels 6 and 7 are not used for encoders. The output of the encoder block is the 24-bit encoder count(s). More than one encoder channel may be read at the same time and more than one Encoder Input block may be present in your Simulink diagram. The parameters of the Encoder Input block are illustrated in Figure 44. Like the Analog Input block, there are fields for the Board Number, and Sample Time. See the Analog Input section for a discussion of these parameters.
107
The Channel(s) to Use parameter specifies which encoder channels are to be read. More than one encoder channel may be specified by entering a vector for this parameter. Note however that encoders are handled using the counters on the MultiQ-PCI board. These counters are also used for the Time Base block. Hence, no channel number may conflict with the clock source of a Time Base block in the same diagram. Clock source 0 corresponds to the same counter as encoder channel 0. The Initial Value(s) parameter is used to preload the encoder counts when the model starts. For example, setting this parameter to 0 will cause all encoders to read a value of 0 initially. The initial value for each encoder channel may be specified separately by entering a vector for this parameter. For example, if the Channel(s) to Use parameter is [2, 4] and the Initial Value(s) parameter is [32768, -8192] then encoder channel 2 will have an initial value of 32768 and channel 4 will have an initial value of -8192 when the model is run. The final parameter, the Simulation Input check-box, puts an input port on the Encoder Input block when it is selected. This input port may be used much like the Simulation Input on the Analog Input block. However, in this case, the input is a count value that is fed to the output (during simulation only) after restricting it to a 24-bit value using the modulus operator. The simulation input is ignored in real-time code.
108
109
Figure 45 Q8 Library
Note that each block also comes with extensive online help for your convenience. The blocks may be used to interface with more than one Q8 card in the same Simulink diagram, if desired. The blocks are discussed in the following subsections.
Analog Input
The Analog Input block is used to interface with the analog-to-digital converters on the Q8. The Analog Input block may be used to read more than one analog input at a time. In this case, the output from the analog input block will be a vector with one entry for each analog input read. To change the analog input parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 46 will appear.
110
The first field allows you to specify which Q8 I/O card to use. The Q8 card is a memorymapped PCI card. The first card is referred to as board number 0 by WinCon. The next card is referred to as board number 1, etc. Hence, if there is more than one Q8 card in your system, simply specify the board number of the card you want. Since the correspondence between the board number and the slot in which the I/O cards are placed depends on the computer manufacturer, the easiest way to determine which card is board number 0, and which card is board number 1, etc. is to output different constant voltages on each board. Which card is which may then be determined easily using a voltmeter. All the Q8 blocks have a Board Number parameter. The second field identifies the analog input channel, or channels, you wish to read. If a Q8 terminal board is being used, then specify a scalar number from 0 to 7 to read one of the eight single-ended analog input channels. To read more than one channel, specify a vector. The channels will be read in the order that they appear in the vector. For example, entering [5 2] will cause the Analog Input block to read analog channel 5 first and then to read analog channel 2. The output from the Analog Input block will be a vector, where the first element corresponds to analog channel 5, and the second element corresponds to analog channel number 2. The output units are volts. In most cases, you will probably want to specify the channels in ascending order. You can do this using the convenient ':' vector shorthand notation of MATLAB. For example, to
111
Analog Output
The Analog Output block is used to interface with the digital-to-analog converters on the Q8 data acquisition card. The Analog Output block may be used to write to more than one analog output at a time. In this case, the input to the Analog Output block must be a vector with one entry for each analog output written. You may put more than one Analog Output block into your diagram, if you prefer. To change the analog output parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 47 below will appear. Like the
112
113
All the Q8 blocks include a sample time parameter so that they may be used in discretetime systems. The default sample time is set to -1 in the case of the Analog Output block. A sampling time of -1 indicates that the sampling rate is inherited from the input signal driving the block. Thus, you will usually not have to change this parameter, even in a multirate system. The sample time can also be specified as a positive scalar. The expression simget(bdroot,'FixedStep') returns the base sampling period as a real number, so you can multiply this expression by an integer to get a multiple of the base sampling period. Alternatively, you can simply enter a real number corresponding to the sampling period for this block. The sample time must be -1 or positive.
114
Digital Input
The Digital Input block is used for reading the digital inputs on the Q8 card. Like the Analog Input block, there are fields for the Board Number, Sample Time and Simulation Input. See the Analog Input section for a discussion of these parameters.
115
Digital Output
The Digital Output block is used to write to the digital outputs of the Q8 data acquisition card. Like the Analog Output block, there are fields for the Board Number, Initial Output(s), Final Output(s), Sample Time and Simulation Input. See the Analog Output section for a discussion of these parameters. The Digital Output block takes inputs that are zero or one, not a voltage, and sends them to the digital outputs of the Q8.
116
Encoder Input
The Encoder Input block is used to read the counter values of the Q8 encoder inputs. Up to eight encoder inputs are supported, number 0 through 7. The output of the encoder block is the 24-bit encoder count(s). More than one encoder channel may be read at the same time and more than one Encoder Input block may be present in your Simulink diagram. The parameters of the Encoder Input block are illustrated in Figure 50. Like the Analog Input block, there are fields for the Board Number, and Sample Time. See the Analog Input section for a discussion of these parameters. The Channel(s) to Use parameter specifies which encoder channels are to be read. More than one encoder channel may be specified by entering a vector for this parameter. The Initial Value(s) parameter is used to preload the encoder counts when the model starts. For example, setting this parameter to 0 will cause all encoders to read a value of 0 initially. The initial value for each encoder channel may be specified separately by entering a vector for this parameter. For example, if the Channel(s) to Use parameter is [2, 4] and the Initial Value(s) parameter is [32768, -8192] then encoder channel 2 will have an initial value of 32768 and channel 4 will have an initial value of -8192 when the model is run. The Do not initialize counts option sets the onboard counter to continue counring encoder pulses even after the controller has stopped. The Quadrature field indicates the type of quadrature encoding to use for all selected channels. The Q8 card provides 1X, 2X or 4X quadrature. The 4X quadrature mode is the default since it provides the highest encoder resolution, yielding four times the encoder resolution. For example, a 1024 count encoder will produce 4096 counts per revolution in 4X quadrature mode. In quadrature mode the A and B inputs are digitally filtered and decoded for the up/down counter. The final parameter, the Simulation Input checkbox, puts an input port on the Encoder Input block when it is selected. This input port may be used much like the Simulation Input on the Analog Input block. However, in this case, the input is a count value that is fed to
117
118
The Clock source parameter sets which of the 2 32-bit counters to use. If COUNTER is selected, then the PWM signal will appear on the CNTR_OUT pin of the CONTROL header on the terminal board. If WATCHDOG is selected, then the PWM signal will appear on the WATCHDOG pin of the CONTROL header on the terminal board. The Period parameter sets the period in seconds of the output signal. The period may range from 60 ns to 257 seconds (4.3 minutes), in 60 ns units. The Pulse width parameter sets the width of the high pulse as a percentage of the period. The pulse width may range from 0 to 100. The CNTR_EN polarity checkbox sets the polarity of the CNTR_EN input. If this option is not checked then the CNTR_EN is an active-low input. Otherwise it is active-high. The CNTR_EN line has a pull up resistor to bring it high when the input is unconnected. Hence, this option is normally checked to enable the counter by default.
119
The Clock source parameter sets which of the 2 32-bit counters to use. If COUNTER is selected, then the PWM signal will appear on the CNTR_OUT pin of the CONTROL header on the terminal board. If WATCHDOG is selected, then the PWM signal will appear on the WATCHDOG pin of the CONTROL header on the terminal board.
120
The watchdog timer is a 32-bit counter. It supports any timeout period from 60 ns to 257.69803776 seconds (4.3 minutes) in 60 ns units. The period is generally programmed to be more than the sampling period of the model, but small enough that the model stops quickly after the watchdog expires. The output of the block changes at the next sampling instant after the watchdog timer expires. The Watchdog Interrupt block may also be used to act on watchdog expiration. The Watchdog Interrupt block is an asynchronous block that is executed immediately upon expiration of the watchdog timer, independent of the sampling period of the model. Checking the Enable WATCHDOG output checkbox enables output of the watchdog state to the WATCHDOG pin on the CONTROL header of the Q8 terminal board. The output remains high as long as the watchdog timer has not expired. If the watchdog expires then the output goes low. This signal can be used to shut off external hardware, such as current
121
Additional Q8 Blocks
The following blocks will be listed with a brief description. For a complete description of each block, refer to the online help available through Simulink. Encoder Extras It is often convenient to calibrate the encoders in the real-time code in response to some event, such as a limit switch being hit or at a certain time. The Encoder Extras library provides a set of Encoder Reset blocks for performing such calibration. One block resets the encoder value based on a level-sensitive input. Two others reset the encoder value based on an edge-triggered input. Since the Encoder Input block sets the initial value of the encoder count, the Encoder Reset blocks are not necessary to set the initial count value. However, they are very useful for calibration. Encoder Reset ( level-sensitive / edge-triggered / edge-triggered with enable): Resets the count value of an encoder in the Q8 data acquisition system. Measure Average Period: Measures the average period of a digital signal applied to the CNT input of one of the encoder DIN connectors.
122
123
124
125
Analog Input
The Analog Input block is used to interface with the analog-to-digital converters on the ESeries. The Analog Input block may be used to read more than one analog input at a time. In this case, the output from the analog input block will be a vector with one entry for each analog input read. You may put more than one analog input block into your diagram, if you prefer. To change the analog input parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 55 below will appear. The first field, Board Type, is used to select the type of E-Series card used. The proper type must be selected for the Analog Input to function properly.
126
127
The Single-Ended/Differential Mode parameter may be a scalar or vector. Each element of the vector must be either 0 or 1. A value of 0 indicates that the corresponding analog input channel specified in the Channel(s) to Use parameter is single-ended. A value of 1
128
129
Analog Output
The Analog Output block is used to interface with the digital-to-analog converters on the ESeries data acquisition cards. The analog output block may be used to write to more than one analog output at a time. In this case, the input to the analog output block must be a vector with one entry for each analog output written. You may put more than one analog output block into your diagram, if you prefer. To change the analog output parameters, double-click on the block after dragging it into your Simulink diagram. The dialog box shown in Figure 56 will appear. Like the Analog Input block, there are fields for the Board Type and Board Number. See the Analog Input section for a discussion of these parameters. The Channel(s) to Use field identifies the analog output channels that will be written by this block. Specify a scalar number of 0 or 1 to write to one of the two analog output channels. To write more than one channel, specify a vector. The channels will be written in the order that they appear in the vector. For example, entering [1 0] will cause the Analog Output block to write the first element of the input vector to analog channel 1 and the second element of the input vector to analog channel 0. The input units are volts. In most cases, you will probably want to specify the channels in ascending order. You can do this using the convenient ':' vector shorthand notation of MATLAB. For example, to write to both analog output channel, simply enter 0:1 into the Channel(s) to Use field.
130
The Bipolar (0) / Unipolar (1) Polarities field specifies whether the analog output is bipolar or unipolar. If you specify a scalar, then all analog output channels in the Channel(s) to Use field will be initialized to the same polarity. To configure each channel with a different polarity, specify a vector containing the polarities for each channel. A value of 0 indicates that the channel is bipolar, while a value of 1 configures the channel as unipolar. The Initial Output(s) field specifies the value(s) that will be written to the analog output channels when the real-time code is initialized, before it starts running. If you specify a scalar, then all analog output channels in the Channel(s) to Use field will be initialized to the same value. To initialize each channel to a different value, specify a vector containing the initial values for each channel. The Final Output(s) field specifies the value(s) that will be written to the analog output channels when the real-time code is stopped. If you specify a scalar, then all analog output
131
Digital Input
The digital input block is used for reading the digital inputs on the E-Series card. The dialog box of the Digital Input block is shown in Figure 57. Like the Analog Input block, there are fields for the Board Number, Sample Time and Simulation Input. See the Analog Input section for a discussion of these parameters.
132
The output of the Digital Input block is zero or one, not a voltage. The digital input channels to read are specified in the Channel(s) to Use parameter, much like the Analog Input block. A vector may be used to specify more than one input channel. The Digital Input block supports up to 6 digital inputs. While the E-Series boards actually have 8 digital I/O lines, channels 6 and 7 are reserved for use encoder inputs. Note also that the digital input channels are shared with the Digital Output block. Thus, a Digital Input block and a Digital Output block cannot share the same channel numbers because the common channels would be using the same digital I/O pin. For example, if a Digital Input block was reading channel 0 then a Digital Output block could not be writing to channel 0.
Digital Output
The Digital Output block is used to write to the digital outputs of the E-Series data acquisition card. The dialog box of the Digital Input block is shown in Figure 58. Like the Analog Output block, there are fields for the Board Number, Initial Output(s), Final Output(s), Sample Time and Simulation Input. See the Analog Output section for a discussion of these parameters. The Digital Output block takes inputs that are zero or one, not a voltage, and sends them to the digital outputs of the E-Series card.
133
The digital output channels to write are specified in the Channel(s) to Use parameter, much like the Analog Output block. A vector may be used to specify more than one output channel. The Digital Output block supports up to 6 digital outputs. However, in this case, the digital output channels are shared with the Digital Input block. Thus, a Digital Output block and a Digital Input block cannot share the same channel numbers because the common channels would be using the same digital I/O pin. For example, if a Digital Output block was writing to channel 0 then a Digital Input block could not be reading from channel 0.
Time Base
The Time Base block allows a hardware timer to be used to generate the sampling rate for the system. When no Time Base block is present in the diagram, the system timer is used. The system timers under RTX and RTLinux are fast and accurate, supporting submillisecond sampling rates, so this block is not strictly necessary, but it is available for those users wanting to use a hardware time-base on their data acquisition card.
134
The Time Base block is required in Windows 2000/XP for sampling rates beyond 10kHz. The parameters for the E-Series Time Base block are shown in Figure 59 above. See the Analog Input section for a discussion of the Board Number parameter. The Clock Source parameter determines which counter on the E-Series card will be used for the hardware time-base. There are two 24-bit counters on the E-Series card, so the clock source may be a scalar integer from 0 to 1. Note however that the same counters are used for the encoder inputs. Hence, the Clock Source parameter cannot conflict with a channel number used in an Encoder Input block. Clock source 0 corresponds to the same counter as encoder channel 0. The Time Base block normally has no inputs or outputs. Checking the Time Output box puts an output port on the Time Base block. This port outputs the time since the simulation began. Hence, this output may be used instead of a separate Clock block (the Clock block is a Simulink block found in the Sources library). Note that only one Time Base block may appear in a Simulink diagram, since only one hardware timer is needed to produce the base sampling rate. If more than one Time Base block is placed in a diagram then an error message will be issued when generating code. Also note that to use the Time Base block, the E-Series Windows driver must be converted to an RTX driver. See the discussion on Time Base blocks in the Troubleshooting section for details.
Encoder Input
The Encoder Input block is used to read the counter values of the E-Series encoder inputs. Up to two encoder inputs are supported, numbered 0 through 1. The output of the encoder
135
The Channel(s) to Use parameter specifies which encoder channels are to be read. More than one encoder channel may be specified by entering a vector for this parameter. Note however that encoders are handled using the counters on the E-Series board. These counters are also used for the Time Base block. Hence, no channel number may conflict with the clock source of a Time Base block in the same diagram. Clock source 0 corresponds to the same counter as encoder channel 0.
136
Encoder Extras
It is often convenient to calibrate the encoders in the real-time code in response to some event, such as a limit switch being hit or at a certain time. The Encoder Extras library provides a set of Encoder Reset blocks for performing such calibration. One block resets the encoder value based on a level-sensitive input. Two others reset the encoder value based on an edge-triggered input. Since the Encoder Input block sets the initial value of the encoder count, the Encoder Reset blocks are not necessary to set the initial count value. However, they are very useful for calibration. For a full discussion of these blocks, refer to the E-Series card manual. The blocks are identical for the E-Series except that a Board Number parameter is used in place of a Base I/O Address parameter, and the E-Series has a Board Type parameter to identify the type of NI E-Series card being used. See the ESeries Analog Input block description for details on the Board Number and Board Type parameters.
137
Serial Initialization
The Serial Initialization block is used to set the serial port parameters such as baud rate, parity, stop bits, etc. A separate block is employed because there are settings that are typically only set once at the start of execution. This technique greatly reduces the number of parameters of the other serial driver blocks. Only one Serial Initialization block may be placed in the diagram per serial channel. The parameters to the Serial Initialization block are shown in Figure 62. The COM Port parameter selects which serial port to initialize. The driver assumes that a 16550A UART or equivalent is available on your system. The UART fifos are used to maximize throughput.
138
Serial Drivers
The Baud Rate parameter is used to set the baud rate. Baud rates as low as 50 and as high as 115,200 are possible. Non-standard baud rates in this range are also permitted, although are not recommended. The default baud rate is 9600 baud. The Word Length parameter sets the number of bits per character sent. If a word length other than 8 is used, then the bytes in the input signal will be truncated to the number of bits in the word length. Hence, an 8 bit word length should be used for all data types except the 8-bit data types int8 and uint8. The default word length is 8 bits. The Parity parameter sets the parity to even, odd, or none. The default is none. The Stop Bits parameter determines the number of stop bits. The choices are 1, 1.5 or 2 stop bits. However, 2 stop bits is only possible with a word length of 5. If a word length other than 5 is used then the stop bits must be set to 1 or 1.5. The Sample Time parameter is only available so that the block acts as a discrete-time block. If all the blocks in your diagram are discrete then more integration methods are allowed by Simulink. You should never need to change this parameter because it has no impact on the real-time code. The Serial Initialization block only executes when the model is started and when it terminates. No code is executed for the Serial Initialization block while the model is running.
Serial Output
The Serial Output block is used to write data to the serial port. It writes all the data at its input to the serial port each sampling instant. Hence, if the input is a vector, the entire vector is written to the serial port. The Serial Output block also supports any of the standard data types at its input. The 8-bit data types, int8 and uint8, are written to the serial port Figure 63 Serial Output parameters as characters. The 8-bit data types are useful for printing messages to the serial port. The larger data types, such as double, are written to the serial port as a series of bytes. For example, a double value is sent as 8 bytes, while a single precision value is sent as 4 bytes. The Serial Input block can be programmed to recognize any of the standard data types as well, so the Serial Input and Output blocks may be used for tele-operation over a null modem cable, or for communicating with embedded systems via a serial link. The To Bytes block can be used to combine data types of different sizes into a single write operation. The Serial Output block has two parameters, as shown in Figure 63: COM Port and No Repeated Sequences Sent. The COM Port parameter identifies the serial port to which to write. A Serial Initialization block should be used to initialize this COM port. The No
139
Serial Drivers
Repeated Sequences Sent parameter is used to prevent redundant information from being sent out the serial port. It is particularly useful for communicating with embedded systems, such as the Quanser PIC-based boards. When the No Repeated Sequences Sent box is checked, the Serial Output will only write its input to the serial port when that input changes (and the initial value). Hence, with this option enabled, you may send commands to an embedded system without worrying that the same command will be sent every sampling instant. The Serial Output block also has an error signal output. The output is normally zero, but it goes to one if the Data Set Ready signal has not been asserted on the serial port. Absence of Data Set Ready generally means that the software at the other end of the connection is not running or has not made a connection. Alternatively, it could mean that the serial link is broken. For example, in Windows, the HyperTerminal program does not assert Data Set Ready until you "connect". Rather than stop the model with an error, the Serial Output block gives the user control over this scenario by supplying the error output. To stop the model on this error, connect the output to a Stop Simulation block or Quanser's Stop With Error block.
Serial Input
The Serial Input block reads from the serial port. Every sampling instant it reads the specified number of items. The data type of each item read can also be specified so that the Serial Input block is fully compatible with the Serial Output block. It may also be used to read different data types from an embedded system connected by a serial link to the PC, such as Quanser's PICbased modules. To prevent the Serial Input block from starving the operating system for CPU time while it waits for data, the Serial Input block uses a time-out interval. If not enough data arrives within the time-out interval then the data is considered invalid and this failure is indicated by the valid output signal.
The Serial Input dialog box of the Serial Input block is shown in Figure 64. The COM Port parameter specifies the serial port from which to read. A Serial Initialization block should be present to initialize this serial port. The Number of Items to Read parameter indicates the number of data items to read from the serial port. The size of each data item depends on the data type selected. For example, if
140
Serial Drivers
the data type is set to double, then each item requires 8 bytes. Thus, if the number of items is set to 2 then 16 bytes will be read from the serial port. The 16 bytes will be interpreted as two 8-byte double precision values and these values will be output as a 2-vector to the data output of the Serial Input block. The From Bytes block can be used to separate data types of different sizes read in a single read operation. The Receive Timeout parameter indicates how long the Serial Input block will wait (polling) until it considers the read to have failed. Since the Serial Input block reads every sampling instant, this parameter should be set to less than the sampling time. The default value is half the base sampling rate of the model. The time-out is for all the data combined not for each individual data item. The Sample Time parameter specifies the sampling period to use for this block. The default value is the same as the base sampling period of the model. Other sampling times may be specified. The sample time must be a positive scalar. For example, to read the serial port every 1/10th of a second, set the Sample Time to 0.1. The Serial Input block has several outputs. The data that has been read is output on the data output port. It will be a vector whose length is the same as the number of data items specified and of the data type indicated in the Data Type parameter. If data was not read successfully from the serial port, then the previous data is output. The valid output is a scalar output. When the data is read successfully, the valid output is one. However, if the receive time-out expired before all the data arrives then the valid output goes to zero. Hence, the valid signal may be used to ignore invalid data or to flag an error. The valid output also goes to zero if an error occurs reading the serial port, such as a framing error, parity error or overrun error. The error signals provides more detail about why a read failed. It is a vector of six elements, with each element corresponding to a different error. When the read completes successfully, the error output is all zero. When an error occurs, the appropriate element in the error vector goes to one. Table 35 enumerates the meaning of each error vector element.
141
Serial Drivers
Element 1 2 3 4 5 6 Error Description No connection Data Set Ready not asserted. Overrun error baud rate setting is likely incorrect Parity error parity setting incorrect or line is noisy Framing error stop bit setting incorrect or line is noisy Break interrupt break signal sent by remote terminal. Connection being broken? Receive time-out all the data did not arrive within the time-out interval
Serial Error
The Serial Error block is designed to be used with the Serial Input block. When the error signal from the Serial Input block is connected to the Serial Error block then the model will be stopped with an appropriate error message whenever one of the selected serial input error occurs. Double-click on the Serial Error block to open the dialog shown in Figure 65. The Serial Error block will detect any error for which the associated check-box is selected. See the Serial Input block for a description of the different types of errors that can be detected. When a selected error is detected, the model will be stopped and an errorspecific message will be issued to the user.
The No Connection error and Receive Timeout errors are not detected by default because these errors are likely to occur before the remote system has been initialized. If you always know that the remote system will be running prior to starting the model, then you can enable the detection of these errors. Note that a receive time-out will occur unless the remote system is sending data at the same rate as the model is expecting to receive data.
142
Is Simulation?
The Is Simulation? block may be used in a Simulink diagram to determine when the model is running as a normal simulation or when it is running as real-time code. The output of the block is one when the model is running as a normal simulation. It is zero when running as real-time code. The block is most useful with enabled subsystems, because it allows you to enable or disable the execution of certain code depending on whether it is running in simulation or real-time. For example, in conjunction with blocks like the MultiQ Analog Input with Simulation Input block, the Is Simulation? block could be used to execute a model of the hardware in simulation, but prevent that model code from executing when the diagram was run in real-time. Hence, the same diagram could be used for simulation as well as the realtime code.
143
Extra Sources
The dialog box of the Smooth Sine Wave block is shown in Figure 67. The block input parameters are the amplitude of the sine wave, its frequency in Hertz, its initial phase in radians, and the sampling rate for this block. If the amplitude is modified during simulation then the phase of the output is adjusted to ensure that the curve is always continuous. If the frequency is changed during simulation then the phase of the sine wave is adjusted to ensure that the output is always continuous. The initial phase parameter only determines the phase at time t=0. Changing this parameter during simulation has no effect on the output. The Sample Time may be zero to make it a continuous-time block or -1 to inherit the sample time from the block to which the sine wave is connected. Otherwise, specify a positive value to
indicate a discrete sampling time. If the Output cosine also option is checked then the block will have an additional output. This output will produce the cosine. Note that very little extra code is required to produce the cosine in addition to the sine. Note, however, that the cosine is not guaranteed to be continuous under parameter changes.
Sequences
Figure 68 shows the different Sequences blocks provided as part of the Quanser Extra Sources.
144
Extra Sources
Enabled Sequence The Enabled Sequence block sequentially outputs the elements of a vector. Each sampling instant that it is enabled, it outputs the next element in the vector. The dialog box of the Enabled Sequence block is shown in Figure 69. If the Repeat Sequence option is checked, then the sequence is repeatedly output. Otherwise, the output stays at the last value in the vector when all elements have been output. The Enabled Sequence block is simpler to use than the Repeating Sequence block, since no time vector is required. It also does not need to perform linear
interpolation. Triggered Sequence The Triggered Sequence block sequentially outputs the elements of a vector. Each time the trigger is fired, it outputs the next element in the vector. The dialog box of the Triggered Sequence block is shown in Figure 70. If the Repeat Sequence option is checked, then the sequence is repeatedly output. Otherwise, the output stays at the last value in the vector when all elements have been output.The Triggered Sequence block is useful when a series of reference positions need to be output, but the time to reach each target is unknown in advance. This block is typically used in conjunction with the Sigmoid or
Triggered Sigmoid blocks. Triggered-Enabled Sequence The Triggered-Enabled Sequence block sequentially outputs the elements of a vector. Each time the trigger is fired and the enable input is asserted, it outputs the next element in the vector. The dialog box of the Triggered-Enabled Sequence block is shown in Figure 71. If the Repeat Sequence option is checked, then the sequence is repeatedly output. Otherwise, the output stays at the last value in the vector when all elements have been output. The Triggered-
145
Extra Sources
Enabled Sequence block is useful when a series of reference positions need to be output, but the time to reach each target is unknown in advance. This block is typically used in conjunction with the Sigmoid or Triggered Sigmoid blocks.
Sigmoids
Quanser supplies Sigmoid blocks, as shown in Figure 72, that can be used to command robot joints. These sigmoid blocks generate trapezoidal velocity profiles, i.e. rectangular acceleration profiles. These result is smooth (i.e. parabolic) position profiles. The maximum acceleration and velocity to be reached are finite and user-specified. As a reminder, applying a step position input to a robot joint controller is never recommended. The reason is that this would request infinite velocity and acceleration and therefore would excite flexible modes that are not taken into consideration by the robot motion controller and could potentially damage the robot itself and its joints.
Sigmoid The Sigmoid block generates a smooth trajectory from the initial position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the initial position to the target position. The dialog box of the Sigmoid block is shown in Figure 73. The Sigmoid block samples its inputs at regular intervals, determined by the Input Sample Time parameter.
146
Extra Sources
Each time the inputs are sampled, the trajectory is re-computed. Hence, the sample time should normally be slower than the time taken to traverse the trajectory.
The output of the Sigmoid block is generated using the sampling rate specified by the Output Sample Time parameter. The Output Sample Time may be set to zero for a continuous-time trajectory. The Sigmoid block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example.
Sigmoid (with limits) The Sigmoid (with limits) block generates a smooth trajectory from the initial position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the initial position to the target position. It differs from the Sigmoid block in that the maximum velocity and acceleration are inputs to the block rather than parameters. Hence, they may be time-varying. The dialog box of the Sigmoid (with limits) block is shown in Figure 74. The Sigmoid (with limits) block samples its inputs at regular intervals, determined by the Input Sample Time parameter. Each time the inputs are sampled, the trajectory is re-computed. Hence, the sample time should normally be slower than the time taken to traverse the trajectory.
147
Extra Sources
The output of the Sigmoid (with limits) block is generated using the sampling rate specified by the Output Sample Time parameter. The Output Sample Time may be set to zero for a continuous-time trajectory. The Sigmoid (with limits) block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example. Triggered Sigmoid The Triggered Sigmoid block generates a smooth trajectory from the initial position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the initial position to the target position. The dialog box of the Triggered Sigmoid block is shown in Figure 75. The Triggered Sigmoid block samples its inputs when the trigger input fires. Each time the inputs are sampled, the trajectory is recomputed. The output of the Triggered Sigmoid block is generated using the sampling rate specified by the Figure 75 Triggered Sigmoid Parameters Output Sample Time parameter. The Output Sample Time may be set to zero for a continuous-time trajectory.
148
Extra Sources
The Triggered Sigmoid block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example. Triggered Sigmoid (with limits) The Triggered Sigmoid (with limits) block generates a smooth trajectory from the initial position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the initial position to the target position. It differs from the Triggered Sigmoid block in that the maximum velocity and acceleration are inputs to the block rather than parameters. Hence, they may be time-varying. The dialog box of the Triggered Sigmoid (with limits) block is shown in Figure 76. The Triggered Sigmoid (with limits) block samples its inputs when the trigger input fires. Each time the inputs are sampled, the trajectory is recomputed.
Figure 76 Triggered Sigmoid (with limits) Block Parameters
The output of the Triggered Sigmoid (with limits) block is generated using the sampling rate specified by the Output Sample Time parameter. The Output Sample Time may be set to zero for a continuous-time trajectory. The Triggered Sigmoid (with limits) block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example. Continuous Sigmoid The Continuous Sigmoid block generates a smooth trajectory from the current position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the current position to the target position. The current position and velocity are determined by the current trajectory and the current time. The initial position and velocity (when the model is started) may be specified as parameters.
149
Extra Sources
The dialog box of the Continuous Sigmoid block is shown in Figure 77. The Continuous Sigmoid block samples its inputs at regular intervals, determined by the Input Sample Time parameter. Each time the inputs are sampled and the target position has changed, the trajectory is re-computed. Hence, the sample time should normally be slower than the time taken to traverse the trajectory. The output of the Continuous Sigmoid block is generated using the sampling rate specified by the Output Sample Time parameter. The Output Sample Time may be set to zero for a continuous-time trajectory. The Continuous Sigmoid block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example.
Continuous Sigmoid (with limits) The Continuous Sigmoid (with limits) block generates a smooth trajectory from the current position (and velocity) to the target position. The velocity at the target position will be zero. It uses the specified maximum velocity and acceleration to derive the fastest possible trajectory from the current position to the target position. The current position and velocity are determined by the current trajectory and the current time. The initial position and velocity (when the model is started) may be specified as parameters. It differs from the Continuous Sigmoid block in that the maximum velocity and acceleration are inputs to the block rather than parameters. Hence, they may be time-varying.
150
Extra Sources
The dialog box of the Continuous Sigmoid (with limits) block is shown in Figure 78. The Continuous Sigmoid (with limits) block samples its inputs at regular intervals, determined by the Input Sample Time parameter. Each time the inputs are sampled and the target position has changed, the trajectory is re-computed. Hence, the sample time should normally be slower than the time taken to traverse the trajectory. The output of the Continuous Sigmoid (with limits) block is generated using the sampling rate specified by the Output Sample Time parameter. The Output Sample Time may be set to zero for a continuoustime trajectory. The Continuous Sigmoid (with limits) block provides the Done signal to indicate when the trajectory reaches its target. This output may be used to trigger another event, or reset encoder counts, for example.
Extra Sinks
Sinks are Simulink blocks, like Scopes, that take an input but generally do not have output ports. Quanser Consulting provides additional sinks to enhance the Simulink environment. Double-click on the Extra Sinks icon in the Quanser Toolbox, qctools, to access these sinks. The extra sinks are illustrated in Figure 79. Two sinks are currently provided: the Stop With Error block and the PC Speaker block.
151
Extra Sinks
Stop With Error
The Stop With Error block is quite useful for reporting error conditions in your model. It stops the model when its input is non-zero and issues an error. The user can specify the error message that is issued. Hence, this block is useful for reporting different errors in your model. For example, the model could be set up to stop when a limit switch is hit and to issue a different error message depending on the limit switch encountered. The Stop With Error block takes a single parameter, the error message string, as illustrated in Figure 80. Quotes are not required around the string because the Error Message parameter is not evaluated. The error message specified will be reported to the user when the input to the block becomes non-zero.
Figure 80 Stop With Error parameters
PC Speaker
The PC Speaker block allows you to produce sound using the PC Speaker. The block is primarily for demonstration purposes since no sound card is required. However, novel uses may be found for this block. The dialog box of the PC Speaker block is shown in Figure 81. The speaker in the PC allows only very limited control. It is really designed for generating a single, grating tone. However, the PC Speaker Figure 81 PC Speaker parameters block uses Pulse-Width Modulation (PWM) techniques to produce an arbitrary analog waveform from the speaker. PWM involves using a square wave of varying duty cycle to emulate an analog signal level. Since the mechanical speaker system acts as a low-pass filter, this technique does in fact produce the desired result. The PC Speaker block takes a single parameter the period of the PWM waveform. The base sampling rate of your model must be at least as fast as the PWM period in order to vary the duty cycle of the PWM waveform. The higher the base sampling rate of your system, the better the resolution of the PWM. The default value corresponds to an 8 kHz PWM frequency. Hence, at the default setting the user will hear the 8 kHz tone on top of the audio waveform being output. Use a faster PWM period to move this tone out of
152
Extra Sinks
hearing range. Writing to the PC speaker is very fast, so impressive sampling rates may be used.
153
Transformations Transformations
Some operations are common when implementing real-time models. For example, converting a transfer function from continuous-time to discrete-time is a typical operation, especially when implementing a multi-rate control system. The Transformations group in the Quanser Toolbox provides a set of Simulink blocks to perform these kinds of functions for you. The block set is depicted in Figure 82.
154
Transformations
parameter is a vector representing the denominator polynomial of the continuous-time transfer function. These two parameters are exactly the same as the continuous-time Transfer Function block provided in Simulink. The last parameter is the sample time. The continuous-time transfer function identified by the first two parameters will be discretized for this sampling period. The resulting discretetime transfer function will be used in the real-time code and in simulation. The default sampling period is the base sampling period of your model.
Discretized Zero-Pole
The Discretized Zero-Pole block converts a continuous-time transfer function in zero-pole form to a discrete-time transfer function. A bilinear transformation (Tustin) is used to perform the conversion. The dialog box of the Discretized Zero-Pole block is shown in Figure 84.
155
Transformations
System Zero-Pole
The System Zero-Pole block implements a zero-pole-gain model. The model is specified as an LTI model and may be multidimensional, continuous or discrete. The model is typically created using the zpk command, but any of the LTI model commands may be used. The dialog box of the System Zero-Pole block is shown in Figure 87.
Figure 87 System Zero-Pole Block parameters
156
Transformations
System State-Space
The System State-Space block implements a state-space model. The model is specified as an LTI model and may be multidimensional, continuous or discrete. The model is typically created using the ss command, but any of the LTI model commands may be used. The dialog box of the System State-Space block is shown in Figure 88.
Figure 88 System State-Space Block parameters
To Bytes
The To Bytes block converts its input to a stream of bytes. The input can be any of the standard data types. For example, if a scalar double value is fed into the block, then 8 bytes will be output from the block. Whether the first byte output is the least-significant or most-significant byte is user-selectable. The To Bytes block actually takes two parameters: the input data type and the byte-ordering.
Figure 89 To Bytes parameters
157
Transformations
The dialog box of the To Bytes block is represented in Figure 89. The Data Type parameter is used to select the type of the input. (The type cannot be determined automatically from the input because Simulink resolves data types after it resolves port widths ). The Byte Order parameter selects whether the bytes are output in little endian or big endian order. For example, suppose the input is the single 32-bit integer 0x12345678 in hexadecimal. If the big endian byte order is chosen, then the output will be the vector [0x12, 0x34, 0x56, 0x78]. When the little endian byte order is selected, then the output is [0x78, 0x56, 0x34, 0x12].
From Bytes
The From Bytes block performs the reverse operation to the To Bytes block. It takes a vector of bytes and combines them into another data type. The output can be any of the standard data types. For example, if the double type is selected then when 8 bytes are fed to the input, a scalar double will be output from the block. Whether the first byte input is the least-significant or most-significant byte is user-selectable. The From Bytes block actually takes two parameters: the output data type and the byte-ordering.
The dialog box of the From Bytes block is depicted in Figure 90. The Data Type parameter is used to select the type of the output. The vector of bytes at the input must be a multiple of the data type size so that the From Bytes block has the right number of bytes to construct the data type at the output. Hence, when the double type is selected, the input must contain a multiple of 8 bytes. The Byte Order parameter selects whether the bytes at the input are in little endian or big endian order. For example, suppose the type is set to uint32 and the input is the vector [0x12, 0x34, 0x56, 0x78] in hexadecimal. When the big endian byte order is selected, then the output is 0x12345678. If the little endian byte order is chosen, then the output is 0x78563412.
158
159
CRS ROBOTS
A465 Motor Pulses to Joint Angles The A465 Motor Pulses to Joint Angles block converts encoder counts read from all six CRS A465 joints into joint angles in radians. The block inputs are the motor encoder pulses. The encoder counts read from the six A465 motors. The encoder counts should be supplied as a 6-vector in order of the joints i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. As an output, the A465 Motor Pulse to Joint Angles block produces the joint angles, in radians, for each of the joints. These joint angles in radians, corresponding to the given encoder counts, are contained in a 6-element vector. They are supplied in the same order as the input i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Motor Pulses to Joint Angles block has no parameters. A465 Joint to World The A465 Joint to World block converts joint angles to world coordinates for the CRS A465 robot. The block inputs are the joint angles in radians for the six A465 joints. The joint angles should be supplied as a 6-vector in order of the joints i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Joint to World block produces the position and orientation of the robot endeffector as a 6-vector in the world coordinates. The vector elements represent the X, Y, and Z cartesian coordinates of the end-effector in millimeters, followed by the yaw, pitch and roll respectively, in radians. The A465 Joint to World block has no parameters. A465 Forward Kinematics The A465 Forward Kinematics block converts joint angles to world coordinates for the CRS A465 robot. As an input to the block, the joint angles should be supplied as a 6-vector in order of the joints i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Forward Kinematics block produces the position and orientation of the robot end-effector as a 6-vector, as well as a stance signal that represents the current robot pose. The stance output is included because the robot can in general achieve the same position and orientation of the end-effector via eight different joint configurations. The stance output differentiates between these configurations and is useful as an input to the A465 Inverse Kinematics block. The world coordinates are supplied in a 6-vector containing the position and orientation of the robot end-effector. The vector elements represent the X, Y, and Z cartesian coordinates of the end-effector in millimeters, followed by the yaw, pitch,
160
CRS ROBOTS
and roll respectively, in radians. The stance is supplied as a 3-vector representing the desired stance of the robot. The elements and their possible values are defined in Table 36. The A465 Forward Kinematics block has no parameters. Element 1 2 3 0 Reaching Backward. Elbow Down. Wrist Flipped. 1 Reaching Forward. Elbow Up. Wrist Not Flipped. -1 Let Inverse Kinematics choose element configuration.
A465 Stance The A465 Stance block outputs the stance corresponding to the given joint angles, for the CRS A465 robot. The block input is a vector containing the joint angles in radians for the six A465 joints. The joint angles, supplied as a 6-vector, should be in order of the joints i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Stance block produces a stance signal that represents the current robot pose. The stance output is useful because the robot can in general achieve the same position and orientation of the end-effector via eight different joint configurations. The stance output differentiates between these configurations and is useful as an input to the A465 Inverse Kinematics or A465 World to Joint blocks. Note that the A465 Forward Kinematics block also provides a stance output and is generally used instead of this block. The stance of the robot is represented by a 3-element vector, whose elements and their possible values are defined in Table 36. The A465 Stance block has no parameters. A465 Inverse Kinematics The A465 Inverse Kinematics block converts world coordinates to joint angles for the CRS A465 robot. Since this mapping is not unique, additional information must be supplied to indicate which of the eight possible solutions (in general) is desired. The block uses the previous joint angles and the desired stance to arrive at a suitable configuration. Typically, the stance supplied by the A465 Forward Kinematics block is used for the stance input. The previous joint angles are maintained by the block itself. It uses the joint angle output from the previous iteration. Look under the block mask for more details. A465 World to Joint The A465 World to Joint block converts world coordinates to joint angles for the CRS A465 robot. Since this mapping is not unique, additional information must be supplied to indicate which of the eight possible solutions (in general) is desired. The block uses the
161
CRS ROBOTS
previous joint angles and the desired stance to arrive at a suitable configuration. Typically, the stance supplied by the A465 Forward Kinematics block is used for the stance input. Note that the A465 Inverse Kinematics block is generally easier to use because it keeps track of the previous joint angles automatically. A465 Joint Angles to Motor Pulses The A465 Joint Angles to Motor Pulses block converts joint angles in radians to encoder counts for all six CRS A465 joints. The block input is a 6-element vector containing the joint angles, in radians. The joint angle elements should be supplied, in the 6-vector, ordered in accordance with the robot joints i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Joint Angles to Motor Pulses block produces the encoder counts for each of the motors from the given joint angles. The encoder counts are generated in a 6-vector with the elements in the same order as the input i.e. base, shoulder, elbow, forearm roll, wrist pitch and wrist roll. The A465 Joint Angles to Motor Pulses block has no parameters.
162
CRS ROBOTS
CRS Catalyst-5 Blocks
The CRS Catalyst 5DOF (also known as CRS A255) is a 5-DOF articulated robot. It has 5 joints powered by 5 motors. The Quanser blocks interfacing to the CRS Catalyst-5 are depicted in Figure 93.
CAT5 Motor Pulses to Joint Angles The CAT5 Motor Pulses to Joint Angles block converts encoder counts read from all five CRS Catalyst-5 joints into joint angles in radians. CAT5 Joint to World The CAT5 Joint to World block converts joint angles to world coordinates for the CRS Catalyst-5 robot. CAT5 Forward Kinematics The CAT5 Forward Kinematics block converts joint angles to world coordinates for the CRS Catalyst-5 robot. This block is functionally equivalent to the CAT5 Joint to World block. CAT5 Inverse Kinematics The CAT5 Inverse Kinematics block converts world coordinates to joint angles for the CRS Catalyst-5 robot. Since there are singularities in the workspace, the block uses the previous
163
CRS ROBOTS
joint angles to arrive at a suitable configuration. The previous joint angles are maintained by the block itself. It uses the joint angle output from the previous iteration. Look under the block mask for more details. CAT5 World to Joint The CAT5 World to Joint block converts world coordinates to joint angles for the CRS Catalyst-5 robot. Since there are singularities in the workspace, the block uses the previous joint angles to arrive at a suitable configuration. Note that the CAT5 Inverse Kinematics block is generally easier to use because it keeps track of the previous joint angles automatically. CAT5 Joint Angles to Motor Pulses The CAT5 Joint Angles to Motor Pulses block converts joint angles in radians to encoder counts for all five CRS Catalyst-5 joints.
164
165
wc_build
Formats: wc_build wc_build('model') wc_build('model','path') Parameters: model Name of the Simulink model for which to build real-time code. path Description: The wc_build command generates and compiles the real-time code for a Simulink model and automatically downloads it to the target machine. It also changes directory to the model directory, or the path specified, prior to building the code so that all intermediate files and the final real-time module reside in the same directory as the Simulink model. The default target is the local machine. With no model specified, the currently open model is built. In the second form of the command, the model to build may be specified explicitly. The final form of the command also allows you to specify the path of the directory containing the model. The model path is only required if the model is not open and it is not in the MATLAB path (see the commands path and wc_path). Directory containing the Simulink model.
167
wc_build
Examples: wc_build wc_build('test') Builds the real-time code for the currently open Simulink model. Builds the real-time code for model 'test.mdl'.
wc_clean
Formats: wc_clean wc_clean('model') Parameters: model Name of the Simulink model for which to clean up intermediate files. Description: The wc_clean command may be used to delete all temporary files created during the building of real-time code. Note that it does not blindly delete source files or header files. It only deletes the source files and header files automatically generated by the Real-Time Workshop. It does delete all object files and other intermediate files, as well as generated real-time code (i.e. *.wcl file). wc_clean uses wc_path to get the path for the model. If no model is specified, the command cleans up intermediate files for the model that is currently open. The wc_clean command also allows you to specify the model explicitly. This command is useful under two circumstances. First, you may wish to archive your work and clear out all unnecessary files. The wc_clean command will do that for you. Second, there may be unusual circumstances where the code is not building cleanly because of old intermediate files left in the model directory. In this case, wc_clean may be used to ensure that no old files are left around. Examples: Clean up intermediate files for the currently open Simulink model. wc_clean wc_clean('test') Clean up intermediate files for the files generated when building model 'test.wcl'.
168
wc_close wc_close
Format: wc_close Description: The wc_close command closes the current WinCon project. The user is prompted to save the project if it has been modified.
wc_disconnect
Formats: wc_disconnect wc_disconnect('model') wc_disconnect('model', 'path') Parameters: model Name of the WinCon model to disconnect. path Description: The wc_disconnect command disconnects a model from WinCon. If no model is specified then the current system is used. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). This function is only useful in MATLAB Releases 11 or above. This function will do nothing in earlier versions. wc_disconnect does not assume that WinCon Server is running. Directory containing the real-time model (see wc_path).
wc_download
Formats: r = wc_download r = wc_download('model') r = wc_download('model','path') Parameters: model Name of the Simulink model to download. path Directory containing the real-time module (see wc_path).
169
wc_download
Return Values: r Boolean: 1 on success, 0 to indicate an error.
Description: The wc_download command runs the WinCon Server automatically, if it is not already running, and downloads real-time code into WinCon. If no model is specified, the current system is used. The path need not be specified if the model is open or is in the MATLAB path. The command also allows you to specify the path of the directory containing the model. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). If the download is successful, a value of 1 is returned. Otherwise a value of 0 is returned.
wc_examples
Formats: r = wc_examples wc_examples Return Value: r String containing the full path to the WinCon examples directory.
Description: The wc_examples command returns the full path to the WinCon examples directory. If a return argument is specified, the returned path is stored as a string into that parameter. If no return argument is specified, the wc_examples command change to the WinCon examples directory.
wc_isrunning
Formats: r = wc_isrunning r = wc_isrunning('model') r = wc_isrunning('model', 'path') Parameters: model path Name of the WinCon model (.wcl). Directory containing the real-time model (see wc_path).
170
wc_isrunning
Return Values: r Description: The wc_isrunning command tests whether the real-time code is currently running. If no model is specified then the current system is used. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). wc_isrunning returns 1 if the model is running, 0 otherwise. Boolean: 1 if true, 0 if false.
wc_newplot
Formats: wc_newplot wc_newplot('model') Parameters: model Description: The wc_newplot command opens a new plot in WinCon. If no model is specified, wc_newplot uses the current system. If no type is specified, the user will be presented with a list of the different plot types to choose from (e.g. Scope, X-Y Graph, Digital Meter, Thermometer). wc_newplot runs WinCon Server automatically, if it is not already running. Name of the Simulink model.
wc_open
Format: r = wc_open('project') Parameter: project Return Value: r Boolean: 1 on success, 0 to indicate an error. WinCon project filename.
171
wc_open
Description: The wc_open command opens the specified WinCon project. wc_open runs WinCon Server automatically, if it is not already running. wc_open returns 1 on success, 0 otherwise. Example: wc_open( 'q_p' ) Opens the WinCon project 'q_p.wcp'.
wc_openplot
Formats: wc_openplot wc_openplot('model') wc_openplot('model', 'plot') Parameters: model plot Description: The wc_openplot command opens in WinCon a Simulink display (e.g. Scope, X-Y Graph, Display) defined in the given model. If no model is specified, wc_openplot uses the current system. If no plot parameter is specified, the user is presented with a list of displays, as defined in the model, to choose from. wc_openplot runs WinCon Server automatically, if it is not already running. Example: wc_openPlot( 'q_p', 'q_p\Angle' ) opens in WinCon the display called 'Angle' in the model 'q_p.mdl'. Name of the Simulink model. Name of plot to open.
wc_path
Formats: p = wc_path p = wc_path('model')
172
wc_path
Parameters: model Return Values: p Description: The wc_path command is used internally by many of the other WinCon scripts. It returns the full path to the directory in which the given model is stored. It is also used by the code generation modules to ensure that the generated code is always produced in the same directory as the Simulink model even if the current directory in MATLAB is different! However, you may find this command useful if you wish to write your own MATLAB scripts that need to know where the Simulink model is stored. A primary example might be a script that automatically runs through a series of tests, modifying the controller gains each time and storing data to the same directory as the model, or to a subdirectory. With no model specified, the command returns the path to the currently open model. The command also allows the model to be specified explicitly. If the model is not open, then it must be in the MATLAB path (see the MATLAB path command). Additionnally, if the model has yet to be saved then an empty string is returned. Use the isempty command to test for an empty matrix. Examples: p = wc_path p = wc_path('test') Returns the path to the currently open model in the variable p. Returns the path to the Simulink model called 'test.mdl' in the variable p. String containing the full path name to the directory where the model is. Name of the Simulink model for which to return the path.
wc_refresh
Formats: r = wc_refresh Return Values: r Boolean: 1 on successful refresh, 0 to indicate an error.
173
wc_refresh
Description: The wc_refresh command refreshes the state of Simulink so that its state is updated correctly during the execution of a MATLAB script. wc_refresh returns 1 if Simulink is refreshed or 0 if Simulink could not be refreshed.
wc_run
Formats: r = wc_run Return Values: r Description: The wc_run command runs the WinCon Server. If it is already running, it brings it to the foreground. wc_run returns 1 if WinCon had not been running or 0 if WinCon was already running or failed to run. Boolean: 1 on success, 0 to indicate an error.
wc_save
Formats: wc_save wc_save('file') Parameter: file Description: The wc_save command saves the current WinCon project. If a filename is specified then the project is saved to the specified file. If no extension is specified, then an appropriate extension (i.e. wcp) is added. Example: wc_save( 'q_p' ) Saves the current WinCon project (e.g. model and associated plots and control panels) to the project file named 'q_p.wcp'. Filename to save the WinCon project to.
174
wc_saveplot wc_saveplot
Formats: wc_saveplot('plot title', 'filename') Parameters: plot title filename Description: The wc_saveplot command saves the WinCon plot data to a MAT file. wc_saveplot looks for the plot with the given title and tells it to save its data to the given file in MAT format. Note that the .mat extension MUST be specified in the filename. It is not added automatically. The WinCon plot name is shown in the plot caption. Also note that when you save data from a plot, WinCon switches it to fixed mode temporarily in order to collect the data from the Server without any decimation It is important to wait until all the data has been collected before you start the controller again. See the script example q_p_script.m, in Section Script Example: script_q_p.m,that ensures that the data has been saved before you start a second run. As a reminder, any data saved in a MAT file can then be loaded into the MATLAB workspace by using the load command. Example: wc_savePlot( 'Scope q_p\Angle', 'scope.mat' ) Saves the data displayed in 'Scope q_p\Angle' to the file 'scope.mat'. Name of the WinCon plot window. Name of the MAT file to save data to.
wc_select
Formats: wc_select wc_select('model') wc_select ('model', 'path') Parameters: model path Name of the Simulink model to select. Directory containing the real-time model (see wc_path).
175
wc_select
Description: The wc_select command selects the given model as the active WinCon model and loads the corresponding real-time code into WinCon Client. If no model is specified then the current system is used. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). wc_select will run WinCon Server automatically, if it is not already running.
wc_setoptions
Formats: wc_setoptions wc_setoptions('model') wc_setoptions('model' , 'os_opt') Parameters: model Name of the Simulink model for which to set the options. May also be 0. os_opt Name of the operating system. Valid values are: 'win', 'dos' or 'nt'. Description: wc_setoptions sets the build options for a model in order to generate real-time code for WinCon. In its first form of the command, when no option is specified, the wc_setoptions command sets the default options for new Simulink models created during that MATLAB session. wc_setoptions is automatically executed during MATLAB startup (i.e. called in matlabrc.m) so that the default Real-Time Workshop options are configured for WinCon whenever a new Simulink model is created. That call also makes WinCon the default for real-time code generation. The second form of the command, with the name of a Simulink model as an argument, changes the settings for an existing Simulink model to those required for that machine operating system. When a Simulink model is specified, it must be open at the time the wc_setoptions command is invoked. If the model is set to the number zero in this case (not a string), then the wc_setoptions command sets the defaults for all new Simulink models created during the current MATLAB session. If the name of the operating system is not specified, a default suitable for the user's machine is assumed (set during installation). The command will not overwrite the base sampling period if you have already specified one. If the integration method is variable step then wc_setoptions changes the integration method to an "equivalent" fixed step integration method. Otherwise it leaves the integration method unchanged.
176
wc_setoptions
The final form of the command allows you to specify a different operating system. Examples: wc_setoptions('test', 'nt') set the options for the 'test.mdl' diagram to build real-time code for a Windows 2000/XP WinCon Client. set the default options to build real-time code for a Windows 2000/XP WinCon Client.
wc_setoptions(0, 'nt')
wc_start
Formats: wc_start wc_start('model') wc_start('model','path') Parameters: model path Name of the model to start. Directory containing the real-time module (see wc_path).
Description: The wc_start command launches the WinCon Server, if it is not already running, and starts the real-time code for the model. If no model is specified then the current system is started. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). The model code can then be stopped using the wc_stop command.
wc_stop
Formats: wc_stop wc_stop('model') wc_stop('model', 'path') Parameters: model path Name of the Simulink model to stop. Directory containing the real-time module (see wc_path).
177
wc_stop
Description: The wc_stop command stops the real-time code running under the WinCon Client. If no model is specified then the current system is stopped. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). wc_stop assumes WinCon Server is running. It will not issue an error if the model has already stopped running. In fact, if a script exits because wc_isrunning returns false, then wc_stop should still be called to update the Simulink diagram status.
wc_update
Formats: wc_update wc_update('model') wc_update('model', 'path') Parameters: model path Description: The wc_update command updates workspace variables in the real-time code. wc_update runs WinCon Server automatically, if it is not already running. If no model is specified then the current system is used. The model path is only required if the model is not open or if it is not in the MATLAB path (see the commands path and wc_path). Name of the model to update. Directory containing the real-time model (see wc_path).
178
179
The WinCon Demonstrations are example Simulink-based diagrams which illustrate how to use WinCon. Some of the examples are hardware-specific and require the presence of a particular data acquisition card or a specific Quanser experiment. The same examples are provided for each data acquisition card. Other examples do not require any hardware. Figure 95 is obtained by double-clicking on the MultiQ-PCI Examples block of the WinCon Demonstration window illustrated in Figure 94. It displays the library of demonstrations available for the Quanser MultiQ-PCI board. If you are using another type of Quanser's data acquisition card (e.g. MultiQ or MultiQ-3), then open the subsystem corresponding to your data acquisition card to acess the associated examples.
181
NOTE: If you are not using a MultiQ-series board, ensure that you have the data acquisition blocks required to run the desired example and possibly a timer block for your particular board. You will need to replace any of the MultiQ-series blocks with the equivalent blocks appropriate for your data acquisition card. See the Real-Time Workshop manuals that came with your MATLAB package for details on writing your own drivers for your board(s), or contact Quanser. Also note that the Simulink files corresponding to the WinCon Demonstration window are stored in the directory returned by the function wc_examples, such as C:\MATLAB6p1\work\Examples. Hardware-specific examples are stored in subdirectories of the Examples directory. Table 38 lists the different subdirectories and what data acquisition card is required by the examples in that directory. Subdirectory MULTIQ MULTIQ-3 MULTIQ-PCI Q8 NIE Data Acquisition Card Quanser's MultiQ-2 data acquisition card (supplanted by MultiQ-3). Quanser's MultiQ-3 data acquisition card. Quanser's MultiQ-PCI data acquisition card. Quanser's Q8 data acquisition card. National Instruments E-Series data acquisition cards.
182
183
A/D #0
0 1 2 4 5 6
Loopback wire
7 4 5 6
3 0 1 2 3
D/A #0
Computer
2. To open the model, follow the instructions given in Section WinCon Demonstrations Window and double-click on the Analog Loopback (q_a_lpbk) block that corresponds to your data acquisition board. For the MultiQ-PCI, the model window depicted in Figure 97 will open. Note that you could have created this model yourself using Simulink and the Quanser Toolbox, as described in Interfacing to Hardware: The Quanser Toolbox on page 89.
184
3. You must first ensure that all your options are set correctly according to the operating system under which the real-time code is going to run. The WinCon Server installer automatically configures the examples so this step is not strictly necessary. (Simulink is also configured to such that the default options are appropriate for WinCon). However, this step is required for pre-existing models which may not be configured for WinCon. To configure the model for WinCon, select WinCon | Set WinCon Options from the Simulink menu bar, as seen in Figure 98 below. Note: If you are running the client on a different PC, you must start the WinCon Server and Connect to the remote WinCon Client before building or downloading the model.
185
This step generates the real-time code for the diagram. Wait until the compilation is complete. The MATLAB window displays the progress of the code generation task and when it is complete, the following message appears: ### Successful completion of Real-Time Workshop build procedure for model: q_a_lpbk
Following the code generation, WinCon Server and WinCon Client are automatically started. The generated code is automatically downloaded to the Client and the system is ready to run. 5. Click on the Start button in the WinCon Server toolbar (shown Figure 100). This action starts the controller, which runs at a sampling frequency of 200 Hz, as set in the Simulink model. Click on the Open Plot button in WinCon Server. The names of all displays in the Simulink model diagram appear in a Multiple Select Variable Tree. You
186
The sine wave has been limited by the A/D input channel, which only has a range of 5 volts. 6. Click Go To Simulink from the WinCon Server toolbar. Double-Click on the Gain block and change it to 4. Note the changes in your Scope plot. This shows that the output of the D/A is being measured by the A/D block. You should also note that you were able to change the gain in real-time! 7. Now Stop the controller via the WinCon Server toolbar. Go back to your Simulink model and select WinCon | Options... from the menu bar. Under the Solver tab, change the Fixed step size from 0.005 to 0.05 (thus changing the sampling frequency from 200Hz to 20Hz). Re-run the controller from WinCon Server. You will get an error message telling you that the model needs to be rebuilt. When you change the base sampling period it affects all discrete time blocks in your system. Hence, Simulink insists that you rebuild the real-time code when the sampling period is changed. Rebuild the real-time code. Note that the code builds much faster because only one file has to be recompiled the source code generated from your model. Now you can run the controller again. Notice the difference in the plotted sine wave. Since the sampling frequency has been lowered, the signal is more discretized than the previous one. Stop the controller. You should now be familiar with setting the sampling period for a model. Go back to the WinCon | Options..., and reset the step size to 0.005 (i.e. 200Hz). Re-build your controller and plot the Scope once again.
187
You can now Stop the controller if you have not done so already. This brings to an end the Analog Loopback Example. From this example, you should have an understanding of the following: How to build a Simulink model and download it to WinCon Client. How to plot model variables in WinCon Scope. How to save Wincon Scope data for later use in the MATLAB environment.
188
2. To open the model, follow the instructions in section WinCon Demonstrations Window, and open the model called q_p.mdl. Remember to choose the model that is meant for your particular board. This model incorporates a simple proportional controller as part of the closed-loop system. The purpose of this controller is to track a desired angle. You should notice the proportional gain block does not have a numeric value but uses a variable Kp instead. This feature allows the user to enter data directly from the MATLAB environment. At this point, you should go to the MATLAB command window and assign Kp an initial value of 0.15.
189
3. You can now Build the controller and start it using the WinCon Server. Open a WinCon Scope and select Theta (deg) Scope. You can also go ahead and open a WinCon Digital Meter by selecting Theta (deg) Display to obtain a digital read-out of the output angle. To fully gauge the performance of a controller, it is important to see the output plotted along with the desired angle. In your Scope plot window, select File | Variables... and select Setpoint (deg). You should now be seeing two plots simultaneously. This plot gives provides a good indication of how your controlller is performing. You should have also noticed that you could have chosen any block to plot under the Variables menu. This flexibility comes in handy when attempting to diagnose different sections of your overall signal path.
190
5. With most controllers it is nescessary to tune the parameters to achieve the desired response. WinCon facilitates this need by allowing parameters to be changed via the Simulink diagram, or through WinCon Control Panels. From your WinCon Server, select Window | Control Panel. A new control panel window will appear. From the menu, select Control | Insert Control. For this application, a knob control will suffice. You will now be prompted to associate a parameter with the knob control. Select Proportional Gain | Gain (1,1). This control is now associated with the proportional gain block in your model. From the menu, select Control | Properties, and set the maximum to a value of 0.5 while leaving the minimum at 0. Finally, de-select Window | Design Mode. Your window should now look similar to Figure 107 below:
191
While adjusting the position of the knob, notice the change in your response (ScopePlot). This feature gives the user a tool to fine-tune the controller. Take note how the response reacts in real-time to changes in the knob setting. For more information about WinCon Control Panels, refer to section WinCon Control Panel on page 78. 6. After finding a setting that achieves the desired response, return to the Simulink model and change the desired angle from 30 to 45 degrees (Amplitude (deg)). Take note how the controller responds to these changes in the desired angle. You can now stop the controller. 7. From your WinCon Server window, select File | Save. Choose a name and location of your WinCon Project. After saving your project, exit WinCon Server. Return to the MATLAB command window and type exit. MATLAB and Simulink should no longer be running. Locate your saved WinCon Project (i.e. .wcp file), and double-click to open it. You should see your Scope as well as the knob control windows pop-up. From WinCon Server, start your controller again. You should now be seeing your response through the scope and your knob will still control the proportional gain. With WinCon Projects, you can re-open the controller with all the displays and controls without requiring MATLAB or Simulink. The Proportional Control example illustrated the following points: Setting model parameters on-the-fly through the MATLAB or Simulink environments as well as directly from WinCon, via its Control Panels. Using WinCon Controls to set model parameters. Using WinCon Projects to save and restore WinCon Server's Client connections, displays, and Control Panels. WinCon Projects also allow you to operate without MATLAB and Simulink.
192
The following script, complete with comments, demonstrates the WinCon functions available in MATLAB. For more information about writing a script, please refer to chapter WinCon Scripting Commands in MATLAB on page 167. The script below initializes Kp to 0.05, and increments it by 0.1 up to a final value of 0.45, while capturing the response for each iteration.
% SCRIPT_Q_P % % % % % % % This WinCon script in Matlab collects the actual position response of the Quanser SRV02-E plant for increasing proportional gains Kp changing from 0.05 V/deg to 0.45 V/deg in increments of 0.1. Copyright (C) 2002 Quanser Consulting Inc. Quanser Consulting Inc.
clear all % sets model name and path model = 'q_p_script'; path = wc_path( model );
193
% Load the data and plot a comparison in a MATLAB Figure % Offset each curve of (5*I) (deg). for I = 1 : N_runs
194
end plot( out ) title( 'Responses for Different Proportional Gains' ) xlabel( 'Sample #' ) ylabel( 'Theta [deg]') grid on
Using the above script, the Matlab program starts by initializing the gain Kp and executing the command wc_start, which starts the controller. The script then waits for the termination of the controller by executing the wc_isrunning function. The controller terminates at sample number 3000 using a Stop Simulation block in the diagram. When the controller stops, a filename is created (res_n.mat, n = 1..5) and the contents of the plot named Scope - q_p_Angle are saved to the file. The script then increments Kp and runs the controller again with a new value of Kp. Note that wc_stop MUST be called for proper operation, even though the controller has already stopped (it disconnects). This process is performed 5 times and at the end of the cycle, the files that were created are loaded into the MATLAB workspace and the plots shown below are generated. In this manner, the user can evaluate system response for different values of Kp. Note that the buffer length of the real-time plot should be longer than the duration of the run. This way you ensure that you do not end up collecting only part of the data from the run. To run the example, type wc_examples in the MATLAB command window. At this point you must change to the directory that matches your DAC card. If you have the MultiQ-PCI, for example, type cd MultiQ-PCI to change to the proper directory. Finally, type script_q_p to run the script. Wait for the script to fully execute. While executing, you will see a digital display showing you the current position of the plant. After 5 iterations, when the script is completed, you will be presented with a plot similar to Figure 99 below.
195
Notice that each position response is offset by 5 degrees from the previous one to better differentiate all 5 responses.
196
Troubleshooting Troubleshooting
On the rare occasion, users may experience problems when trying to run WinCon. This Troubleshooting section is designed to assist the user in diagnosing some of the potential problems.
197
198
WinCon Menu Missing from Simulink Diagram WinCon Menu Missing from Simulink Diagram
If the WinCon menu is missing from the Simulink diagrams, then WinCon Link is not running. Make sure that you rebooted the computer after installing WinCon Server. You can run WinCon Link at any time, but be sure to close any Simulink diagrams first. Then run WinCon Link and reopen the Simulink diagrams.
199
200
3. Right-click on the Windows device you wish to convert, then click Convert to RTX. 4. Click Apply to select another device or click OK to close the RTX Properties control panel. If the RTX Properties control panel could not remove the specified device, you will receive a warning to uninstall the device and the Device Manager will be started. To uninstall the device: 1. Select the device you are trying to convert to RTX. 2. From the Action menu, click Uninstall. 3. Restart your system. 4. To verify that the device has been installed correctly, open the RTX Properties control panel and check the Devices tab. Your device will be listed under the RTX Hardware list, along with the IRQ and Shareable flag set by default.
201
202
203
Index
Stichwortverzeichnis
A A465 robot....................................................................................................................159-162 Administrator.......................................................................................15, 23, 58, 64, 198, 200 aliasing...................................................................................................................................68 analog input..........................................................................110, 111, 113, 115, 117, 120, 184 Analog Input ................................................................................................................119, 121 analog output.........................................................................................112, 113, 115-117, 184 B big endian.............................................................................................................................158 bilinear transformation.................................................................................................154, 155 Board Number...............................................................................111, 113, 115-117, 119-121 buffer size.............................................................................................................................197 byte-ordering................................................................................................................157, 158 C Catalyst-5 robot....................................................................................................159, 163, 164 Channel(s) to Use.........................................................................................112, 113, 116, 117 Channel(s) to Use field.................................................................................................112, 113 checksum................................................................................................................................36 compatibility....................................................................................................................15, 83 COM Port......................................................................................................................138-140 computation delay............................................................................................................39, 74 configuration............................................................................................................17, 18, 184 continuous-time transfer function................................................................................154, 155 CRS 255 robot......................................................................................................................159 CRS C500 controller............................................................................................................159 D data acquisition.............................................................................................................112, 116 data compression....................................................................................................................68 Data Type Conversion block................................................................................................199 decimation...................................................................................................................67-69, 75 Deterministic functions...............................................................................................51-53, 75 device drivers.............................................................................................37, 41, 54, 165, 200 Device Manager...........................................................................................................200, 201 Digital Input..................................................................................................................115-117 Digital Output...............................................................................................................116, 117 digital-to-analog...........................................................................................................112, 115 discrete-time.................................................................................................................112, 114 discrete-time transfer function.............................................................................................155 discretization........................................................................................................154, 155, 187 DLLs................................................................................................................................54, 55 DMA......................................................................................................................................41 Do not initialize counts........................................................................................................117 download................................................................................................................................77 dynamic link libraries.......................................................................................................54, 55 E Encoder................................................................................................................................117 Encoder Extras.....................................................................................................................122
Index
Encoder Input.......................................................................................................................117 Encoder Reset.......................................................................................................................122 E-Series............................................................................15, 126-130, 132, 133, 135-137, 182 External mode........................................................................................................................49 F Final Output(s).............................................................................................................113, 116 Final Output(s) field.............................................................................................................113 foreground time................................................................................................................39, 43 Forward Kinematics......................................................................................................160-163 Frame rate...............................................................................................................................37 H HAL Timer Period.................................................................................................43, 200, 202 hardware...............................................................................................................................115 hardware clock...........................................................................................................41, 43, 44 hardware interrupts.........................................................................................................41, 200 hardware timer.....................................................................................................................123 I IEEE-standard......................................................................................................................157 Initial Output(s)............................................................................................................113, 116 Initial Output(s) field............................................................................................................113 Initial Value(s).....................................................................................................................117 Invalid file format................................................................................................................198 Inverse Kinematics.......................................................................................................160-164 J joint angles....................................................................................................................160-164 L latency....................................................................................................................................41 limit switch.......................................................................................97, 99, 106, 109, 137, 152 little endian...........................................................................................................................158 load command................................................................................................................76, 175 localhost.................................................................................................................................57 LTI model.....................................................................................................................156, 157 M make_wc script.......................................................................................................................48 MathWorks...............................................................................................................................1 MATLAB Command Window......................................................30, 189, 191, 192, 195, 199 MATLAB Compiler.......................................................................................................55, 199 MATLAB Fcn block..............................................................................................................55 MATLAB scripts...................................................................................................55, 167, 173 MATLAB workspace.............................................25, 65, 75-77, 99, 163, 164, 175, 178, 195 Maximum Computation Time..........................................................................................39, 74 Measure Performance.............................................................................................................37 mex command......................................................................................................................199 Microchip.............................................................................................................................157 MultiQ-2...................................................................................................................44, 89, 182 MultiQ-3 (MQ3)...........................................44, 89, 90, 95, 102, 109, 181, 182, 189, 199, 200 MultiQ-PCI..........................................16, 44, 89, 100-102, 104-109, 181, 182, 184, 195, 198
Index
MultiQ-PCI Time-Base block................................................................................................44 multi-rate..............................................................................................................................112 N National Instruments..............................................................................................15, 126, 182 nt_msvc.tmf template makefile..............................................................................................48 P performance variables......................................................................................................38, 74 PIC microcontroller......................................................................................................140, 157 plug-and-play.......................................................................................................................199 Project....................................................15, 27, 32, 33, 37, 43, 65, 78, 83, 169, 171, 174, 192 Pulse-Width Modulation......................................................................................................152 Q q_a_lpbk model............................................................................................................184, 186 q_p model.....................................................................171, 172, 174, 175, 188, 189, 193, 195 q_sine model....................................................................................................50, 76, 197, 198 Q8.........................................................................15, 44, 89, 110-112, 114-117, 119-125, 182 qctools command...................................................................................................89, 143, 151 Quadrature............................................................................................................................117 R Real-Time Workshop..................................................1, 25, 42, 45-48, 50, 168, 176, 182, 186 reporting error conditions.....................................................................................................152 robot......................................................................................................................146, 159-164 RTX Properties.............................................................................................................200-202 S Sample Time.................................................................................................115-117, 119, 121 Sampling Interval.............................................................................................................39, 74 Scope block............................................................................................................................65 script_q_p program..............................................................................................................193 Service Pack.........................................................................................................................197 Set WinCon Options........................................................................................46, 47, 185, 198 S-functions.......................................................................................................50, 55, 165, 199 simget...........................................................................................................................112, 114 simget(bdroot,'FixedStep')...............................................................91, 94, 102, 104, 130, 132 Simulation Input...................................................................................................112, 115-117 Simulation Output................................................................................................................115 SimuLinux..............................................................................................................................85 SLX........................................................................................................................................85 speaker..........................................................................................................................151-153 SRV02-E servo module................................................................................................189, 193 ss command..........................................................................................................................157 standard C library.............................................................................................................53, 54 State Space block.................................................................................................................155 system clock...........................................................................................................................43 T Target Language Compiler........................................................................................1, 48, 165 TCP/IP......................................................................................................13, 17, 18, 25, 36, 59 technical support..................................................................................................................203
Index
template makefile...........................................................................................................48, 198 tf command...........................................................................................................................156 Threshold..................................................................................................25, 28, 35, 37, 39, 43 Time Base.............................................................................................................................123 timeouts................................................................................................................................197 To File block..........................................................................................................................75 To Workspace block........................................................................................................75, 76 Transfer Function block................................................................................................154-156 Tustin transformation...................................................................................................154, 155 U Universal Power Module..............................................................................................188, 189 Update Diagram...................................................................................................................191 W watchdog..............................................................................................................................110 watchdog timer.............................................................................................100, 106, 107, 110 wc_comm external interface..................................................................................................49 wcdemos...............................................................................................................................181 wctools command.......................................................................................................46, 85, 87 win_msvc.tmf template makefile.........................................................................................198 Win32 functions................................................................................................................50-53 WinCon Controller Library........................................................................................25, 50, 59 Windows operating system functions....................................................................................50 workspace variables...............................................................................................................77 world coordinates.........................................................................................160, 161, 163, 164 X X-Y Graph blocks............................................30, 32, 46, 65, 66, 71, 75, 76, 87, 88, 171, 172 Z Zero-Pole block............................................................................................................155, 156 zpk command.......................................................................................................................156