Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist paused state through path edits #838

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 9 additions & 51 deletions lib/widgets/editor/split_auto_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import 'package:pathplanner/services/log.dart';
import 'package:pathplanner/trajectory/auto_simulator.dart';
import 'package:pathplanner/trajectory/config.dart';
import 'package:pathplanner/trajectory/dc_motor.dart';
import 'package:pathplanner/trajectory/trajectory.dart';
import 'package:pathplanner/util/wpimath/geometry.dart';
import 'package:pathplanner/path/pathplanner_path.dart';
import 'package:pathplanner/util/prefs.dart';
import 'package:pathplanner/widgets/editor/path_painter.dart';
Expand Down Expand Up @@ -52,7 +50,6 @@
bool _paused = false;

late AnimationController _previewController;
late bool _holonomicMode;

@override
void initState() {
Expand All @@ -62,8 +59,6 @@

_treeOnRight =
widget.prefs.getBool(PrefsKeys.treeOnRight) ?? Defaults.treeOnRight;
_holonomicMode =
widget.prefs.getBool(PrefsKeys.holonomicMode) ?? Defaults.holonomicMode;

double treeWeight = widget.prefs.getDouble(PrefsKeys.editorTreeWeight) ??
Defaults.editorTreeWeight;
Expand Down Expand Up @@ -237,52 +232,7 @@
simPath = PathPlannerTrajectory.fromStates(allStates);
}
} else {
num halfWheelbase = (widget.prefs.getDouble(PrefsKeys.robotWheelbase) ??
Defaults.robotWheelbase) /
2;
num halfTrackwidth = (widget.prefs.getDouble(PrefsKeys.robotTrackwidth) ??
Defaults.robotTrackwidth) /
2;
List<Translation2d> moduleLocations = _holonomicMode
? [
Translation2d(halfWheelbase, halfTrackwidth),
Translation2d(halfWheelbase, -halfTrackwidth),
Translation2d(-halfWheelbase, halfTrackwidth),
Translation2d(-halfWheelbase, -halfTrackwidth),
]
: [
Translation2d(0, halfTrackwidth),
Translation2d(0, -halfTrackwidth),
];

int numMotors = _holonomicMode ? 1 : 2;
DCMotor driveMotor = DCMotor.fromString(
widget.prefs.getString(PrefsKeys.driveMotor) ??
Defaults.driveMotor,
numMotors)
.withReduction(widget.prefs.getDouble(PrefsKeys.driveGearing) ??
Defaults.driveGearing);
RobotConfig config = RobotConfig(
massKG:
widget.prefs.getDouble(PrefsKeys.robotMass) ?? Defaults.robotMass,
moi: widget.prefs.getDouble(PrefsKeys.robotMOI) ?? Defaults.robotMOI,
moduleConfig: ModuleConfig(
wheelRadiusMeters:
widget.prefs.getDouble(PrefsKeys.driveWheelRadius) ??
Defaults.driveWheelRadius,
maxDriveVelocityMPS:
widget.prefs.getDouble(PrefsKeys.maxDriveSpeed) ??
Defaults.maxDriveSpeed,
driveMotor: driveMotor,
driveCurrentLimit:
widget.prefs.getDouble(PrefsKeys.driveCurrentLimit) ??
Defaults.driveCurrentLimit,
wheelCOF:
widget.prefs.getDouble(PrefsKeys.wheelCOF) ?? Defaults.wheelCOF,
),
moduleLocations: moduleLocations,
holonomic: _holonomicMode,
);
RobotConfig config = RobotConfig.fromPrefs(widget.prefs);

try {
simPath = AutoSimulator.simulateAuto(
Expand Down Expand Up @@ -310,6 +260,14 @@
_previewController.duration = Duration(
milliseconds: (simPath.states.last.timeSeconds * 1000).toInt());
_previewController.repeat();
} else {
double prevTime = _previewController.value *
(_previewController.duration!.inMilliseconds / 1000.0);
_previewController.duration = Duration(
milliseconds: (simPath.states.last.timeSeconds * 1000).toInt());
double newPos = prevTime / simPath.states.last.timeSeconds;
_previewController.forward(from: newPos);
_previewController.stop();

Check warning on line 270 in lib/widgets/editor/split_auto_editor.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/editor/split_auto_editor.dart#L264-L270

Added lines #L264 - L270 were not covered by tests
}
} else {
// Trajectory failed to generate. Notify the user
Expand Down
16 changes: 13 additions & 3 deletions lib/widgets/editor/split_path_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,19 @@
}

if (_simTraj != null) {
_previewController.duration = Duration(
milliseconds: (_simTraj!.states.last.timeSeconds * 1000).toInt());
_previewController.repeat();
if (!_paused) {
_previewController.duration = Duration(
milliseconds: (_simTraj!.states.last.timeSeconds * 1000).toInt());
_previewController.repeat();
} else if (_previewController.duration != null) {
double prevTime = _previewController.value *
(_previewController.duration!.inMilliseconds / 1000.0);
_previewController.duration = Duration(
milliseconds: (_simTraj!.states.last.timeSeconds * 1000).toInt());
double newPos = prevTime / _simTraj!.states.last.timeSeconds;
_previewController.forward(from: newPos);
_previewController.stop();

Check warning on line 750 in lib/widgets/editor/split_path_editor.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/editor/split_path_editor.dart#L743-L750

Added lines #L743 - L750 were not covered by tests
}
} else {
// Trajectory failed to generate. Notify the user
Log.warning(
Expand Down
Loading