Difference between revisions of "Bots-hitechnic-compass"

From Earlham CS Department
Jump to navigation Jump to search
(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...)
 
Line 1: Line 1:
HiTechnic compass
+
Back to [https://wiki.cs.earlham.edu/index.php/Robotics-2010 Robotics Main 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]
 
* 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 the registers are mapped you can use the <code>UltraSonic()</code> 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.
 
* Because of the way the registers are mapped you can use the <code>UltraSonic()</code> 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.
 
* Calibration is rarely necessary and shouldn't be an issue for us in the near-term.
 
* Example code:
 
* Example code:
#!/usr/bin/env python
+
#!/usr/bin/env python
 
+
# This example uses the "plain" UltraSonic (i.e. digital) sensor interface  
# This example uses the "plain" UltraSonic (i.e. digital) sensor interface  
+
# with the HiTechnic compass sensor.  The compass_heading() function  
# with the HiTechnic compass sensor.  The compass_heading() function  
+
# attempts to do the conversion to degrees (but omits the adder register  
# attempts to do the conversion to degrees (but omits the adder register  
+
# as documented by HiTechnic).   
# as documented by HiTechnic).   
+
 
 
 
  import time
 
  import time
 
  import nxt.locator
 
  import nxt.locator
 
  from nxt.sensor import *
 
  from nxt.sensor import *
 
+
 
  def id_nxt(b):
 
  def id_nxt(b):
name, host, signal_strength, user_flash = b.get_device_info()
+
name, host, signal_strength, user_flash = b.get_device_info()
print 'NXT brick name: %s' % name
+
print 'NXT brick name: %s' % name
print 'Host address: %s' % host
+
print 'Host address: %s' % host
print 'Bluetooth signal strength: %s' % signal_strength
+
print 'Bluetooth signal strength: %s' % signal_strength
print 'Free user flash: %s' % user_flash
+
print 'Free user flash: %s' % user_flash
               
+
             
 
  def compass_heading(b, p):
 
  def compass_heading(b, p):
# Because of limitations in the UltraSonic interface it returns 1/2 the  
+
# Because of limitations in the UltraSonic interface it returns 1/2 the  
# actual heading.
+
# actual heading.
return UltrasonicSensor(b, p).get_sample() * 2
+
return UltrasonicSensor(b, p).get_sample() * 2
 
+
 
  print 'Looking for brick 1 ...'
 
  print 'Looking for brick 1 ...'
 
  sock = nxt.locator.find_one_brick(host='00:16:53:06:ED:B8', name='NXT')
 
  sock = nxt.locator.find_one_brick(host='00:16:53:06:ED:B8', name='NXT')
 
+
 
  if sock:
 
  if sock:
print 'Found brick 1'  
+
print 'Found brick 1'  
 
  else:
 
  else:
print 'Timed-out, no NXT bricks found, exiting'  
+
print 'Timed-out, no NXT bricks found, exiting'  
exit
+
exit
 
+
 
  if sock:
 
  if sock:
print 'Connecting to the brick ...'
+
print 'Connecting to the brick ...'
bot = sock.connect()
+
bot = sock.connect()
+
 
if bot:
+
if bot:
print 'Connected to the brick'
+
print 'Connected to the brick'
else:
+
else:
print 'Timed-out connecting to brick 1, exiting'
+
print 'Timed-out connecting to brick 1, exiting'
exit
+
exit
 
+
if bot:
+
if bot:
id_nxt(bot)
+
id_nxt(bot)
 
+
while 1:
+
while 1:
print 'Compass heading: ', compass_heading(bot, PORT_4)  
+
print 'Compass heading: ', compass_heading(bot, PORT_4)  
time.sleep(1)
+
time.sleep(1)

Revision as of 07:57, 25 February 2010

Back to Robotics Main Page


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:
#!/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)