From f25aba5f29accfa50830712a566de27f30a40d8c Mon Sep 17 00:00:00 2001 From: Niklas Jensen Date: Thu, 1 Jan 2026 23:32:11 +0100 Subject: [PATCH] Fixed the controls and cleaned up some lookup tables --- .../lib/platform_shared/websocket_message.ts | 136 +++++++++++++++++- app/src/lib/stores/model-store.ts | 52 +++---- app/src/routes/controller/Controls.svelte | 68 +++++---- platform_shared/websocket_message.proto | 28 +++- 4 files changed, 228 insertions(+), 56 deletions(-) diff --git a/app/src/lib/platform_shared/websocket_message.ts b/app/src/lib/platform_shared/websocket_message.ts index cb5acc7..c6f2e6f 100644 --- a/app/src/lib/platform_shared/websocket_message.ts +++ b/app/src/lib/platform_shared/websocket_message.ts @@ -67,6 +67,39 @@ export function modesEnumToJSON(object: ModesEnum): string { } } +export enum WalkGaits { + TROT = 0, + CRAWL = 1, + UNRECOGNIZED = -1, +} + +export function walkGaitsFromJSON(object: any): WalkGaits { + switch (object) { + case 0: + case "TROT": + return WalkGaits.TROT; + case 1: + case "CRAWL": + return WalkGaits.CRAWL; + case -1: + case "UNRECOGNIZED": + default: + return WalkGaits.UNRECOGNIZED; + } +} + +export function walkGaitsToJSON(object: WalkGaits): string { + switch (object) { + case WalkGaits.TROT: + return "TROT"; + case WalkGaits.CRAWL: + return "CRAWL"; + case WalkGaits.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + export interface Vector { x: number; y: number; @@ -200,6 +233,10 @@ export interface SystemInformation { staticSystemInformation: StaticSystemInformation | undefined; } +export interface WalkGaitData { + gait: WalkGaits; +} + export interface SubscribeNotification { tag: number; } @@ -2326,6 +2363,64 @@ export const SystemInformation: MessageFns = { }, }; +function createBaseWalkGaitData(): WalkGaitData { + return { gait: 0 }; +} + +export const WalkGaitData: MessageFns = { + encode(message: WalkGaitData, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.gait !== 0) { + writer.uint32(8).int32(message.gait); + } + return writer; + }, + + decode(input: BinaryReader | Uint8Array, length?: number): WalkGaitData { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseWalkGaitData(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + if (tag !== 8) { + break; + } + + message.gait = reader.int32() as any; + continue; + } + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skip(tag & 7); + } + return message; + }, + + fromJSON(object: any): WalkGaitData { + return { gait: isSet(object.gait) ? walkGaitsFromJSON(object.gait) : 0 }; + }, + + toJSON(message: WalkGaitData): unknown { + const obj: any = {}; + if (message.gait !== 0) { + obj.gait = walkGaitsToJSON(message.gait); + } + return obj; + }, + + create, I>>(base?: I): WalkGaitData { + return WalkGaitData.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): WalkGaitData { + const message = createBaseWalkGaitData(); + message.gait = object.gait ?? 0; + return message; + }, +}; + function createBaseSubscribeNotification(): SubscribeNotification { return { tag: 0 }; } @@ -4017,6 +4112,30 @@ export const protoMetadata: ProtoMetadata = { "reservedRange": [], "reservedName": [], "visibility": 0, + }, { + "name": "WalkGaitData", + "field": [{ + "name": "gait", + "number": 1, + "label": 1, + "type": 14, + "typeName": ".WalkGaits", + "extendee": "", + "defaultValue": "", + "oneofIndex": 0, + "jsonName": "gait", + "options": undefined, + "proto3Optional": false, + }], + "extension": [], + "nestedType": [], + "enumType": [], + "extensionRange": [], + "oneofDecl": [], + "options": undefined, + "reservedRange": [], + "reservedName": [], + "visibility": 0, }, { "name": "SubscribeNotification", "field": [{ @@ -4296,6 +4415,17 @@ export const protoMetadata: ProtoMetadata = { "reservedRange": [], "reservedName": [], "visibility": 0, + }, { + "name": "WalkGaits", + "value": [{ "name": "TROT", "number": 0, "options": undefined }, { + "name": "CRAWL", + "number": 1, + "options": undefined, + }], + "options": undefined, + "reservedRange": [], + "reservedName": [], + "visibility": 0, }], "service": [], "extension": [], @@ -4308,8 +4438,8 @@ export const protoMetadata: ProtoMetadata = { "trailingComments": "", "leadingDetachedComments": [], }, { - "path": [4, 23], - "span": [87, 0, 105, 1], + "path": [4, 24], + "span": [94, 0, 112, 1], "leadingComments": " WebSocket message wrapper\n Only ONE field will be set at a time (oneof ensures this)\n", "trailingComments": "", "leadingDetachedComments": [], @@ -4320,6 +4450,7 @@ export const protoMetadata: ProtoMetadata = { }, references: { ".ModesEnum": ModesEnum, + ".WalkGaits": WalkGaits, ".Vector": Vector, ".I2CDevice": I2CDevice, ".PinConfig": PinConfig, @@ -4339,6 +4470,7 @@ export const protoMetadata: ProtoMetadata = { ".SonarData": SonarData, ".HumanInputData": HumanInputData, ".SystemInformation": SystemInformation, + ".WalkGaitData": WalkGaitData, ".SubscribeNotification": SubscribeNotification, ".UnsubscribeNotification": UnsubscribeNotification, ".PingMsg": PingMsg, diff --git a/app/src/lib/stores/model-store.ts b/app/src/lib/stores/model-store.ts index 9999c38..f31f592 100644 --- a/app/src/lib/stores/model-store.ts +++ b/app/src/lib/stores/model-store.ts @@ -1,4 +1,4 @@ -import { HumanInputData, ModeData, ModesEnum } from '$lib/platform_shared/websocket_message' +import { HumanInputData, ModeData, ModesEnum, WalkGaitData, WalkGaits } from '$lib/platform_shared/websocket_message' import { persistentStore } from '$lib/utilities/svelte-utilities' import { writable, type Writable } from 'svelte/store' @@ -8,34 +8,38 @@ export const jointNames = persistentStore('joint_names', []) export const model = writable() -export const modes = ['deactivated', 'idle', 'calibration', 'rest', 'stand', 'walk'] as const - -export type Modes = (typeof modes)[number] - - - -export enum WalkGaits { - Trot = 0, - Crawl = 1 -} - -export const walkGaits = ['trot', 'crawl'] as const - -export const walkGaitLabels: Record = { - [WalkGaits.Trot]: 'Trot', - [WalkGaits.Crawl]: 'Crawl' -} - -export const walkGaitToMode = (gait: WalkGaits): 'trot' | 'crawl' => { - return gait === WalkGaits.Trot ? 'trot' : 'crawl' -} - export const mode: Writable = writable(ModeData.create({ mode: ModesEnum.DEACTIVATED })) -export const walkGait: Writable = writable(WalkGaits.Trot) +export const walkGait: Writable = writable( WalkGaitData.create({gait: WalkGaits.TROT }) ) export const outControllerData = writable( HumanInputData.create( {left: {x:0,y:0}, right: {x:0,y:0}, height:0, s1:0, speed:0} ) ) export const kinematicData = writable([0, 0, 0, 0, 1, 0]) export const input: Writable = writable( HumanInputData.create( {left: {x:0,y:0}, right: {x:0,y:0}, height:0, s1:0, speed:0} ) ) + + +// Following code is generated from CLAUDE CODE +// Auto-generate modes array from ModesEnum (excluding UNRECOGNIZED) +export const modes = Object.values(ModesEnum) + .filter((v): v is ModesEnum => typeof v === 'number' && v !== ModesEnum.UNRECOGNIZED) + +// Auto-generate mode labels from enum keys +export const modeLabels: Record = Object.entries(ModesEnum) + .filter(([_, v]) => typeof v === 'number' && v !== ModesEnum.UNRECOGNIZED) + .reduce((acc, [key, value]) => { + acc[value as ModesEnum] = key.charAt(0) + key.slice(1).toLowerCase() + return acc + }, {} as Record) + +// Auto-generate walk gaits array from WalkGaits enum (excluding UNRECOGNIZED) +export const walkGaits = Object.values(WalkGaits) + .filter((v): v is WalkGaits => typeof v === 'number' && v !== WalkGaits.UNRECOGNIZED) + +// Auto-generate walk gait labels from enum keys +export const walkGaitLabels: Record = Object.entries(WalkGaits) + .filter(([_, v]) => typeof v === 'number' && v !== WalkGaits.UNRECOGNIZED) + .reduce((acc, [key, value]) => { + acc[value as WalkGaits] = key.charAt(0) + key.slice(1).toLowerCase() + return acc + }, {} as Record) diff --git a/app/src/routes/controller/Controls.svelte b/app/src/routes/controller/Controls.svelte index af14a2b..e00b145 100644 --- a/app/src/routes/controller/Controls.svelte +++ b/app/src/routes/controller/Controls.svelte @@ -1,27 +1,37 @@ @@ -150,26 +160,24 @@ {#each modes as modeValue (modeValue)} {/each} - {#if $mode === ModesEnum.Walk} + {#if $mode.mode === ModesEnum.WALK}
- {#each Object.values(WalkGaits) as gaitValue (gaitValue)} - {#if typeof gaitValue === 'number'} - - {/if} + {#each walkGaits as gaitValue (gaitValue)} + {/each}
@@ -182,7 +190,8 @@ min="0" step="0.01" max="1" - oninput={e => handleRange(Number((e.target as HTMLInputElement).value), 's1')} + oninput={e => + handleRange(Number((e.target as HTMLInputElement).value), 's1')} class="range range-xs range-primary" /> @@ -194,7 +203,8 @@ min="0" step="0.01" max="1" - oninput={e => handleRange(Number((e.target as HTMLInputElement).value), 'speed')} + oninput={e => + handleRange(Number((e.target as HTMLInputElement).value), 'speed')} class="range range-xs range-primary" /> diff --git a/platform_shared/websocket_message.proto b/platform_shared/websocket_message.proto index 7c489de..ed55beb 100644 --- a/platform_shared/websocket_message.proto +++ b/platform_shared/websocket_message.proto @@ -13,6 +13,7 @@ message IMUData { float temp = 4; } +DEACTIVATED = 0; enum ModesEnum { DEACTIVATED = 0; IDLE = 1; @@ -21,6 +22,22 @@ enum ModesEnum { STAND = 4; WALK = 5; } +message StaticSystemInformation { + string esp_platform = 1; + string firmware_version = 2; + uint32 cpu_freq_mhz = 3; + string cpu_type = 4; + int32 cpu_rev = 5; + uint32 cpu_cores = 6; + uint32 sketch_size = 7; + uint32 free_sketch_space = 8; + string sdk_version = 9; + string arduino_version = 10; + uint32 flash_chip_size = 11; + uint32 flash_chip_speed = 12; + string cpu_reset_reason = 13; +} + message IMUCalibrateData { bool success = 1; } message ModeData { ModesEnum mode = 1; } @@ -56,7 +73,16 @@ message SonarData { string dummy_field = 1; } message HumanInputData { Vector left = 10; Vector right = 11; float height = 20; float speed = 21; float s1 = 22; } - +message SystemInformation { + AnalyticsData analytics_data = 1; StaticSystemInformation static_system_information = 2; +} +enum WalkGaits { + TROT = 0; + CRAWL = 1; +} +message WalkGaitData { + WalkGaits gait = 1; +} message SubscribeNotification { int32 tag = 1; } message UnsubscribeNotification {int32 tag = 1; }