www.robojackets.org 2011 te sessions supported by: basic concepts of programming november 3, 2012
TRANSCRIPT
![Page 1: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/1.jpg)
www.robojackets.org
2011 TE Sessions Supported by:
Basic Concepts of Programming
November 3, 2012
![Page 2: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/2.jpg)
Good programs:• Take time• Can be easily read• Are easy to improve upon
The best way to make a good program is to break the project up into smaller tasks.
Before you begin…
![Page 3: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/3.jpg)
• Dataflow is from left to right – the wires show the order the code is run
• If two different blocks of code are not connected in any way, they will run at the same time when the VI starts
• Pressing ctrl+h in labview shows a dialog box that briefly summarizes each icon function as well as wire data.
General LabVIEW Info
![Page 4: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/4.jpg)
• This box contains the operations that will be used while coding.
• The programming header contains the operations that will be used most frequently.
Function Palette
![Page 5: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/5.jpg)
Picture of Function Palette
![Page 6: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/6.jpg)
Basic Constant Types• Numeric• Strings (usually words)• Boolean (true or false?)
LabVIEW Constants
![Page 7: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/7.jpg)
• Usually trigger parts of a program• Come in many forms such as buttons, knobs
and dropdown boxes (known as ring controls in LabVIEW)
Controls
![Page 8: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/8.jpg)
• Show outputs• Examples: graphs, gauges, slide fills
Indicators
![Page 9: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/9.jpg)
2 main types in programming: “while” and “for”Biggest difference: while can be infinite, for is always finite
Loops
While LoopFor Loops
![Page 10: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/10.jpg)
Called “while loops,” because the code keeps running while a condition is met (while x < 5, while x ≠ 7, or while a = “false”)NOTE: Your code runs until the while loop condition is met.
While Loops
IndexStop
![Page 11: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/11.jpg)
Stopping While Loops
![Page 12: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/12.jpg)
Stopping While Loops (cont’d)
![Page 13: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/13.jpg)
Normally, while loops run as fast as your computer can allow them to run. However, that may be too fast for your program.
Timing Changes
![Page 14: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/14.jpg)
Timing Changes (cont’d)
![Page 15: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/15.jpg)
• Shift registers remember the value that occurs at the end of the loop and bring it back to the beginning of the loop.
• Shift registers can be found in both while and for loops.
• Shift registers usually have to be initialized (this means, set the first value).
Shift Registers
![Page 16: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/16.jpg)
Example without Shift Registers
Initialize
![Page 17: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/17.jpg)
Example with Shift Registers
Shift Registers
![Page 18: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/18.jpg)
• Make a while loop that does the following– Increments an integer by 1 every loop iteration– Multiplies a double by 2 every loop iteration
• Displays both of these numbers
– Waits .5 seconds for each loop iteration– Has a stop button to terminate the loop
While Loop Example
![Page 19: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/19.jpg)
Solution
![Page 20: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/20.jpg)
For loops are a special type of while loop that can only be stopped when it has run a set number of times.
For Loops
![Page 21: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/21.jpg)
For loops are great for making arrays in LabVIEW
Array- indexed list of similar elements
[4, 7, 12, 16, 25] : an array of numbers[dog, cat, bird, fish] : an array of animal words
For Loops Usage: Arrays
![Page 22: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/22.jpg)
For Loop Array ExampleArray Indicator
Index
Count
Random Numbers
![Page 23: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/23.jpg)
You can divide your code to run when certain conditions are met. Case statements should be used in while loops.
Case Statements
This code adds 1 every second the button is pushed down.
![Page 24: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/24.jpg)
Case Statement Example (False)
Case: False
![Page 25: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/25.jpg)
Case Statement Example (True)
Case: True
![Page 26: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/26.jpg)
• Write code to simulate an input device– Using a while loop, two case structures, and two
buttons, have two counters that increment by 1 for each unit of time that each button is pressed
– If button 1 is pressed, counter 1 will increment– If button 2 is pressed, counter 2 will increment– If both buttons are pressed, both counters will
increment
Activity
![Page 27: Www.robojackets.org 2011 TE Sessions Supported by: Basic Concepts of Programming November 3, 2012](https://reader036.vdocuments.mx/reader036/viewer/2022062511/551ab28b550346856e8b4f4b/html5/thumbnails/27.jpg)
Solution