Difference between revisions of "Sensors"

From EG1004 Lab Manual
Jump to: navigation, search
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
<h1 align=center>EG1004 Lab 7: Sensors</h1>
''This writeup is intended for use with the NXT. For the EV3 version, see [[Sensors (EV3)]].''
= Objectives =
The experimental objective of this lab is to design various Mindstorms programs that use rotation, light, touch, and ultrasonic sensors.


<h2>1 OBJECTIVES</h2>
These exercises will build a foundation of experience with sensors programming that can be used with the semester-long design project.


<p>The experimental objective of this lab is to design two programs. The first
= Overview =
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 <b><i>LabVIEW Lab</i></b>. </p>


<p>We will learn to use light, touch, ultrasonic and rotation sensors so that we
== Mindstorms Program ==
can use these tools in our semester-long design projects.</p>
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.


<h2>2 OVERVIEW</h2>
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.


<h3>Mindstorms Program</h3>
= Assignment =
A zip file including the following programs needs to be submitted to the [http://eg.poly.edu EG Website]. If you don't know how to make a zip file, read the page [[How to Compress Your Files]] in the ''Instructional Presentations'' section of this manual.
* [[#Task|Ultrasonic Sensor Task]]
* [[#Course_1|Light Sensor Task: Course 1]]
* [[#Course_2|Light Sensor Task: Course 2]]


<p>Before we can learn to use sensors, we must become familiar with the <b><i>
== Lab Report ==
NXT</i></b>. Remember that the Mindstorms program is a compiler: a program used
There is no lab report for this lab.
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. </p>


<p>The NXT houses all the programming instructions that control the movement
== Team PowerPoint Presentation ==
of your robot. Once you have created your program in Mindstorms, it is uploaded
There is no presentation for this lab.
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.</p>


<h3>LabVIEW Program</h3>
= Materials and Equipment =
* Lab PC
* Mindstorms Software
* USB Cable
* NXT Unit


<p>The thermocouple records temperatures that are transmitted through the DAC
= Procedure =
board. LabVIEW uses these values to operate the heating and cooling system you
== Rotation Sensor ==
designed in the <b><i>LabVIEW Lab</i></b>. To program your heating and cooling
# Hover over the Sensor sub-palette (indicated by the yellow block on the left side of the window) and select the rotation sensor block
system VI to gather information from an outside source (thermocouple), you
#: [[Image:lab_sensors_54.png|thumb|500px|center]]
must add an AI Sample Channel. In order to wire this VI, you must right-click on
# Place it on the sequence beam
the icon, select Visible Items, and then Terminals.</p>
#: [[Image:lab_sensors_55.png|thumb|500px|center]]
# Select the rotation sensor block placed on the sequence beam and change the output to rotations. The configuration panel can be found on the bottom left corner of the window.
#: [[Image:lab_sensors_56.png|thumb|500px|center]]
# Hover over the Advanced sub-palette (indicated by the red block on the left side of the window) and select the Number to Text block
#: [[Image:lab_sensors_57.png|thumb|500px|center]]
# Place the Number to Text block next to the Rotation Sensor block.
#: [[Image:lab_sensors_58.png|thumb|500px|center]]
# Hover over the Action sub-palette (indicated by the light green block on the left side of the window) and select the Display block
#: [[Image:lab_sensors_59.png|thumb|500px|center]]
#Place the Display block next to the Number to Text block.
#: [[Image:lab_sensors_60.png|thumb|500px|center]]
# Configure the display block to show text.
#: [[Image:lab_sensors_61.png|thumb|500px|center]]
# Expand the data hub by clicking near the bottom left corner of the Display block
#: [[Image:lab_sensors_62.png|thumb|500px|center]]
#: [[Image:lab_sensors_63.png|thumb|500px|center]]
# Wire the plugs to the blocks as shown below.
#: [[Image:lab_sensors_64.png|thumb|500px|center]]
# Hover over the Flow sub-palette (indicated by the light orange block on the left side of the window) and select the Loop block
#: [[Image:lab_sensors_65.png|thumb|500px|center]]
# Place the loop block to the left of the Rotation Sensor block
#: [[Image:lab_sensors_66.png|thumb|500px|center]]
# Select all of the blocks to the right of the loop block and drag them into the loop block.
#: [[Image:lab_sensors_67.png|thumb|500px|center]]
With the program now completed, upload it to your NXT and run the program. Turn the motor that is connected to port A and look at the display. You should see numbers on the display that correspond to the number of times you've turned the motor.
=== Example for Rotation Sensor ===
Suppose you wrote a program that had your robot's motors move forward for 3 seconds. The procedure for this was covered in [[Product Evaluation and Quality Improvement]].
[[Image:lab_sensors_68.png|thumb|500px|center]]
Let's say you want to add the code that we previously made so that you can read the number of rotations that your robot made while it's moving. In order to do that, you'll need to create a new sequence beam.
# Start by clicking on the sequence beam below the starting point.
#: [[Image:lab_sensors_69.png|thumb|500px|center]]
# Drag the beam to your desired destination and double click at that point to create the new beam
#: [[Image:lab_sensors_70.png|thumb|500px|center]]
# Create the program previously made on the new beam
#: [[Image:lab_sensors_71.png|thumb|500px|center]]
=== Example #2 for Rotation Sensor ===
Suppose we wanted to create a program that displayed the number of rotations, but instead of having it loop forever, it would stop measuring the number of rotations once you've rotated it three times.
# Create the program shown below
#: [[Image:lab_sensors_72.png|thumb|500px|center]]
# Click on the loop block and change the control to sensor in the configuration menu.
#: [[Image:lab_sensors_73.png|thumb|500px|center]]
# Change the sensor to Rotation Sensor.
#: [[Image:lab_sensors_74.png|thumb|500px|center]]
# Set the loop conditions to greater than 3 rotations
#: [[Image:lab_sensors_75.png|thumb|500px|center]]
Your completed program should look like the one on the image below.
[[Image:lab_sensors_76.png|thumb|500px|center]]
When you run this program, you should be able to see the number of rotations on the NXT's display. If you make more than 3 rotations on the motor, the program should end.


<p>Developing advanced programming skills in both Mindstorms and LabVIEW will
== Ultrasonic Sensor ==
allow you to successfully complete your semester-long design project. This lab
For this portion of the lab, you will learn how to use the ultrasonic sensor in order to determine the distance between the robot and an object.
will help you acquire those skills.</p>
The code for obtaining a distance reading and displaying it on the NXT's screen is almost exactly the same as the code for the rotation sensor. The only difference is that instead of the rotation sensor block, you must use the ultrasonic sensor block
[[Image:lab_sensors_77.png|thumb|500px|center]]
=== Example for Ultrasonic Sensor ===
Suppose we wanted to write a program in which our NXT would show a happy face if the Ultrasonic Sensor detected a distance greater than 40 in, and show a sad face if the Ultrasonic Sensor detected a distance less than 40 in.
# To start off this program, we'll first need the switch block, which can found in the Flow sub-palette
#: [[Image:lab_sensors_78.png|thumb|500px|center]]
# In the configuration panel, change the sensor to the Ultrasonic Sensor
#: [[Image:lab_sensors_79.png|thumb|500px|center]]
# In the configuration panel, change the distance to 40
#: [[Image:lab_sensors_80.png|thumb|500px|center]]
#: If you look at the switch block, you'll notice two peculiar objects; a mountain and a flower. The mountain represents the case in which the sensor value is greater than 40, and the flower represents the case in which the sensor value is less than 40.
#: [[Image:lab_sensors_81.png|thumb|500px|center]]
# Place a display block into each of the two sequence beams in the switch block
#: [[Image:lab_sensors_82.png|thumb|500px|center]]
# Configure each display block so that it shows the correct image. Remember that the NXT should display happy face when the distance sensed by the Ultrasonic Sensor is greater than 40 in and show a sad face when the distance is less than 40 in.
# Place the entire switch block into a loop block.
#: [[Image:lab_sensors_83.png|thumb|500px|center]]
=== Example #2 for Ultrasonic Sensor ===
Now suppose we wanted to add an additional case to the program where the NXT would display a caution sign when the Ultrasonic Sensor senses a distance less than 40 in but greater than 30 in, and display a sad face when the distance sensed is less than 30. In this situation, one switch case won't be enough, as the program will only check to see if the value obtained is greater than or less than one specific number. To overcome this problem, we'll need an additional switch case inside of the switch case we already have.
[[Image:lab_sensors_84.png|thumb|500px|center]]
In this program, when the distanced sensed is greater than 40, it will display a happy face, just like before. When the distance sensed is less than 40, it will check to see if it's greater than or less than 30, and show the appropriate image based on that.
=== Task ===
Create a program in which your robot maintains a distance of 8 and 20 in from the wall. In other words, your robot should move away from the wall if the ultrasonic sensor senses a distance less than 8 in and moves towards the wall if the ultrasonic sensor senses a distance greater than 20 in.


== Touch Sensor ==
For this portion of the lab, you will learn how to use the touch sensor to control the actions of your robot based whether the touch sensor has been pressed or bumped.
=== Example for Touch Sensor ===
Suppose you wanted to create a program in which your robot would move when the touch sensor is pressed, and would stop when the touch sensor was released.
# Insert a switch block and have it set to the touch sensor
#: [[Image:lab_sensors_85.png|thumb|500px|center]]
# Insert a move block into each of the sequence beams. Configure one motor block to move continuously and set the other motor block to stop
#: [[Image:lab_sensors_86.png|thumb|500px|center]]
# Place the switch block into a loop block
#: [[Image:lab_sensors_87.png|thumb|500px|center]]


<h2>3 YOUR ASSIGNMENT</h2>
== Light Sensor ==
For this portion of the lab, you will learn how to use the light sensor in order to determine the light intensity of the sensor's reflected light. You will also learn how to use the light sensor to follow a line.
The program for obtaining the light intensity and displaying it on the NXT's screen is the same as that of the rotation sensor and the ultrasonic sensor, except you need to use the light sensor block.


<ul>
[[Image:lab_sensors_88.png|thumb|500px|center]]
<li><b>A Zip file including all LabVIEW programs (.vi) needs to be submitted to
the [http://eg.poly.edu|the EG1004 Web site]. If you don't know how to make a zip
file, read the page [[How to Compress Your Files]] in the <i>Instructional
Presentations</i> section of this manual.</b></li>
</ul>


<h3>Lab Report</h3>
=== Line Following Code Using One Light Sensor ===
The code for following a line using one light sensor is shown below.


<p>There is no lab report for this lab.</p>
[[Image:lab_sensors_89.png|thumb|500px|center]]


<h3>Team PowerPoint Presentation</h3>
This block of code alternates between the left and right motor of the robot, depending on whether the light sensor sees the line. For example, let us assume that motor A is the left motor and motor C is the right motor. Thus, when the light sensor sees the line, the right motor (motor C) stops while the left motor (motor A) starts turning. This causes the robot to turn away from the line while moving forward. Also, when the light sensor doesn't see the line, the left motor stops while the right motor starts turning. This causes the robot to turn towards the line while moving forwards.


<p>There is no presentation for this lab.</p>
=== Line Following Code Using Two Light Sensors ===
The code for following a line using two light sensors is shown below.


<h2>4 MATERIALS AND EQUIPMENT</h2>
[[Image:lab_sensors_90.png|thumb|500px|center]]


<ul>
This block of code alternates between turning the left and right motor of the robot, depending on which light sensor sees the line. First, let us assume that motor A is the left motor and motor C is the right motor. Also, we'll assume that light sensor 1 is the left light sensor and light sensor 2 is the right light sensor.  Thus, when the left light sensor sees the line, but the right line sensor doesn't, the left motor stops while the right motor starts moving. If the right light sensor sees the line, but the left light sensor doesn't see the line, the right motor stops while the left motor starts moving. If neither light sensor see the line, then both motors start turning.
<li>Lab PC</li>
For positioning, the robot should be placed such that the light sensors are in between the line.
<li>Mindstorms and LabVIEW Software</li>
<li>USB Cable</li>
<li>NXT Unit</li>
<li>Multiple NXT Sensor Array</li>
<li>DAC Board</li>
<li>Thermocouple</li>
</ul>


<h2>5 PROCEDURE</h2>
=== Tasks ===
==== Course 1 ====
[[Image:lab_sensors_91.png|thumb|500px|center]]


<h3>Program 1: Mindstorms Sensors</h3>
Create a program in which your robot travels from point A to point C in a clockwise manner, then rotates 180 degrees and finally returns to point A.


<p>The program is broken up into three main parts. In Part A you will use
==== Course 2 ====
the touch sensors to start, stop and reverse the direction of the motor. In
[[Image:lab_sensors_92.png|thumb|500px|center]]
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>
Create a program in which your robot travels from point A to point H in a clockwise manner, rotates 180 degrees, and travels to point C.


<p>In this part of the exercise you first create a program that causes Motor A
= Appendix: Advanced Mindstorms Reference =
to move when the touch sensor connected to Port 1 is pushed and stop when the
== Wait ==
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>
<table>
<tr>
<td valign=top>[[Image:Lab_sensors_30.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_26.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_27.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_28.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_29.jpg]]</td>
</tr>
</table>


<ol>
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.


<li>Open MindStorms 1.1. Create a new program.</li>
== Switch ==
[[Image:Lab_sensors_31.jpg]]


<li>To use the rotation sensor to control the speed of the motor, we will use the
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.
Rotation Sensor Block to read the value of the Rotation Sensor on Port B.<br>
[[Image:Lab_sensors_1.jpg]]</li>
<p>&nbsp;</p>


<li>Next we will have to convert the value of the Rotation Sensor to a number value
== Task Split ==
that the motor can use to determine speed. We will use the Math Block.<br>
[[Image:Lab_sensors_32.jpg]]
[[Image:Lab_sensors_2.jpg]]</li>
<p>&nbsp;</p>


<li>Change the block to Division. You can alter the settings of a block in the
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.
Configuration Panel located in the bottom left corner of the window.<br>
[[Image:Lab_sensors_3.jpg]]</li>
<p>&nbsp;</p>


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


<p>[[Image:Lab_sensors_4.jpg]]</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.


<li>Next, highlight the degrees on the Rotation Sensor Block and wire it to “A�? on
== Touch Sensors ==
the Math Block.</li>
There are touch sensor blocks that use the Wait, Loop, and Switch structures.


<p>[[Image:Lab_sensors_5.jpg]]</p>
<table>
<tr>
<td valign=top>[[Image:Lab_sensors_30.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_34.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_35.jpg]]</td>
</tr>
</table>


<p>This takes the value of the Rotation Sensor and uses that as input A on the
The touch sensor Wait Block commands will pause the motor(s) until the touch sensor is pressed, released or bumped, depending on its configuration.
Math Block.</p>


<li>In the Math Block type “2�? into the “B�? box. This will convert the
The touch sensor Loop executes until the sensor is pressed, released or bumped, depending on its configuration.
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>&nbsp;</p>


<li>Since we will be using this value further along in the program, we want to store
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.
this value as a variable. Use a Variable Block and string it next to the Math Bock.<br>
[[Image:Lab_sensors_6.jpg]]</li>
<p>&nbsp;</p>


<li>Change the Variable Block settings to “Write�? and “Number 1�?.  Using the drop
== Light Sensors ==
down menu in the Variable Block, wire the “#�? output from the Math Block to the
There are light sensor blocks that use the Wait, Loop, and Switch structures.
“#�? input on the Variable Block. The string of code should look like this:<br>
[[Image:Lab_sensors_7.jpg]]</li>
<p>&nbsp;</p>


<li>We want to constantly check the value of the Rotation Sensor and change
<table>
the speed accordingly. To do this we want to use a Loop. Bring out a Loop,
<tr>
select all the code that was written and place it inside the loop. The final
<td valign=top>[[Image:Lab_sensors_26.jpg]]</td>
line of code should look like this:<br>
<td valign=top>[[Image:Lab_sensors_37.jpg]]</td>
[[Image:Lab_sensors_8.jpg]]</li>
<td valign=top>[[Image:Lab_sensors_36.jpg]]</td>
</tr>
</table>


<h4>TASK 2: USE VARIABLE</h4>
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.


<li>In a separate task we want to write the code to start our program. To
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.
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.<br>
[[Image:Lab_sensors_9.jpg]]</li>
<p>&nbsp;</p>


<li>Create a new line under the first line of code written.</li>
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.


<li>We want our program to start when the Touch Sensor on Port 2 is bumped.
== Ultrasonic Sensors ==
Use a Wait Block.<br>
There are ultrasonic sensor blocks that use the Wait, Loop, and Switch structures.
[[Image:Lab_sensors_10.jpg]]</li>
<p>&nbsp;</p>


<li>Its default is a Wait For Touch. Change the settings accordingly to Port 2
<table>
and Bumped. </li>
<tr>
<td valign=top>[[Image:Lab_sensors_28.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_39.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_38.jpg]]</td>
</tr>
</table>


<li>Next, we want to use the stored Variable. Since we will be using the Motor
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.
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.<br>
[[Image:Lab_sensors_11.jpg]]</li>
<p>&nbsp;</p>


<li>This will be set to Logic 1 and “Write�?. Logic dictates that True will be
The ultrasonic sensor Loop executes until the distance measured is greater than or less than a constant value, depending on its configuration.
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
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.
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>
== Display block ==
<table>
<tr>
<td valign=top>[[Image:Lab_sensors_53.jpg]]</td>
</tr>
</table>


<li>Wire the Variable and Logic Blocks to Motor A using their respective drop
The Display Block is used to alter the display of the NXT Brick. You can choose either pre-installed images or print your own variables by wiring sensors or other variable containers to the block.
down menus.  Remember, you want to control Direction and Power of Motor A.</li>


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


<p>[[Image:Lab_sensors_13.jpg]]</p>
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.


<li>Finally, you want to constantly control the speed of Motor A. Insert a
<table>
Loop into the string of code and place inside of it the two Variable Blocks and
<tr>
the Motor A block. Your final code for this task should look like this: </li>
<td valign=top>[[Image:Lab_sensors_29.jpg]]</td>
 
<td valign=top>[[Image:Lab_sensors_40.jpg]]</td>
<p>[[Image:Lab_sensors_14.jpg]]</p>
<td valign=top>[[Image:Lab_sensors_41.jpg]]</td>
 
</tr>
<h4>TASK 3: MOTOR FLIP DIRECTION</h4>
</table>
 
<li>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.</li>
 
<li>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.<br>
[[Image:Lab_sensors_15.jpg]]</li>
<p>&nbsp;</p>
 
<li>Place the Switch Block on the new task line. Its default is set to Touch
Sensor.</li>
 
<li>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.
</li>
 
<li>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.</li>
 
<li>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.<br>
[[Image:Lab_sensors_16.jpg]]</li>
<p>&nbsp;</p>
 
<li>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. </li>
 
<li>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: </li>
 
<p>[[Image:Lab_sensors_17.jpg]]</p>
 
<li>Next we want to place a Wait Block changed to Time.<br>
[[Image:Lab_sensors_18.jpg]]</li>
<p>&nbsp;</p>


<li>Have it Wait for 1 second.</li>
The Timer  Wait Block will pause the program as it waits for the timer value to match the input value.


<li>Lastly, we want to constantly check if the touch sensor is being pressed, so
The Timer Loop executes a selection of code while the timer is less than or greater than a certain value.
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:</li>


<p>[[Image:Lab_sensors_19.jpg]]</p>
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.


<h4>TASK 4: STOP MOTOR A AFTER TOUCH SENSOR 2 IS PRESSED</h4>
== Variables ==
 
Variables can be used to store Number, Logic or Text Values. Variables can "Written" (1) or "Read" (2).
<li>The last task simply ends the program when Touch Senor 2 is pressed.
First, create a new task string.</li>
 
<li>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.
</li>
 
<li>Next, place a Stop Block.<br>
[[Image:Lab_sensors_20.jpg]]</li>
<p>&nbsp;</p>
 
<p>This Block will stop the whole program.</p>
 
<li>Your final code for this task should look like:</li>
 
<p>[[Image:Lab_sensors_21.jpg]]</p>
 
<p>If you followed each step correctly, your Final Code for Part A should
resemble: </p>
 
<p>[[Image:Lab_sensors_22.jpg]]</p>
 
<li>Test your Program.  After a TA approves that it works correctly, Save it and
move onto Part B.</li>
</ol>
 
<h3>Part B:</h3>
 
<p>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.</p>
 
<h3>Part C:</h3>
 
<p>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.</p>
 
<p>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.</p>
 
<p align=center>[[Image:Lab_sensors_23.jpg]]</p>
 
<p class=caption>Figure 1: Test Assembly, angled view</p>
 
<p align=center>[[Image:Lab_sensors_24.jpg]]</p>
 
<p class=caption>Figure 2: Test Assembly, side view</p>
 
<p align=center>[[Image:Lab_sensors_25.jpg]]</p>
 
<p class=caption>Figure 3: Test Assembly, top view</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>
 
<h4>Wait</h4>
 
<p>[[Image:Lab_sensors_26.jpg]][[Image:Lab_sensors_27.jpg]]
[[Image:Lab_sensors_28.jpg]][[Image:Lab_sensors_29.jpg]]
[[Image:Lab_sensors_30.jpg]]</p>
 
<p>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.</p>
 
<h4>Switch</h4>
 
<p>[[Image:Lab_sensors_31.jpg]]</p>
 
<p>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.</p>
 
<h4>Task Split</h4>
 
<p>[[Image:Lab_sensors_32.jpg]]</p>
 
<p>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. </p>
 
<h4>Loops</h4>
 
<p>[[Image:Lab_sensors_33.jpg]]</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>
 
<h4>Touch Sensors</h4>
 
<p>There are touch sensor blocks that use the Wait, Loop, and Switch
structures.</p>
 
<p>[[Image:Lab_sensors_34.jpg]][[Image:Lab_sensors_35.jpg]][[Image:Lab_sensors_30.jpg]]</p>
 
<p>The touch sensor Wait Block commands will pause the motor(s) until the
touch sensor is pressed, released or bumped, depending on its
configuration.</p>
 
<p>The touch sensor Loop executes until the sensor is pressed, released or
bumped, depending on its configuration.</p>
 
<p>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.</p>
 
<h4>Light Sensors</h4>
 
<p>There are light sensor blocks that use the Wait, Loop, and Switch
structures.</p>
 
<p>[[Image:Lab_sensors_36.jpg]][[Image:Lab_sensors_37.jpg]][[Image:Lab_sensors_26.jpg]]</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>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>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.</p>
 
<h4>Ultrasonic Sensors</h4>
 
<p>[[Image:Lab_sensors_38.jpg]][[Image:Lab_sensors_39.jpg]][[Image:Lab_sensors_28.jpg]]</p>
 
<p>There are ultrasonic sensor blocks that use the Wait, Loop, and Switch structures.</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>The ultrasonic sensor Loop executes until the distance measured is greater
than or less than a constant value, depending on its configuration.</p>
 
<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>
 
<h4>Timers</h4>
 
<p>There are Timer blocks that use the Wait, Loop, and Switch structures.</p>
 
<p>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.</p>
 
<p>[[Image:Lab_sensors_40.jpg]][[Image:Lab_sensors_41.jpg]][[Image:Lab_sensors_29.jpg]]</p>
 
<p>The Timer  Wait Block will pause the program as it waits for the timer value
to match the input value. </p>
 
<p>The Timer Loop executes a selection of code while the timer is less than or
greater than a certain value. </p>
 
<p>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. </p>
 
<h4>Variables</h4>
 
<p>Variables can be used to store Number, Logic or Text Values. Variables can
“Written�? (1) or “Read�? (2). </p>


<table>
<table>
<tr><td>[[Image:Lab_sensors_42.jpg]]</td><td>[[Image:Lab_sensors_43.jpg]]</td></tr>
<tr>
<td valign=top>[[Image:Lab_sensors_42.jpg]]</td>
<td valign=top>[[Image:Lab_sensors_43.jpg]]</td>
</tr>
<tr><td align=center>(1)</td><td align=center>(2)</td></tr>
<tr><td align=center>(1)</td><td align=center>(2)</td></tr>
</table>
</table>


<p>In order to use variables correctly you should first define a variable by
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.
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>
 
<h3>Program 2: LabVIEW Temperature Indicator System</h3>
 
<ol>
<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>
 
<p align=center>[[Image:Lab_sensors_44.png]]</p>
 
<p class=caption>Figure 4: AI Sample Channel node</p>
 
<h4>Wiring the Sample Channel node</h4>
 
<ol>
<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>
 
<ol>
<li>Connect 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 the 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>Please clean up your workstation. Return all unused materials to your TA.</p>


<p>Refer to section <b><i>3 Your Assignment</i></b> for the instructions you
{{Laboratory Experiments}}
need to prepare your assignments this week.</p>

Latest revision as of 00:28, 5 March 2014

This writeup is intended for use with the NXT. For the EV3 version, see Sensors (EV3).

Objectives

The experimental objective of this lab is to design various Mindstorms programs that use rotation, light, touch, and ultrasonic sensors.

These exercises will build a foundation of experience with sensors programming that can be used with the semester-long design project.

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.

Assignment

A zip file including the following programs needs to be submitted to the EG Website. If you don't know how to make a zip file, read the page How to Compress Your Files in the Instructional Presentations section of this manual.

Lab Report

There is no lab report for this lab.

Team PowerPoint Presentation

There is no presentation for this lab.

Materials and Equipment

  • Lab PC
  • Mindstorms Software
  • USB Cable
  • NXT Unit

Procedure

Rotation Sensor

  1. Hover over the Sensor sub-palette (indicated by the yellow block on the left side of the window) and select the rotation sensor block
    Lab sensors 54.png
  2. Place it on the sequence beam
    Lab sensors 55.png
  3. Select the rotation sensor block placed on the sequence beam and change the output to rotations. The configuration panel can be found on the bottom left corner of the window.
    Lab sensors 56.png
  4. Hover over the Advanced sub-palette (indicated by the red block on the left side of the window) and select the Number to Text block
    Lab sensors 57.png
  5. Place the Number to Text block next to the Rotation Sensor block.
    Lab sensors 58.png
  6. Hover over the Action sub-palette (indicated by the light green block on the left side of the window) and select the Display block
    Lab sensors 59.png
  7. Place the Display block next to the Number to Text block.
    Lab sensors 60.png
  8. Configure the display block to show text.
    Lab sensors 61.png
  9. Expand the data hub by clicking near the bottom left corner of the Display block
    Lab sensors 62.png
    Lab sensors 63.png
  10. Wire the plugs to the blocks as shown below.
    Lab sensors 64.png
  11. Hover over the Flow sub-palette (indicated by the light orange block on the left side of the window) and select the Loop block
    Lab sensors 65.png
  12. Place the loop block to the left of the Rotation Sensor block
    Lab sensors 66.png
  13. Select all of the blocks to the right of the loop block and drag them into the loop block.
    Lab sensors 67.png

With the program now completed, upload it to your NXT and run the program. Turn the motor that is connected to port A and look at the display. You should see numbers on the display that correspond to the number of times you've turned the motor.

Example for Rotation Sensor

Suppose you wrote a program that had your robot's motors move forward for 3 seconds. The procedure for this was covered in Product Evaluation and Quality Improvement.

Lab sensors 68.png

Let's say you want to add the code that we previously made so that you can read the number of rotations that your robot made while it's moving. In order to do that, you'll need to create a new sequence beam.

  1. Start by clicking on the sequence beam below the starting point.
    Lab sensors 69.png
  2. Drag the beam to your desired destination and double click at that point to create the new beam
    Lab sensors 70.png
  3. Create the program previously made on the new beam
    Lab sensors 71.png

Example #2 for Rotation Sensor

Suppose we wanted to create a program that displayed the number of rotations, but instead of having it loop forever, it would stop measuring the number of rotations once you've rotated it three times.

  1. Create the program shown below
    Lab sensors 72.png
  2. Click on the loop block and change the control to sensor in the configuration menu.
    Lab sensors 73.png
  3. Change the sensor to Rotation Sensor.
    Lab sensors 74.png
  4. Set the loop conditions to greater than 3 rotations
    Lab sensors 75.png

Your completed program should look like the one on the image below.

Lab sensors 76.png

When you run this program, you should be able to see the number of rotations on the NXT's display. If you make more than 3 rotations on the motor, the program should end.

Ultrasonic Sensor

For this portion of the lab, you will learn how to use the ultrasonic sensor in order to determine the distance between the robot and an object. The code for obtaining a distance reading and displaying it on the NXT's screen is almost exactly the same as the code for the rotation sensor. The only difference is that instead of the rotation sensor block, you must use the ultrasonic sensor block

Lab sensors 77.png

Example for Ultrasonic Sensor

Suppose we wanted to write a program in which our NXT would show a happy face if the Ultrasonic Sensor detected a distance greater than 40 in, and show a sad face if the Ultrasonic Sensor detected a distance less than 40 in.

  1. To start off this program, we'll first need the switch block, which can found in the Flow sub-palette
    Lab sensors 78.png
  2. In the configuration panel, change the sensor to the Ultrasonic Sensor
    Lab sensors 79.png
  3. In the configuration panel, change the distance to 40
    Lab sensors 80.png
    If you look at the switch block, you'll notice two peculiar objects; a mountain and a flower. The mountain represents the case in which the sensor value is greater than 40, and the flower represents the case in which the sensor value is less than 40.
    Lab sensors 81.png
  4. Place a display block into each of the two sequence beams in the switch block
    Lab sensors 82.png
  5. Configure each display block so that it shows the correct image. Remember that the NXT should display happy face when the distance sensed by the Ultrasonic Sensor is greater than 40 in and show a sad face when the distance is less than 40 in.
  6. Place the entire switch block into a loop block.
    Lab sensors 83.png

Example #2 for Ultrasonic Sensor

Now suppose we wanted to add an additional case to the program where the NXT would display a caution sign when the Ultrasonic Sensor senses a distance less than 40 in but greater than 30 in, and display a sad face when the distance sensed is less than 30. In this situation, one switch case won't be enough, as the program will only check to see if the value obtained is greater than or less than one specific number. To overcome this problem, we'll need an additional switch case inside of the switch case we already have.

Lab sensors 84.png

In this program, when the distanced sensed is greater than 40, it will display a happy face, just like before. When the distance sensed is less than 40, it will check to see if it's greater than or less than 30, and show the appropriate image based on that.

Task

Create a program in which your robot maintains a distance of 8 and 20 in from the wall. In other words, your robot should move away from the wall if the ultrasonic sensor senses a distance less than 8 in and moves towards the wall if the ultrasonic sensor senses a distance greater than 20 in.

Touch Sensor

For this portion of the lab, you will learn how to use the touch sensor to control the actions of your robot based whether the touch sensor has been pressed or bumped.

Example for Touch Sensor

Suppose you wanted to create a program in which your robot would move when the touch sensor is pressed, and would stop when the touch sensor was released.

  1. Insert a switch block and have it set to the touch sensor
    Lab sensors 85.png
  2. Insert a move block into each of the sequence beams. Configure one motor block to move continuously and set the other motor block to stop
    Lab sensors 86.png
  3. Place the switch block into a loop block
    Lab sensors 87.png

Light Sensor

For this portion of the lab, you will learn how to use the light sensor in order to determine the light intensity of the sensor's reflected light. You will also learn how to use the light sensor to follow a line. The program for obtaining the light intensity and displaying it on the NXT's screen is the same as that of the rotation sensor and the ultrasonic sensor, except you need to use the light sensor block.

Lab sensors 88.png

Line Following Code Using One Light Sensor

The code for following a line using one light sensor is shown below.

Lab sensors 89.png

This block of code alternates between the left and right motor of the robot, depending on whether the light sensor sees the line. For example, let us assume that motor A is the left motor and motor C is the right motor. Thus, when the light sensor sees the line, the right motor (motor C) stops while the left motor (motor A) starts turning. This causes the robot to turn away from the line while moving forward. Also, when the light sensor doesn't see the line, the left motor stops while the right motor starts turning. This causes the robot to turn towards the line while moving forwards.

Line Following Code Using Two Light Sensors

The code for following a line using two light sensors is shown below.

Lab sensors 90.png

This block of code alternates between turning the left and right motor of the robot, depending on which light sensor sees the line. First, let us assume that motor A is the left motor and motor C is the right motor. Also, we'll assume that light sensor 1 is the left light sensor and light sensor 2 is the right light sensor. Thus, when the left light sensor sees the line, but the right line sensor doesn't, the left motor stops while the right motor starts moving. If the right light sensor sees the line, but the left light sensor doesn't see the line, the right motor stops while the left motor starts moving. If neither light sensor see the line, then both motors start turning. For positioning, the robot should be placed such that the light sensors are in between the line.

Tasks

Course 1

Lab sensors 91.png

Create a program in which your robot travels from point A to point C in a clockwise manner, then rotates 180 degrees and finally returns to point A.

Course 2

Lab sensors 92.png

Create a program in which your robot travels from point A to point H in a clockwise manner, rotates 180 degrees, and travels to point C.

Appendix: Advanced Mindstorms Reference

Wait

Lab sensors 30.jpg Lab sensors 26.jpg Lab sensors 27.jpg Lab sensors 28.jpg Lab sensors 29.jpg

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.

Switch

Lab sensors 31.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

Lab sensors 32.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

Lab sensors 33.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.

Lab sensors 30.jpg Lab sensors 34.jpg Lab sensors 35.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.

Lab sensors 26.jpg Lab sensors 37.jpg Lab sensors 36.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

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

Lab sensors 28.jpg Lab sensors 39.jpg Lab sensors 38.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.

Display block

Lab sensors 53.jpg

The Display Block is used to alter the display of the NXT Brick. You can choose either pre-installed images or print your own variables by wiring sensors or other variable containers to the block.

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.

Lab sensors 29.jpg Lab sensors 40.jpg Lab sensors 41.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).

Lab sensors 42.jpg Lab sensors 43.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.