Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rotx = 1.0
- roty = 2.0
- rotz = 3.0
- accx = 0.0
- accy = 0.0
- accz = 0.0
- rotation = "rot;"
- rotation = rotation + (str(rotx))
- rotation = rotation + (";")
- rotation = rotation + (str(roty))
- rotation = rotation + (";")
- rotation = rotation + (str(rotz))
- dataToSend1 = (' '.join(format(ord(x), 'b') for x in rotation))
- import smbus
- import socket
- import time
- TCP_IP = '192.168.178.34'
- TCP_PORT = 5005
- BUFFER_SIZE = 1024
- MESSAGE = "Hello, World!"
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((TCP_IP, TCP_PORT))
- while True:
- s.send(rotation)
- data = s.recv(BUFFER_SIZE)
- print "received data:", data
- time.sleep(1)
- #!/usr/bin/python
- import smbus
- import math
- #Register
- power_mgmt_1 = 0x6b
- power_mgmt_2 = 0x6c
- def read_byte(reg):
- return bus.read_byte_data(address, reg)
- def read_word(reg):
- h = bus.read_byte_data(address, reg)
- l = bus.read_byte_data(address, reg+1)
- value = (h << 8) + l
- return value
- def read_word_2c(reg):
- val = read_word(reg)
- if (val >= 0x8000):
- return -((65535 - val) + 1)
- else:
- return val
- def dist(a,b):
- return math.sqrt((a*a)+(b*b))
- def get_y_rotation(x,y,z):
- radians = math.atan2(x, dist(y,z))
- return -math.degrees(radians)
- def get_x_rotation(x,y,z):
- radians = math.atan2(y, dist(x,z))
- return math.degrees(radians)
- bus = smbus.SMBus(0) # bus = smbus.SMBus(0) fuer Revision 1
- address = 0x68 # via i2cdetect
- # Aktivieren, um das Modul ansprechen zu koennen
- bus.write_byte_data(address, power_mgmt_1, 0)
- gyroskop_xout = read_word_2c(0x43)
- gyroskop_yout = read_word_2c(0x45)
- gyroskop_zout = read_word_2c(0x47)
- rotx = beschleunigung_xout / 16384.0
- roty = beschleunigung_yout / 16384.0
- rotz = beschleunigung_zout / 16384.0
- accx = read_word_2c(0x3b)
- accy = read_word_2c(0x3d)
- accz = read_word_2c(0x3f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement