Skip to content

Commit 22025de

Browse files
Williangalvanipatrickelectric
authored andcommitted
frontend: add interface for Gyro calibration
1 parent 6e88695 commit 22025de

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

core/frontend/src/components/vehiclesetup/Configure.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import FailsafesConfigration from './configuration/failsafes/Failsafes.vue'
4242
import LightsConfigration from './configuration/lights.vue'
4343
import BaroCalib from './overview/BaroCalib.vue'
4444
import GripperInfo from './overview/gripper.vue'
45+
import GyroCalib from './overview/GyroCalib.vue'
4546
import LeakInfo from './overview/LeakInfo.vue'
4647
import LightsInfo from './overview/LightsInfo.vue'
4748
import ParamSets from './overview/ParamSets.vue'
@@ -68,12 +69,14 @@ export default Vue.extend({
6869
ArdupilotMavlinkCompassSetup,
6970
ArdupilotAccelerometerSetup,
7071
SpinningLogo,
72+
GyroCalib,
7173
},
7274
data() {
7375
return {
7476
page_selected: null as string | null,
7577
pages: [
7678
{ title: 'Parameters', component: ParamSets },
79+
{ title: 'Gyroscope', component: GyroCalib },
7780
{ title: 'Accelerometer', component: ArdupilotAccelerometerSetup },
7881
{ title: 'Compass', component: ArdupilotMavlinkCompassSetup },
7982
{ title: 'Baro', component: BaroCalib },
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<template>
2+
<div class="main-container">
3+
<v-card outline class="pa-2" width="600px">
4+
<v-card-title class="align-center justify-center">
5+
Calibrate Gyroscopes
6+
</v-card-title>
7+
<v-card-text>
8+
A calibrated gyro should display a value of 0 on all axes when the vehicle is stationary.
9+
Symptoms of a mis-calibrated gyro include yaw drift and small attitude offsets.
10+
</v-card-text>
11+
<v-card-text>
12+
<v-simple-table>
13+
<thead>
14+
<tr>
15+
<th>IMU</th>
16+
<th>Angular speed (mrad/s)</th>
17+
<th>Offsets (mrad/s)</th>
18+
<th>Calibration temperature (°C)</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<tr v-for="item in valid_table_items" :key="item.name">
23+
<td>{{ item.name }}</td>
24+
<td>{{ item.value }}</td>
25+
<td style="min-width: 150px;">
26+
{{ renderVec3(item.offsets) }}
27+
</td>
28+
<td>{{ item.calibration_temperature?.toFixed(1) }}</td>
29+
</tr>
30+
</tbody>
31+
</v-simple-table>
32+
</v-card-text>
33+
<v-card-text>
34+
The Gyroscopes can be automatically calibrated at startup. Be mindful that this is not recommended for
35+
vehicles that start up on moving platforms (such as boats).
36+
<div class="ma-5 pa-5">
37+
<inline-parameter-editor
38+
v-if="ins_gyr_cal"
39+
:param="ins_gyr_cal"
40+
:label="'Calibrate gyroscopes automaicallly'"
41+
/>
42+
</div>
43+
</v-card-text>
44+
<v-card-actions class="justify-center">
45+
<v-btn
46+
color="primary"
47+
@click="calibrate"
48+
>
49+
Calibrate Gyroscopes
50+
</v-btn>
51+
</v-card-actions>
52+
<v-card-actions class="justify-center">
53+
{{ calibration_status }}
54+
</v-card-actions>
55+
</v-card>
56+
</div>
57+
</template>
58+
59+
<script lang="ts">
60+
import { vec3 } from 'gl-matrix'
61+
import Vue from 'vue'
62+
63+
import InlineParameterEditor from '@/components/parameter-editor/InlineParameterEditor.vue'
64+
import autopilot_data from '@/store/autopilot'
65+
import mavlink from '@/store/mavlink'
66+
import Parameter from '@/types/autopilot/parameter'
67+
import { Dictionary } from '@/types/common'
68+
import decode from '@/utils/deviceid_decoder'
69+
import mavlink_store_get from '@/utils/mavlink'
70+
71+
import { calibrator, PreflightCalibration } from '../calibration'
72+
73+
interface CalibrationStatus {
74+
param?: Parameter
75+
name: string
76+
value: vec3|null
77+
offsets: vec3|null
78+
calibration_temperature: number|null
79+
}
80+
export default Vue.extend({
81+
name: 'GyroCalibrate',
82+
components: {
83+
InlineParameterEditor,
84+
},
85+
data() {
86+
return {
87+
calibration_status: '',
88+
}
89+
},
90+
computed: {
91+
table_items(): CalibrationStatus[] {
92+
return [1, 2, 3].map((index) => {
93+
const suffix = index === 1 ? '' : index.toString()
94+
const gyrId = autopilot_data.parameter(`INS_GYR${suffix}_ID`)
95+
const offsets = ['X', 'Y', 'Z'].map((axis) => {
96+
const rawValue = autopilot_data.parameter(`INS_GYROFFS${suffix}_${axis}`)?.value
97+
return rawValue ? rawValue * 1000 : null
98+
}) as [number, number, number]
99+
100+
return {
101+
name: gyrId ? decode(gyrId.name, gyrId.value).deviceName ?? '?' : '?',
102+
param: gyrId,
103+
value: this[`gyro_read${index}`],
104+
offsets: vec3.fromValues(...offsets),
105+
calibration_temperature: autopilot_data.parameter(`INS_GYR${index}_CALTEMP`)?.value ?? 0,
106+
}
107+
})
108+
},
109+
valid_table_items(): CalibrationStatus[] {
110+
return this.table_items.filter((item: CalibrationStatus) => item.param?.value !== 0)
111+
},
112+
ins_gyr_cal(): Parameter | undefined {
113+
return autopilot_data.parameter('INS_GYR_CAL')
114+
},
115+
gyro_read1(): vec3 | null {
116+
const msg = mavlink_store_get(mavlink, 'RAW_IMU.messageData.message') as Dictionary<number>
117+
if (!msg) return null
118+
return vec3.fromValues(msg.xgyro, msg.ygyro, msg.zgyro)
119+
},
120+
gyro_read2(): vec3 | null {
121+
const msg = mavlink_store_get(mavlink, 'SCALED_IMU2.messageData.message') as Dictionary<number>
122+
if (!msg) return null
123+
return vec3.fromValues(msg.xgyro, msg.ygyro, msg.zgyro)
124+
},
125+
gyro_read3(): vec3 | null {
126+
const msg = mavlink_store_get(mavlink, 'SCALED_IMU3.messageData.message') as Dictionary<number>
127+
if (!msg) return null
128+
return vec3.fromValues(msg.xgyro, msg.ygyro, msg.zgyro)
129+
},
130+
},
131+
mounted() {
132+
for (const msg of ['RAW_IMU', 'SCALED_IMU2', 'SCALED_IMU3']) {
133+
mavlink.setMessageRefreshRate({ messageName: msg, refreshRate: 10 })
134+
}
135+
},
136+
methods: {
137+
async calibrate() {
138+
this.calibration_status = 'Calibrating...'
139+
for await (const value of calibrator.calibrate(PreflightCalibration.GYROSCOPE)) {
140+
this.calibration_status = value
141+
}
142+
},
143+
renderVec3(value: vec3 | null): string {
144+
if (!value) {
145+
return 'N/A'
146+
}
147+
return [value[0], value[1], value[2]].map((v) => v.toFixed(2)).join(', ')
148+
},
149+
},
150+
151+
})
152+
</script>
153+
154+
<style scoped="true">
155+
.main-container {
156+
display: flex;
157+
flex-direction: column;
158+
align-items: center;
159+
padding: 10px;
160+
}
161+
</style>

0 commit comments

Comments
 (0)