Skip to content

Commit 27c25ef

Browse files
frontend: MainView: Limit update rate of model-viewer to 1rad
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent ee28652 commit 27c25ef

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

core/frontend/src/views/MainView.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ import mavlink_store_get from '@/utils/mavlink'
103103
import CPUUsage from '@/widgets/CpuPie.vue'
104104
import Networking from '@/widgets/Networking.vue'
105105
106+
interface Orientation {
107+
roll: number
108+
pitch: number
109+
yaw: number
110+
}
111+
106112
interface AppItem {
107113
icon?: string
108114
title?: string
@@ -128,6 +134,7 @@ export default Vue.extend({
128134
windowHeight: window.innerHeight,
129135
windowWidth: window.innerWidth,
130136
fetch_streams_task: new OneMoreTime({ delay: 10000, disposeWith: this }),
137+
lastOrientation: { roll: 0, pitch: 0, yaw: 0 } as Orientation,
131138
}),
132139
computed: {
133140
apps(): AppItem[] {
@@ -232,11 +239,23 @@ export default Vue.extend({
232239
has_internet(): boolean {
233240
return helper.has_internet !== InternetConnectionState.OFFLINE
234241
},
242+
attitudeMessage(): Orientation | undefined {
243+
return mavlink_store_get(mavlink, 'ATTITUDE.messageData.message') as Orientation | undefined
244+
},
235245
orientation(): string {
236-
const msg = mavlink_store_get(mavlink, 'ATTITUDE.messageData.message') as
237-
{ roll: number; pitch: number; yaw: number } | undefined
238-
if (!msg) return '0deg 0deg 0deg'
239-
return `${msg.roll}rad ${-msg.pitch}rad ${-msg.yaw}rad`
246+
const { roll, pitch, yaw } = this.lastOrientation
247+
return `${roll}rad ${-pitch}rad ${-yaw}rad`
248+
},
249+
},
250+
watch: {
251+
attitudeMessage(msg: Orientation | undefined): void {
252+
if (!msg) return
253+
const { roll, pitch, yaw } = msg
254+
const last = this.lastOrientation
255+
// Only update if any axis changed by more than 1 rad
256+
if (Math.abs(roll - last.roll) > 1 || Math.abs(pitch - last.pitch) > 1 || Math.abs(yaw - last.yaw) > 1) {
257+
this.lastOrientation = { roll, pitch, yaw }
258+
}
240259
},
241260
},
242261
mounted() {

0 commit comments

Comments
 (0)