forked from alkaza/oscar-pages
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit_code.js
More file actions
executable file
·647 lines (593 loc) · 28.6 KB
/
edit_code.js
File metadata and controls
executable file
·647 lines (593 loc) · 28.6 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
//Fills the textbox with the updated source code text
function Parameter(name, value, comment) {
this.name = name;
this.value = value;
this.comment = comment;
}
//All parameters
var horizonDistance = new Parameter('horizonDistance', 7.5, "Horizon");
var maxLocalPlanDistance = new Parameter('maxLocalPlanDistance', 12.2, "Plan Distance");
var pathDensity = new Parameter('pathDensity', 0.02, "Path Density");
var rollOutDensity = new Parameter('rollOutDensity', 0.3, "Horizontal Density");
var rollOutsNumber = new Parameter('rollOutsNumber', 4, "Rollouts Number");
//12-23 Added
var maxVelocity = new Parameter('maxVelocity', 4, "Max Velocity");
var maxAcceleration = new Parameter('maxAcceleration', 1.4, "Acceleration");
var maxDeceleration = new Parameter('maxDeceleration', -1.4, "Deceleration");
var enableFollowing = new Parameter('enableFollowing', false, "Enable Following");
var enableSwerving = new Parameter('enableSwerving', false, "Enable Avoidance");
var minFollowingDistance = new Parameter('minFollowingDistance', 30.0, "Follow Distance");
var minDistanceToAvoid = new Parameter('minDistanceToAvoid', 0.5, "Avoiding Distance");
var maxDistanceToAvoid = new Parameter('maxDistanceToAvoid', 0.5, "Avoidance Limit");
var enableStopSignBehavior = new Parameter('enableStopSignBehavior', false, "Enable Stop Sign Stop");
var enableTrafficLightBehavior = new Parameter('enableTrafficLightBehavior', false, "Enable Traffic Light");
var enableLaneChange = new Parameter('enableLaneChange', false, "Enable Lane Change");
var horizontalSafetyDistance = new Parameter('horizontalSafetyDistance', 0.05, "Lateral Safety");
var verticalSafetyDistance = new Parameter('verticalSafetyDistance', 0.05, "Longitudinal Safety");
var velocitySource = new Parameter('velocitySource', 1, "Velocity Source");
var parameters_dict = {
"horizonDistance" : horizonDistance,
"maxLocalPlanDistance" : maxLocalPlanDistance,
"pathDensity" : pathDensity,
"rollOutDensity" : rollOutDensity,
"rollOutsNumber" : rollOutsNumber,
//12-23 Added
"maxVelocity" : maxVelocity,
"maxAcceleration" : maxAcceleration,
"maxDeceleration" : maxDeceleration,
"enableFollowing" : enableFollowing,
"enableSwerving" : enableSwerving,
"minFollowingDistance" : minFollowingDistance,
"minDistanceToAvoid" : minDistanceToAvoid,
"maxDistanceToAvoid" : maxDistanceToAvoid,
"enableStopSignBehavior" : enableStopSignBehavior,
"enableTrafficLightBehavior": enableTrafficLightBehavior,
"enableLaneChange" : enableLaneChange,
"horizontalSafetyDistance" : horizontalSafetyDistance,
"verticalSafetyDistance" : verticalSafetyDistance,
"velocitySource" : velocitySource,
};
let parameter_list = [horizonDistance, maxLocalPlanDistance, pathDensity, rollOutDensity, rollOutsNumber,
maxVelocity, maxAcceleration, maxDeceleration, enableFollowing, enableSwerving,
minFollowingDistance, minDistanceToAvoid, maxDistanceToAvoid, enableStopSignBehavior, enableTrafficLightBehavior,
enableLaneChange, horizontalSafetyDistance, verticalSafetyDistance, velocitySource];
Blockly.Blocks['launch_tag'] = {
init: function() {
this.appendDummyInput()
.appendField("Configuration File");
this.appendStatementInput("param_s")
.setCheck(null);
this.setColour(0);
this.setTooltip("creates the config file");
this.setHelpUrl("");
}
};
Blockly.JavaScript['launch_tag'] = function(block) {
var statements_param_s = Blockly.JavaScript.statementToCode(block, 'param_s');
// Adds the launch tag to the parameters.
var code = statements_param_s + //Changes the parameters_dict values to the user defined ones
'var code_string = "";' +
'code_string = code_string.concat("<pre><launch><br>");' +
'parameter_list.forEach(function(element) {' +
'code_string = code_string.concat(" <!-- " + element.comment + " --><br>" + " <arg name =\\"" + element.name + "\\" default=\\"" + element.value + "\\" /><br>");' +
'});' +
'code_string = code_string.concat(" <!-- Unmodified Parameters --><br>");' +
'code_string = code_string.concat("</launch><br></pre>");' +
'document.getElementById("source_code_textbox").innerHTML = code_string;' +
//This variable is the actual launch file NOT the html formatted code.
'var full_code = "";' +
'full_code = full_code.concat("<launch>");' +
'parameter_list.forEach(function(element) {' +
'full_code = full_code.concat("<!-- " + element.comment + " -->" + "<arg name =\\"" + element.name + "\\" default=\\"" + element.value + "\\" />");' +
'});' +
'full_code = full_code.concat("' +
' <!-- Parameters not in app --> ' +
' <arg name=\\"mapSource\\" default=\\"0\\" /> <!-- Autoware=0, Vector Map Folder=1, kml=2 --> ' +
' <arg name=\\"mapFileName\\" default=\\"\\" /> <arg name=\\"minVelocity\\" default=\\"0.1\\" /> ' +
' <arg name=\\"speedProfileFactor\\" default=\\"1.2\\" /> ' +
' <arg name=\\"smoothingDataWeight\\" default=\\"0.45\\" /> ' +
' <arg name=\\"smoothingSmoothWeight\\" default=\\"0.4\\" /> ' +
' <arg name=\\"width\\" default=\\"0.10\\" /> <!-- Vehicle Size --> ' +
' <arg name=\\"length\\" default=\\"0.10\\" /> <!-- Vehicle Size --> ' +
' <arg name=\\"wheelBaseLength\\" default=\\"0.1\\" /> <!-- Vehicle Size -->' +
' <arg name=\\"turningRadius\\" default=\\"5.2\\" /> ' +
' <arg name=\\"maxSteerAngle\\" default=\\"0.45\\" /> ' +
' <arg name=\\"steeringDelay\\" default=\\"1.2\\" /> ' +
' <arg name=\\"minPursuiteDistance\\" default=\\"3.0\\" /> ' +
' <arg name=\\"additionalBrakingDistance\\" default=\\"5.0\\" /> ' +
' <arg name=\\"giveUpDistance\\" default=\\"-4.0\\" /> ' +
' <node pkg=\\"op_local_planner\\" type=\\"op_common_params\\" name=\\"op_common_params\\" output=\\"screen\\"> ' +
' <!-- Common Parameters --> ' +
' <param name=\\"mapSource\\" value=\\"$(arg mapSource)\\" /> <!-- Autoware=0, Vector Map Folder=1, kml=2 --> ' +
' <param name=\\"mapFileName\\" value=\\"$(arg mapFileName)\\" /> ' +
' <param name=\\"pathDensity\\" value=\\"$(arg pathDensity)\\" /> ' +
' <param name=\\"rollOutDensity\\" value=\\"$(arg rollOutDensity)\\" /> ' +
' <param name=\\"rollOutsNumber\\" value=\\"$(arg rollOutsNumber)\\" /> ' +
' <param name=\\"maxVelocity\\" value=\\"$(arg maxVelocity)\\" /> ' +
' <param name=\\"minVelocity\\" value=\\"$(arg minVelocity)\\" /> ' +
' <param name=\\"maxLocalPlanDistance\\" value=\\"$(arg maxLocalPlanDistance)\\" /> ' +
' <param name=\\"horizonDistance\\" value=\\"$(arg horizonDistance)\\" /> ' +
' <param name=\\"minFollowingDistance\\" value=\\"$(arg minFollowingDistance)\\" /> <!-- should be bigger than Distance to follow --> ' +
' <param name=\\"minDistanceToAvoid\\" value=\\"$(arg minDistanceToAvoid)\\" /> <!-- should be smaller than minFollowingDistance and larger than maxDistanceToAvoid --> ' +
' <param name=\\"maxDistanceToAvoid\\" value=\\"$(arg maxDistanceToAvoid)\\" /> <!-- should be smaller than minDistanceToAvoid --> ' +
' <param name=\\"speedProfileFactor\\" value=\\"$(arg speedProfileFactor)\\" /> ' +
' <param name=\\"smoothingDataWeight\\" value=\\"$(arg smoothingDataWeight)\\" /> ' +
' <param name=\\"smoothingSmoothWeight\\" value=\\"$(arg smoothingSmoothWeight)\\" /> ' +
' <param name=\\"horizontalSafetyDistance\\" value=\\"$(arg horizontalSafetyDistance)\\" /> ' +
' <param name=\\"verticalSafetyDistance\\" value=\\"$(arg verticalSafetyDistance)\\" /> ' +
' <param name=\\"enableSwerving\\" value=\\"$(arg enableSwerving)\\" /> ' +
' <param name=\\"enableFollowing\\" value=\\"$(arg enableFollowing)\\" /> ' +
' <param name=\\"enableTrafficLightBehavior\\" value=\\"$(arg enableTrafficLightBehavior)\\" /> ' +
' <param name=\\"enableStopSignBehavior\\" value=\\"$(arg enableStopSignBehavior)\\" /> ' +
' <param name=\\"enableLaneChange\\" value=\\"$(arg enableLaneChange)\\" /> ' +
' <param name=\\"width\\" value=\\"$(arg width)\\" /> ' +
' <param name=\\"length\\" value=\\"$(arg length)\\" /> ' +
' <param name=\\"wheelBaseLength\\" value=\\"$(arg wheelBaseLength)\\" /> ' +
' <param name=\\"turningRadius\\" value=\\"$(arg turningRadius)\\" /> ' +
' <param name=\\"maxSteerAngle\\" value=\\"$(arg maxSteerAngle)\\" /> ' +
' <param name=\\"steeringDelay\\" value=\\"$(arg steeringDelay)\\" /> ' +
' <param name=\\"minPursuiteDistance\\" value=\\"$(arg minPursuiteDistance)\\" /> ' +
' <param name=\\"additionalBrakingDistance\\" value=\\"$(arg additionalBrakingDistance)\\" /> ' +
' <param name=\\"giveUpDistance\\" value=\\"$(arg giveUpDistance)\\" /> ' +
' <param name=\\"maxAcceleration\\" value=\\"$(arg maxAcceleration)\\" /> ' +
' <param name=\\"maxDeceleration\\" value=\\"$(arg maxDeceleration)\\" /> ' +
' <param name=\\"velocitySource\\" value=\\"$(arg velocitySource)\\" /> <!-- read velocities from (0- Odometry, 1- autoware current_velocities, 2- car_info) \\"\\" -->' +
' </node>' +
'</launch>");';
return code;
};
Blockly.Blocks['sethorizondistance'] = {
init: function() {
this.appendDummyInput()
.appendField("Horizon")
.appendField(new Blockly.FieldNumber(7.5, 0, 10, 0.5), "horizonDistance");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['sethorizondistance'] = function(block) {
var number_horizondistance = block.getFieldValue('horizonDistance');
var code = 'parameters_dict["horizonDistance"].value =' + number_horizondistance + ';';
return code;
};
Blockly.Blocks['setmaxlocalplandistance'] = {
init: function() {
this.appendDummyInput()
.appendField("Plan Distance")
.appendField(new Blockly.FieldNumber(12.2, 0, 10, 0.5), "maxLocalPlanDistance");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(200);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setmaxlocalplandistance'] = function(block) {
var number_maxlocalplandistance = block.getFieldValue('maxLocalPlanDistance');
var code = 'parameters_dict["maxLocalPlanDistance"].value =' + number_maxlocalplandistance + ';';
return code;
}
Blockly.Blocks['setpathdensity'] = {
init: function() {
this.appendDummyInput()
.appendField("Path Density")
.appendField(new Blockly.FieldNumber(0.02, 0, 10), "pathDensity");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setpathdensity'] = function(block) {
var number_pathdensity = block.getFieldValue('pathDensity');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["pathDensity"].value =' + number_pathdensity + ';';
return code;
};
Blockly.Blocks['setrolloutdensity'] = {
init: function() {
this.appendDummyInput()
.appendField("Horizontal Density")
.appendField(new Blockly.FieldNumber(0.3, 0, 10), "rollOutDensity");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(140);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setrolloutdensity'] = function(block) {
var number_rolloutdensity = block.getFieldValue('rollOutDensity');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["rollOutDensity"].value =' + number_rolloutdensity + ';';
return code;
};
Blockly.Blocks['setrolloutsnumber'] = {
init: function() {
this.appendDummyInput()
.appendField("Rollouts Number")
.appendField(new Blockly.FieldNumber(4, 0, 10), "rollOutsNumber");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(110);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setrolloutsnumber'] = function(block) {
var number_rolloutsnumber = block.getFieldValue('rollOutsNumber');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["rollOutsNumber"].value =' + number_rolloutsnumber + ';';
return code;
};
//01-12 Added
Blockly.Blocks['setMaxVelocity'] = {
init: function() {
this.appendDummyInput()
.appendField("Max Velocity")
.appendField(new Blockly.FieldNumber(4, 0, 10), "maxVelocity");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(80);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMaxVelocity'] = function(block) {
var number_maxVelocity = block.getFieldValue('maxVelocity');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["maxVelocity"].value =' + number_maxVelocity + ';';
return code;
};
Blockly.Blocks['setMaxAcceleration'] = {
init: function() {
this.appendDummyInput()
.appendField("Max Acceleration")
.appendField(new Blockly.FieldNumber(1.4, 0, 10), "maxAcceleration");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(50);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMaxAcceleration'] = function(block) {
var number_maxAcceleration = block.getFieldValue('maxAcceleration');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["maxAcceleration"].value =' + number_maxAcceleration + ';';
return code;
};
Blockly.Blocks['setMaxDeceleration'] = {
init: function() {
this.appendDummyInput()
.appendField("Max Deceleration")
.appendField(new Blockly.FieldNumber(-1.4, -10, 0), "maxDeceleration");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMaxDeceleration'] = function(block) {
var number_maxDeceleration = block.getFieldValue('maxDeceleration');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["maxDeceleration"].value =' + number_maxDeceleration + ';';
return code;
};
Blockly.Blocks['setEnableFollowing'] = {
init: function() {
this.appendDummyInput()
.appendField("Enable Following")
.appendField(new Blockly.FieldDropdown([["False","opt_false"], ["True","opt_true"]]), "enableFollowing");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("This variable handles ----.");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setEnableFollowing'] = function(block) {
var dropdown_enableFollowing = block.getFieldValue("enableFollowing");
// TODO: Assemble JavaScript into code variable.
if(dropdown_enableFollowing == "opt_true" ){
var dropdown_value = true;
} else if (dropdown_enableFollowing == "opt_false"){
var dropdown_value = false;
}
var code = 'parameters_dict["enableFollowing"].value =' + dropdown_value + ';';
return code;
};
Blockly.Blocks['setEnableSwerving'] = {
init: function() {
this.appendDummyInput()
.appendField("Enable Swerving")
.appendField(new Blockly.FieldDropdown([["False","opt_false"], ["True","opt_true"]]), "enableSwerving");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(200);
this.setTooltip("This variable handles ----.");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setEnableSwerving'] = function(block) {
var dropdown_enableSwerving = block.getFieldValue("enableSwerving");
// TODO: Assemble JavaScript into code variable.
if(dropdown_enableSwerving == "opt_true" ){
var dropdown_value = true;
} else if (dropdown_enableSwerving == "opt_false"){
var dropdown_value = false;
}
var code = 'parameters_dict["enableSwerving"].value =' + dropdown_value + ';';
return code;
};
Blockly.Blocks['setMinFollowingDistance'] = {
init: function() {
this.appendDummyInput()
.appendField("Min Following Distance")
.appendField(new Blockly.FieldNumber(30, 0, 50), "minFollowingDistance");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("Should be bigger than Distance to follow. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMinFollowingDistance'] = function(block) {
var number_minFollowingDistance = block.getFieldValue('minFollowingDistance');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["minFollowingDistance"].value =' + number_minFollowingDistance + ';';
return code;
};
Blockly.Blocks['setMinDistanceToAvoid'] = {
init: function() {
this.appendDummyInput()
.appendField("Min Distance To Avoid")
.appendField(new Blockly.FieldNumber(0.5, 0, 10), "minDistanceToAvoid");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(140);
this.setTooltip("Should be smaller than minFollowingDistance and larger than maxDistanceToAvoid. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMinDistanceToAvoid'] = function(block) {
var number_minDistanceToAvoid = block.getFieldValue('minDistanceToAvoid');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["minDistanceToAvoid"].value =' + number_minDistanceToAvoid + ';';
return code;
};
Blockly.Blocks['setMaxDistanceToAvoid'] = {
init: function() {
this.appendDummyInput()
.appendField("Max Distance To Avoid")
.appendField(new Blockly.FieldNumber(0.5, 0, 10), "maxDistanceToAvoid");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(110);
this.setTooltip("Should be smaller than minDistanceToAvoid. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setMaxDistanceToAvoid'] = function(block) {
var number_maxDistanceToAvoid = block.getFieldValue('maxDistanceToAvoid');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["maxDistanceToAvoid"].value =' + number_maxDistanceToAvoid + ';';
return code;
};
Blockly.Blocks['setEnableStopSignBehavior'] = {
init: function() {
this.appendDummyInput()
.appendField("Enable Stop Sign Behavior")
.appendField(new Blockly.FieldDropdown([["False","opt_false"], ["True","opt_true"]]), "enableStopSignBehavior");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(80);
this.setTooltip("This variable handles ----.");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setEnableStopSignBehavior'] = function(block) {
var dropdown_enableStopSignBehavior = block.getFieldValue("enableStopSignBehavior");
// TODO: Assemble JavaScript into code variable.
if(dropdown_enableStopSignBehavior == "opt_true" ){
var dropdown_value = true;
} else if (dropdown_enableStopSignBehavior == "opt_false"){
var dropdown_value = false;
}
var code = 'parameters_dict["enableStopSignBehavior"].value =' + dropdown_value + ';';
return code;
};
Blockly.Blocks['setEnableTrafficLightBehavior'] = {
init: function() {
this.appendDummyInput()
.appendField("Enable Traffic Light Behavior")
.appendField(new Blockly.FieldDropdown([["False","opt_false"], ["True","opt_true"]]), "enableTrafficLightBehavior");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(50);
this.setTooltip("This variable handles ----.");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setEnableTrafficLightBehavior'] = function(block) {
var dropdown_enableTrafficLightBehavior = block.getFieldValue("enableTrafficLightBehavior");
// TODO: Assemble JavaScript into code variable.
if(dropdown_enableTrafficLightBehavior == "opt_true" ){
var dropdown_value = true;
} else if (dropdown_enableTrafficLightBehavior == "opt_false"){
var dropdown_value = false;
}
var code = 'parameters_dict["enableTrafficLightBehavior"].value =' + dropdown_value + ';';
return code;
};
Blockly.Blocks['setEnableLaneChange'] = {
init: function() {
this.appendDummyInput()
.appendField("Enable Lane Change")
.appendField(new Blockly.FieldDropdown([["False","opt_false"], ["True","opt_true"]]), "enableLaneChange");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("This variable handles ----.");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setEnableLaneChange'] = function(block) {
var dropdown_enableLaneChange = block.getFieldValue("enableLaneChange");
// TODO: Assemble JavaScript into code variable.
if(dropdown_enableLaneChange == "opt_true" ){
var dropdown_value = true;
} else if (dropdown_enableLaneChange == "opt_false"){
var dropdown_value = false;
}
var code = 'parameters_dict["enableLaneChange"].value =' + dropdown_value + ';';
return code;
};
Blockly.Blocks['setHorizontalSafetyDistance'] = {
init: function() {
this.appendDummyInput()
.appendField("Horizontal Safety Distance")
.appendField(new Blockly.FieldNumber(0.05, 0, 1), "horizontalSafetyDistance");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setHorizontalSafetyDistance'] = function(block) {
var number_horizontalSafetyDistance = block.getFieldValue('horizontalSafetyDistance');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["horizontalSafetyDistance"].value =' + number_horizontalSafetyDistance + ';';
return code;
};
Blockly.Blocks['setVerticalSafetyDistance'] = {
init: function() {
this.appendDummyInput()
.appendField("Vertical Safety Distance")
.appendField(new Blockly.FieldNumber(0.05, 0, 1), "verticalSafetyDistance");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(200);
this.setTooltip("This variable handles ----. Min: -- Max --");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setVerticalSafetyDistance'] = function(block) {
var number_verticalSafetyDistance = block.getFieldValue('verticalSafetyDistance');
// TODO: Assemble JavaScript into code variable.
var code = 'parameters_dict["verticalSafetyDistance"].value =' + number_verticalSafetyDistance + ';';
return code;
};
Blockly.Blocks['setVelocitySource'] = {
init: function() {
this.appendDummyInput()
.appendField("Velocity Source")
.appendField(new Blockly.FieldDropdown([["autoware current_velocities","1"], ["odometry","0"], ["car_info","2"]]), "velocitySource");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("Reads velocities from (0- Odometry, 1- autoware current_velocities, 2- car_info)");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setVelocitySource'] = function(block) {
var dropdown_velocitySource = block.getFieldValue("velocitySource");
// TODO: Assemble JavaScript into code variable.
if(dropdown_velocitySource == "0" ){
var dropdown_value = "0";
} else if (dropdown_velocitySource == "1"){
var dropdown_value = "1";
} else if (dropdown_velocitySource == "2"){
var dropdown_value = "2";
}
var code = 'parameters_dict["velocitySource"].value =' + dropdown_value + ';';
return code;
};
function getSourceCode(){
runCode();
// var new_code = showCode();
// var encoded_code = new_code.replace(/;/g,'');
// document.getElementById("source_code_textbox").innerHTML = encoded_code;
}
function pushCode(){
//Ajax call to the server /generateCode
var current_gen_code = localStorage.getItem("generated_code");
var dup = false;
alert(current_gen_code);
var image_name = prompt("Please enter your new image name. No duplicate names, special characters, or spaces.");
if (image_name != null){
var sani_image_name = sanitizeString(image_name).toLowerCase();
//Check for duplicate
$.ajax({
type :'POST',
url :'https://build.3rinnovation.com/readImage',
data :{
name: email,
},
dataType :'text',
encode :true,
async :false,
error :function(req, err){
console.log(err);
}
})
.done(function(response){
// Parse the input into an array of json elements
var data_split = response.replace("{","").replace("}","").split("',");
for (var i = 0; i < data_split.length; i++) {
data_split[i] = data_split[i].replace(/'/g,"");
}
var imageList = new Array();
data_split.forEach(function(item){
imageList.push(item);
});
imageList.forEach(function(item){
if( sani_image_name == item){
dup = true; //duplicate name found
}
});
});
if(dup){
alert("No duplicate Docker Image names permitted.");
}else{
if (confirm("Are you sure you want to add a new Docker Image named [ " + sani_image_name + " ]?")){
//ajax generateCode
$.ajax({
type :'POST',
url :'https://build.3rinnovation.com/addCode',
data :{
name : email,
image_name : sani_image_name,
code : current_gen_code
},
dataType :'text',
encode :true,
async :false,
error :function(req, err){
console.log(err + 'in ajax error..');
}
})
.done(function(response){
//Success or failure message
console.log(response + "in response..");
});
} else {
alert("New Docker Image not added.");
}
}
}
//Send user defined path & launch file as a string?
//include an alert where you can put the path the user wants?
//we need the username, user inputted path, and code, then the ajax call to "/generateCode"
}
function sanitizeString(str){
str = str.replace(/[^a-z0-9_-]/gim,"");
return str.trim();
}
getSourceCode();