-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecordPoints
280 lines (237 loc) · 9.93 KB
/
RecordPoints
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
persistent_get("Directory", function(val){ if (val===undefined){out("building directory"); var dirset = []; dirset.push(" ");persistent_set("Directory",dirset)}})
//AddToDir("boxadd")
var db_fetch = undefined
Dexter.LINK2 = 321246
Dexter.LINK3 = 298982
var pidXYZ = 0x3e4ccccc
var pidRP = 0x3dcccccc
var PID_DELTATNOT = 16
var PID_DELTAT = 17
var PID_D = 18
var PID_I = 19
var PID_P = 20
var PID_ADDRESS = 21
var DIFF_FORCE_SPEED_FACTOR_ANGLE = 55
var DIFF_FORCE_SPEED_FACTOR_ROT = 56
var SPEED_FACTORA = 27
var SPEED_FACTORB = 28
var DEF_SPEED_FACTOR_A = 30
var DEF_SPEED_FACTOR_DIFF = 8
var gJobDone = 0
var gWindowVals = undefined
var timeXYZ = []
function setFollowMe(){
var retCMD = []
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ANGLE, DEF_SPEED_FACTOR_DIFF))
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ROT, DEF_SPEED_FACTOR_DIFF))
retCMD.push(make_ins("w", PID_P, 0))
retCMD.push(make_ins("w", PID_ADDRESS, 3))
retCMD.push(make_ins("w", PID_ADDRESS, 4))
retCMD.push(make_ins("w", PID_ADDRESS, 0))
retCMD.push(make_ins("w", PID_ADDRESS, 1))
retCMD.push(make_ins("w", PID_ADDRESS, 2))
retCMD.push(make_ins("w", SPEED_FACTORA, DEF_SPEED_FACTOR_A))
retCMD.push(make_ins("S", "J1Friction",5 ))
retCMD.push(make_ins("S", "J2Friction",5 ))
retCMD.push(make_ins("S", "J3Friction",5 ))
retCMD.push(make_ins("S", "J4Friction",15 ))
retCMD.push(make_ins("S", "J5Friction",15 ))
retCMD.push(make_ins("w", 67, 0))
retCMD.push(make_ins("w", 68, 0))
retCMD.push(make_ins("w", 69, 0))
retCMD.push(make_ins("w", 70, 0))
retCMD.push(make_ins("w", 71, 0))
retCMD.push(make_ins("w", 79, 50 ^ 200 ))
retCMD.push(make_ins("w", 80, 50 ^ 200 ))
retCMD.push(make_ins("w", 81, 50 ^ 200 ))
retCMD.push(make_ins("w", 42, 12448))
return retCMD
}
function setForceProtect(){
var retCMD = []
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ANGLE, 4))
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ROT, 4))
retCMD.push(make_ins("w", SPEED_FACTORA, 15))
retCMD.push(make_ins("S", "J1Friction",2 ))
retCMD.push(make_ins("S", "J2Friction",3 ))
retCMD.push(make_ins("S", "J3Friction",9 ))
retCMD.push(make_ins("S", "J4Friction",15 ))
retCMD.push(make_ins("S", "J5Friction",15 ))
retCMD.push(make_ins("w", PID_ADDRESS, 0))
retCMD.push(make_ins("w", PID_P, pidXYZ))
retCMD.push(make_ins("w", PID_ADDRESS, 1))
retCMD.push(make_ins("w", PID_ADDRESS, 2))
retCMD.push(make_ins("w", PID_ADDRESS, 3))
retCMD.push(make_ins("w", PID_P, pidRP))
retCMD.push(make_ins("w", PID_ADDRESS, 4))
retCMD.push(make_ins("w", 67, 9000))
retCMD.push(make_ins("w", 68, 9000))
retCMD.push(make_ins("w", 69, 9000))
retCMD.push(make_ins("w", 70, 9000))
retCMD.push(make_ins("w", 71, 9000))
retCMD.push(make_ins("w", 78,1 ))
retCMD.push(make_ins("w", 78,0 ))
retCMD.push(make_ins("w", 42, 12448))
return retCMD
}
function setKeepPossition(){
var retCMD = []
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ANGLE, 0))
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ROT, 0))
retCMD.push(make_ins("w", PID_ADDRESS, 0))
retCMD.push(make_ins("w", PID_P, pidXYZ))
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ROT, 0))
retCMD.push(make_ins("w", DIFF_FORCE_SPEED_FACTOR_ROT, 0))
retCMD.push(make_ins("w", PID_ADDRESS, 1))
retCMD.push(make_ins("w", PID_ADDRESS, 2))
retCMD.push(make_ins("w", PID_ADDRESS, 3))
retCMD.push(make_ins("w", PID_P, pidRP))
retCMD.push(make_ins("w", PID_ADDRESS, 4))
retCMD.push(make_ins("w", SPEED_FACTORA, 0))
retCMD.push(make_ins("w", 42, 12960))
return retCMD
}
function reduceArray(array){
var rtVal = []
for (var i = 0;i < array.length;i++){
for (var j = 0;j < array[i].length;j++){
rtVal.push (array[i][j])
}
}
return rtVal
}
function RoundArray(my_array){
var x = 0;
var len = my_array.length
while(x < len){
my_array[x] = Math.round(my_array[x])
x++
}
return my_array
}
function updateXYZPoint(){
//debugger; my_array[x] = Math.round(my_array[x])
var xyzPoint = Kin.J_angles_to_xyz([Dexter.my_dex.robot_status[Dexter.J1_FORCE_CALC_ANGLE] + Dexter.my_dex.robot_status[Dexter.J1_DELTA] + Dexter.my_dex.robot_status[Dexter.J1_ANGLE] ,
Dexter.my_dex.robot_status[Dexter.J2_FORCE_CALC_ANGLE] + Dexter.my_dex.robot_status[Dexter.J2_DELTA]+ Dexter.my_dex.robot_status[Dexter.J2_ANGLE],
Dexter.my_dex.robot_status[Dexter.J3_FORCE_CALC_ANGLE] + Dexter.my_dex.robot_status[Dexter.J3_DELTA] + + Dexter.my_dex.robot_status[Dexter.J3_ANGLE],
Dexter.my_dex.robot_status[Dexter.J4_FORCE_CALC_ANGLE] + (Dexter.my_dex.robot_status[Dexter.J4_DELTA] / 16) + Dexter.my_dex.robot_status[Dexter.J4_ANGLE],
Dexter.my_dex.robot_status[Dexter.J5_FORCE_CALC_ANGLE] + (Dexter.my_dex.robot_status[Dexter.J5_DELTA] / 16), + Dexter.my_dex.robot_status[Dexter.J5_ANGLE]])
dex.set_in_window(gWindowVals.window_index, "X_display", "innerHTML", Math.round(xyzPoint[5][0]))
dex.set_in_window(gWindowVals.window_index, "Y_display", "innerHTML", Math.round(xyzPoint[5][1]))
dex.set_in_window(gWindowVals.window_index, "Z_display", "innerHTML", Math.round(xyzPoint[5][2]))
xyzPoint.push(Vector.normalize(Vector.subtract(xyzPoint[5], xyzPoint[4])))
return xyzPoint
}
var pointIdx = 0
function distance(pointA, pointB){
var rt = [Math.abs(pointA[5][0]-pointB[5][0]),Math.abs(pointA[5][1]-pointB[5][1]),Math.abs(pointA[5][2]-pointB[5][2])]
return Math.sqrt(Math.pow(rt[0],2)+Math.pow(rt[1],2)+Math.pow(rt[2],2))
}
function replayPointsitr(points, times){
var rt =[]
for (var j=0;j<times;j++){
for (var i = 0;i < points.length;i++){
rt.push(make_ins("a",RoundArray(Kin.xyz_to_J_angles(points[i][5], points[i][6] , Dexter.RIGHT_UP_OUT))))
}}
return rt
}
function AddToDir(MacroStr){
out(MacroStr)
var closeStr = MacroStr
persistent_get("Directory",function(val){ val.push(closeStr); persistent_set("Directory",val) })
}
//var dirset = []
//dirset.push("KBhello")
//persistent_set("Directory",dirset)
//AddToDir("boxcorners")
function handleWindowUI(vals){ //vals contains name-value pairs for each
//html elt in show_window's content with a name.
gWindowVals = vals
if(vals.clicked_button_value == "SetPoint" ){ // Clicked button value holds the name of the clicked button.
timeXYZ[pointIdx] = updateXYZPoint()
pointIdx = pointIdx +1
out(pointIdx)
}
else if(vals.clicked_button_value == "Follow" ) {
Job.j1.user_data.choicemade = function (){return setFollowMe()}
out("Set FollowMe mode")
}
else if(vals.clicked_button_value == "Keep" ){
Job.j1.user_data.choicemade = function (){return setKeepPossition()}
out("Set set Keep mode")
}
else if(vals.clicked_button_value == "Protect" ){
Job.j1.user_data.choicemade = function (){return setForceProtect()}
}
else if(vals.clicked_button_value == "Record" )
{
persistent_set(vals.macro_name,timeXYZ)
var MacroStr = vals.macro_name
persistent_get("Directory",AddToDir(MacroStr))
}
else if(vals.clicked_button_value == "Dir" )
{
persistent_get("Directory",function(val){out (val)})
}
else if(vals.clicked_button_value == "Play" ){
db_fetch = undefined
persistent_get(vals.macro_name,function(val){db_fetch = val})
Job.j1.user_data.choicemade = function ()
{ var rt = []
rt.push(Robot.wait_until(function(){return db_fetch}))
rt.push(function(){return replayPointsitr(db_fetch,1)})
return rt
}
}
else if (vals.clicked_button_value == "Done" ){
gJobDone = 1
gWindowVals = undefined
for (var i = 0;i < pointIdx-1;i++){
out(timeXYZ[i])
}
out("outta here " )
//Job.j1.user_data.choicemade = function (){return Dexter.move_all_joints(0, 0, 0, 0, 0)}
}
}
show_window({content:
`<input name="SetPoint" type="button" accesskey="p" value="SetPoint"/>
<input name="SetFollowMe" type="button" value="Follow"/>
<input name="SetKeepPoint" type="button" value="Keep"/>
<input name="SetForceProtect" type="button" value="Protect"/>
<input name="PlayMacro" type="button" value="Play"/>
<input name="Write Time" type="button" value="Record"/><br/>
<input name="Dir" type="button" value="Dir"/><br/><br/>
Mode: <span id="mode_id">None</mode><br/>
X: <span name="X_display" id="X_id">0</span><br/>
Y: <span name="Y_display" id="Y_id">0</span><br/>
Z: <span name="Z_display" id="Z_id">0</span><br/><br/>
Macro Name <input type="text" name="macro_name" id="mn_id" <br/><br/>
<input type="submit" value="Done"/>`,
callback: handleWindowUI})
function resolve_choice()
{
var na = []
na.push(make_ins("g"))
na.push(function(){if (this.user_data.choicemade != undefined) {
var rtval = this.user_data.choicemade
this.user_data.choicemade = undefined
return rtval
}})
na.push(function(){if (gWindowVals != undefined){updateXYZPoint()}})
na.push(function(){if (gJobDone == 0) {return resolve_choice()}})
return na
}
new Dexter({name: "my_dex", ip_address: "192.168.1.144", port: 50000, enable_heartbeat: false, simulate: false})
new Job({name: "j1", robot: Robot.my_dex, keep_history: true,
do_list: [
make_ins("S", "MaxSpeed",80000),
make_ins("S", "Acceleration",1),
function(){return resolve_choice},
make_ins("S", "MaxSpeed",240000),
make_ins("S", "Acceleration",1),
Dexter.move_all_joints(0, 0, 0, 0, 0)
]})
Job.j1.start()
Job.j1.inter_do_item_dur = 138
Dexter.heartbeat_dur = 25
//DrawNum(123456, 23000, [0, 1])