-
Notifications
You must be signed in to change notification settings - Fork 0
/
fans.py
65 lines (50 loc) · 1.61 KB
/
fans.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pcars.stream import PCarsStreamReceiver
from pyudmx import pyudmx
from time import *
import math
dev = pyudmx.uDMXDevice()
dev.open()
#print 'found '+dev.Device.serial_number
cv = [0 for v in range(0, 512)]
class MyPCarsListener(object):
def handlePacket(self, data):
# You probably want to do something more exciting here
# You probably also want to switch on data.packetType
# See listings in packet.py for packet types and available fields for each
#print dir(data)
#for i in range(len( data._data)):
#print data._data[i]
#print data._data['windDirectionY'],
#print data._data.['windDirectionX']
#print data._data
#data._data['speed']
#print data._data['steering']
try:
temp =int(data._data['speed'])
temp=math.pow(temp,1.3)
cv[0]=int(temp)
steer=data._data['steering']
if steer>0:
#wind left
cv[0]=cv[0]*(steer*.1)
#cv[0] =int(data._data['throttle'])
print data._data['steering'],' steering'
except:
print 'cant get speed'
if cv[0]>254:
cv[0]=254
cv[0]=int(cv[0]+1)
print cv[0]
try:
sent = dev.send_multi_value(1, cv)
#print time.clock()
except:
print 'cant send dmx'
#sent = dev.send_multi_value(1, cv)
listener = MyPCarsListener()
stream = PCarsStreamReceiver()
try:
stream.addListener(listener)
stream.start()
except:
''