Skip to content

Commit

Permalink
Fix issue with moving rotation target beyond other target (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Sep 27, 2024
1 parent 8095ea2 commit 0a5726d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/path/pathplanner_path.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:file/file.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart';
Expand Down Expand Up @@ -197,24 +198,24 @@ class PathPlannerPath {

Map<String, dynamic> toJson() {
// Make sure rotation targets and event markers are sorted
rotationTargets
.sort((a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));
eventMarkers
.sort((a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));
final sortedTargets = List.of(rotationTargets).sorted(
(a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));
final sortedMarkers = List.of(eventMarkers).sorted(
(a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));

return {
'version': 1.0,
'waypoints': [
for (Waypoint w in waypoints) w.toJson(),
],
'rotationTargets': [
for (RotationTarget t in rotationTargets) t.toJson(),
for (RotationTarget t in sortedTargets) t.toJson(),
],
'constraintZones': [
for (ConstraintsZone z in constraintZones) z.toJson(),
],
'eventMarkers': [
for (EventMarker m in eventMarkers) m.toJson(),
for (EventMarker m in sortedMarkers) m.toJson(),
],
'globalConstraints': globalConstraints.toJson(),
'goalEndState': goalEndState.toJson(),
Expand Down Expand Up @@ -353,9 +354,8 @@ class PathPlannerPath {

pathPoints.clear();

List<RotationTarget> unaddedTargets = List.from(rotationTargets);
unaddedTargets
.sort((a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));
final unaddedTargets = rotationTargets.sorted(
(a, b) => a.waypointRelativePos.compareTo(b.waypointRelativePos));

// first point
pathPoints.add(PathPoint(
Expand Down

0 comments on commit 0a5726d

Please sign in to comment.