Bots-hitechnic-compass

From Earlham CS Department
Revision as of 07:51, 25 February 2010 by Charliep (talk | contribs) (New page: HiTechnic compass * Detailed design and usage information for the HiTechnic [http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034 compass sensor] * Because of the way th...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

HiTechnic compass

  • Detailed design and usage information for the HiTechnic compass sensor
  • Because of the way the registers are mapped you can use the UltraSonic() method to work with this compass. The value returned is 1/2 the actual heading in degrees, that is you multiply the returned value by 2 to calculate the heading.
  • Calibration is rarely necessary and shouldn't be an issue for us in the near-term.
  • Example code:
  1. !/usr/bin/env python
  1. This example uses the "plain" UltraSonic (i.e. digital) sensor interface
  2. with the HiTechnic compass sensor. The compass_heading() function
  3. attempts to do the conversion to degrees (but omits the adder register
  4. as documented by HiTechnic).
import time
import nxt.locator
from nxt.sensor import *
def id_nxt(b):

name, host, signal_strength, user_flash = b.get_device_info() print 'NXT brick name: %s' % name print 'Host address: %s' % host print 'Bluetooth signal strength: %s' % signal_strength print 'Free user flash: %s' % user_flash

def compass_heading(b, p):

# Because of limitations in the UltraSonic interface it returns 1/2 the # actual heading. return UltrasonicSensor(b, p).get_sample() * 2

print 'Looking for brick 1 ...'
sock = nxt.locator.find_one_brick(host='00:16:53:06:ED:B8', name='NXT')
if sock:

print 'Found brick 1'

else:

print 'Timed-out, no NXT bricks found, exiting' exit

if sock:

print 'Connecting to the brick ...' bot = sock.connect()

if bot: print 'Connected to the brick' else: print 'Timed-out connecting to brick 1, exiting' exit

if bot: id_nxt(bot)

while 1: print 'Compass heading: ', compass_heading(bot, PORT_4) time.sleep(1)