Fixed up IMU properly this time
This commit is contained in:
@@ -160,6 +160,9 @@ export interface IMUCalibrateData {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
export interface IMUCalibrateExecute {
|
||||
}
|
||||
|
||||
export interface ModeData {
|
||||
mode: ModesEnum;
|
||||
}
|
||||
@@ -274,6 +277,7 @@ export interface WebsocketMessage {
|
||||
pongmsg?: PongMsg | undefined;
|
||||
imu?: IMUData | undefined;
|
||||
imuCalibrate?: IMUCalibrateData | undefined;
|
||||
imuCalibrateExecute?: IMUCalibrateExecute | undefined;
|
||||
mode?: ModeData | undefined;
|
||||
input?: ControllerInputData | undefined;
|
||||
analytics?: AnalyticsData | undefined;
|
||||
@@ -1223,6 +1227,49 @@ export const IMUCalibrateData: MessageFns<IMUCalibrateData> = {
|
||||
},
|
||||
};
|
||||
|
||||
function createBaseIMUCalibrateExecute(): IMUCalibrateExecute {
|
||||
return {};
|
||||
}
|
||||
|
||||
export const IMUCalibrateExecute: MessageFns<IMUCalibrateExecute> = {
|
||||
encode(_: IMUCalibrateExecute, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: BinaryReader | Uint8Array, length?: number): IMUCalibrateExecute {
|
||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||
const end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = createBaseIMUCalibrateExecute();
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
}
|
||||
reader.skip(tag & 7);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(_: any): IMUCalibrateExecute {
|
||||
return {};
|
||||
},
|
||||
|
||||
toJSON(_: IMUCalibrateExecute): unknown {
|
||||
const obj: any = {};
|
||||
return obj;
|
||||
},
|
||||
|
||||
create<I extends Exact<DeepPartial<IMUCalibrateExecute>, I>>(base?: I): IMUCalibrateExecute {
|
||||
return IMUCalibrateExecute.fromPartial(base ?? ({} as any));
|
||||
},
|
||||
fromPartial<I extends Exact<DeepPartial<IMUCalibrateExecute>, I>>(_: I): IMUCalibrateExecute {
|
||||
const message = createBaseIMUCalibrateExecute();
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
function createBaseModeData(): ModeData {
|
||||
return { mode: 0 };
|
||||
}
|
||||
@@ -2832,6 +2879,7 @@ function createBaseWebsocketMessage(): WebsocketMessage {
|
||||
pongmsg: undefined,
|
||||
imu: undefined,
|
||||
imuCalibrate: undefined,
|
||||
imuCalibrateExecute: undefined,
|
||||
mode: undefined,
|
||||
input: undefined,
|
||||
analytics: undefined,
|
||||
@@ -2865,6 +2913,9 @@ export const WebsocketMessage: MessageFns<WebsocketMessage> = {
|
||||
if (message.imuCalibrate !== undefined) {
|
||||
IMUCalibrateData.encode(message.imuCalibrate, writer.uint32(962).fork()).join();
|
||||
}
|
||||
if (message.imuCalibrateExecute !== undefined) {
|
||||
IMUCalibrateExecute.encode(message.imuCalibrateExecute, writer.uint32(970).fork()).join();
|
||||
}
|
||||
if (message.mode !== undefined) {
|
||||
ModeData.encode(message.mode, writer.uint32(1042).fork()).join();
|
||||
}
|
||||
@@ -2953,6 +3004,14 @@ export const WebsocketMessage: MessageFns<WebsocketMessage> = {
|
||||
message.imuCalibrate = IMUCalibrateData.decode(reader, reader.uint32());
|
||||
continue;
|
||||
}
|
||||
case 121: {
|
||||
if (tag !== 970) {
|
||||
break;
|
||||
}
|
||||
|
||||
message.imuCalibrateExecute = IMUCalibrateExecute.decode(reader, reader.uint32());
|
||||
continue;
|
||||
}
|
||||
case 130: {
|
||||
if (tag !== 1042) {
|
||||
break;
|
||||
@@ -3050,6 +3109,9 @@ export const WebsocketMessage: MessageFns<WebsocketMessage> = {
|
||||
pongmsg: isSet(object.pongmsg) ? PongMsg.fromJSON(object.pongmsg) : undefined,
|
||||
imu: isSet(object.imu) ? IMUData.fromJSON(object.imu) : undefined,
|
||||
imuCalibrate: isSet(object.imuCalibrate) ? IMUCalibrateData.fromJSON(object.imuCalibrate) : undefined,
|
||||
imuCalibrateExecute: isSet(object.imuCalibrateExecute)
|
||||
? IMUCalibrateExecute.fromJSON(object.imuCalibrateExecute)
|
||||
: undefined,
|
||||
mode: isSet(object.mode) ? ModeData.fromJSON(object.mode) : undefined,
|
||||
input: isSet(object.input) ? ControllerInputData.fromJSON(object.input) : undefined,
|
||||
analytics: isSet(object.analytics) ? AnalyticsData.fromJSON(object.analytics) : undefined,
|
||||
@@ -3085,6 +3147,9 @@ export const WebsocketMessage: MessageFns<WebsocketMessage> = {
|
||||
if (message.imuCalibrate !== undefined) {
|
||||
obj.imuCalibrate = IMUCalibrateData.toJSON(message.imuCalibrate);
|
||||
}
|
||||
if (message.imuCalibrateExecute !== undefined) {
|
||||
obj.imuCalibrateExecute = IMUCalibrateExecute.toJSON(message.imuCalibrateExecute);
|
||||
}
|
||||
if (message.mode !== undefined) {
|
||||
obj.mode = ModeData.toJSON(message.mode);
|
||||
}
|
||||
@@ -3139,6 +3204,9 @@ export const WebsocketMessage: MessageFns<WebsocketMessage> = {
|
||||
message.imuCalibrate = (object.imuCalibrate !== undefined && object.imuCalibrate !== null)
|
||||
? IMUCalibrateData.fromPartial(object.imuCalibrate)
|
||||
: undefined;
|
||||
message.imuCalibrateExecute = (object.imuCalibrateExecute !== undefined && object.imuCalibrateExecute !== null)
|
||||
? IMUCalibrateExecute.fromPartial(object.imuCalibrateExecute)
|
||||
: undefined;
|
||||
message.mode = (object.mode !== undefined && object.mode !== null) ? ModeData.fromPartial(object.mode) : undefined;
|
||||
message.input = (object.input !== undefined && object.input !== null)
|
||||
? ControllerInputData.fromPartial(object.input)
|
||||
@@ -3744,6 +3812,18 @@ export const protoMetadata: ProtoMetadata = {
|
||||
"reservedRange": [],
|
||||
"reservedName": [],
|
||||
"visibility": 0,
|
||||
}, {
|
||||
"name": "IMUCalibrateExecute",
|
||||
"field": [],
|
||||
"extension": [],
|
||||
"nestedType": [],
|
||||
"enumType": [],
|
||||
"extensionRange": [],
|
||||
"oneofDecl": [],
|
||||
"options": undefined,
|
||||
"reservedRange": [],
|
||||
"reservedName": [],
|
||||
"visibility": 0,
|
||||
}, {
|
||||
"name": "ModeData",
|
||||
"field": [{
|
||||
@@ -4622,6 +4702,18 @@ export const protoMetadata: ProtoMetadata = {
|
||||
"jsonName": "imuCalibrate",
|
||||
"options": undefined,
|
||||
"proto3Optional": false,
|
||||
}, {
|
||||
"name": "imu_calibrate_execute",
|
||||
"number": 121,
|
||||
"label": 1,
|
||||
"type": 11,
|
||||
"typeName": ".socket_message.IMUCalibrateExecute",
|
||||
"extendee": "",
|
||||
"defaultValue": "",
|
||||
"oneofIndex": 0,
|
||||
"jsonName": "imuCalibrateExecute",
|
||||
"options": undefined,
|
||||
"proto3Optional": false,
|
||||
}, {
|
||||
"name": "mode",
|
||||
"number": 130,
|
||||
@@ -4790,8 +4882,8 @@ export const protoMetadata: ProtoMetadata = {
|
||||
"trailingComments": "",
|
||||
"leadingDetachedComments": [],
|
||||
}, {
|
||||
"path": [4, 25],
|
||||
"span": [109, 0, 128, 1],
|
||||
"path": [4, 26],
|
||||
"span": [110, 0, 130, 1],
|
||||
"leadingComments": " WebSocket message wrapper\n Only ONE field will be set at a time (oneof ensures this)\n",
|
||||
"trailingComments": "",
|
||||
"leadingDetachedComments": [],
|
||||
@@ -4810,6 +4902,7 @@ export const protoMetadata: ProtoMetadata = {
|
||||
".socket_message.IMUData": IMUData,
|
||||
".socket_message.StaticSystemInformation": StaticSystemInformation,
|
||||
".socket_message.IMUCalibrateData": IMUCalibrateData,
|
||||
".socket_message.IMUCalibrateExecute": IMUCalibrateExecute,
|
||||
".socket_message.ModeData": ModeData,
|
||||
".socket_message.ControllerInputData": ControllerInputData,
|
||||
".socket_message.AnalyticsData": AnalyticsData,
|
||||
|
||||
@@ -6,23 +6,23 @@
|
||||
import { slide } from 'svelte/transition'
|
||||
import { onDestroy, onMount } from 'svelte'
|
||||
import { socket } from '$lib/stores'
|
||||
import { MessageTopic, type IMUMsg, type IMUCalibrationResult } from '$lib/types/models'
|
||||
import { useFeatureFlags } from '$lib/stores/featureFlags'
|
||||
import { Rotate3d } from '$lib/components/icons'
|
||||
|
||||
import { IMUReport } from '$lib/platform_shared/imu_report';
|
||||
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
||||
import { IMUCalibrateData, IMUCalibrateExecute, IMUData } from '$lib/platform_shared/websocket_message'
|
||||
|
||||
Chart.register(...registerables)
|
||||
|
||||
const features = useFeatureFlags()
|
||||
let intervalId: ReturnType<typeof setInterval> | number
|
||||
let isCalibrating = $state(false)
|
||||
let calibrationResult = $state<IMUCalibrationResult | null>(null)
|
||||
let calibrationResult = $state<IMUCalibrateData | null>(null)
|
||||
|
||||
let angleChartElement: HTMLCanvasElement
|
||||
let tempChartElement: HTMLCanvasElement
|
||||
let altitudeChartElement: HTMLCanvasElement
|
||||
let angleChartElement: HTMLCanvasElement = $state()!
|
||||
let tempChartElement: HTMLCanvasElement = $state()!
|
||||
let altitudeChartElement: HTMLCanvasElement = $state()!
|
||||
|
||||
let angleChart: Chart
|
||||
let tempChart: Chart
|
||||
@@ -77,7 +77,7 @@
|
||||
borderColor: colors.primary,
|
||||
backgroundColor: colors.primary,
|
||||
borderWidth: 2,
|
||||
data: $imu.x,
|
||||
data: $imu.map(datapoint => datapoint.x),
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
@@ -85,7 +85,7 @@
|
||||
borderColor: colors.secondary,
|
||||
backgroundColor: colors.secondary,
|
||||
borderWidth: 2,
|
||||
data: $imu.y,
|
||||
data: $imu.map(datapoint => datapoint.y),
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
@@ -93,7 +93,7 @@
|
||||
borderColor: colors.accent,
|
||||
backgroundColor: colors.accent,
|
||||
borderWidth: 2,
|
||||
data: $imu.z,
|
||||
data: $imu.map(datapoint => datapoint.z),
|
||||
yAxisID: 'y'
|
||||
}
|
||||
]
|
||||
@@ -124,7 +124,7 @@
|
||||
borderColor: colors.secondary,
|
||||
backgroundColor: colors.secondary,
|
||||
borderWidth: 2,
|
||||
data: $imu.bmp_temp,
|
||||
data: $imu.map(datapoint => datapoint.bmpTemp),
|
||||
yAxisID: 'y'
|
||||
}
|
||||
]
|
||||
@@ -155,7 +155,7 @@
|
||||
borderColor: colors.primary,
|
||||
backgroundColor: colors.primary,
|
||||
borderWidth: 2,
|
||||
data: $imu.altitude,
|
||||
data: $imu.map(datapoint => datapoint.altitude),
|
||||
yAxisID: 'y'
|
||||
}
|
||||
]
|
||||
@@ -188,50 +188,55 @@
|
||||
|
||||
const updateData = () => {
|
||||
if ($features.imu) {
|
||||
angleChart.data.labels = $imu.x
|
||||
angleChart.data.datasets[0].data = $imu.x
|
||||
angleChart.data.datasets[1].data = $imu.y
|
||||
angleChart.data.datasets[2].data = $imu.z
|
||||
const x = $imu.map(datapoint => datapoint.x)
|
||||
const y= $imu.map(datapoint => datapoint.y)
|
||||
const z = $imu.map(datapoint => datapoint.z)
|
||||
|
||||
angleChart.data.labels = Array.from({ length: $imu.length }, (_, i) => i + 1)
|
||||
angleChart.data.datasets[0].data = x
|
||||
angleChart.data.datasets[1].data = y
|
||||
angleChart.data.datasets[2].data = z
|
||||
|
||||
const allValues = [...$imu.x, ...$imu.y, ...$imu.z]
|
||||
const allValues = [...x, ...y, ...z]
|
||||
angleChart.options.scales!.y!.min = Math.min(...allValues) - 1
|
||||
angleChart.options.scales!.y!.max = Math.max(...allValues) + 1
|
||||
angleChart.update('none')
|
||||
}
|
||||
|
||||
if ($features.bmp) {
|
||||
updateChartData(tempChart, $imu.bmp_temp)
|
||||
updateChartData(altitudeChart, $imu.altitude)
|
||||
updateChartData(tempChart, $imu.map(datapoint => datapoint.bmpTemp))
|
||||
updateChartData(altitudeChart, $imu.map(datapoint => datapoint.altitude))
|
||||
}
|
||||
}
|
||||
|
||||
const eventListeners: (() => void)[] = [];
|
||||
onMount(() => {
|
||||
socket.on(MessageTopic.imu, (buffer: ArrayBuffer) => {
|
||||
// Temporary conversions here
|
||||
let data = IMUReport.decode(new BinaryReader(new Uint8Array(buffer)))
|
||||
console.log(data)
|
||||
imu.addData(data)
|
||||
})
|
||||
eventListeners.push(...[
|
||||
socket.on(IMUData, (data) => {
|
||||
console.log(data)
|
||||
imu.addData(data)
|
||||
}),
|
||||
|
||||
socket.on(MessageTopic.imuCalibrate, (data: IMUCalibrationResult) => {
|
||||
isCalibrating = false
|
||||
calibrationResult = data
|
||||
})
|
||||
socket.on(IMUCalibrateData, (data) => {
|
||||
isCalibrating = false
|
||||
calibrationResult = data
|
||||
})
|
||||
])
|
||||
|
||||
initializeCharts()
|
||||
intervalId = setInterval(updateData, 200)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
socket.off(MessageTopic.imu)
|
||||
socket.off(MessageTopic.imuCalibrate)
|
||||
for (let offFunction of eventListeners) {
|
||||
offFunction();
|
||||
}
|
||||
clearInterval(intervalId)
|
||||
})
|
||||
|
||||
function startCalibration() {
|
||||
isCalibrating = true
|
||||
calibrationResult = null
|
||||
socket.sendEvent(MessageTopic.imuCalibrate, {})
|
||||
socket.sendEvent(IMUCalibrateExecute, {})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -50,10 +50,7 @@
|
||||
console.log(data);
|
||||
}
|
||||
onMount(() => {
|
||||
|
||||
|
||||
socket.on(IMUData, handleData)
|
||||
return () => socket.off(IMUData, handleData)
|
||||
return socket.on(IMUData, handleData)
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
} from '$lib/components/icons'
|
||||
import StatusItem from '$lib/components/StatusItem.svelte'
|
||||
import { KnownNetworkItem } from '$lib/platform_shared/websocket_message'
|
||||
import { WifiSettings, type WifiStatus } from '$lib/rest_message'
|
||||
import { WifiSettings, type WifiStatus } from '$lib/platform_shared/rest_message'
|
||||
|
||||
let networkEditable: KnownNetworkItem = $state( KnownNetworkItem.create() )
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ message StaticSystemInformation {
|
||||
|
||||
|
||||
message IMUCalibrateData { bool success = 1; }
|
||||
message IMUCalibrateExecute {}
|
||||
message ModeData { ModesEnum mode = 1; }
|
||||
message ControllerInputData {
|
||||
Vector left = 1;
|
||||
@@ -115,6 +116,7 @@ message WebsocketMessage {
|
||||
PongMsg pongmsg = 31;
|
||||
IMUData imu = 110;
|
||||
IMUCalibrateData imu_calibrate = 120;
|
||||
IMUCalibrateExecute imu_calibrate_execute = 121;
|
||||
ModeData mode = 130;
|
||||
ControllerInputData input = 140;
|
||||
AnalyticsData analytics = 150;
|
||||
|
||||
Reference in New Issue
Block a user