APPENDIX D
HiTechnic NXT Compass Sensor

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.

North, West, East, and South

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

image

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.

Using the Compass Sensor

Figure D-2 shows the NXT-G programming block used to configure the Compass Sensor.

image

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:

  • Absolute Reading: Returns a value between 0 and 359, depending on the direction heading.
  • Relative Reading: Enables you to use the sensor to help your bot maintain a specific direction (such as 90). You set a target heading (for example, 90 degrees, which is a heading of east) and the block returns a value showing the difference between the current absolute heading and the target heading. If your absolute heading is 85, the returned value will be 5 (the difference between the target, 90, and the current absolute heading). If the heading is 95, the returned value will be −5. This scheme allows you to decide which way to turn to get back to your target heading quickly. A negative number means your bot should turn counterclockwise and a positive value means your bot needs to turn clockwise.
  • Calibrate: Lets you calibrate the sensor in the bot's working environment so that you obtain the best readings possible, allowing the sensor to try to compensate for variations in the magnetic field due to the robot itself.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.126.211