【类 型】:factor 电量显示组件 电量滤波
【原 因】:返航点ui图标乱跳不稳定,给电流滤波 【过 程】:取前7个电量值 去掉一个最高 一个最低 剩下平均出一个值 【影 响】:
This commit is contained in:
parent
39853d620f
commit
d1e4d64ede
@ -29,11 +29,19 @@ export default {
|
||||
name: 'BatteryStatus',
|
||||
data () {
|
||||
return {
|
||||
batteryValues: [], // 存储最近的 7 个电量值
|
||||
filteredBattery: 0, // 滤波后的电量值
|
||||
showBattery: true, // 用于控制显示电量或续航时间
|
||||
interval: null // 用于存储定时器 ID
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
batteryValue () {
|
||||
if (this.plane && this.plane.planeState && this.plane.planeState.currentBattery) {
|
||||
return this.plane.planeState.currentBattery
|
||||
}
|
||||
return 0
|
||||
},
|
||||
statusColor () {
|
||||
// 获取剩余电量百分比和返航电量百分比
|
||||
const remaining = this.batteryRemaining
|
||||
@ -66,14 +74,14 @@ export default {
|
||||
},
|
||||
// 剩余飞行时间 (分钟)
|
||||
endurance () {
|
||||
if (this.plane && this.plane.planeState && this.plane.planeState.currentBattery > 2) {
|
||||
return Math.floor(this.batteryRemainingPower / 1000 / this.plane.planeState.currentBattery * 60)
|
||||
if (this.filteredBattery > 2) {
|
||||
return Math.floor(this.batteryRemainingPower / 1000 / this.filteredBattery * 60)
|
||||
}
|
||||
return 0
|
||||
},
|
||||
// 控制 Tooltip 显示的条件
|
||||
showTooltip () {
|
||||
return Number(this.batteryRemainingPower) !== 0 || Number(this.endurance) !== 0
|
||||
return Number(this.batteryRemainingPower) > 0 || Number(this.endurance) > 0
|
||||
},
|
||||
// 剩余电量 (百分比)
|
||||
batteryRemaining () {
|
||||
@ -103,7 +111,7 @@ export default {
|
||||
if (rtlTime <= 0) {
|
||||
return 0
|
||||
}
|
||||
const currentBattery = this.plane.planeState.currentBattery // 电流 (安培)
|
||||
const currentBattery = this.filteredBattery // 滤波之后 电流 (安培)
|
||||
const batteryCapacity = this.plane.planeState.battCapacity // 电池总容量 (mAh)
|
||||
// 计算返航所需电量(mAh),假设电流与电量是线性关系
|
||||
const rtlPowerRequired = rtlTime * currentBattery / 3.6 // 返航所需电量 (mAh)
|
||||
@ -167,6 +175,28 @@ export default {
|
||||
}
|
||||
},
|
||||
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 () {
|
||||
this.checkDisplayConditions()
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user