Skip to content

Commit

Permalink
Fix stop point export issue and auto-export paths
Browse files Browse the repository at this point in the history
  • Loading branch information
shueja committed Feb 28, 2024
1 parent ee0d51b commit f3c3b7c
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/config/eventmarker/CommandDraggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CommandDraggable extends Component<Props, State> {
onChange={(e) => command.setType(e.target.value as CommandType)}
>
{CommandUIData.map((data) => (
<MenuItem value={data.id}>{data.name}</MenuItem>
<MenuItem key={data.id} value={data.id}>{data.name}</MenuItem>
))}
</Select>
{command.type === "named" && (
Expand Down
3 changes: 3 additions & 0 deletions src/components/field/svg/FieldEventMarkerAddLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class FieldConstraintsAddLayer extends Component<Props, State> {
let newMarker = activePath.addEventMarker();

newMarker.setTarget({ uuid: point.uuid });
if (!activePath.isTrajectoryStale) {
newMarker.setTrajTargetIndex(index);
}
this.context.model.uiState.setSelectedSidebarItem(newMarker);
}}
></circle>
Expand Down
5 changes: 3 additions & 2 deletions src/components/sidebar/SidebarEventMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ class SidebarMarker extends Component<Props, State> {
let marker = this.props.marker;
let selected = this.props.marker.selected;
let isInSameSegment = marker.isInSameSegment();
let isBoundToTrajectory = marker.trajTargetIndex !== undefined;
let targetMissing = marker.getTargetIndex() === undefined;
let issueTitle: string;
if (targetMissing) {
issueTitle = "Marker targets missing waypoint! Select a new target.";
} else {
if (isInSameSegment === undefined) {
issueTitle = "Path not generated yet. Marker will not show.";
issueTitle = "Marker added since last generation. Marker will not show or export.";
} else {
issueTitle =
"Stop point between targeted waypoint and actual time! Marker will not export.";
Expand Down Expand Up @@ -82,7 +83,7 @@ class SidebarMarker extends Component<Props, State> {
<span></span>
)}
<span>
<span>{this.waypointIDToText(this.props.marker.target)} </span>
<span>{targetMissing ? "?" : this.waypointIDToText(this.props.marker.target)} </span>
<span style={{}}>
(
{(this.props.marker.offset < 0 ? "" : "+") +
Expand Down
13 changes: 10 additions & 3 deletions src/document/DocumentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export class DocumentManager {
usesObstacles: false,
},
});
this.model.document.pathlist.addPath("NewPath");
this.model.document.pathlist.setExporter((uuid)=>{
try {
this.writeTrajectory(()=>this.getTrajFilePath(uuid), uuid)
} catch (e) {
console.error(e);
}
}
);
this.model.document.history.clear();
this.setupEventListeners();
this.newFile();
Expand Down Expand Up @@ -457,9 +464,9 @@ export class DocumentManager {
var file = await filePath();
console.log("file: " + file);

const exportedEventMarkers = chorPath.eventMarkers.map((m) => {
const exportedEventMarkers = chorPath.eventMarkers.flatMap((m) => {
if (m.timestamp === undefined) return [];
return {
name: m.name,
timestamp: m.timestamp,
command: m.command.asSavedCommand(),
};
Expand Down
76 changes: 59 additions & 17 deletions src/document/HolonomicPathStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Instance, types, getRoot, destroy } from "mobx-state-tree";
import { Instance, types, getRoot, destroy, addDisposer } from "mobx-state-tree";
import {
SavedConstraint,
SavedEventMarker,
Expand Down Expand Up @@ -34,7 +34,7 @@ import {
EventMarkerStore,
IEventMarkerStore,
} from "./EventMarkerStore";
import { autorun, toJS } from "mobx";
import { autorun, IReactionDisposer, reaction, toJS } from "mobx";

export const HolonomicPathStore = types
.model("HolonomicPathStore", {
Expand All @@ -52,7 +52,7 @@ export const HolonomicPathStore = types
defaultControlIntervalCount: 40,
usesDefaultObstacles: true,
obstacles: types.array(CircularObstacleStore),
eventMarkers: types.array(EventMarkerStore),
eventMarkers: types.array(EventMarkerStore)
})
.views((self) => {
return {
Expand Down Expand Up @@ -245,7 +245,6 @@ export const HolonomicPathStore = types
})
.filter((item, pos, ary) => !pos || item != ary[pos - 1])
.sort((a, b) => a - b);
console.log(wptIndices);
return wptIndices;
// remove duplicates
},
Expand All @@ -266,7 +265,20 @@ export const HolonomicPathStore = types
},
splitTrajectories() {
let trajectories = [];
const split = this.stopPointIndices();

let split: number[] = [];
{
let stopPointIndex = 0;
self.generatedWaypoints.forEach((point, i)=>{

// start and end points are always bounds for split parts
if (point.isStopPoint || i == 0 || i == self.generatedWaypoints.length - 1) {
split.push(stopPointIndex);
}
stopPointIndex += point.controlIntervalCount;
})
}
//const split = this.stopPointIndices();
for (let i = 1; i < split.length; i++) {
const prev = split[i - 1];
let cur = split[i];
Expand Down Expand Up @@ -300,7 +312,6 @@ export const HolonomicPathStore = types
m.timestamp <= endTime
)
.map((m) => ({
name: m.name,
timestamp: m.timestamp! - startTime,
command: m.command.asSavedCommand(),
}));
Expand Down Expand Up @@ -662,7 +673,7 @@ export const HolonomicPathStore = types
name: saved.name,
target: target as WaypointID,
offset: saved.offset,
trajTargetIndex: targetIndex,
trajTargetIndex: self.isTrajectoryStale ? undefined : targetIndex,
command: CommandStore.create({
type: rootCommandType,
name: "",
Expand All @@ -684,7 +695,7 @@ export const HolonomicPathStore = types
marker = EventMarkerStore.create({
name: "Marker",
target: "first",
trajTargetIndex: 0,
trajTargetIndex: undefined,
offset: 0,
command: CommandStore.create({
type: "named",
Expand Down Expand Up @@ -766,18 +777,49 @@ export const HolonomicPathStore = types
},
};
})
.actions((self) => ({
afterCreate() {
.actions((self) => {
let staleDisposer : IReactionDisposer;
let autosaveDisposer : IReactionDisposer;
let exporter : (uuid:string)=>void;
let afterCreate = () => {
// Anything accessed in here will cause the trajectory to be marked stale
autorun(() => {
console.log(toJS(self.waypoints));
console.log(toJS(self.constraints));
staleDisposer = autorun(() => {
toJS(self.waypoints);
toJS(self.constraints);
// does not need toJS to do a deep check on this, since it's just a boolean
console.log(self.usesControlIntervalGuessing);
console.log(toJS(self.obstacles));
self.usesControlIntervalGuessing;
toJS(self.obstacles);
self.setIsTrajectoryStale(true);
});
},
}));
autosaveDisposer = reaction(
()=>{
if (self.generated.length == 0) {
return [];
}
//toJS(self.splitTrajectories());
return self.splitTrajectories()},
(value)=>{
if (value.length > 0) {
exporter(self.uuid);
}
}
)

}
let setExporter = (exportFunction: (uuid:string)=>void) =>{
exporter = exportFunction;
}
let beforeDestroy = ()=>{
staleDisposer();
autosaveDisposer();
console.log("Deleted ", self.uuid);
}
return {
afterCreate, setExporter, beforeDestroy
}



});
export interface IHolonomicPathStore
extends Instance<typeof HolonomicPathStore> {}
13 changes: 13 additions & 0 deletions src/document/PathListStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export const PathListStore = types
paths: types.map(HolonomicPathStore),
activePathUUID: "",
})
.actions((self)=>{
let pathExporter: (uuid: string) =>void = (uuid)=>{};
return {
setExporter(exportFunction: (uuid:string)=>void) {
pathExporter = exportFunction;
self.paths.forEach((p)=>p.setExporter(pathExporter));
},
getExporter() : (uuid:string) => void {
return pathExporter;
}
}
})
.views((self) => {
return {
asSavedPathList(): SavedPathList {
Expand Down Expand Up @@ -73,6 +85,7 @@ export const PathListStore = types
name: usedName,
waypoints: [],
});
path.setExporter(self.getExporter());
path.addConstraint(ConstraintStores.StopPoint)?.setScope(["first"]);
path.addConstraint(ConstraintStores.StopPoint)?.setScope(["last"]);
self.paths.put(path);
Expand Down

0 comments on commit f3c3b7c

Please sign in to comment.