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

Add Relative Altitude Mini Widget #576

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.AltitudeIndicator">
<AltitudeIndicator :mini-widget="miniWidget" />
</template>
<template v-if="miniWidget.component === MiniWidgetType.ArmerButton">
<ArmerButton :options="miniWidget" />
</template>
Expand Down Expand Up @@ -36,6 +39,7 @@ import { toRefs } from 'vue'

import { type MiniWidget, MiniWidgetType } from '@/types/miniWidgets'

import AltitudeIndicator from './mini-widgets/RelativeAltitudeIndicator.vue'
import ArmerButton from './mini-widgets/ArmerButton.vue'
import BaseCommIndicator from './mini-widgets/BaseCommIndicator.vue'
import BatteryIndicator from './mini-widgets/BatteryIndicator.vue'
Expand Down
26 changes: 26 additions & 0 deletions src/components/mini-widgets/RelativeAltitudeIndicator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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 @@ -3,6 +3,7 @@
* The enum value is equal to the component's filename, without the '.vue' extension
*/
export enum MiniWidgetType {
AltitudeIndicator = 'AltitudeIndicator',
ArmerButton = 'ArmerButton',
BaseCommIndicator = 'BaseCommIndicator',
BatteryIndicator = 'BatteryIndicator',
Expand Down
Loading