Skip to content

Commit

Permalink
Add Relative Altitude Mini Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjohnson97 authored Nov 19, 2023
1 parent b73b03a commit f9a899a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/assets/altitude-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/components/MiniWidgetInstantiator.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<template>
<template v-if="miniWidget.component === MiniWidgetType.RelativeAltitudeIndicator">
<RelativeAltitudeIndicator :mini-widget="miniWidget" />
</template>
<template v-if="miniWidget.component === MiniWidgetType.ArmerButton">
<ArmerButton :options="miniWidget" />
</template>
Expand Down Expand Up @@ -43,6 +46,7 @@ import DepthIndicator from './mini-widgets/DepthIndicator.vue'
import JoystickCommIndicator from './mini-widgets/JoystickCommIndicator.vue'
import MiniVideoRecorder from './mini-widgets/MiniVideoRecorder.vue'
import ModeSelector from './mini-widgets/ModeSelector.vue'
import RelativeAltitudeIndicator from './mini-widgets/RelativeAltitudeIndicator.vue'
import SatelliteIndicator from './mini-widgets/SatelliteIndicator.vue'
import VeryGenericIndicator from './mini-widgets/VeryGenericIndicator.vue'
import ViewSelector from './mini-widgets/ViewSelector.vue'
Expand Down
24 changes: 24 additions & 0 deletions src/components/mini-widgets/RelativeAltitudeIndicator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<div class="flex items-center w-fit min-w-[8rem] max-w-[9rem] h-12 p-1 text-white justify-center">
<img src="@/assets/altitude-icon.svg" class="h-full" :draggable="false" />
<div class="flex flex-col items-start justify-center ml-1 min-w-[4rem] max-w-[6rem] select-none">
<div>
<span class="font-mono text-xl font-semibold leading-6 w-fit">{{ round(altitude, 2).toFixed(2) }}</span>
<span class="text-xl font-semibold leading-6 w-fit"> m</span>
</div>
<span class="w-full text-sm font-semibold leading-4 whitespace-nowrap">Alt (Rel)</span>
</div>
</div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { round } from '@/libs/utils'
import { useMainVehicleStore } from '@/stores/mainVehicle'
const store = useMainVehicleStore()
const altitude = ref(0)
watch(store.altitude, () => (altitude.value = store.altitude.rel))
</script>
4 changes: 3 additions & 1 deletion src/libs/vehicle/ardupilot/ardupilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type ArduPilot = ArduPilotVehicle<any>
* Generic ArduPilot vehicle
*/
export abstract class ArduPilotVehicle<Modes> extends Vehicle.AbstractVehicle<Modes> {
_altitude = new Altitude({ msl: 0 })
_altitude = new Altitude({ msl: 0, rel: 0 })
_attitude = new Attitude({ roll: 0, pitch: 0, yaw: 0 })
_communicationDropRate = 0
_communicationErrors = 0
Expand Down Expand Up @@ -269,6 +269,8 @@ export abstract class ArduPilotVehicle<Modes> extends Vehicle.AbstractVehicle<Mo
this._velocity.ground = Math.sqrt(this._velocity.x ** 2 + this._velocity.y ** 2)
this._velocity.overall = Math.sqrt(this._velocity.x ** 2 + this._velocity.y ** 2 + this._velocity.z ** 2)
this.onVelocity.emit()
this._altitude.rel = position.relative_alt / 1000 // (mm to meters)
this.onAltitude.emit()
break
}
case MAVLinkType.GPS_RAW_INT: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/vehicle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class Attitude {
*/
export class Altitude {
msl: number // Mean Sea Level, in meters

rel: number // Relative altitude, in meters
/**
* Create object
* @param {Partial<Altitude>} init
Expand Down
1 change: 1 addition & 0 deletions src/types/miniWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum MiniWidgetType {
BaseCommIndicator = 'BaseCommIndicator',
BatteryIndicator = 'BatteryIndicator',
DepthIndicator = 'DepthIndicator',
RelativeAltitudeIndicator = 'RelativeAltitudeIndicator',
VeryGenericIndicator = 'VeryGenericIndicator',
JoystickCommIndicator = 'JoystickCommIndicator',
MiniVideoRecorder = 'MiniVideoRecorder',
Expand Down

0 comments on commit f9a899a

Please sign in to comment.