Skip to content

Commit 3eef133

Browse files
Fixed inefficiencies; converted radians to degrees
1 parent 4f852f2 commit 3eef133

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

teapot/teapot.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
name = 'BeaglePotBlack'
99

10-
num_chars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
10+
conversion_factor = 0.0174532925 # multiply to get degrees from radians
1111

1212
port = 4774 # port of the data broadcast
1313
buff = 1024 # maximum size of the data from the BBB
@@ -59,7 +59,6 @@ def display():
5959
glRotatef(180,1,0,0) # The teapot is upside down by default
6060
glRotatef(90,0,1,0) # Make it face spout forward
6161
####
62-
# These next three should now be in the correct order
6362
global yaw, roll, pitch
6463
glRotatef(yaw,1,0,0)
6564
glRotatef(roll,0,1,0)
@@ -73,8 +72,7 @@ def display():
7372
return
7473

7574
def animate():
76-
####
77-
#Get data gets the values that are being broadcast over udp.
75+
#gets the values that are being broadcast over udp.
7876
global roll, pitch, yaw
7977
[yaw, roll, pitch] = get_data()
8078
glutPostRedisplay()
@@ -91,18 +89,9 @@ def get_data():
9189
if not sock:
9290
make_sock()
9391
result = select.select([sock],[],[])
94-
msg = result[0][0].recv(buff)
95-
current_float_string = "" #hold the current float in string while it is constructed
96-
float_array = [] #array to be returned
97-
for char in msg:
98-
if char == ',':
99-
float_array.append(float(current_float_string))
100-
current_float_string = ""
101-
elif char == '\0': #assuming that packet contains '\0' on the end, may be wrong
102-
float_array.append(float(current_float_string))
103-
return float_array
104-
elif char in num_chars:
105-
current_float_string.append(char)
106-
return [0, 0, 0]
92+
packet = result[0][0].recv(buff)
93+
exploded = packet.split(",")
94+
return (conversion_factor*float(exploded[0]), conversion_factor*float(exploded[1]), conversion_factor*float(exploded[2]))
95+
10796

10897
if __name__ == '__main__': main()

0 commit comments

Comments
 (0)