A new sensor from HiTechnic Products is available for your NXT robots. This sensor does not come with the basic NXT kit, but you can purchase it directly from the online Lego Store, http://shop.lego.com
, or from the HiTechnic Products Web site, http://www.hitechnic.com
.
This is a fun sensor to play with and can give your robots a good sense of direction—pun intended. If you are considering purchasing a new sensor for your robots, this would be a good one to start off using. This appendix provides some details about the HiTechnic NXT Compass Sensor.
The Compass Sensor provides digital feedback to your NXT Brick in the form of an integer value in the range of 0 to 359. It does not return negative values for directional headings. So, for example, if your bot is heading east, you will get a return value of 90. Take a look at Figure D-1 for a better understanding of how compass points (North, West, East, South) correspond to numeric values (0 to 360).
Figure D-1. A compass with standard North, West, East, and South headings
When using the HiTechnic NXT Compass Sensor, it is helpful to know that some of the values the sensor returns to the NXT Brick match up to directions such as north, south, east, and west. You can also get rough estimates for northwest, northeast, southwest, and southeast. Simply put, the sensor returns the magnetic bearing.
Figure D-2 shows the NXT-G programming block used to configure the Compass Sensor.
Figure D-2. The Compass Sensor programming block
The Compass Sensor block is on the left side of the small program, and you can see that it works just like other NXT-G blocks. It has a configuration panel as well as a data hub that can send and receive data using data wires.
In the Port section, you can select the port number to use when attaching the Compass Sensor.
The Action section has a drop-down menu that gives you three options:
Other options with the Compass Sensor allow you to define a range of values (for example, between 0 and 359 degrees) that you can use to obtain a TRUE
/FALSE
= response—this response is useful for keeping your robot moving within a certain direction; if the robot strays outside the range, you could use a condition block such as the SWITCH
block to put the bot back on course.
It's a fun sensor to play with, and a robot with a sense of direction can perform some very useful movements with a large degree of accuracy.