-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollerMessages.py
98 lines (86 loc) · 3.5 KB
/
controllerMessages.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import time
def getMsgDrive (y, magnitude):
y = y * 255
y=int(y)
y=round(y)
if (y>=25):
direction="01"
if (magnitude>0.95): y=255
elif(y<=-25):
direction="00"
y=y*-1
if (magnitude > 0.95): y = 255
else:
direction = "00"
drive_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "02", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": direction, # "string. clockwise or counterclockwise. <00|01>",
"power": "00", # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 0.1, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (drive_msg)
drive_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "02", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": direction, # "string. clockwise or counterclockwise. <00|01>",
"power": "{0:x}".format(y), # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 0.1, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (drive_msg)
def getMsgSteer (x):
x = x * 255
x=int(x)
x=round(x)
if (x>=25): direction="00"
elif (x<=-25):
direction="01"
x=x*-1
else:
direction = "00"
steer_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "00", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": direction, # "string. clockwise or counterclockwise. <00|01>",
"power": "00", # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 0.1, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (steer_msg)
steer_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "00", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": direction, # "string. clockwise or counterclockwise. <00|01>",
"power": "{0:x}".format(x), # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 0.1, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (steer_msg)
def getMsgUp():
Up_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "03", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": "01", # "string. clockwise or counterclockwise. <00|01>",
"power": "ff", # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 8, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (Up_msg)
def getMsgDown():
Down_msg = {
"sbrick_id": "88:6B:0F:80:29:D1", # "string. SBrick ID. <sbrick MAC>",
"channel": "03", # " string. hex string. the LEGO power function port you
# want to drive. <00|01|02|03>",
"direction": "00", # "string. clockwise or counterclockwise. <00|01>",
"power": "ff", # "string. hex string. FF means 100% speed. <00~FF>",
"exec_time": 7, # "number. seconds. 5566 means forever."
"timestamp": time.time()
}
return (Down_msg)