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 last_pos = robot.pos.x, robot.pos.y, robot.pos.z
18 robot_trail = curve()
19 max_trail = 500
20
21 def set_robot(x, y, a):
22     global robot, last_pos
23     robot.pos = (x - AREA_X/2, y - AREA_Y/2, 150)
24     robot.axis = (math.cos(a*math.pi/180) * 300,
25                   math.sin(a*math.pi/180) * 300,
26                   0)
27
28     pos = robot.pos.x, robot.pos.y, robot.pos.z
29     if pos != last_pos:
30         robot_trail.append(pos)
31         last_pos = pos
32     robot_trail_l = len(robot_trail.pos)
33     if robot_trail_l> max_trail:
34         robot_trail.pos = robot_trail.pos[robot_trail_l - max_trail:]
35
36 while True:
37     try:
38         os.mkfifo("/tmp/.robot")
39     except:
40         pass
41     while True:
42         f = open("/tmp/.robot")
43         while True:
44             l = f.readline()
45             if l == "":
46                 break
47             x,y,a = map(lambda x:int(x), l[:-1].split(" "))
48             set_robot(x,y,a)
49         f.close()
50
51     """
52     k = scene.kb.getkey()
53     x,y,z = scene.center
54     if k == "left":
55         scene.center = x-10,y,z
56     elif k == "right":
57         scene.center = x+10,y,z
58     elif k == "up":
59         scene.center = x,y+10,z
60     elif k == "down":
61         scene.center = x,y-10,z
62     """