-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blender script
43 lines (37 loc) · 872 Bytes
/
Blender script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import mathutils
import serial
qw = 0.0
qx = 0.0
qy = 0.0
qz = 0.0
arduino = serial.Serial()
arduino.baudrate = 115200
arduino.port = '/dev/ttyUSB0'
def Port():
global qw, qx, qy, qz
global arduino
data = arduino.readline().strip()
quat = data.decode('ascii').split(',')
qw, qx, qy, qz = [float(s) for s in quat]
print(qw)
print(qx)
print(qy)
print(qz)
def Cube():
global qw, qx, qy, qz
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
obj = cont.owner
obj['qw'] = qw
obj['qx'] = qx
obj['qy'] = qy
obj['qz'] = qz
quat_cube = mathutils.Quaternion((obj['qw'], obj['qx'], obj['qy'], obj['qz']))
quat_cube.normalize()
obj.localOrientation = quat_cube()
def Close():
global arduino
arduino.close()
def Start():
global arduino
arduino.open()