forked from ryuichiueda/RobotDesign3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
154 lines (130 loc) · 3.04 KB
/
main.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function onChangeRange()
{
rangeToText();
sendAngles();
}
function rangeToText()
{
var j = 0; //シミュレータの配列に角度を入れるためのカウンタ
for (i=1;i<=6;i++){
if(i==4)
continue;
angle = document.getElementById("J" + i).value;
angles[j] = angle;
j++;
document.getElementById("J" + i + "value").value = angle;
}
}
function sendAngles()
{
if(window.location.href.substr(0,4) == "file")
return;
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function(){
if(httpReq.readyState != 4 || httpReq.status != 200)
return;
org = document.getElementById("angles_log").innerHTML;
document.getElementById("angles_log").innerHTML = httpReq.responseText + "<br />" + org;
}
//var url = "/ajax/last_articles.cgi?num=" + num;
var url = "/angles.py?angles="
var j = 0; //シミュレータの配列に角度を入れるためのカウンタ
for (i=1;i<=6;i++){
if(i==4)
continue;
url += angles[j] + ',';
j++;
}
url = url.replace(/,$/,"");
url = url + "&ev=" + ev;
httpReq.open("GET",url,true);
httpReq.send(null);
}
function numToSlide(obj)
{
target = obj.id.replace(/value/,"");
document.getElementById(target).value = obj.value;
sendAngles();
}
function readAd(){
if(window.location.href.substr(0,4) == "file")
return;
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function(){
if(httpReq.readyState != 4 || httpReq.status != 200)
return;
vs = httpReq.responseText.split(" ");
document.getElementById("ch0_value").innerHTML = vs[0];
document.getElementById("ch1_value").innerHTML = vs[1];
readAd();
}
var url = "/ad.py? + Math.random()"
httpReq.open("GET",url,true);
httpReq.send(null);
}
function ev(val)
{
if(window.location.href.substr(0,4) == "file")
return;
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function(){
if(httpReq.readyState != 4 || httpReq.status != 200)
return;
}
url = "/ev.py?onoff=" + val;
httpReq.open("GET",url,true);
httpReq.send(null);
}
function run()
{
seq = document.getElementById("sequence").value;
lns = seq.split("\n");
t = 0;
for(i=0;i<lns.length;i++){
as = lns[i].split(",");
if(as.length < 6)
continue;
setTimeout( function(a) { oneStep(a); }, t , as );
t += parseInt(as[5]);
}
}
function oneStep(as)
{
for(k=0;k<5;k++){
angles[k] = as[k];
}
ev = as[6];
j=0;
for(k=1;k<=6;k++){
if(k==4)
continue;
document.getElementById("J" + k + "value").value = angles[j++];
}
sendAngles();
}
function init()
{
readAd();
drawRobot();
}
/*
function runCode()
{
document.getElementById("angles_log").innerHTML = "";
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function(){
if(httpReq.readyState != 4 || httpReq.status != 200)
return;
document.getElementById("angles_log").innerHTML += httpReq.responseText;
}
httpReq.open("GET","/run.bash",true);
httpReq.send(null);
}
function stopCode()
{
var httpReq = new XMLHttpRequest();
httpReq.open("GET","/stop.bash",false);
httpReq.send(null);
document.getElementById("angles_log").innerHTML = "";
}
*/