Difference between revisions of "Sensors"

From EG1004 Lab Manual
Jump to: navigation, search
Line 1: Line 1:
<html>
<style>
h1 {color:#4444cc; text-align:center}
h2 {color:#4444cc}
p.caption {font-family:Arial; text-align:center; font-weight:bold}
</style>
<head>
</head>
<h1 align=center>EG1004 Lab 7: Sensors</h1>
<h1 align=center>EG1004 Lab 7: Sensors</h1>


<h2>1 OBJECTIVES</h2>
<h2>1 OBJECTIVES</h2>


<p>The experimental objective of this lab is to design two programs.
<p>The experimental objective of this lab is to design two programs. The first
The first is a RoboLAB program that uses light and touch
is a Mindstorms program that uses light, touch and ultrasonic sensors to stop a
sensors to stop a motor when a yellow brick is detected. The second is a
motor when a red ball is detected. The second is a LabVIEW program that uses a
LabVIEW program that uses a thermocouple to measure air temperature in the
thermocouple to measure air temperature in the heating and cooling program you
heating and cooling program you designed in the <b><i>LabVIEW Lab</i></b>.</p>
designed in the <b><i>LabVIEW Lab</i></b>. </p>


<p>We will learn to use light, touch, and temperature sensors so that
<p>We will learn to use light, touch, ultrasonic and rotation sensors so that we
we can use these tools in our semester-long design projects.</p>
can use these tools in our semester-long design projects.</p>


<h2>2 OVERVIEW</h2>
<h2>2 OVERVIEW</h2>


<h3>RoboLAB Program</h3>
<h3>Mindstorms Program</h3>


<p>Before we can learn to use sensors, we must become familiar with
<p>Before we can learn to use sensors, we must become familiar with the <b><i>
the <b><i>RCX</i></b>. Remember that the RoboLAB
NXT</i></b>. Remember that the Mindstorms program is a compiler: a program used
program is a compiler: a program used to make other programs. Just as a
to make other programs. Just as a compiler is used when creating and debugging a
compiler is used when creating and debugging a C++ program, RoboLAB compiles
C++ program, Mindstorms similarly compiles programs for the NXT. The
programs for the RCX. The RoboLAB interface is graphic; a text compiler like
Mindstorms interface is graphic; a text compiler like those used for C++ is not.
those used for C++ is not. However, the principle is very much the same.
However, the principle is very much the same. Actions are taken based upon
Actions are taken based upon circumstances set by the programmer. </p>
circumstances set by the programmer. </p>


<p>The RCX houses all the programming instructions that control the
<p>The NXT houses all the programming instructions that control the movement
movement of your robot. Once you have created your program in RoboLAB, it is
of your robot. Once you have created your program in Mindstorms, it is uploaded
uploaded to the RCX. The RCX then dictates the robot's motion. If your robot
to the NXT. The NXT then dictates the robot's motion. If your robot does not
does not do what you intended, you must rewrite the program in RoboLAB and
do what you intended, you must rewrite the program in Mindstorms and upload
upload the corrected version to the RCX.</p>
the corrected version to the NXT.</p>


<h3>LabVIEW Program</h3>
<h3>LabVIEW Program</h3>


<p>The thermocouple records temperatures that are transmitted through
<p>The thermocouple records temperatures that are transmitted through the DAC  
the DAC board. LabVIEW uses these values to operate the heating and cooling
board. LabVIEW uses these values to operate the heating and cooling system you  
system you designed in the <b><i>LabVIEW Lab</i></b>. To program your
designed in the <b><i>LabVIEW Lab</i></b>. To program your heating and cooling  
heating and cooling system VI to gather information from an outside source
system VI to gather information from an outside source (thermocouple), you
(thermocouple), you must add an AI Sample
must add an AI Sample Channel. In order to wire this VI, you must right-click on
Channel. In order to wire this VI, you must right-click on
the icon, select Visible Items, and then Terminals.</p>
the icon, select Visible Items, and then Terminals.</p>


<p>Developing advanced programming skills in both RoboLAB and LabVIEW
<p>Developing advanced programming skills in both Mindstorms and LabVIEW will
will allow you to successfully complete your semester-long design project. This lab will
allow you to successfully complete your semester-long design project. This lab  
help you acquire those skills.</p>
will help you acquire those skills.</p>
 


<h2>3 YOUR ASSIGNMENT</h2>
<h2>3 YOUR ASSIGNMENT</h2>
Line 48: Line 58:
<ul>
<ul>
<li><b>A Zip file including all LabVIEW programs (.vi) needs to be submitted to
<li><b>A Zip file including all LabVIEW programs (.vi) needs to be submitted to
[http://eg.poly.edu the EG1004 Web site].</b>
[[http://eg.poly.edu|the EG1004 Web site]]. If you don't know how to make a zip
If you don't know how to make a zip file, read the page [[How to Compress Your Files]] in the
file, read the page [[How to Compress Your Files]] in the <i>Instructional
<i>Instructional Presentations</i> section.</li>
Presentations</i> section.</b></li>
</ul>
</ul>


<h3>There is no lab report for this lab.</h3>
<h3>Lab Report</h3>
 
<p>There is no lab report for this lab.</p>


<p>Instead of a lab report this week, you will write a draft of the proposal cover letter for your
Semester Long Design Project. Bring a hardcopy of your draft to your recitation the same day that
you present Milestone 2. Before you begin, you must read the section titled
[[Instructions for Preparing your Final Proposal Cover Letter]] in the <i>Technical
Communication</i> section of this online manual. You should also read the
[[Final Proposal Cover Letter Guidelines]] in the same section</p>
<h3>Team PowerPoint Presentation</h3>
<h3>Team PowerPoint Presentation</h3>


Line 70: Line 75:
<ul>
<ul>
<li>Lab PC</li>
<li>Lab PC</li>
 
<li>Mindstorms and LabVIEW Software</li>
<li>RoboLAB and LabVIEW Software</li>
<li>USB Cable</li>
<li>USB Tower</li>
<li>NXT Unit</li>
<li>RCX Unit</li>
<li>Multiple NXT Sensor Array</li>
<li>Light Sensor Array</li>
<li>DAC Board</li>
<li>DAC Board</li>
<li>Thermocouple</li>
<li>Thermocouple</li>
Line 81: Line 85:
<h2>5 PROCEDURE</h2>
<h2>5 PROCEDURE</h2>


<h3>Program 1: RoboLAB Sensors</h3>
<h3>Program 1: Mindstorms Sensors</h3>
 
<p>The program is broken up into three main parts. In Part A you will use
the touch sensors to start, stop and reverse the direction of the motor. In
Part B you will add the ultrasonic sensor to the program and have it reverse the
direction of the motor when it is greater than 20cm or less than 8cm from the
wall. In Part C you will add the light sensor to the program in order
to stop the motor when it detects a red ball. Your TA will provide you with
access to a testing assembly. You can see pictures of the testing assembly
in Figures 1-3. Remember to test after each part.</p>
 
<h3>Part A:</h3>
 
<p>In this part of the exercise you first create a program that causes Motor A
to move when the touch sensor connected to Port 1 is pushed and stop when the
touch sensor connected to Port 2 is pushed. Also if the touch sensor connected
to Port 1 is pushed while the motor is running then the motor must flip
direction. There is a motor connected to Port B, and this motor will
control the speed of Motor A, using the motor’s rotation sensor. The following
steps will help you build part of this program.</p>
 
<h4>TASK 1: STORE VARIABLE</h4>
 
<ol>


<p>In this exercise, you must find a yellow brick out of a collection of  multi-colored
<li>Open MindStorms 1.1. Create a new program.</li>
bricks. The yellow brick has a larger light reflectivity than bricks of other
colors. Thus, you can find the yellow brick by searching for the largest light
reflectivity among all the candidate bricks. You will be provided with a test
assembly that continually moves a light sensor, mounted on a motor, back and
forth along a short track. There is a touch sensor at each end of the track
that indicates that the end of the track has been reached. The light sensor,
the two touch sensors, and the motor are all connected to the RCX.</p>


<p>You must create a RoboLAB program for the test assembly. See Figures
<li>To use the rotation sensor to control the speed of the motor, we will use the
1-3.  The test assembly has four main
Rotation Sensor Block to read the value of the Rotation Sensor on Port B.
components: a motor, a light sensor, and two touch sensors.  The objective of this assignment is to create
[[Image:Lab_sensors_1.jpg]]</li>
a RoboLAB program that will move the light sensor side-to-side until it detects
the yellow brick. When it does,  it will stop running.  To move the light sensor, you must run the
motor.  If you reverse the direction of
the motor, the light sensor will move in the opposite direction.  If the yellow brick is removed from the
test block, then the light sensor must move all the way to one side until it hits the touch sensor, then
reverse direction and move to the other side until it hits the other touch sensor. This process must
continue until the yellow brick is placed back on the test block and the light sensor detects it. The
program ends once the yellow brick is detected</p>


<p align=center>[[Image:lab_sensors_2.jpg]]</p>
<li>Next we will have to convert the value of the Rotation Sensor to a number value
that the motor can use to determine speed. We will use the Math Block.
[[Image:Lab_sensors_2.jpg]]</li>


<p class=caption>Figure 1: Test Assembly, angled view</p>
<li>Change the block to Division. You can alter the settings of a block in the
Configuration Panel located in the bottom left corner of the window.
[[Image:Lab_sensors_3.jpg]]</li>


<p align=center>[[Image:lab_sensors_4.jpg]]</p>
<li>To take the value of the Rotation Sensor, use the drop down menu of the
Rotation Sensor block. Also do this for the Math Block.</li>


<p class=caption>Figure 2: Test Assembly, side view</p>
<li>Next, highlight the degrees on the Rotation Sensor Block and wire it to “A�? on
the Math Block.[[Image:Lab_sensors_4.jpg]][[Image:Lab_sensors_5.jpg]]<br>
This takes the value of the Rotation Sensor and uses that as input A on the
Math Block.</li>


<p align=center>[[Image:lab_sensors_6.jpg]]</p>
<li>In the Math Block type “2�? into the “B�? box. This will convert the
degrees of the Rotation Sensor to a percentage that the motor value can read. 
We would ideally like to use 1.8 (i.e Divide by 180 degrees, then Multiply by
100%), but MindStorms 1.1 can only recognize whole numbers, not decimals.</li>


<p class=caption>Figure 3: Test Assembly, top view</p>
<li>Since we will be using this value further along in the program, we want to store
this value as a variable. Use a Variable Block and string it next to the Math Bock.
[[Image:Lab_sensors_6.jpg]]</li>


<ol>
<li>Change the Variable Block settings to “Write�? and “Number 1�?.  Using the drop
<li>Before we begin, we need to determine the light percentage that allows the sensor to
down menu in the Variable Block, wire the “#�? output from the Math Block to the
  detect the yellow brick.</li>
“#�? input on the Variable Block. The string of code should look like this:
[[Image:Lab_sensors_7.jpg]]</li>
 
<li>We want to constantly check the value of the Rotation Sensor and change
the speed accordingly. To do this we want to use a Loop. Bring out a Loop,
select all the code that was written and place it inside the loop. The final
line of code should look like this:[[Image:Lab_sensors_8.jpg]]</li>
 
<h4>TASK 2: USE VARIABLE</h4>
 
<li>In a separate task we want to write the code to start our program. To
create another task line hold the “Shift Key�? and click and drag the beam from 
the existing white beam on the left side of the screen. Double click, to confirm
the length and location of the new beam.[[Image:Lab_sensors_9.jpg]]</li>
 
<li>Create a new line under the first line of code written.</li>
 
<li>We want our program to start when the Touch Sensor on Port 2 is bumped.
Use a Wait Block.[[Image:Lab_sensors_10.jpg]]</li>
 
<li>Its default is a Wait For Touch. Change the settings accordingly to Port 2
and Bumped. </li>
 
<li>Next, we want to use the stored Variable. Since we will be using the Motor
on Port A, we must account for both direction and speed of the motor. We will
use another Variable block to determine direction. Place this after the Wait
for touch block.[[Image:Lab_sensors_11.jpg]]</li>
 
<li>This will be set to Logic 1 and “Write�?. Logic dictates that True will be
Forward and False will be Reverse.  <b>The Logic Variable Block must be set to
True in order for the motor to go forward when the program starts.</b></li>
 
<li>Now we want to use the Stored  Variable in conjunction with a Variable
Logic Block to control the Motor A.  Place another Variable block set to Number
1 and�? Read�?. This will read the value from the Stored Variable 1. Then place a
Variable Block set to Logic 1 and “Read�?. This will read the value from the
previous Variable Logic  Block.  Lastly place a Motor A Block. Your task so far
should look like this: </li>
 
<p>[[Image:Lab_sensors_12.jpg]]</p>
 
<li>Wire the Variable and Logic Blocks to Motor A using their respective drop
down menus.  Remember, you want to control Direction and Power of Motor A.</li>
 
 
<p>[[Image:Lab_sensors_13.jpg]]</p>
 
<li>Finally, you want to constantly control the speed of Motor A. Insert a
Loop into the string of code and place inside of it the two Variable Blocks and
the Motor A block. Your final code for this task should look like this: </li>
 
<p>[[Image:Lab_sensors_14.jpg]]</p>
 
<h4>TASK 3: MOTOR FLIP DIRECTION</h4>
 
<p>14. The next task we want to accomplish is to be able to switch the direction
of Motor A if the Touch Sensor on Port 1 is pressed.  First, create a new task
line as described in Task 2.  </p>
 
<p><img src="lab7_files/image021.jpg">15. Since we want the program to
differentiate between when the Touch Sensor is pressed from when it is not
pressed, we will use a Switch Block. </p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p> Place the Switch Block on the new task line. Its default is set to Touch
Sensor. </p>
 
<p>16. The Top and Bottom sections of the Switch Block correspond to whether the
Touch Sensor is pressed or not pressed, respectively. Since we want nothing to
happen when the Touch Sensor is not pressed, leave the Bottom section empty.
</p>
 
<p>17. In the Top Section, we will first place a Variable Block set to Logic 1
and “Read�?. This will read the value from the Variable Logic Block we created in
Step 10. </p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p><img src="lab7_files/image022.jpg">18. Since the direction of the Motor
corresponds to the True or False value stated in the Variable Logic Block from
Task 2, it is then possible to use a Logic Block to change its value.   </p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p>The Logic Block allows you to use operations such as AND, OR &amp; NOT in the
Configuration Panel in the lower left corner of the window. Now place a Logic
Block set to “NOT�? in the code string. </p>
 
<p>19.To change the value of the Variable Logic Block from its value of True to
False, wire the “Value�? of the Variable Logic Block to “A�? in the drop down menu
of the Logic Block. Next we want to place another Variable Block set to Logic 1
and “Write�?. Now wire the “Result�? of the Logic Block to the�? Value�? of this
Variable Logic Block via the drop down menus. We are basically saying that if
the Value of Logic 1 is TRUE, then “NOT TRUE�? gives a result of FALSE.  Your
code should look like this: </p>
 
<p><img src="lab7_files/image024.jpg"></p>
 
<p>&nbsp;</p>
 
<p><img src="lab7_files/image025.jpg">20. Next we want to place a Wait Block
changed to Time. </p>
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 
<p> Have it Wait for 1 second.  </p>
 
<p>&nbsp;</p>
 
<p>Lastly, we want to constantly check if the touch sensor is being pressed, so
place the entire Switch Block within a Loop Block. The Wait Block is necessary
due to the fact that when the Touch Sensor is pressed we want the program to
Wait a certain amount of time so the Motor can change direction before the Loop
rechecks its direction. Your final code for this task should look like: </p>
 
<p><b><img src="lab7_files/image027.jpg"></b></p>
 
<p><b>TASK 4: STOP MOTOR A AFTER TOUCH SENSOR 2 IS PRESSED</b></p>
 
<p>21. The last task simply ends the program when Touch Senor 2 is pressed.
First, create a new task string.</p>
 
<p>22. Place 2 Wait Blocks in sequence. Set them to Touch Sensor and “Bumped.�?
The first Wait Block is to account for the Start of the program, as indicated in
Step 9. The second Wait Block will be used to determine when to end the program.
</p>
 
<p><img src="lab7_files/image029.jpg">23. Next, place a Stop Block. </p>
 
<p>&nbsp;</p>


<li>Make sure
<p>&nbsp;</p>
  the RCX is turned on, the USB Tower is plugged in, and the RCX is within range
  of the USB Tower.</li>


<li>Pull down the Project menu, select COM Port, and choose USB1. Click the check mark.</li>
<p>This Block will stop the whole program.</p>


<li>Pull down the Project menu, select Interrogate RCX.</li>
<p>24. Your final code for this task should look like: </p>


<li>Within a few seconds, the RCX Present indicator will turn green and the battery power meter will begin
<p><img src="lab7_files/image030.jpg"></p>
to read. Notice the small gray buttons labeled 1, 2, and 3 on top of the picture of the RCX. These buttons
represent the <b><i>inputs </i></b>on the RCX.</li>


<p><b>Note: </b><i>If a window opens when you launch RoboLAB with </i>Install Extras <i>highlighted,
<p>If you followed each step correctly, your Final Code for Part A should
you must click on the </i>Install Extras <i>button and </i><b><i>restart </i></b><i>RoboLAB. If
resemble: </p>
</i>Remove Extras <i>is highlighted, click the check box and continue.</i></p>


<p><img src="lab7_files/image032.jpg"></p>


<li>Click on the 1 button. A gray box will appear. Click on the box and set the two menus to Reflection
<p>Test your Program.  After a TA approves that it works correctly, Save it and
and Percent.</li>
move onto Part B. </p>


<li>Input 1 (Sensor 1) is now set up to receive data from a light sensor. Plug a light sensor
<h3>Part B:</h3>
onto Input 1 on the RCX. The sensor returns a percentage between <b><i>1 </i></b>and <b><i>100</i></b>.
Put the sensor in front of the yellow brick. When the number stabilizes, this percentage
is the amount of reflected light given off by the yellow brick. Your screen will look like Figure 4.</li>


<p align=center>[[Image:lab_sensors_7.gif]]</p>
<p>In this part of the program you will modify what you had created in Part A to
include the ultrasonic sensor.&nbsp; In this portion of the exercise you will to
add another task to utilize the ultrasonic sensor connected to Port 3.&nbsp; In
addition to its functionality from Part A, the motor must now reverse itself
when the ultrasonic sensor on Port 3 detects a distance greater than 20cm or
less than 8cm.&nbsp; The idea behind this is to keep the motor on the track at
all times.&nbsp; Using what you have learned in Part A you can create this
portion of the program on your own.&nbsp; Remember to save your VI.&nbsp; Once
you are done, you may move on to Part C.</p>


<p class=caption>Figure 4: Interrogate RCX window</p>
<h3>Part C:</h3>


<li>It is a good idea to test the sensor. To do this, shine the light sensor at
<p>In this part of the program you will modify what you have done in Parts A and
different colors of Lego blocks. Note the light percentage returned and the factors that affect the reading,
B.&nbsp;You will add the light sensor to Port 4 and use input from that to stop
e.g., glossiness, distance, and color.</li>
the motor.&nbsp; When the light sensor connected to Port 4 detects the red ball,
the motor will stop.&nbsp; You will need to determine what the light sensor
value for the color red is. To do this, maneuver the red ball near the light
sensor.&nbsp;On the NXT module, go to the View menu, Reflected Light, and choose
Port 4.&nbsp;The percentage value displayed on the NXT module is the light
sensor value for red. Use this to finish this final part of the program.</p>


<li>Now you will program the light and touch sensors. For the purposes of this lab, program the
<p>When this program is done the touch sensor on Port 1 should be able to
<b><i>motor</i></b> to Port A, Input 1 is the <b><i>light sensor</i></b>, Input 2 is <b><i>touch sensor
start Motor A and also flip its direction.&nbsp;The touch sensor on Port 2
2</i></b>, and Input 3 is <b><i>touch sensor 3</i></b>.</li>
should be able to stop Motor A and end the program.&nbsp;The ultrasonic sensor
on Port 3 should be able to reverse the direction of the motor when the distance
of the motor is greater than 20cm or less than 8cm from the wall.&nbsp;And the
light sensor on Port 4 should be able to stop Motor A and end the program when
it sees the red ball.&nbsp;Also, the speed of Motor A is controlled by Motor
B.</p>


<li>Open the Functions palette and write a program that will use each of the touch sensors to help the
<p align=center><img src="lab7_files/image034.jpg"></p>
light sensor detect the yellow brick. In order to do this, you will need to be familiar with the tools
on the Functions palette, shown in Figure 5.</li>


</ol>
<p align=center>Figure 1: Test Assembly, angled view</p>


<p align=center>[[Image:lab_sensors_8.gif]]</p>
<p align=center><img src="lab7_files/image036.jpg"></p>


<p class=caption>Figure 5: The Functions palette</p>
<p align=center>Figure 2: Test Assembly, side view</p>


<h4>Wait For</h4>
<p align=center>&nbsp;</p>


<p>[[Image:lab_sensors_9.gif]]</p>
<p align=center>&nbsp;</p>


<p>The Wait For icon allows your program to wait (pause) for a certain amount of
<p align=center><img src="lab7_files/image038.jpg"></p>
time, or until a particular condition is met. The program will run up to the Wait For command and then pause until the
set period of time has elapsed or until the specific condition has been met. If
a Wait For command
needs information from a sensor, the sensor must be wired to a <b><i>port modifier </i></b>so RoboLAB knows where to find it.</p>


<h4>Forks and Splits</h4>
<p align=center>Figure 3: Test Assembly, top view</p>


<p>[[Image:lab_sensors_10.gif]] [[Image:lab_sensors_11.gif]]</p>
<h4>Testing</h4>
<p>In order to test your program, ask your TA for the assembly, connect the
NXT to the USB outlet and run the program you created.</p>


<p>The Fork Split command is in the Structures menu. It will split the path of the program based on a condition
<h4>Wait </h4>
you set. For instance, the program will perform one of two tasks depending on
<p>The Wait Block allows your program to wait (pause) for a certain amount of
the value it receives from the light sensor. Every Fork Split in the program <b><i>must </i></b>be accompanied by a Fork
time, or until a particular condition is met. The program will run up to the
Merge. This combination of a Fork
Wait command and then pause until the set period of time has elapsed or until
Split and a Fork Merge works like a pair of parenthesis. Every open parenthesis must be
the specific condition has been met. If a Wait command needs information from a
closed. Sensor Forks must be connected to a <b><i>port modifier </i></b>so
sensor, the sensor in the Configuration Panel of the block located in the bottom
RoboLAB knows where to look for sensor input.</p>
left corner of the screen. This is so Mindstorms knows where to find it.<img
src="lab7_files/image039.jpg"><img src="lab7_files/image040.jpg"><img
src="lab7_files/image041.jpg"><img src="lab7_files/image042.jpg"><img
src="lab7_files/image043.jpg"></p>


<h4>Task Split</h4>
<h4>Switch</h4>
<h4><img src="lab7_files/image044.jpg"> </h4>
<p>&nbsp;</p>


<p>The Task Split command is also located in the Structures
<p>The Switch Block command is in the Flow menu. It will split the path of the
menu. It allows you to create two separate tasks that
program based on a condition you set. For instance, the program will perform one
will run simultaneously. When implemented, your original program becomes two
of two tasks depending on the value it receives from a sensor.   Sensor switches
separate independent tasks. Each task must end with its own red stop light.</p>
must be specified in the Configuration Panel so Mindstorms knows where to look
for sensor input.</p>


<h4>Jumps and Lands</h4>
<h4>&nbsp;</h4>
<h4>&nbsp;</h4>
<h4>&nbsp;</h4>
<h4>Task Split</h4>
<p>&nbsp;</p>


<p>[[Image:lab_sensors_12.gif]] [[Image:lab_sensors_13.gif]]</p>
<p><img src="lab7_files/image045.jpg"></p>


<p>The Jumps menu is found in the Structures
<p>To create two independent tasks that run simultaneously, you must create a
menu. When the program reaches a Jump command, it skips to wherever you have placed a Land command. Note that
new beam to place blocks on.  As illustrated, begin on left side of the screen
there are <b><i>six </i></b>different colored Jump and Land commands. So, the red Jump will always correspond with
where the first line of code is written.  Hold the “Shift�? key and your
the red Land, and so on. You can use a Jump and Land with a Fork Split to make a <b><i>loop</i></b>.</p>
“pointer�? will change to a spool of “wire.�? Drag the spool to your desired
destination and double click to confirm the new beam. </p>


<h4>Loops</h4>
<h4>Loops</h4>
<p><img src="lab7_files/image046.jpg"></p>


<p>[[Image:lab_sensors_14.gif]]</p>
<p>The Loop block is under the Flow menu.  You can set the loop to constantly
check for certain conditions based on what criteria is selected in the
Configuration Panel.  Loops can depend on Time, Count, Sensor or Logic Values.
Loops can also be set to “Forever.�? This will continue to Loop the code inside
of it until the program ends. </p>


<p>The Loops menu is under the Structures menu. Hover your cursor over each of the
<p>&nbsp;</p>
icons to learn what they do. All loops must be used in conjunction with a Loop End command.</p>


<h4>Touch Sensors</h4>
<h4>Touch Sensors</h4>
<p>There are touch sensor blocks that use the Wait, Loop, and Switch
structures.</p>
<p><img src="lab7_files/image047.jpg"><img src="lab7_files/image048.jpg"><img
src="lab7_files/image043.jpg"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<p>There are touch sensor structures that use the Wait For, Loop, and Fork structures.</p>
<p>&nbsp;</p>


<p>[[Image:lab_sensors_15.gif]] [[Image:lab_sensors_16.gif]]</p>
<p>&nbsp;</p>


<p>The touch sensor Wait For commands will pause the motor(s) until
<p>&nbsp;</p>
the touch sensor is released or pushed, depending on the direction of the
arrow.</p>


<p>[[Image:lab_sensors_17.gif]]</p>
<p>&nbsp;</p>


<p>The touch sensor Fork takes one input and produces two outputs, splitting the path into
<p>The touch sensor Wait Block commands will pause the motor(s) until the
two possibilities. The first possibility is the result when the touch sensor is
touch sensor is pressed, released or bumped, depending on its
released and the second is the result when the touch sensor is pushed.</p>
configuration.</p>


<p>[[Image:lab_sensors_18.gif]] [[Image:lab_sensors_19.gif]]</p>
<p>The touch sensor Loop executes until the sensor is pressed, released or
bumped, depending on its configuration.</p>


<p>The touch sensor Loop executes when the sensor is pushed or released, depending on the
<p>The touch sensor Switch takes one input and produces two outputs, splitting
direction of the arrow.</p>
the path into two possibilities. The first possibility is the result when the  
touch sensor is pushed and the second is the result when the touch sensor is
released.</p>


<h4>Light Sensors</h4>
<h4>Light Sensors</h4>
<p>There are light sensor blocks that use the Wait, Loop, and Switch
structures.</p>
<p><img src="lab7_files/image049.jpg"><img src="lab7_files/image050.jpg"><img
src="lab7_files/image039.jpg"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<p>[[Image:lab_sensors_20.gif]]</p>
<p align=center>&nbsp;</p>


<p>A light sensor Fork works in the same way as a touch sensor Fork, except there is an extra
<p>&nbsp;</p>
connection that is attached to a <b><i>numeric constant</i></b>. The RCX
decides if the light sensor is returning a value higher or lower than the
constant, and chooses a program path based on that information.</p>


<p>[[Image:lab_sensors_21.gif]] [[Image:lab_sensors_22.gif]]</p>
<p><br> <br> </p>
<p>The light sensor Loop works just like the touch sensor Loop. Depending on the
value the sensor returns, the loop will either continue executing the code
inside the loop, or it will move on to the rest of the program.</p>


<h4>Timers</h4>
<p>&nbsp;</p>
 
<p>The light sensor Wait Block will pause the motor(s) when the measured value
of reflected light is greater than or less than a constant value, depending on
its configuration.</p>


<p>[[Image:lab_sensors_23.gif]]</p>
<p>The light sensor Loop executes until the measured value of reflected light is
greater than or less than a constant value, depending on its configuration.</p>


<p>Timer structures are linked and used like the sensors are used; however, instead of getting
<p>The light sensor Switch takes one input and produces two outputs, splitting
values from sensors, they hold values in timer containers. Timers count the time elapsed from
the path into two possibilities. The first possibility is the result when the  
when they are reset.</p>
value of reflected light is greater than a constant value and the second is
the result when the value is less than the constant.</p>


<p>Before using a timer, it  must be reset to <i>0</i>. This is done using the Zero Timer command
<h4>Ultrasonic Sensors</h4>
in the Reset menu. This command takes two inputs and gives one output.</p>
<p><img src="lab7_files/image051.jpg">There are ultrasonic sensor blocks that
use the Wait, Loop, and Switch structures.</p>


<p>[[Image:lab_sensors_24.gif]]</p>
<p><img src="lab7_files/image052.jpg"><img src="lab7_files/image041.jpg"></p>


<p>The Timer Modifier and value can be found in the same menu as the port and motor modifiers. The
<p>&nbsp;</p>
timer modifier indicates which timer a structure is referring to. The value of the timer can be used
for comparison in a timer loop or a timer fork by using the timer value command.</p>


<p>[[Image:lab_sensors_25.gif]] [[Image:lab_sensors_26.gif]]</p>
<p>&nbsp;</p>


<p>The Timer Loop executes a selection of code while the timer is less than or
<p>&nbsp;</p>
greater than a certain value. The structure has four connections: one input for
the flow of the program, one output for the flow of the program, one to specify
which timer to look at, and one to specify what value the timer is being compared
to.</p>


<p>[[Image:lab_sensors_27.gif]]</p>
<p>&nbsp;</p>


<p>The Wait For Timer will pause the program as it waits for the timer value
<p>&nbsp;</p>
to match the input value. This structure has four connections: one input for
the flow of the program, one output for the flow of the program, one to specify
which timer to look at, and one to specify what value the timer is being
compared to.</p>


<p>[[Image:lab_sensors_28.gif]]</p>
<p>&nbsp;</p>


<p>The Timer Fork works the same as the Light Sensor Fork and the Touch Sensor Fork.</p>
<p>The ultrasonic sensor Wait Block will pause the motor(s) when the distance
measured is greater than or less than a constant value, depending on its
configuration.</p>


<p>It compares the value of the timer to a set value and pauses the
<p>The ultrasonic sensor Loop executes until the distance measured is greater
program until the timer equals the value it is being compared to. The structure
than or less than a constant value, depending on its configuration.</p>
has five connections: one input for the flow of the program, one output for the
flow of the program if the timer is greater than the compared value, one output
for the flow of the program if the timer is less than the compared value, one
to specify which timer to look at, and one to specify what value the timer is
being compared to.</p>


<h4>Other Structures</h4>
<p>The ultrasonic sensor Switch takes one input and produces two outputs,
splitting the path into two possibilities. The first possibility is the result
when the distance measured is greater than the constant value and the second
is the result when the value is less than the constant.</p>


<p>[[Image:lab_sensors_29.gif]]</p>
<p>&nbsp;</p>


<p>The Flip Direction function will change the direction of any motor attached to it.</p>
<p>&nbsp;</p>


<p>It has two inputs and one output. The output and the first input control the flow of
<h4>&nbsp;</h4>
the program. The other input is the <b><i>port modifier</i></b> which indicates which motor's
<p>&nbsp;</p>
direction should be changed.</p>


<p>[[Image:lab_sensors_30.gif]] [[Image:lab_sensors_31.gif]] [[Image:lab_sensors_32.gif]]</p>
<h4>&nbsp;</h4>
<h4>Timers</h4>
<p>There are Timer blocks that use the Wait, Loop, and Switch structures.</p>


<p>Containers are structures that can be used like Timers, because they hold values and can be
<p>Timer structures are linked and used like the sensors are used; however,
reset. They can be compared to loops and forks, and work like variables in C++, because they
instead of getting values from sensors, they hold values in timer containers.
can be added to and set to be equal to specific values. This structure should be experimented
Timers count the time elapsed from when they are reset.</p>
with independently.</p>


<p>Remember, RoboLAB will tell you the name of each icon if you hover your cursor over it. When
<p><img src="lab7_files/image053.jpg"><img src="lab7_files/image054.jpg"><img
you are finished, your TA must <b>test</b> your program.</p>
src="lab7_files/image042.jpg"></p>


<p><b>Note:</b><i> To receive data from an input for a touch sensor, set the two menus to
<p>&nbsp;</p>


</i>Switch <i>and </i>Boolean <i>and follow the same steps.</i></p>
<p>&nbsp;</p>


<p>&nbsp;</p>


<h3>Program 2: LabVIEW Temperature Indicator System</h3>
<p>   </p>


<ol>
<p>&nbsp;</p>
<li>Open the heating and cooling program you designed in the <b><i>LabVIEW Lab</i></b>. Switch the case to
the <b><i>automatic </i></b>case.</li>


<li>From the Functions palette select All Functions, NI measurements, and Data Acquisition, then
<p>&nbsp;</p>
select Analog Input, and then AI Sample Channel.</li>


<li>Drag and drop the AI Sample Channel node into the automatic case on the back panel of your existing
<p>&nbsp;</p>
program.</li>


<li>Right-click on the AI Sample Channel node and select Visible Items, then Terminals.</li>
<p>The Timer  Wait Block will pause the program as it waits for the timer value
to match the input value. </p>


<li>Right-click on the AI Sample Channel node and click the Select Type menu. Select Scaled Value.</li>
<p>The Timer Loop executes a selection of code while the timer is less than or
greater than a certain value. </p>


<li>Wire the AI Sample Channel node as shown in Figure 6.</li>
<p>The Timer Switch works the same as the light, touch and ultrasonic sensor
</ol>
switches. It compares the value of the timer to a set value and pauses the
program until the timer equals the value it is being compared to. </p>


<p align=center><b><i>[[Image:lab_sensors_33.jpg]]</i></b></p>
<h4>Variables</h4>
<p>Variables can be used to store Number, Logic or Text Values. Variables can
“Written�? (1) or “Read�? (2). </p>


<p class=caption>Figure 6:  AI Sample Channel node.</p>
<p><img src="lab7_files/image055.jpg"><img src="lab7_files/image056.jpg"></p>


<h4>Wiring the Sample Channel node</h4>
<p>&nbsp;</p>


<ol>
<p>&nbsp;</p>
<li>Device ID (<b><i>integer)</i></b>: the DAC board is recognized by the computer as <b><i>1</i></b>.</li>


<li>Channel (<b><i>string)</i></b>: for our purposes we will always set this to <b><i>thermocouple</i></b>.</li>
<p>&nbsp;</p>


<li>Upper Limit (<b><i>real number)</i></b>: for our purposes we will always set this to <b><i>+5</i></b>.</li>
<p>           (1)                                       (2)</p>


<li>Lower Limit (<b><i>real number)</i></b>: for our purposes we will always set this to <b><i>-5</i></b>.</li>
<p>In order to use variables correctly you should first define a variable by
either “writing�? it or by storing an input value from a sensor. You can then use
the Variable by “reading�? it. Both methods are used in Part A of this lab. </p>


<li>Output.</li>
<h3>Program 2: LabVIEW Temperature Indicator System</h3>


<li>Change the thermometer to an Indicator by right clicking on it and selecting Change to Indicator.</li>
<ol start=1 type=1>
<li>Connect the output from the Sample Channel to the thermometer.</li>
<li>Open the
    heating and cooling program you designed in the <b><i>LabVIEW Lab</i></b>
.
    Switch the case to the <b><i>automatic </i></b>case.</li>
<li>From the
    Functions palette select All Functions, NI measurements, and Data
    Acquisition, then select Analog Input, and then AI Sample Channel.</li>
<li>Drag and drop
    the AI Sample Channel node into the automatic case on the back panel of
    your existing program.</li>
<li>Right-click
    on the AI Sample Channel node and select Visible Items, then
Terminals.</li>
<li>Right-click
    on the AI Sample Channel node and click the Select Type menu. Select
    Scaled Value.</li>
<li>Wire the
    AI Sample Channel node as shown in Figure 4.</li>
</ol>
</ol>
<p align=center><img src="lab7_files/image058.jpg"></p>


<p align=center>Figure 4: AI Sample Channel node</p>
<h4>Wiring the Sample Channel node</h4>
<ol start=1 type=1>
<li>Device ID <b>(<i>integer)</i></b>:
    the DAC board is recognized by the computer as <b><i>1</i></b>.</li>
<li>Channel <b>(<i>string)</i></b>:
    for our purposes we will always set this to <b><i>thermocouple</i></b>
.</li>
<li>Upper
    Limit <b>(<i>real number)</i></b>: for our purposes we will always set
    this to <b><i>+5</i></b>.</li>
<li>Lower
    Limit <b>(<i>real number)</i></b>: for our purposes we will always set
    this to <b><i>-5</i></b>.</li>
<li>Output.</li>
<li>Change the
    thermometer to an Indicator by right clicking on it and selecting Change
    to Indicator.</li>
<li>Connect
    the output from the Sample Channel to the thermometer.</li>
</ol>
<h4>Testing Your Design</h4>
<h4>Testing Your Design</h4>
<ol>
<ol start=1 type=1>
<li>Connect the <b><font color=#aaaa00>yellow</font></b> wire of the thermocouple to pin <b><i>3 </i></b>on the DAC
<li>Connect
board.</li>
    the <b>yellow</b> wire of the thermocouple to pin <b><i>3</i></b> on the
    DAC board.</li>
<li>Connect
    the <b>orange</b> wire of the thermocouple to pin <b><i>4</i></b> on the
    DAC board.</li>
<li>Run the
    program <b><i>continuously</i></b>.</li>
<li>Hold the
    thermocouple between your fingers to make the temperature rise. Confirm
    that the indicator on your program rises.</li>
<li>Place
    thermocouple in a cup of cold water to make the temperature fall. Confirm
    that the indicator on your program falls.</li>
</ol>
<p>Have all sketches and original data signed by your TA. Your lab work is now
complete.</p>


<li>Connect the <b><font color=#ee8866>orange</font></b> wire of the thermocouple to pin <b><i>4 </i></b>on the DAC
<p>Please clean up your workstation. Return all unused materials to your
board.</li>
TA.</p>


<li>Run the program <b><i>continuously</i></b>.</li>
<p>Refer to section <b><i>3 Your Assignment</i></b> for the instructions you
need to prepare your assignments this week.</p>


<li>Hold the thermocouple between your fingers to make the temperature rise. Confirm that the indicator on your
<p>&nbsp;</p>
program rises.</li>
 
<li>Place thermocouple in a cup of cold water to make the temperature fall. Confirm that the indicator on your
program falls.</li>
</ol>


<p>Have all sketches and original data signed by your TA. Your lab work is now complete.</p>
<p>&nbsp;</p>


<p>Please clean up your workstation. Return all unused materials to your TA.</p>
<p>&nbsp;</p>


<p>Refer to section <b><i>3 Your Assignment</i></b> for the instructions you need to prepare your assignments this week.</p>
<p>&nbsp;</p>


<p>&nbsp;</p>


[[Main_Page | Return to Table of Contents]]
</html>

Revision as of 01:41, 12 October 2007

<html> <style> h1 {color:#4444cc; text-align:center} h2 {color:#4444cc} p.caption {font-family:Arial; text-align:center; font-weight:bold} </style>

<head> </head>

EG1004 Lab 7: Sensors

1 OBJECTIVES

The experimental objective of this lab is to design two programs. The first is a Mindstorms program that uses light, touch and ultrasonic sensors to stop a motor when a red ball is detected. The second is a LabVIEW program that uses a thermocouple to measure air temperature in the heating and cooling program you designed in the LabVIEW Lab.

We will learn to use light, touch, ultrasonic and rotation sensors so that we can use these tools in our semester-long design projects.

2 OVERVIEW

Mindstorms Program

Before we can learn to use sensors, we must become familiar with the NXT. Remember that the Mindstorms program is a compiler: a program used to make other programs. Just as a compiler is used when creating and debugging a C++ program, Mindstorms similarly compiles programs for the NXT. The Mindstorms interface is graphic; a text compiler like those used for C++ is not. However, the principle is very much the same. Actions are taken based upon circumstances set by the programmer.

The NXT houses all the programming instructions that control the movement of your robot. Once you have created your program in Mindstorms, it is uploaded to the NXT. The NXT then dictates the robot's motion. If your robot does not do what you intended, you must rewrite the program in Mindstorms and upload the corrected version to the NXT.

LabVIEW Program

The thermocouple records temperatures that are transmitted through the DAC board. LabVIEW uses these values to operate the heating and cooling system you designed in the LabVIEW Lab. To program your heating and cooling system VI to gather information from an outside source (thermocouple), you must add an AI Sample Channel. In order to wire this VI, you must right-click on the icon, select Visible Items, and then Terminals.

Developing advanced programming skills in both Mindstorms and LabVIEW will allow you to successfully complete your semester-long design project. This lab will help you acquire those skills.


3 YOUR ASSIGNMENT

  • A Zip file including all LabVIEW programs (.vi) needs to be submitted to [EG1004 Web site]. If you don't know how to make a zip file, read the page How to Compress Your Files in the Instructional Presentations section.

Lab Report

There is no lab report for this lab.

Team PowerPoint Presentation

There is no presentation for this lab.

4 MATERIALS AND EQUIPMENT

  • Lab PC
  • Mindstorms and LabVIEW Software
  • USB Cable
  • NXT Unit
  • Multiple NXT Sensor Array
  • DAC Board
  • Thermocouple

5 PROCEDURE

Program 1: Mindstorms Sensors

The program is broken up into three main parts. In Part A you will use the touch sensors to start, stop and reverse the direction of the motor. In Part B you will add the ultrasonic sensor to the program and have it reverse the direction of the motor when it is greater than 20cm or less than 8cm from the wall. In Part C you will add the light sensor to the program in order to stop the motor when it detects a red ball. Your TA will provide you with access to a testing assembly. You can see pictures of the testing assembly in Figures 1-3. Remember to test after each part.

Part A:

In this part of the exercise you first create a program that causes Motor A to move when the touch sensor connected to Port 1 is pushed and stop when the touch sensor connected to Port 2 is pushed. Also if the touch sensor connected to Port 1 is pushed while the motor is running then the motor must flip direction. There is a motor connected to Port B, and this motor will control the speed of Motor A, using the motor’s rotation sensor. The following steps will help you build part of this program.

TASK 1: STORE VARIABLE

  1. Open MindStorms 1.1. Create a new program.
  2. To use the rotation sensor to control the speed of the motor, we will use the Rotation Sensor Block to read the value of the Rotation Sensor on Port B. Lab sensors 1.jpg
  3. Next we will have to convert the value of the Rotation Sensor to a number value that the motor can use to determine speed. We will use the Math Block. Lab sensors 2.jpg
  4. Change the block to Division. You can alter the settings of a block in the Configuration Panel located in the bottom left corner of the window. Lab sensors 3.jpg
  5. To take the value of the Rotation Sensor, use the drop down menu of the Rotation Sensor block. Also do this for the Math Block.
  6. Next, highlight the degrees on the Rotation Sensor Block and wire it to “A�? on the Math Block.Lab sensors 4.jpgLab sensors 5.jpg
    This takes the value of the Rotation Sensor and uses that as input A on the Math Block.
  7. In the Math Block type “2�? into the “B�? box. This will convert the degrees of the Rotation Sensor to a percentage that the motor value can read.  We would ideally like to use 1.8 (i.e Divide by 180 degrees, then Multiply by 100%), but MindStorms 1.1 can only recognize whole numbers, not decimals.
  8. Since we will be using this value further along in the program, we want to store this value as a variable. Use a Variable Block and string it next to the Math Bock. Lab sensors 6.jpg
  9. Change the Variable Block settings to “Write�? and “Number 1�?.  Using the drop down menu in the Variable Block, wire the “#�? output from the Math Block to the “#�? input on the Variable Block. The string of code should look like this: Lab sensors 7.jpg
  10. We want to constantly check the value of the Rotation Sensor and change the speed accordingly. To do this we want to use a Loop. Bring out a Loop, select all the code that was written and place it inside the loop. The final line of code should look like this:Lab sensors 8.jpg
  11. TASK 2: USE VARIABLE

  12. In a separate task we want to write the code to start our program. To create another task line hold the “Shift Key�? and click and drag the beam from  the existing white beam on the left side of the screen. Double click, to confirm the length and location of the new beam.Lab sensors 9.jpg
  13. Create a new line under the first line of code written.
  14. We want our program to start when the Touch Sensor on Port 2 is bumped. Use a Wait Block.Lab sensors 10.jpg
  15. Its default is a Wait For Touch. Change the settings accordingly to Port 2 and Bumped.
  16. Next, we want to use the stored Variable. Since we will be using the Motor on Port A, we must account for both direction and speed of the motor. We will use another Variable block to determine direction. Place this after the Wait for touch block.Lab sensors 11.jpg
  17. This will be set to Logic 1 and “Write�?. Logic dictates that True will be Forward and False will be Reverse.  The Logic Variable Block must be set to True in order for the motor to go forward when the program starts.
  18. Now we want to use the Stored  Variable in conjunction with a Variable Logic Block to control the Motor A.  Place another Variable block set to Number 1 and�? Read�?. This will read the value from the Stored Variable 1. Then place a Variable Block set to Logic 1 and “Read�?. This will read the value from the previous Variable Logic  Block.  Lastly place a Motor A Block. Your task so far should look like this:
  19. Lab sensors 12.jpg

  20. Wire the Variable and Logic Blocks to Motor A using their respective drop down menus.  Remember, you want to control Direction and Power of Motor A.
  21. Lab sensors 13.jpg

  22. Finally, you want to constantly control the speed of Motor A. Insert a Loop into the string of code and place inside of it the two Variable Blocks and the Motor A block. Your final code for this task should look like this:
  23. Lab sensors 14.jpg

    TASK 3: MOTOR FLIP DIRECTION

    14. The next task we want to accomplish is to be able to switch the direction of Motor A if the Touch Sensor on Port 1 is pressed.  First, create a new task line as described in Task 2. 

    <img src="lab7_files/image021.jpg">15. Since we want the program to differentiate between when the Touch Sensor is pressed from when it is not pressed, we will use a Switch Block.

     

     

     

     

     

     Place the Switch Block on the new task line. Its default is set to Touch Sensor.

    16. The Top and Bottom sections of the Switch Block correspond to whether the Touch Sensor is pressed or not pressed, respectively. Since we want nothing to happen when the Touch Sensor is not pressed, leave the Bottom section empty.

    17. In the Top Section, we will first place a Variable Block set to Logic 1 and “Read�?. This will read the value from the Variable Logic Block we created in Step 10.

     

     

    <img src="lab7_files/image022.jpg">18. Since the direction of the Motor corresponds to the True or False value stated in the Variable Logic Block from Task 2, it is then possible to use a Logic Block to change its value.   

     

     

     

     

    The Logic Block allows you to use operations such as AND, OR & NOT in the Configuration Panel in the lower left corner of the window. Now place a Logic Block set to “NOT�? in the code string.

    19.To change the value of the Variable Logic Block from its value of True to False, wire the “Value�? of the Variable Logic Block to “A�? in the drop down menu of the Logic Block. Next we want to place another Variable Block set to Logic 1 and “Write�?. Now wire the “Result�? of the Logic Block to the�? Value�? of this Variable Logic Block via the drop down menus. We are basically saying that if the Value of Logic 1 is TRUE, then “NOT TRUE�? gives a result of FALSE.  Your code should look like this:

    <img src="lab7_files/image024.jpg">

     

    <img src="lab7_files/image025.jpg">20. Next we want to place a Wait Block changed to Time.

     

     

     Have it Wait for 1 second. 

     

    Lastly, we want to constantly check if the touch sensor is being pressed, so place the entire Switch Block within a Loop Block. The Wait Block is necessary due to the fact that when the Touch Sensor is pressed we want the program to Wait a certain amount of time so the Motor can change direction before the Loop rechecks its direction. Your final code for this task should look like:

    <img src="lab7_files/image027.jpg">

    TASK 4: STOP MOTOR A AFTER TOUCH SENSOR 2 IS PRESSED

    21. The last task simply ends the program when Touch Senor 2 is pressed. First, create a new task string.

    22. Place 2 Wait Blocks in sequence. Set them to Touch Sensor and “Bumped.�? The first Wait Block is to account for the Start of the program, as indicated in Step 9. The second Wait Block will be used to determine when to end the program.

    <img src="lab7_files/image029.jpg">23. Next, place a Stop Block.

     

     

    This Block will stop the whole program.

    24. Your final code for this task should look like:

    <img src="lab7_files/image030.jpg">

    If you followed each step correctly, your Final Code for Part A should resemble:

    <img src="lab7_files/image032.jpg">

    Test your Program.  After a TA approves that it works correctly, Save it and move onto Part B.

    Part B:

    In this part of the program you will modify what you had created in Part A to include the ultrasonic sensor.  In this portion of the exercise you will to add another task to utilize the ultrasonic sensor connected to Port 3.  In addition to its functionality from Part A, the motor must now reverse itself when the ultrasonic sensor on Port 3 detects a distance greater than 20cm or less than 8cm.  The idea behind this is to keep the motor on the track at all times.  Using what you have learned in Part A you can create this portion of the program on your own.  Remember to save your VI.  Once you are done, you may move on to Part C.

    Part C:

    In this part of the program you will modify what you have done in Parts A and B. You will add the light sensor to Port 4 and use input from that to stop the motor.  When the light sensor connected to Port 4 detects the red ball, the motor will stop.  You will need to determine what the light sensor value for the color red is. To do this, maneuver the red ball near the light sensor. On the NXT module, go to the View menu, Reflected Light, and choose Port 4. The percentage value displayed on the NXT module is the light sensor value for red. Use this to finish this final part of the program.

    When this program is done the touch sensor on Port 1 should be able to start Motor A and also flip its direction. The touch sensor on Port 2 should be able to stop Motor A and end the program. The ultrasonic sensor on Port 3 should be able to reverse the direction of the motor when the distance of the motor is greater than 20cm or less than 8cm from the wall. And the light sensor on Port 4 should be able to stop Motor A and end the program when it sees the red ball. Also, the speed of Motor A is controlled by Motor B.

    <img src="lab7_files/image034.jpg">

    Figure 1: Test Assembly, angled view

    <img src="lab7_files/image036.jpg">

    Figure 2: Test Assembly, side view

     

     

    <img src="lab7_files/image038.jpg">

    Figure 3: Test Assembly, top view

    Testing

    In order to test your program, ask your TA for the assembly, connect the NXT to the USB outlet and run the program you created.

    Wait

    The Wait Block allows your program to wait (pause) for a certain amount of time, or until a particular condition is met. The program will run up to the Wait command and then pause until the set period of time has elapsed or until the specific condition has been met. If a Wait command needs information from a sensor, the sensor in the Configuration Panel of the block located in the bottom left corner of the screen. This is so Mindstorms knows where to find it.<img src="lab7_files/image039.jpg"><img src="lab7_files/image040.jpg"><img src="lab7_files/image041.jpg"><img src="lab7_files/image042.jpg"><img src="lab7_files/image043.jpg">

    Switch

    <img src="lab7_files/image044.jpg"> 

     

    The Switch Block command is in the Flow menu. It will split the path of the program based on a condition you set. For instance, the program will perform one of two tasks depending on the value it receives from a sensor.   Sensor switches must be specified in the Configuration Panel so Mindstorms knows where to look for sensor input.

     

     

     

    Task Split

     

    <img src="lab7_files/image045.jpg">

    To create two independent tasks that run simultaneously, you must create a new beam to place blocks on.  As illustrated, begin on left side of the screen where the first line of code is written.  Hold the “Shift�? key and your “pointer�? will change to a spool of “wire.�? Drag the spool to your desired destination and double click to confirm the new beam.

    Loops

    <img src="lab7_files/image046.jpg">

    The Loop block is under the Flow menu.  You can set the loop to constantly check for certain conditions based on what criteria is selected in the Configuration Panel.  Loops can depend on Time, Count, Sensor or Logic Values. Loops can also be set to “Forever.�? This will continue to Loop the code inside of it until the program ends.

     

    Touch Sensors

    There are touch sensor blocks that use the Wait, Loop, and Switch structures.

    <img src="lab7_files/image047.jpg"><img src="lab7_files/image048.jpg"><img src="lab7_files/image043.jpg">

     

     

     

     

     

     

    The touch sensor Wait Block commands will pause the motor(s) until the touch sensor is pressed, released or bumped, depending on its configuration.

    The touch sensor Loop executes until the sensor is pressed, released or bumped, depending on its configuration.

    The touch sensor Switch takes one input and produces two outputs, splitting the path into two possibilities. The first possibility is the result when the touch sensor is pushed and the second is the result when the touch sensor is released.

    Light Sensors

    There are light sensor blocks that use the Wait, Loop, and Switch structures.

    <img src="lab7_files/image049.jpg"><img src="lab7_files/image050.jpg"><img src="lab7_files/image039.jpg">

     

     

     

     

     



     

    The light sensor Wait Block will pause the motor(s) when the measured value of reflected light is greater than or less than a constant value, depending on its configuration.

    The light sensor Loop executes until the measured value of reflected light is greater than or less than a constant value, depending on its configuration.

    The light sensor Switch takes one input and produces two outputs, splitting the path into two possibilities. The first possibility is the result when the value of reflected light is greater than a constant value and the second is the result when the value is less than the constant.

    Ultrasonic Sensors

    <img src="lab7_files/image051.jpg">There are ultrasonic sensor blocks that use the Wait, Loop, and Switch structures.

    <img src="lab7_files/image052.jpg"><img src="lab7_files/image041.jpg">

     

     

     

     

     

     

    The ultrasonic sensor Wait Block will pause the motor(s) when the distance measured is greater than or less than a constant value, depending on its configuration.

    The ultrasonic sensor Loop executes until the distance measured is greater than or less than a constant value, depending on its configuration.

    The ultrasonic sensor Switch takes one input and produces two outputs, splitting the path into two possibilities. The first possibility is the result when the distance measured is greater than the constant value and the second is the result when the value is less than the constant.

     

     

     

     

     

    Timers

    There are Timer blocks that use the Wait, Loop, and Switch structures.

    Timer structures are linked and used like the sensors are used; however, instead of getting values from sensors, they hold values in timer containers. Timers count the time elapsed from when they are reset.

    <img src="lab7_files/image053.jpg"><img src="lab7_files/image054.jpg"><img src="lab7_files/image042.jpg">

     

     

     

      

     

     

     

    The Timer  Wait Block will pause the program as it waits for the timer value to match the input value.

    The Timer Loop executes a selection of code while the timer is less than or greater than a certain value.

    The Timer Switch works the same as the light, touch and ultrasonic sensor switches. It compares the value of the timer to a set value and pauses the program until the timer equals the value it is being compared to.

    Variables

    Variables can be used to store Number, Logic or Text Values. Variables can “Written�? (1) or “Read�? (2).

    <img src="lab7_files/image055.jpg"><img src="lab7_files/image056.jpg">

     

     

     

               (1)                                       (2)

    In order to use variables correctly you should first define a variable by either “writing�? it or by storing an input value from a sensor. You can then use the Variable by “reading�? it. Both methods are used in Part A of this lab.

    Program 2: LabVIEW Temperature Indicator System

    1. Open the heating and cooling program you designed in the LabVIEW Lab . Switch the case to the automatic case.
    2. From the Functions palette select All Functions, NI measurements, and Data Acquisition, then select Analog Input, and then AI Sample Channel.
    3. Drag and drop the AI Sample Channel node into the automatic case on the back panel of your existing program.
    4. Right-click on the AI Sample Channel node and select Visible Items, then Terminals.
    5. Right-click on the AI Sample Channel node and click the Select Type menu. Select Scaled Value.
    6. Wire the AI Sample Channel node as shown in Figure 4.

    <img src="lab7_files/image058.jpg">

    Figure 4: AI Sample Channel node

    Wiring the Sample Channel node

    1. Device ID (integer): the DAC board is recognized by the computer as 1.
    2. Channel (string): for our purposes we will always set this to thermocouple .
    3. Upper Limit (real number): for our purposes we will always set this to +5.
    4. Lower Limit (real number): for our purposes we will always set this to -5.
    5. Output.
    6. Change the thermometer to an Indicator by right clicking on it and selecting Change to Indicator.
    7. Connect the output from the Sample Channel to the thermometer.

    Testing Your Design

    1. Connect the yellow wire of the thermocouple to pin 3 on the DAC board.
    2. Connect the orange wire of the thermocouple to pin 4 on the DAC board.
    3. Run the program continuously.
    4. Hold the thermocouple between your fingers to make the temperature rise. Confirm that the indicator on your program rises.
    5. Place thermocouple in a cup of cold water to make the temperature fall. Confirm that the indicator on your program falls.

    Have all sketches and original data signed by your TA. Your lab work is now complete.

    Please clean up your workstation. Return all unused materials to your TA.

    Refer to section 3 Your Assignment for the instructions you need to prepare your assignments this week.

     

     

     

     

     

    </html>