Skip to content

Commit

Permalink
altitude-slider: added altitude slider component
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjohnson97 committed Feb 10, 2024
1 parent 3acf75b commit b044fa3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
{{ format(timeNow, 'E LLL do HH:mm') }}
</div>
</div>
<AltitudeSlider />
<Transition name="fade">
<div v-if="showBottomBarNow" class="bottom-container">
<SlideToConfirm />
Expand Down Expand Up @@ -155,6 +156,7 @@ import {
} from '@/libs/joystick/protocols/cockpit-actions'
import { useMissionStore } from '@/stores/mission'
import AltitudeSlider from './components/AltitudeSlider.vue'
import Dialog from './components/Dialog.vue'
import EditMenu from './components/EditMenu.vue'
import MiniWidgetContainer from './components/MiniWidgetContainer.vue'
Expand Down
44 changes: 44 additions & 0 deletions src/components/AltitudeSlider.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div v-if="showAltitudeSlider" class="slider-div">
<slider
v-model="altitude_setpoint"
orientation="vertical"
width="100%"
height="20"
color="rgb(59 130 246)"
track-color="rgb(59 130 246 / 0.5)"
always-show-handle="true"
step="0.1"
/>
<div class="slider-value"><span>Alt (Rel)</span></div>
<div class="slider-value">{{ formattedValue }}</div>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import slider from 'vue3-slider'
import { altitude_setpoint, showAltitudeSlider } from '@/libs/altitude-slider'
const formattedValue = computed(() => altitude_setpoint.value.toFixed(1))
</script>
<style scoped>
.slider-value {
white-space: nowrap;
text-align: center;
font-size: 0.8rem;
}
.slider-div {
position: fixed;
right: 2%;
top: 25%;
bottom: 0;
width: 25px;
height: 50%;
display: flex;
flex-direction: column;
justify-content: center;
z-index: 100;
}
</style>
11 changes: 11 additions & 0 deletions src/libs/altitude-slider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ref, watch } from 'vue'

export const showAltitudeSlider = ref(false)
export const altitude_setpoint = ref(0)

/**
* Watches the altitude value for changes and updates the altitude accordingly.
*/
watch(altitude_setpoint, (newValue, oldValue) => {
console.log(`Altitude changed from ${oldValue} to ${newValue}`)
})
5 changes: 3 additions & 2 deletions src/libs/vehicle/ardupilot/ardupilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,18 @@ export abstract class ArduPilotVehicle<Modes> extends Vehicle.AbstractVehicle<Mo

/**
* Takeoff
* @param {number} altitude_septoint
* @returns {void}
*/
takeoff(): void {
takeoff(altitude_septoint: number): void {
const guidedMode = this.modesAvailable().get('GUIDED')
if (guidedMode === undefined) {
return
}

this.setMode(guidedMode as Modes)
this.arm()
this._takeoff(10)
this._takeoff(altitude_septoint)
this.onTakeoff.emit()
return
}
Expand Down
6 changes: 6 additions & 0 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineStore } from 'pinia'
import { computed, reactive, ref, watch } from 'vue'

import { defaultGlobalAddress } from '@/assets/defaults'
import { altitude_setpoint, showAltitudeSlider } from '@/libs/altitude-slider'
import * as Connection from '@/libs/connection/connection'
import { ConnectionManager } from '@/libs/connection/connection-manager'
import type { Package } from '@/libs/connection/m2r/messages/mavlink2rest'
Expand Down Expand Up @@ -168,7 +169,12 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
if (!mainVehicle.value) {
throw new Error('No vehicle available for takeoff')
}

showAltitudeSlider.value = true

const confirmed = await slideToConfirm('Confirm Takeoff', 'Takeoff Command Confirmed')
showAltitudeSlider.value = false

if (confirmed) {
mainVehicle.value.takeoff(altitude_setpoint.value)
} else {
Expand Down

0 comments on commit b044fa3

Please sign in to comment.