This block measures the earth's magnetic field to determine which way you robot is heading. It returns the heading as a number ranging from 0 to 359 degrees. Using data wires, it can send out the current heading and a logic signal (true/false) based on whether the current heading falls inside or outside a trigger range.
A trigger range consists of upper and lower limit values in a range of numbers where a change in the reading results in the condition of being either inside or outside the range. For example, you might program your robot to head south so you could set the trigger range to be from 170 to 190. As long as your robot is headed in a direction between these two numbers, the condition will be true.
Specify the trigger points by using the slider or by typing the values into the input boxes. To specify the portion of the compass sensor’s range (inside or outside the trigger range) that will generate the “true” signal, use the radio buttons or the pull-down menu. The “true” portion of the range will be in color; the “false” portion will be gray.
The default setting for the compass sensor block is for headings that are greater than 90 degrees and less than 270 degrees to generate a “true” signal. The compare function above the range allows you to switch the “true” portion of the range to be either inside or outside the range selected.
You must drag at least one output data wire from this block’s data hub to another block for any information to be sent.
The sensor may be connected directly to an NXT sensor port or via the HiTechnic Sensor Multiplexer (MUX). When configuring the sensor via the multiplexer, there are two port selections to make. The first is the NXT to MUX connection and the second, the MUX to SENSOR connection.
When connecting the sensor directly to the NXT, choose the port the sensor is connected to.
To connect the sensor via the multiplexer, click the right arrow symbol to display the port options.
Click the check box to select that the sensor will be connected vial the MUX. Configure the MUX to Sensor connection by selecting the MUX port (1 - 4) that is connected to the sensor.
Click on the right arrow symbol again, to display the NXT to MUX port selection.
Select the NXT port that is connected to the Sensor Multiplexer.
Ensure you select Absolute Reading to operate in this mode. For details about Relative Heading mode, look further down this page.
If you choose the Compare function Inside Range above the slider, the block will be triggered when the heading is between the two trigger values; select Outside Range to trigger the block when the heading is outside the two trigger values. Use the slider to set the trigger values or type them directly into the input boxes (0–359).
Note:
The compass measures the very weak earth's magnetic field. Ensure that is
mounted at least 4 inches or 10 centimeters away from the NXT and motors.
Also ensure that it is mounted horizontally as the heading will not be
accurate if the compass isn't level.
You can control the Compass Sensor block dynamically by connecting data wires (from other blocks’ data hubs) to the Compass Sensor block’s data hub.
Open a block’s data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area.
Data wires carrying input information to a block are connected to the plugs on the left side of its data hub. Data wires carrying output information are connected to the plugs on the right side.
[A] Input plug
[B] Output plug
[C] Number data wire (yellow)
[D] Logic data wire (green)
[E] Text data wire (orange)
[F] Broken data wire (gray)
If an input plug has a corresponding output plug (see A above), the input data will pass through from the input plug to the output plug without being changed. In this case, you can only use the output plug if the input plug is connected to an input data wire; connecting an output data wire to such an output plug without a connected input data wire will cause the output data wire to be “broken” (and colored gray).
Each data wire carries a specific type of data between blocks. For example, if a data wire is dragged from a logic plug on a block’s data hub, it can only be connected to a logic plug on another block’s data hub. The chart below shows what kind of data each plug can accept or send out.
Data wires are identified with specific colors: wires carrying number data are colored yellow, wires carrying logic data are colored green, and wires carrying text data are colored orange.
If you try to connect a data wire to a plug of the wrong data type, the data wire will be broken (and colored gray). You will not be able to download your program if a data wire is broken.
If you click a broken wire you can read why it is broken in the small help window in the lower right corner of the work area.
If an input data wire transmits a value outside the possible range of the plug it is connected to, the block will either ignore the value or change it to a value within its range. For plugs that allow just a few input values (example: just 0, 1, or 2), the plug will ignore the input if a value arrives outside its range.
For plugs that accept larger input ranges (example: 0 – 100), the plug will force any input outside its range to fit. For example, if a Move block’s Power plug receives an input value of 150, the block will change the input value to 100 (i.e., a number within the Power plug’s range).
You must click on the Data Hub to open it as shown.
The Compass Block may be operated in Relative Heading mode. This is provided to make it easier to create a program which allows your robot to travel in a particular direction. You can select this mode by changing the Action to Relative Reading.
After you have selected Relative Reading, you'll notice that the Target box becomes enabled and the compare slider limits change to -90 and 90.
In Relative Heading mode, the Target heading is compared with the current compass heading and the difference is used instead of the absolute heading. This makes it much easier to control the steering of your robot. Simply set the Target heading to the direction you want your robot to go in and then set the compare range from -90 to 0. This will make it trigger if you need to turn left else you need to turn right.
The HiTechnic compass sensor will be influenced by local magnetic interference in the same way as any other magnetic compass. Objects such as metal items, motors, batteries and wires can cause magnetic interference. Local magnetic interference may cause the compass to output a heading several degrees different than the actual magnetic heading. This is called compass deviation. To correct for deviation, the HiTechnic compass sensor has a built in calibration function that calculates correction offsets and stores them in the compass.
Calibration is optional and usually not required for normal operation. To minimize the need for calibration make sure you mount the compass at least 4 – 6 inches (10 – 15 cm) away from the NXT and NXT motors.
To calibrate the compass under program control, select the Calibrate action (value 2 wired to the Action plug input) and then program your robot to rotate (turn in a tight circle) between 1½ and 2 times (more than 360 degrees) so that it completes a full turn in about 20 seconds. Once the turns have been completed, use another Compass Sensor block with the Action set to either Absolute or Relative Reading to bring the sensor out of calibration mode. If the calibration failed, the Absolute Heading returned by this block will be -1. To test if the calibration was successful with this block, set the action to test the Absolute Heading for Inside Range 0 to 360; then the Yes/No output will be True only if the sensor calibration was successful. The compass will retain the calibration settings until another calibration is performed, even if it is unplugged.
The Compare lets you set a range and easily determine if you are inside or outside the range.
The Components for using the Range function are;
Inside Range / Outside Range: Select if you want to test for an Absolute Heading inside the range or outside the range.
A : The lower limit of the range (0 – 359)
B : The upper limit of the range (0 – 359)
To use the Range function, set the lower and upper limit of your range and whether you want to test for inside or outside the range.
Examples showing the logical result.
A |
B |
Range |
Absolute Heading |
Logical Value |
85 |
95 |
Inside Range |
90 |
|
85 |
95 |
Inside Range |
100 |
|
85 |
95 |
Outside Range |
90 |
|
85 |
95 |
Outside Range |
100 |