-
Notifications
You must be signed in to change notification settings - Fork 15
1165 feature see waypoint information on missions page #1168
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
Merged
1Blademaster
merged 4 commits into
main
from
1165-feature-see-waypoint-information-on-missions-page
Apr 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { distance } from "@turf/turf" | ||
| import { intToCoord } from "./dataFormatters" | ||
| import { isGlobalFrameHomeCommand } from "./filterMissions" | ||
|
|
||
| const STOP_COMMANDS = [20, 21, 189] | ||
| const RTL_COMMAND = 20 | ||
|
|
||
| function toFiniteNumber(value) { | ||
| const parsedValue = Number(value) | ||
| return Number.isFinite(parsedValue) ? parsedValue : null | ||
| } | ||
|
|
||
| function buildHomeWaypoint(homePosition) { | ||
| const homeLat = toFiniteNumber(homePosition?.lat) | ||
| const homeLon = toFiniteNumber(homePosition?.lon) | ||
|
|
||
| if (homeLat === null || homeLon === null) { | ||
| return null | ||
| } | ||
|
|
||
| // TODO: Allow home waypoint altitude to be used for absolute altitude | ||
| // calculations in the future. | ||
| return { | ||
| isHome: true, | ||
| seq: "Home", | ||
| x: homeLat, | ||
| y: homeLon, | ||
| z: 0, | ||
| lat: intToCoord(homeLat), | ||
| lon: intToCoord(homeLon), | ||
| altitude: 0, | ||
| } | ||
| } | ||
|
|
||
| function buildResolvedWaypoint(missionItem) { | ||
| const x = toFiniteNumber(missionItem?.x) | ||
| const y = toFiniteNumber(missionItem?.y) | ||
| const z = toFiniteNumber(missionItem?.z) | ||
|
|
||
| const hasPosition = x !== null && y !== null && x !== 0 && y !== 0 | ||
|
|
||
| return { | ||
| seq: missionItem?.seq, | ||
| isHome: false, | ||
| x, | ||
| y, | ||
| z, | ||
| lat: hasPosition ? intToCoord(x) : null, | ||
| lon: hasPosition ? intToCoord(y) : null, | ||
| altitude: hasPosition ? z : null, | ||
| } | ||
| } | ||
|
|
||
| function getDisplayPointLabel(point) { | ||
| if (!point) { | ||
| return null | ||
| } | ||
|
|
||
| return point.isHome ? "Home" : point.seq | ||
| } | ||
|
|
||
| export function buildMissionWaypointLegMetrics(missionItems, homePosition) { | ||
| if (!Array.isArray(missionItems) || missionItems.length === 0) { | ||
| return [] | ||
| } | ||
|
|
||
| const metricsByIndex = [] | ||
| const homeWaypoint = buildHomeWaypoint(homePosition) | ||
| const stopCommandItem = [...missionItems] | ||
| .filter((item) => STOP_COMMANDS.includes(item.command)) | ||
| .sort((a, b) => a.seq - b.seq) | ||
| .at(0) | ||
|
|
||
| let previousWaypoint = homeWaypoint | ||
| let previousAltitude = homeWaypoint ? homeWaypoint.altitude : null | ||
|
|
||
|
1Blademaster marked this conversation as resolved.
|
||
| for (let idx = 0; idx < missionItems.length; idx++) { | ||
| const missionItem = missionItems[idx] | ||
|
|
||
| if (stopCommandItem && missionItem.seq > stopCommandItem.seq) { | ||
| continue | ||
| } | ||
|
|
||
| if (idx === 0 && isGlobalFrameHomeCommand(missionItem)) { | ||
| continue | ||
| } | ||
|
|
||
| const resolvedWaypoint = buildResolvedWaypoint(missionItem) | ||
| const isRtlCommand = missionItem.command === RTL_COMMAND | ||
| const currentWaypoint = | ||
| isRtlCommand && homeWaypoint | ||
| ? homeWaypoint | ||
| : resolvedWaypoint.lat !== null && resolvedWaypoint.lon !== null | ||
| ? resolvedWaypoint | ||
| : previousWaypoint | ||
| const currentAltitude = | ||
| isRtlCommand && homeWaypoint | ||
| ? homeWaypoint.altitude | ||
| : resolvedWaypoint.altitude !== null | ||
| ? resolvedWaypoint.altitude | ||
| : previousAltitude | ||
|
1Blademaster marked this conversation as resolved.
|
||
|
|
||
| let distanceMeters = null | ||
| let gradientPercent = null | ||
|
|
||
| if ( | ||
| previousWaypoint?.lat !== null && | ||
| previousWaypoint?.lon !== null && | ||
| currentWaypoint?.lat !== null && | ||
| currentWaypoint?.lon !== null | ||
| ) { | ||
| distanceMeters = distance( | ||
| [previousWaypoint.lon, previousWaypoint.lat], | ||
| [currentWaypoint.lon, currentWaypoint.lat], | ||
| { units: "meters" }, | ||
| ) | ||
| } | ||
|
|
||
| if ( | ||
| previousWaypoint?.lat !== null && | ||
| previousWaypoint?.lon !== null && | ||
| previousAltitude !== null && | ||
| currentAltitude !== null | ||
| ) { | ||
| const horizontalDistanceMeters = | ||
| distanceMeters ?? | ||
| distance( | ||
| [previousWaypoint.lon, previousWaypoint.lat], | ||
| [currentWaypoint.lon, currentWaypoint.lat], | ||
| { units: "meters" }, | ||
| ) | ||
|
|
||
| if (horizontalDistanceMeters > 0) { | ||
| gradientPercent = | ||
| ((currentAltitude - previousAltitude) / horizontalDistanceMeters) * | ||
| 100 | ||
| } | ||
| } | ||
|
|
||
| metricsByIndex[idx] = { | ||
| currentWaypoint, | ||
| previousWaypoint, | ||
| distanceMeters, | ||
| gradientPercent, | ||
| previousWaypointLabel: getDisplayPointLabel(previousWaypoint), | ||
| currentWaypointLabel: getDisplayPointLabel(currentWaypoint), | ||
| } | ||
|
|
||
| if (resolvedWaypoint.lat !== null && resolvedWaypoint.lon !== null) { | ||
| previousWaypoint = resolvedWaypoint | ||
| } | ||
|
|
||
| if (resolvedWaypoint.altitude !== null) { | ||
| previousAltitude = resolvedWaypoint.altitude | ||
| } | ||
| } | ||
|
|
||
| return metricsByIndex | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.