robotsim first test
[aversive.git] / projects / microb2010 / tests / hostsim / display.py
1 import math, sys, time, os
2 from visual import *
3
4 AREA_X = 3000.
5 AREA_Y = 2100.
6
7 area = [ (0.0, 0.0, -0.2), (3000.0, 2100.0, 0.2) ]
8 areasize = reduce(lambda x,y:tuple([abs(x[i])+abs(y[i]) for i in range(len(x))]) , area)
9 area_box = box(size=areasize, color=(0.0, 1.0, 0.0))
10
11 scene.autoscale=0
12
13 robot = box(pos = (0, 0, 150),
14             size = (300,300,300),
15             color = (1, 0, 0) )
16
17 def set_robot(x, y, a):
18     global robot
19     robot.pos = (x - AREA_X/2, y - AREA_Y/2, 150)
20     robot.axis = (math.cos(a*math.pi/180) * 300,
21                   math.sin(a*math.pi/180) * 300,
22                   0)
23
24 while True:
25     try:
26         os.mkfifo("/tmp/.robot")
27     except:
28         pass
29     while True:
30         f = open("/tmp/.robot")
31         while True:
32             l = f.readline()
33             if l == "":
34                 break
35             x,y,a = map(lambda x:int(x), l[:-1].split(" "))
36             set_robot(x,y,a)
37         f.close()
38
39     """
40     k = scene.kb.getkey()
41     x,y,z = scene.center
42     if k == "left":
43         scene.center = x-10,y,z
44     elif k == "right":
45         scene.center = x+10,y,z
46     elif k == "up":
47         scene.center = x,y+10,z
48     elif k == "down":
49         scene.center = x,y-10,z
50     """