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

Fix headings to wrap optimally before solver #204

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "BSD-3-Clause"
tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = [ "dialog-confirm", "dialog-save", "dialog-open", "fs-all", "shell-open"] }
tauri = { version = "1.4", features = [ "window-set-title", "path-all", "dialog-confirm", "dialog-save", "dialog-open", "fs-all", "shell-open", "devtools"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
trajoptlib = { git = "https://github.com/SleipnirGroup/TrajoptLib.git", rev = "20bb8c2ef016ceedab0dc5c0271ad9b69048039a" }
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/tauri.conf.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"confirm": true,
"open": true,
"save": true
},
"window": {
"setTitle": true
},
"path": {
"all": true
}
},
"bundle": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/config/WaypointConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WaypointData } from "../../document/UIStateStore";
import Waypoint from "../../assets/Waypoint";
import { Circle, CircleOutlined, Help } from "@mui/icons-material";
import inputStyles from "../input/InputList.module.css";
import { angleModulus } from "../../util/MathUtil";

type Props = { waypoint: IHolonomicWaypointStore | null };

Expand Down Expand Up @@ -61,7 +62,7 @@ class WaypointPanel extends Component<Props, State> {
showCheckbox={false}
enabled={waypoint.headingConstrained}
setEnabled={(_) => {}}
number={waypoint.heading}
number={angleModulus(waypoint.heading)}
setNumber={(heading) => waypoint!.setHeading(heading)}
></Input>
<Input
Expand Down
1 change: 1 addition & 0 deletions src/document/DocumentModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const StateStore = types
);
}
return new Promise((resolve, reject) => {
pathStore.fixWaypointHeadings();
const controlIntervalOptResult =
pathStore.optimizeControlIntervalCounts(self.document.robotConfig);
if (controlIntervalOptResult !== undefined) {
Expand Down
28 changes: 28 additions & 0 deletions src/document/HolonomicPathStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { SavedWaypointId } from "./previousSpecs/v0_1";
import { timeStamp } from "console";
import { IRobotConfigStore } from "./RobotConfigStore";
import { angleModulus } from "../util/MathUtil";

export const HolonomicPathStore = types
.model("HolonomicPathStore", {
Expand Down Expand Up @@ -329,6 +330,33 @@ export const HolonomicPathStore = types
self.generating = generating;
});
},
fixWaypointHeadings() {
let fullRots = 0;
let prevHeading = 0;
self.waypoints.forEach((point, i, pts) => {
if (i == 0) {
prevHeading = point.heading;
} else {
if (point.headingConstrained) {
let prevHeadingMod = angleModulus(prevHeading);
let heading = pts[i].heading;
let headingMod = angleModulus(heading);
if (prevHeadingMod < 0 && headingMod > prevHeadingMod + Math.PI) {
// negative rollunder
fullRots--;
} else if (
prevHeadingMod > 0 &&
headingMod < prevHeadingMod - Math.PI
) {
shueja marked this conversation as resolved.
Show resolved Hide resolved
// positive rollover
fullRots++;
}
point.heading = fullRots * 2 * Math.PI + headingMod;
prevHeading = point.heading;
}
}
});
},
};
})
.actions((self) => {
Expand Down
27 changes: 27 additions & 0 deletions src/util/MathUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* A port of WPILib's MathUtil.inputModulus
*/
export function inputModulus(
input: number,
maximumInput: number,
minimumInput: number
) {
let modulus = maximumInput - minimumInput;

// Wrap input if it's above the maximum input
let numMax = Math.trunc((input - minimumInput) / modulus);
input -= numMax * modulus;

// Wrap input if it's below the minimum input
let numMin = Math.trunc((input - maximumInput) / modulus);
input -= numMin * modulus;

return input;
}

/**
* A port of WPILib's MathUtil.angleModulus
*/
export function angleModulus(input: number) {
return inputModulus(input, Math.PI, -Math.PI);
}
Loading