Skip to content

Commit

Permalink
Fix a couple issues (#821)
Browse files Browse the repository at this point in the history
* fix crash from exiting path while optimizing

* fix ideal starting state issue
  • Loading branch information
mjansen4857 authored Oct 6, 2024
1 parent 96ad2d1 commit 720c43e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 1 addition & 3 deletions lib/path/pathplanner_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ class PathPlannerPath {
pos = waypoints.length - 1;
}

// Force start/end rotation targets to start/end state rotation
pathPoints.first.rotationTarget =
RotationTarget(0, idealStartingState.rotation);
// Force end rotation target to end state rotation
pathPoints.last.rotationTarget =
RotationTarget(waypoints.length - 1, goalEndState.rotation);

Expand Down
28 changes: 17 additions & 11 deletions lib/widgets/editor/tree_widgets/path_optimization_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,38 @@ class _PathOptimizationTreeState extends State<PathOptimizationTree> {
}

void _runOptimization() async {
RobotConfig config = RobotConfig.fromPrefs(widget.prefs);

setState(() {
_running = true;
_currentResult = null;
});

RobotConfig config = RobotConfig.fromPrefs(widget.prefs);

widget.onUpdate?.call(_currentResult?.path);

final result = await PathOptimizer.optimizePath(
widget.path,
config,
widget.fieldSizeMeters,
_robotSize,
onUpdate: (result) => setState(() {
_currentResult = result;
widget.onUpdate?.call(_currentResult?.path);
}),
onUpdate: (result) {
if (mounted) {
setState(() {
_currentResult = result;
widget.onUpdate?.call(_currentResult?.path);
});
}
},
);

setState(() {
_running = false;
_currentResult = result;
});
if (mounted) {
setState(() {
_running = false;
_currentResult = result;
});

widget.onUpdate?.call(_currentResult?.path);
widget.onUpdate?.call(_currentResult?.path);
}
}

void _discardOptimization() {
Expand Down

0 comments on commit 720c43e

Please sign in to comment.