35
35
import com .jlbabilino .json .JSONSerializerException ;
36
36
37
37
import javafx .beans .property .BooleanProperty ;
38
- import javafx .beans .property .ObjectProperty ;
39
38
import javafx .beans .property .ReadOnlyBooleanProperty ;
40
39
import javafx .beans .property .SimpleBooleanProperty ;
41
- import javafx .beans .property .SimpleObjectProperty ;
42
40
import javafx .beans .value .ObservableValue ;
43
41
import javafx .concurrent .Service ;
44
42
import javafx .concurrent .Task ;
@@ -397,8 +395,6 @@ public void paste() {
397
395
398
396
private static class TrajectoryGenerationService extends Service <HolonomicTrajectory > {
399
397
400
- // private final ObjectProperty<SwerveDrivetrain> drive = new SimpleObjectProperty<>(this, "drive", null);
401
- // private final ObjectProperty<HolonomicPath> path = new SimpleObjectProperty<>(this, "path", null);
402
398
private SwerveDrivetrain drive = null ;
403
399
private HolonomicPath path = null ;
404
400
@@ -410,28 +406,24 @@ protected Task<HolonomicTrajectory> createTask() {
410
406
Task <HolonomicTrajectory > optimizeTask = new Task <HolonomicTrajectory >() {
411
407
@ Override
412
408
protected HolonomicTrajectory call () throws PluginLoadException , InvalidPathException , TrajectoryGenerationException {
413
- // Thread generationThread = Thread.currentThread();
414
409
System .out .println ("Path optimizing: " + path .toString ());
415
410
if (drive != null && path != null ) {
416
- // new Thread(() -> {
417
- // while (!isCancelled()) {}
418
- // generationThread.stop();
419
- // }).start();
420
411
HolonomicTrajectory traj = OptimalTrajectoryGenerator .generate (drive , path );
421
412
System .out .println ("Generation complete, closing task..." );
422
413
return traj ;
423
414
} else {
424
415
throw new TrajectoryGenerationException ("No path specified for optimization service." );
425
416
}
426
- // System.out.println("Error generating path: " + e.getMessage() + System.lineSeparator());
427
417
}
428
418
};
429
419
return optimizeTask ;
430
420
}
431
421
}
432
422
433
- private static final TrajectoryGenerationService SERVICE = new TrajectoryGenerationService ();
434
- public static final ReadOnlyBooleanProperty IS_GENERATION_RUNNING = SERVICE .runningProperty ();
423
+ private final TrajectoryGenerationService service = new TrajectoryGenerationService ();
424
+ public final ReadOnlyBooleanProperty generationRunningProperty () {
425
+ return service .runningProperty ();
426
+ }
435
427
public void generateTrajectory () {
436
428
if (documentManager .getIsDocumentOpen () && documentManager .getDocument ().isPathSelected ()) {
437
429
HDocument hDocument = documentManager .getDocument ();
@@ -442,31 +434,17 @@ public void generateTrajectory() {
442
434
obstacles .add (hPath .getObstacles ().get (i ).toObstacle ());
443
435
}
444
436
HolonomicPath path = hPath .toPath (obstacles );
445
- SERVICE .drive = drive ;
446
- SERVICE .path = path ;
447
- SERVICE .setOnSucceeded (workerState -> {
437
+ service .drive = drive ;
438
+ service .path = path ;
439
+ service .setOnSucceeded (workerState -> {
448
440
HolonomicTrajectory traj = (HolonomicTrajectory ) workerState .getSource ().getValue ();
449
441
hPath .setTrajectory (HTrajectory .fromTrajectory (traj ));
450
442
});
451
- if (!SERVICE .isRunning ()) {
452
- SERVICE .restart ();
443
+ if (!service .isRunning ()) {
444
+ service .restart ();
453
445
}
454
446
}
455
447
}
456
- // public void toggleTrajectoryGeneration() {
457
- // if (SERVICE.isRunning()) {
458
- // System.out.println("Cancelling trajopt");
459
- // SERVICE.cancel();
460
- // } else {
461
- // System.out.println("Restarting trajopt");
462
- // generateTrajectory();
463
- // }
464
- // }
465
- // public void cancelTrajectoryGeneration() {
466
- // if (SERVICE.isRunning()) {
467
- // SERVICE.cancel();
468
- // }
469
- // }
470
448
471
449
private static final Rotate ROTATE_90_CLOCKWISE = new Rotate (-90 );
472
450
private static final Rotate ROTATE_90_COUNTERCLOCKWISE = new Rotate (90 );
0 commit comments