====== compas2OSC.py ====== ===== CMPS10 - Tilt Compensated Compass Module ===== * [[http://www.robotshop.com/en/devantech-tilt-magnetic-compass.html]] * http://www.hobbytronics.co.uk/cmps10-tilt-compass ** Registre de 23 bytes :** * 0 Software version * 1 Compass Bearing as a byte, i.e. 0-255 for a full circle * 2,3 Compass Bearing as a word, i.e. 0-3599 for a full circle, representing 0-359.9 degrees. * 4 Pitch angle - signed byte giving angle in degrees from the horizontal plane * 5 Roll angle - signed byte giving angle in degrees from the horizontal plane * 6,,7,8,9 Unused * 10,11 Magnetometer X axis raw output, 16 bit signed integer with register 10 being the upper 8 bits * 12,13 Magnetometer Y axis raw output, 16 bit signed integer with register 12 being the upper 8 bits * 14,15 Magnetometer Z axis raw output, 16 bit signed integer with register 14 being the upper 8 bits * 16,17 Accelerometer X axis raw output, 16 bit signed integer with register 16 being the upper 8 bits * 18,19 Accelerometer Y axis raw output, 16 bit signed integer with register 18 being the upper 8 bits * 20,21 Accelerometer Z axis raw output, 16 bit signed integer with register 20 being the upper 8 bits * 22 Command register ===== HMC6352 ===== la boussole HMC6352 est sur un bus i2c. Donne l'angle au nord en degrĂ© dans le sens horaire (heading) Mais pas de compensation en fonction de l'inclinaison de la tĂȘte ! d'ou pas d'usage .. #!/usr/bin/python # -*- coding: utf-8 -*- import sys,time,liblo from smbus import SMBus BUS_NUMBER = 2 IP='127.0.0.1' PORT=9001 ADRS=33 # 0x21 - compass osc_path='/pos/compas' b = SMBus(BUS_NUMBER) # 0 indicates /dev/i2c-0 data = {} try: target = liblo.Address('127.0.0.1',9001) except liblo.AddressError, err: print str(err) sys.exit() while True: try: b.write_byte(0x21,0x41) # send 'A' to HMC6352 compass time.sleep(0.02) data_block = b.read_i2c_block_data(0x21,2) heading = (data_block[0] * 2**8 + data_block[1]) / 10 time.sleep(0.02) # print('Compas',heading) liblo.send(target, osc_path, heading) except KeyError: pass except KeyboardInterrupt: quit() except StopIteration: session = None print "end" except: # print('echec') continue