hal_demo
1 #!/bin/bash 2 #******************************************************************** 3 # Description: hal_demo 4 # 5 # This script is used to test/demo the Hardware Abstraction Layer 6 # 7 # There are actually a number of demos, and right now they may 8 # change frequently. To avoid cluttering up the scripts directory, 9 # this file contains all the demos. Select the one you want by 10 # giving an argument. For example, "hal_demo jogwheel" will run 11 # the jogwheel demo. 12 # 13 # if you don't specify a demo, this prints a usage message 14 # 15 # Author: 16 # License: GPL Version 2 17 # System: Linux 18 # 19 # Copyright (c) 2004-2009 All rights reserved. 20 #*******************************************************************/ 21 if [ ! $1 ] ; then 22 echo "Usage: scripts/hal_demo <demo_name>" 23 echo "Run from the emc2 directory only" 24 # print the list of demos 25 scripts/hal_demo list 26 exit 0 27 fi 28 # 29 # the first demo isn't a real demo - it simply lists all the demos 30 # 31 if [ $1 = list ] ; then 32 echo "Available demos are:" 33 echo " list - prints this list" 34 echo " load - loads hal core modules" 35 echo " unload - unloads hal code modules" 36 echo " parport1 - an introductory demo - step by step" 37 echo " siggen - another introductory demo - signal generator" 38 echo " scope - simple demo of halscope" 39 exit 0 40 fi 41 # 42 # The next two demos aren't really demos either - they simply 43 # load or unload the rtapi enviroment 44 # 45 # here is the "load" command 46 # 47 if [ $1 = load ] ; then 48 # load the rtos and rtapi 49 if ! scripts/realtime start ; then 50 exit -1 51 fi 52 # done 53 echo "RTAPI core loaded" 54 exit 0 55 fi 56 # 57 # here is the "unload" command 58 # 59 if [ $1 = unload ] ; then 60 # unload any left-over modules 61 bin/halcmd unloadrt all 62 # unload the rtos and rtapi 63 if ! scripts/realtime stop ; then 64 exit -1 65 fi 66 # done 67 echo "RTAPI core unloaded" 68 exit 0 69 fi 70 # 71 # We're almost ready for the real demos, first we must 72 # make sure the rtapi core is loaded 73 # 74 HAL_LIB_STR=`/sbin/lsmod | awk '{print $1}' | grep -x hal_lib ` 75 if [ ! "$HAL_LIB_STR" ] ; then 76 echo "All of the demos require the RTAPI and HAL_LIB modules" 77 echo "to be loaded. Use 'hal_demo load' to load them." 78 exit -1 79 fi 80 # 81 # The first demo: "parport1" simply tests the parallel port 82 # this one is a step by step, tutorial/intro to HAL concepts 83 # 84 if [ $1 = parport1 ] ; then 85 echo "(Comments that are part of the demo are in parenthesis.)" 86 echo "(This demo echos its commands to the screen so you can" 87 echo " see what each step does. Echoed commands start with '$')" 88 echo "Hit enter to install the parport module" 89 read 90 # change the 0278 if your port is at a different address 91 echo "$ bin/halcmd loadrt hal_parport cfg=\"0278\"" 92 bin/halcmd loadrt hal_parport cfg="0278" 93 echo "Hit enter see the component list" 94 read 95 echo "$ bin/halcmd show comp" 96 bin/halcmd show comp 97 echo "Hit enter to create a 1mS thread" 98 read 99 echo "$ bin/halcmd loadrt threads name1=parport.thread period1=1000000" 100 bin/halcmd loadrt threads name1=parport.thread period1=1000000 101 echo "Hit enter see the threads and functions" 102 read 103 echo "$ bin/halcmd show thread" 104 bin/halcmd show thread 105 echo "(the period is in nano-seconds)" 106 echo "$ bin/halcmd show funct" 107 bin/halcmd show funct 108 echo "Hit enter to continue" 109 read 110 echo "(connecting the parport read and write" 111 echo " functions to the 1mS thread)" 112 echo "$ bin/halcmd addf parport.0.read parport.thread" 113 bin/halcmd addf parport.0.read parport.thread 114 echo "$ bin/halcmd addf parport.0.write parport.thread" 115 bin/halcmd addf parport.0.write parport.thread 116 echo "(start the realtime thread)" 117 echo "$ bin/halcmd start" 118 bin/halcmd start 119 echo "Hit enter see the threads and functions again" 120 read 121 echo "$ bin/halcmd show thread" 122 bin/halcmd show thread 123 echo "(thread now has functions attached)" 124 echo "$ bin/halcmd show funct" 125 bin/halcmd show funct 126 echo "(functions have a non-zero users count)" 127 echo "Hit enter to see the pins" 128 read 129 echo "$ bin/halcmd show pin" 130 bin/halcmd show pin 131 echo "Hit enter to see the parameters" 132 read 133 echo "$ bin/halcmd show param" 134 bin/halcmd show param 135 echo "Hit enter to create some signals" 136 read 137 echo "$ bin/halcmd newsig jumper1 bit" 138 bin/halcmd newsig jumper1 bit 139 echo "$ bin/halcmd newsig jumper2 bit" 140 bin/halcmd newsig jumper2 bit 141 echo "(signals created - lets look at them)" 142 echo "$ bin/halcmd show sig" 143 bin/halcmd show sig 144 echo "Hit enter to connect signals to pins" 145 read 146 echo "(use signal jumper1 to connect input pin 10 to output pin 2)" 147 echo "$ bin/halcmd linksp jumper1 parport.0.pin-10-in" 148 bin/halcmd linksp jumper1 parport.0.pin-10-in 149 echo "$ bin/halcmd linksp jumper1 parport.0.pin-02-out" 150 bin/halcmd linksp jumper1 parport.0.pin-02-out 151 echo "(connections made - lets take a look)" 152 echo "$ bin/halcmd show sig" 153 bin/halcmd show sig 154 echo "(If you have a breakout board or other access to the port" 155 echo " you can apply a signal to pin 10 and verify that pin 2" 156 echo " follows it - updated every 1mS )" 157 echo "Hit enter to add another output" 158 read 159 echo "$ bin/halcmd linksp jumper1 parport.0.pin-03-out" 160 bin/halcmd linksp jumper1 parport.0.pin-03-out 161 echo "(input pin 10 is now routed to output pins 2 and 3 )" 162 echo "$ bin/halcmd show sig" 163 bin/halcmd show sig 164 echo "Hit enter to invert the pin 3 output" 165 read 166 echo "(invert pin 3 by setting a parameter of the parport module)" 167 echo "$ bin/halcmd setp parport.0.pin-03-out-invert TRUE" 168 bin/halcmd setp parport.0.pin-03-out-invert TRUE 169 echo "(if you have access to the pins, you can verify" 170 echo " that pin 3 is now inverted)" 171 echo "Hit enter to see the parameters" 172 read 173 echo "$ bin/halcmd show param" 174 bin/halcmd show param 175 echo "Hit enter to try halmeter" 176 read 177 echo "(running halmeter, a GUI application - it should" 178 echo " appear in another window.)" 179 echo "(click on the select button, then select a pin, signal," 180 echo " or parameter to observe. You can change what you are" 181 echo " observing at any time.)" 182 echo "(the meter updates approx. every 0.1 seconds - if you" 183 echo " have access to the pins, change the input and halmeter" 184 echo " will show the changes.)" 185 echo "(an interesting paremeter to observe is parport.thread.time" 186 echo " which is the most recent execution time of the thread in" 187 echo " nanoseconds. you should be able to see it change a little" 188 echo " due to jitter and other factors." 189 echo "(Click exit to shut down halmeter.)" 190 echo "$ bin/halmeter" 191 bin/halmeter 192 echo "Hit enter to finish the demo" 193 read 194 echo "(deleting signals)" 195 echo "$ bin/halcmd delsig jumper1" 196 bin/halcmd delsig jumper1 197 echo "$ bin/halcmd delsig jumper2" 198 bin/halcmd delsig jumper2 199 echo "(unloading realtime modules)" 200 echo "$ bin/halcmd unloadrt all" 201 bin/halcmd unloadrt all 202 exit 0 203 fi 204 # 205 # The next demo: "siggen" tests the signal generator component 206 # and halmeter. 207 # this one is also a step by step tutorial 208 # 209 if [ $1 = siggen ] ; then 210 echo "(Comments that are part of the demo are in parenthesis.)" 211 echo "(This demo echos its commands to the screen so you can" 212 echo " see what each step does. Echoed commands start with '$')" 213 echo "Hit enter to install the siggen module" 214 read 215 echo "$ bin/halcmd loadrt siggen" 216 bin/halcmd loadrt siggen 217 echo "Hit enter see the component list" 218 read 219 echo "$ bin/halcmd show comp" 220 bin/halcmd show comp 221 echo "Hit enter to create a 1mS thread" 222 read 223 echo "$ bin/halcmd loadrt threads name1=siggen.thread period1=1000000" 224 bin/halcmd loadrt threads name1=siggen.thread period1=1000000 225 echo "Hit enter see the threads and functions" 226 read 227 echo "$ bin/halcmd show thread" 228 bin/halcmd show thread 229 echo "(the period is in nano-seconds)" 230 echo "$ bin/halcmd show funct" 231 bin/halcmd show funct 232 echo "Hit enter to continue" 233 read 234 echo "(connecting the siggen update function to the 1mS thread)" 235 echo "$ bin/halcmd addf siggen.0.update siggen.thread" 236 bin/halcmd addf siggen.0.update siggen.thread 237 echo "(start the realtime thread)" 238 echo "$ bin/halcmd start" 239 bin/halcmd start 240 echo "Hit enter see the threads and functions again" 241 read 242 echo "$ bin/halcmd show thread" 243 bin/halcmd show thread 244 echo "(thread now has function attached)" 245 echo "$ bin/halcmd show funct" 246 bin/halcmd show funct 247 echo "(function has a non-zero users count)" 248 echo "Hit enter to see the pins" 249 read 250 echo "$ bin/halcmd show pin" 251 bin/halcmd show pin 252 echo "Hit enter to see the parameters" 253 read 254 echo "$ bin/halcmd show param" 255 bin/halcmd show param 256 echo "Hit enter to change the frequency to 0.1Hz" 257 read 258 echo "$ bin/halcmd setp siggen.0.frequency 0.1" 259 bin/halcmd setp siggen.0.frequency 0.1 260 echo "Hit enter to see the parameters" 261 read 262 echo "$ bin/halcmd show param" 263 bin/halcmd show param 264 echo "Hit enter to try halmeter" 265 read 266 echo "(running halmeter, a GUI application - it should" 267 echo " appear in another window.)" 268 echo "(it will initially display the sine signal, click" 269 echo " on the select button, then select a pin, signal, or" 270 echo " parameter to observe. You can change what you are" 271 echo " observing at any time.)" 272 echo "(the meter updates approx. every 0.1 seconds - if you" 273 echo " select one of the output pins, you should see it go" 274 echo " through a complete cycle every 10 seconds, since we" 275 echo " set the frequency to 0.1Hz.)" 276 echo "(Click exit to shut down halmeter.)" 277 echo "$ bin/halmeter pin siggen.0.sine" 278 bin/halmeter pin siggen.0.sine 279 echo "Hit enter to finish the demo" 280 read 281 echo "(unloading realtime modules)" 282 echo "$ bin/halcmd unloadrt all" 283 bin/halcmd unloadrt all 284 exit 0 285 fi 286 # 287 # The next demo: "scope" lets the user play with the scope 288 # using siggen as a signal source. 289 # this one is also a step by step tutorial 290 # 291 if [ $1 = scope ] ; then 292 echo "The first part of this demo is identical to the siggen" 293 echo "demo. Hit enter to get started" 294 read 295 echo "First we load the siggen demo (not echoed)" 296 bin/halcmd loadrt siggen 297 bin/halcmd loadrt threads name1=siggen.thread period1=1000000 298 bin/halcmd addf siggen.0.update siggen.thread 299 bin/halcmd start 300 bin/halcmd setp siggen.0.frequency 10 301 echo "Then we load the realtime component of halscope:" 302 echo "$ bin/halcmd loadrt scope_rt" 303 bin/halcmd loadrt scope_rt 304 echo "Finally we start the user component (in the background" 305 echo "so that the foreground can continue to give instructions):" 306 echo "$ bin/halscope &" 307 bin/halscope & 308 echo "HALSCOPE should appear in a new window. Select this " 309 echo "window again and hit enter for step by step instructions" 310 read 311 echo "First we need to set the sample rate. Click on then name" 312 echo "of a realtime thread (this example has only one)." 313 echo "You can optionally change the multiplier if you don't" 314 echo "want to sample every time the thread runs. You can also" 315 echo "change the record length to allow for more channels. For" 316 echo "the demo, you want at least 4 channels, so change it." 317 echo "When you are done, click OK, then come back to this" 318 echo "window and hit enter for the next step." 319 read 320 echo "Now we need to select the pins/signals/parameters that" 321 echo "we are going to observe. The 16 buttons in a vertical" 322 echo "column are the channel select buttons. Click #1" 323 echo "In the dialog that pops up, select a pin - perhaps the" 324 echo "triangle output of the siggen. Note that the channel" 325 echo "number and name appear in the lower left of the scope" 326 echo "window. This is the selected (highlighted) channel." 327 echo "Now click on another channel number like #3, and select" 328 echo "another pin, perhaps the sine output. Then come back" 329 echo "to this window and hit enter for the next step" 330 read 331 echo "Now you have a couple channels. To start sampling, click" 332 echo "on NORMAL in the 'Run Mode' window in the upper right." 333 echo "The state display at the top right of the display will" 334 echo "change from IDLE to PRE-TRIG as the scope acquires" 335 echo "pre-trigger data. The status display will show a bar" 336 echo "that represents the portion of the record that has been" 337 echo "captured. The state will change to TRIGGER? when the" 338 echo "pre-trigger phase is done, to show that it is waiting " 339 echo "for a trigger. Currently the only working trigger source" 340 echo "is the manual one, so click the 'Force' button to cause" 341 echo "a trigger. You can also click on 'Auto', which causes" 342 echo "the scope to trigger automaticlly after a delay. Fully" 343 echo "functional triggering is under construction. When the" 344 echo "scope triggers, the state will change to TRIGGERED and" 345 echo "the bar will show progress as it acquires post-trigger" 346 echo "data. When it is done, the waveforms will display, and" 347 echo "the scope will begin acquiring data again. Hit enter" 348 echo "for the next step." 349 read 350 echo "The signals are likely to be near the top of the screen" 351 echo "if you used a low numbered channel. Use the position" 352 echo "slider in the vertical menu (lower right) to move the" 353 echo "selected signal (the green one) down. Use the gain" 354 echo "slider to scale it if you wish. Note the scale displayed" 355 echo "below the slider - it has a very wide range. When the" 356 echo "selected channel is adjusted to your liking, click on" 357 echo "the channel number for the other channel to select it." 358 echo "(Note the name and number at the bottom left.) Adjust" 359 echo "the second channels vertical position and gain, then" 360 echo "hit enter for the next step" 361 read 362 echo "Now that vertical is set, lets look at horizontal. The" 363 echo "horizontal controls are above the screen. Below the" 364 echo "sliders and sample rate display is a graphic that shows" 365 echo "the display as a large box, and the data record as a" 366 echo "smaller box (probably half or all black). Move the zoom" 367 echo "slider one click to the right. Note that the large box" 368 echo "is now shorter. Now move the position slider, and see" 369 echo "how the large box moves with respect to the smaller one." 370 echo "This display quickly shows you what portion of the record" 371 echo "you are viewing. Zoom in some more to clearly see the" 372 echo "sine and triangle waveforms. Hit enter for the next step." 373 read 374 echo "If you want to change the sample rate, use the 'Change" 375 echo "Rate/Len' button, which brings up the same dialog that" 376 echo "appeared when the program started. To add more channels," 377 echo "click on additional channel number buttons. If you want" 378 echo "to turn a channel off, select it and click the 'Channel" 379 echo "Off' button (the signal source, position, etc, will be" 380 echo "remembered if you turn it back on again. To change the" 381 echo "signal captured by a channel, select the channel and click" 382 echo "the 'Source' button. An interesting item to look at is" 383 echo "the paremeter 'siggen.thread.time', which is the time" 384 echo "needed by the thread, in nano-seconds. It is updated" 385 echo "every time the thread runs, and varies based on cache hits" 386 echo "and other loading. Its value will be in the thousands" 387 echo "of nanoseconds (a few microseconds), so the trace will" 388 echo "initially be off scale. Set the scale to 5K/div or so to" 389 echo "make it visible. Hit enter for the next step." 390 read 391 echo "To shut down the scope, use the [X] button in the corner" 392 echo "Hit enter to finish the demo" 393 read 394 bin/halcmd unloadrt all 395 exit 0 396 fi 397 # 398 # 399 # if we get here, the user asked for a non-existant demo 400 # 401 echo "Sorry, there is no demo called '$1'" 402 scripts/hal_demo 403 exit -1 404