Difference between revisions of "Bots-hitechnic-compass"
Jump to navigation
Jump to search
(→HiTechnic compass) |
(→HiTechnic compass) |
||
Line 2: | Line 2: | ||
---- | ---- | ||
== HiTechnic compass == | == HiTechnic compass == | ||
− | [http://cs.earlham.edu/~leemasa/robotics/hicompass.py hicompass library] | + | Copy the [http://cs.earlham.edu/~leemasa/robotics/hicompass.py hicompass library] into your NXT directory |
* Detailed design and usage information for the HiTechnic [http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034 compass sensor] | * Detailed design and usage information for the HiTechnic [http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034 compass sensor] | ||
Line 20: | Line 20: | ||
=== Examples === | === Examples === | ||
Plug your compass into port four and place the following code somewhere in a program that already works with your robot | Plug your compass into port four and place the following code somewhere in a program that already works with your robot | ||
− | + | import hicompass | |
bot = (whatever variable you use to refer to your bot) | bot = (whatever variable you use to refer to your bot) | ||
compass = hicompass.CompassSensor(bot,PORT_4) | compass = hicompass.CompassSensor(bot,PORT_4) |
Revision as of 10:38, 8 March 2010
Back to Robotics Main Page
HiTechnic compass
Copy the hicompass library into your NXT directory
- Detailed design and usage information for the HiTechnic compass sensor
- Note: The description of how heading is stored in the sensor is incorrect. 0x44 points to the low byte and 0x45 points to the high bit. In other words, the formula for getting heading is (0x44) + 255*(0x45)
Functions
Expect more functions in the near future
- CompassSensor(bot, port) - declares a HiTechnic compass object
- get_manufacturer() - returns the eight-character string in the "manufacturer" block of the device (should be HiTechnc)
- get_sample() - returns the heading measurement of the sensor in degrees clockwise from due North.
- Although bus errors wit the hicompass are relatively rare, get_sample() automatically tries again if it fails to get a heading.
- calibrate_mode() - sets the compass to calibrate mode to correct for magnetic interference.
- see Calibrating the Compass below
- measure_mode() - sets the compass to measure mode. The compass is in this mode by default
Examples
Plug your compass into port four and place the following code somewhere in a program that already works with your robot
import hicompass bot = (whatever variable you use to refer to your bot) compass = hicompass.CompassSensor(bot,PORT_4) print compass.get_manufacturer() heading = compass.get_sample() while heading > 10: heading = compass.get_sample() print 'Heading: ', heading
This will tell the sensor to collect headings until it is within ten degrees East of due North.
Calibrating the Compass
- Assemble a mobile robot that can drive in a circle
- The size and precision of the circle is unimportant as long as the robot can make a full revolution
- Set your compass sensor to calibrate mode and instruct your robot to drive in a circle
- The robot should make between one and a half and two revolutions in about twenty seconds and stop
- Be sure to set your compass sensor back to measure mode when you are done!
Notes
The compass sensor is a very sensitive device. Here are some tips to make sure you get accurate readings
- Keep the sensor level
- Make sure the sensor is steady. The more it bounces around the less accurate your readings will be
- Keep the sensor at least four inches from your NXT brick and six from your motors. They generate magnetic fields that will result in inaccurate readings.