【类 型】:factor 电量显示组件 电量滤波

【原  因】:返航点ui图标乱跳不稳定,给电流滤波
【过  程】:取前7个电量值 去掉一个最高 一个最低 剩下平均出一个值
【影  响】:
This commit is contained in:
tk 2024-10-12 13:50:32 +08:00
parent 39853d620f
commit d1e4d64ede

View File

@ -29,11 +29,19 @@ export default {
name: 'BatteryStatus', name: 'BatteryStatus',
data () { data () {
return { return {
batteryValues: [], // 7
filteredBattery: 0, //
showBattery: true, // showBattery: true, //
interval: null // ID interval: null // ID
} }
}, },
computed: { computed: {
batteryValue () {
if (this.plane && this.plane.planeState && this.plane.planeState.currentBattery) {
return this.plane.planeState.currentBattery
}
return 0
},
statusColor () { statusColor () {
// //
const remaining = this.batteryRemaining const remaining = this.batteryRemaining
@ -66,14 +74,14 @@ export default {
}, },
// () // ()
endurance () { endurance () {
if (this.plane && this.plane.planeState && this.plane.planeState.currentBattery > 2) { if (this.filteredBattery > 2) {
return Math.floor(this.batteryRemainingPower / 1000 / this.plane.planeState.currentBattery * 60) return Math.floor(this.batteryRemainingPower / 1000 / this.filteredBattery * 60)
} }
return 0 return 0
}, },
// Tooltip // Tooltip
showTooltip () { showTooltip () {
return Number(this.batteryRemainingPower) !== 0 || Number(this.endurance) !== 0 return Number(this.batteryRemainingPower) > 0 || Number(this.endurance) > 0
}, },
// () // ()
batteryRemaining () { batteryRemaining () {
@ -103,7 +111,7 @@ export default {
if (rtlTime <= 0) { if (rtlTime <= 0) {
return 0 return 0
} }
const currentBattery = this.plane.planeState.currentBattery // () const currentBattery = this.filteredBattery // ()
const batteryCapacity = this.plane.planeState.battCapacity // (mAh) const batteryCapacity = this.plane.planeState.battCapacity // (mAh)
// mAh线 // mAh线
const rtlPowerRequired = rtlTime * currentBattery / 3.6 // (mAh) const rtlPowerRequired = rtlTime * currentBattery / 3.6 // (mAh)
@ -167,6 +175,28 @@ export default {
} }
}, },
watch: { watch: {
//
batteryValue (val) {
//
this.batteryValues.push(Number(val))
// 7 7
if (this.batteryValues.length > 7) {
this.batteryValues.shift()
}
// 3
if (this.batteryValues.length >= 3) {
//
const sortedValues = [...this.batteryValues].sort((a, b) => a - b)
//
sortedValues.pop()
sortedValues.shift()
//
const average = sortedValues.reduce((acc, val) => acc + val, 0) / sortedValues.length
this.filteredBattery = average.toFixed(2)
} else {
this.filteredBattery = val
}
},
batteryRemainingPower () { batteryRemainingPower () {
this.checkDisplayConditions() this.checkDisplayConditions()
}, },