Skip to content

Commit 89c23bd

Browse files
authored
Alpha 0.1.10/573 add moveable home location (#597)
* Add moveable mission home location * Remove unused deconstructed var
1 parent ab35bef commit 89c23bd

4 files changed

Lines changed: 86 additions & 4 deletions

File tree

gcs/src/components/mapComponents/homeMarker.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import resolveConfig from "tailwindcss/resolveConfig"
1111
import tailwindConfig from "../../../tailwind.config"
1212
const tailwindColors = resolveConfig(tailwindConfig).theme.colors
1313

14-
export default function HomeMarker({ lat, lon, lineTo = null }) {
14+
export default function HomeMarker({
15+
lat,
16+
lon,
17+
updateMissionHomePositionDragCb,
18+
lineTo = null,
19+
}) {
1520
return (
1621
<>
1722
<MarkerPin
@@ -20,6 +25,8 @@ export default function HomeMarker({ lat, lon, lineTo = null }) {
2025
colour={tailwindColors.green[400]}
2126
text={"H"}
2227
showOnTop={true}
28+
draggable={true}
29+
dragEndCallback={updateMissionHomePositionDragCb}
2330
/>
2431
{lineTo !== null && (
2532
<DrawLineCoordinates

gcs/src/components/missions/missionsMap.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function MapSectionNonMemo({
5454
markerDragEndCallback,
5555
rallyDragEndCallback,
5656
addNewMissionItem,
57+
updateMissionHomePosition,
5758
mapId = "dashboard",
5859
}) {
5960
const [connected] = useSessionStorage({
@@ -289,6 +290,9 @@ function MapSectionNonMemo({
289290
<HomeMarker
290291
lat={intToCoord(homePosition.lat)}
291292
lon={intToCoord(homePosition.lon)}
293+
updateMissionHomePositionDragCb={({ x, y }) => {
294+
updateMissionHomePosition(x, y)
295+
}}
292296
lineTo={
293297
filteredMissionItems.length > 0 && [
294298
intToCoord(filteredMissionItems[0].y),
@@ -331,6 +335,18 @@ function MapSectionNonMemo({
331335
</svg>
332336
</div>
333337
</ContextMenuItem>
338+
<ContextMenuItem
339+
onClick={() => {
340+
updateMissionHomePosition(
341+
clickedGpsCoords.lat,
342+
clickedGpsCoords.lng,
343+
)
344+
}}
345+
>
346+
<div className="w-full flex justify-between gap-2">
347+
<p>Set home position</p>
348+
</div>
349+
</ContextMenuItem>
334350
</div>
335351
)}
336352
</Map>

gcs/src/helpers/dataFormatters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function intToCoord(val) {
88
}
99

1010
export function coordToInt(val) {
11-
return val * 1e7
11+
return parseInt(val * 1e7)
1212
}
1313

1414
export const dataFormatters = {

gcs/src/missions.jsx

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { ResizableBox } from "react-resizable"
1111
import { v4 as uuidv4 } from "uuid"
1212

1313
// Custom component and helpers
14-
import { Button, Divider, FileButton, Tabs } from "@mantine/core"
14+
import { Button, Divider, FileButton, Tabs, Tooltip } from "@mantine/core"
15+
import { IconInfoCircle } from "@tabler/icons-react"
1516
import Layout from "./components/layout"
1617
import MissionItemsTable from "./components/missions/missionItemsTable"
1718
import MissionsMapSection from "./components/missions/missionsMap"
@@ -403,6 +404,53 @@ export default function Missions() {
403404
}
404405
}
405406

407+
function updateMissionHomePosition(lat, lon) {
408+
const newHomePosition = {
409+
lat: Number.isInteger(lat) ? lat : coordToInt(lat),
410+
lon: Number.isInteger(lon) ? lon : coordToInt(lon),
411+
alt: 0.1,
412+
}
413+
setHomePosition(newHomePosition)
414+
415+
// Also update the first waypoint if it is a home position waypoint
416+
if (missionItems.length > 0 && isGlobalFrameHomeCommand(missionItems[0])) {
417+
// Check if the first item is a home position command
418+
const updatedMissionItems = [...missionItems]
419+
updatedMissionItems[0] = {
420+
...updatedMissionItems[0],
421+
x: newHomePosition.lat,
422+
y: newHomePosition.lon,
423+
}
424+
setMissionItems(updatedMissionItems)
425+
} else {
426+
// If the first item is not a home position command, add a new home position item
427+
const newHomeMissionItem = {
428+
id: uuidv4(),
429+
seq: 0,
430+
x: newHomePosition.lat,
431+
y: newHomePosition.lon,
432+
z: 0.1,
433+
frame: parseInt(
434+
Object.keys(MAV_FRAME_LIST).find(
435+
(key) => MAV_FRAME_LIST[key] === "MAV_FRAME_GLOBAL",
436+
),
437+
),
438+
command: 16, // MAV_CMD_NAV_WAYPOINT
439+
param1: 0,
440+
param2: 0,
441+
param3: 0,
442+
param4: 0,
443+
current: 0,
444+
autocontinue: 1,
445+
target_component: targetInfo.target_component,
446+
target_system: targetInfo.target_system,
447+
mission_type: 0,
448+
mavpackettype: "MISSION_ITEM_INT",
449+
}
450+
setMissionItems((prevItems) => [newHomeMissionItem, ...prevItems])
451+
}
452+
}
453+
406454
return (
407455
<Layout currentPage="missions">
408456
{/* Banner to let people know that things are still under development */}
@@ -472,7 +520,17 @@ export default function Missions() {
472520
<Divider className="my-1" />
473521

474522
<div className="flex flex-col gap-2">
475-
<p className="font-bold">Home location</p>
523+
<p className="font-bold">
524+
Home location{" "}
525+
<span>
526+
<Tooltip
527+
className="inline"
528+
label="The home location is written to a mission save file."
529+
>
530+
<IconInfoCircle size={20} />
531+
</Tooltip>
532+
</span>
533+
</p>
476534
<p>
477535
Lat:{" "}
478536
{intToCoord(homePosition?.lat).toFixed(
@@ -509,6 +567,7 @@ export default function Missions() {
509567
markerDragEndCallback={updateMissionItem}
510568
rallyDragEndCallback={updateRallyItem}
511569
addNewMissionItem={addNewMissionItem}
570+
updateMissionHomePosition={updateMissionHomePosition}
512571
mapId="missions"
513572
/>
514573
</div>

0 commit comments

Comments
 (0)