From 89704573537ea3effe46f8cc97e7e4abaf43900c Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 14 Oct 2025 20:01:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Fix=20different=20typing=20probl?= =?UTF-8?q?ems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/api.ts | 8 ++--- app/src/lib/components/Stream.svelte | 4 +-- app/src/lib/components/Visualization.svelte | 34 ++++--------------- .../lib/components/menu/GithubButton.svelte | 2 +- .../lib/components/widget/ChartWidget.svelte | 2 +- app/src/lib/stores/location-store.ts | 3 +- app/src/routes/+layout.svelte | 4 +-- app/src/routes/connection/Connection.svelte | 6 ++-- .../peripherals/camera/CameraSetting.svelte | 14 +++++++- .../routes/peripherals/i2c/i2cSetting.svelte | 2 +- app/src/routes/peripherals/imu/imu.svelte | 4 +-- 11 files changed, 37 insertions(+), 46 deletions(-) diff --git a/app/src/lib/api.ts b/app/src/lib/api.ts index 00956e1..31ab1f9 100644 --- a/app/src/lib/api.ts +++ b/app/src/lib/api.ts @@ -1,6 +1,6 @@ import { get } from 'svelte/store' import { Err, Ok, type Result } from './utilities' -import { location } from './stores' +import { apiLocation } from './stores' export const api = { get(endpoint: string, params?: RequestInit) { @@ -44,7 +44,7 @@ async function sendRequest( try { response = await fetch(endpoint, request) - } catch (error) { + } catch { return Err.new(new Error(), 'An error has occurred') } @@ -67,9 +67,9 @@ async function sendRequest( } function resolveUrl(url: string): string { - if (url.startsWith('http') || !get(location)) return url + if (url.startsWith('http') || !get(apiLocation)) return url const protocol = window.location.protocol - return `${protocol}//${get(location)}${url.startsWith('/') ? '' : '/'}${url}` + return `${protocol}//${get(apiLocation)}${url.startsWith('/') ? '' : '/'}${url}` } export class ApiError extends Error { diff --git a/app/src/lib/components/Stream.svelte b/app/src/lib/components/Stream.svelte index e4b51cd..2b4369f 100644 --- a/app/src/lib/components/Stream.svelte +++ b/app/src/lib/components/Stream.svelte @@ -1,8 +1,8 @@ diff --git a/app/src/lib/components/Visualization.svelte b/app/src/lib/components/Visualization.svelte index ff76e47..3ca6797 100644 --- a/app/src/lib/components/Visualization.svelte +++ b/app/src/lib/components/Visualization.svelte @@ -59,8 +59,6 @@ let gui_panel: GUI let Throttler = new throttler() - let feet_trace = new Array(4).fill([]) - let trace_lines: BufferGeometry[] = [] let target: Object3D let target_position = { x: 0, z: 0, yaw: 0 } @@ -179,7 +177,7 @@ .addDirectionalLight({ x: 10, y: 20, z: 10, color: 0xffffff, intensity: 3 }) .addAmbientLight({ color: 0xffffff, intensity: 0.5 }) .addFogExp2(0xcccccc, 0.015) - .addModel($model) + .addModel($model as URDFRobot) .addTransformControls(sceneManager.model) .fillParent() .addRenderCb(render) @@ -193,32 +191,13 @@ sceneManager.scene.add(target) if (debug) { - sceneManager.addDragControl(updateAngles) + sceneManager.addDragControl((angles: Record) => { + Object.entries(angles).forEach(([name, angle]) => { + updateAngles(name, angle) + }) + }) } if (sky) sceneManager.addSky() - - for (let i = 0; i < 4; i++) { - const geometry = new BufferGeometry() - const material = new LineBasicMaterial({ color: extractFootColor() }) - const line = new Line(geometry, material) - trace_lines.push(geometry) - sceneManager.scene.add(line) - } - } - - const renderTraceLines = (foot_positions: Vector3[]) => { - if (!settings['Trace feet']) { - if (!feet_trace.length) return - trace_lines.forEach((line, i) => line.setFromPoints(feet_trace[i].slice(-1))) - feet_trace = new Array(4).fill([]) - return - } - - trace_lines.forEach((line, i) => { - feet_trace[i].push(foot_positions[i]) - feet_trace[i] = feet_trace[i].slice(-settings['Trace points']) - line.setFromPoints(feet_trace[i]) - }) } const calculate_kinematics = () => { @@ -311,7 +290,6 @@ const toes = getToeWorldPositions(robot) - renderTraceLines(toes) update_camera(robot) update_gait() calculate_kinematics() diff --git a/app/src/lib/components/menu/GithubButton.svelte b/app/src/lib/components/menu/GithubButton.svelte index 33be628..b1bebe4 100644 --- a/app/src/lib/components/menu/GithubButton.svelte +++ b/app/src/lib/components/menu/GithubButton.svelte @@ -2,7 +2,7 @@ import { Github } from '../icons' interface Props { - github: { url: string; version: string } + github: { url: string; version: string; active?: boolean; href?: string } } let { github }: Props = $props() diff --git a/app/src/lib/components/widget/ChartWidget.svelte b/app/src/lib/components/widget/ChartWidget.svelte index bdb43c4..74f1dae 100644 --- a/app/src/lib/components/widget/ChartWidget.svelte +++ b/app/src/lib/components/widget/ChartWidget.svelte @@ -6,7 +6,7 @@ import { slide } from 'svelte/transition' let chartElement: HTMLCanvasElement - let chart: Chart<'line', number[], string> + let chart: Chart<'line', number[], number> interface Props { label: string diff --git a/app/src/lib/stores/location-store.ts b/app/src/lib/stores/location-store.ts index d0d044f..908ec7c 100644 --- a/app/src/lib/stores/location-store.ts +++ b/app/src/lib/stores/location-store.ts @@ -2,4 +2,5 @@ import { persistentStore } from '$lib/utilities' import { writable } from 'svelte/store' import { PUBLIC_VITE_USE_HOST_NAME } from '$env/static/public' -export const location = PUBLIC_VITE_USE_HOST_NAME ? writable('') : persistentStore('location', '') +export const apiLocation = + PUBLIC_VITE_USE_HOST_NAME ? writable('') : persistentStore('location', '') diff --git a/app/src/routes/+layout.svelte b/app/src/routes/+layout.svelte index 4d8fad0..efe2843 100644 --- a/app/src/routes/+layout.svelte +++ b/app/src/routes/+layout.svelte @@ -18,7 +18,7 @@ servoAngles, servoAnglesOut, socket, - location, + apiLocation, useFeatureFlags, walkGait } from '$lib/stores' @@ -34,7 +34,7 @@ const features = useFeatureFlags() onMount(async () => { - const ws = $location ? $location : window.location.host + const ws = $apiLocation ? $apiLocation : window.location.host socket.init(`ws://${ws}/api/ws`) addEventListeners() diff --git a/app/src/routes/connection/Connection.svelte b/app/src/routes/connection/Connection.svelte index 0c91f88..1b05565 100644 --- a/app/src/routes/connection/Connection.svelte +++ b/app/src/routes/connection/Connection.svelte @@ -1,10 +1,10 @@ @@ -19,7 +19,7 @@
- +
diff --git a/app/src/routes/peripherals/camera/CameraSetting.svelte b/app/src/routes/peripherals/camera/CameraSetting.svelte index 043a6cc..2287680 100644 --- a/app/src/routes/peripherals/camera/CameraSetting.svelte +++ b/app/src/routes/peripherals/camera/CameraSetting.svelte @@ -2,7 +2,19 @@ import { api } from '$lib/api' import Spinner from '$lib/components/Spinner.svelte' import type { CameraSettings } from '$lib/types/models' - let settings: CameraSettings = $state() + let settings: CameraSettings = $state({ + brightness: 0, + contrast: 0, + framesize: 0, + vflip: false, + hmirror: false, + special_effect: 0, + quality: 0, + saturation: 0, + sharpness: 0, + denoise: 0, + wb_mode: 0 + }) const getCameraSettings = async () => { const result = await api.get('/api/camera/settings') diff --git a/app/src/routes/peripherals/i2c/i2cSetting.svelte b/app/src/routes/peripherals/i2c/i2cSetting.svelte index 3fb88f4..bdf55a7 100644 --- a/app/src/routes/peripherals/i2c/i2cSetting.svelte +++ b/app/src/routes/peripherals/i2c/i2cSetting.svelte @@ -16,7 +16,7 @@ }) const handleSettings = (data: Record) => { - settings = data + settings = data as PeripheralsConfiguration } const handleSave = () => { diff --git a/app/src/routes/peripherals/imu/imu.svelte b/app/src/routes/peripherals/imu/imu.svelte index 59cb96b..f038a8e 100644 --- a/app/src/routes/peripherals/imu/imu.svelte +++ b/app/src/routes/peripherals/imu/imu.svelte @@ -195,8 +195,8 @@ } if ($features.bmp) { - updateChartData(tempChart, $imu.bmp_temp, 'Temperature') - updateChartData(altitudeChart, $imu.altitude, 'Altitude') + updateChartData(tempChart, $imu.bmp_temp) + updateChartData(altitudeChart, $imu.altitude) } }