Jump to navigation Jump to search
Back to Robotics Main Page
- 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:
#!/usr/bin/env python # This example uses the "plain" UltraSonic (i.e. digital) sensor interface # with the HiTechnic compass sensor. The compass_heading() function # attempts to do the conversion to degrees (but omits the adder register # 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)