-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
137 lines (90 loc) · 3.24 KB
/
test.js
File metadata and controls
137 lines (90 loc) · 3.24 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const { DataState, Window, Textbox, Element } = require("./index.js")
var w = new Window({address: "127.0.0.1", port: 1234}, {});
var a = w.add_subplot({top:1,bottom:2,left:1,right:2},{
width : 600,
height : 400,
margins : {
top: 30, right: 20, bottom: 30, left: 50
},
xlim : [0,20],
ylim : [0,4.0],
xlabel : "Time Since (sec)",
ylabel : "Value"
});
let state_text = new DataState.SingleValue();
Textbox.write(w, {top:2,bottom:3,left:1,right:3}, {title:"Platform.state"},[
{
datastate: state_text,
config: { postprocessor: (t)=>t+" yee yee", color: "#aa00ff"}
}
]);
var a2 = w.add_subplot({top:1,bottom:2,left:2,right:3},{
width : 600,
height : 600,
margins : {
top: 30, right: 20, bottom: 30, left: 50
},
xlim : [-2.5,2.5],
ylim : [-0.05,4.95],
xtick_count: 10,
title : "Flow Map"
});
let voltage = new DataState.TimeSince({tmax_seconds:20});
let current = new DataState.TimeSince({tmax_seconds:20});
a.plot(voltage, {scolor:"steelblue"});
a.plot(current, {scolor:"green"});
let body_pose=new DataState.Pose();
let head_pose=new DataState.Pose();
//let body_cov=new DataState.Covariance2d(body_pose);
let trajectory = new DataState.Trajectory({tmax_seconds:5});
a2.plot(trajectory, {scolor:"red"})
let landscape = new DataState.Path()
let landscape_element = a2.plot(landscape, {scolor:"#0000aa"})
a2.add_element(new Element.Pointer(body_pose, {fcolor:"#000000aa"}));
a2.add_element(new Element.Pointer(head_pose, {fcolor:"#aa0000aa", skewness: 4, width:0.05}));
//a2.add_element(new Element.Covariance2d(body_cov, {scolor: "#aa00aa85", nsig: 1}));
//a2.add_element(new Element.Covariance2d(body_cov, {scolor: "#aa00aa56", nsig: 2}));
//a2.add_element(new Element.Covariance2d(body_cov, {scolor: "#aa00aa2d", nsig: 3}));
//let mat = new DataState.MatrixRGBBottomCenter({dimensions:[50,50]});
//a2.imshow(mat, {dimensions:[50,50]});
point = new DataState.Point()
point.x = -1
point.y = 4
a2.add_element(new Element.Circle(point, {fcolor:"#00ff00aa", radius: 1}));
w.init().then((url)=>{
console.log(url)
w.start();
});
setInterval(()=>{
// body_cov.covariance = [[Math.random()/10, 0],
// [0, Math.random()/10]]
},1000)
setTimeout(()=>{
landscape.set([...Array(30)].map((d,i) => ({x: 0.1*i, y: 0.01*i**2})))
},1000)
setTimeout(()=>{
a2.remove_element(landscape_element)
},3000)
setInterval(()=>{
voltage.push(Math.random()+1)
current.push(Math.random()+3)
}, 100)
var iter = [...Array(50)]
let randcolor = ()=>[parseInt(Math.random()*255), parseInt(Math.random()*255), parseInt(Math.random()*255)]
setInterval(()=>{
// DISCO!!
//mat.update(iter.map((d)=>iter.map((d)=>randcolor())));
}, 1000)
var t0 = Date.now();
setInterval(()=>{
t = (Date.now()-t0)*5e-4
body_pose.x = 2*Math.sin(t);
body_pose.y = 2-2*Math.cos(t);
body_pose.heading = Math.PI/2 - t;
body_pose.copy_to(head_pose)
head_pose.heading += 0.4*Math.sin(t*5)
trajectory.push(body_pose)
},30)
setInterval(()=>{
state_text.value="Heloo"
}, 1000)