🎨 Fix different typing problems
This commit is contained in:
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import { Err, Ok, type Result } from './utilities'
|
import { Err, Ok, type Result } from './utilities'
|
||||||
import { location } from './stores'
|
import { apiLocation } from './stores'
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
get<TResponse>(endpoint: string, params?: RequestInit) {
|
get<TResponse>(endpoint: string, params?: RequestInit) {
|
||||||
@@ -44,7 +44,7 @@ async function sendRequest<TResponse>(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
response = await fetch(endpoint, request)
|
response = await fetch(endpoint, request)
|
||||||
} catch (error) {
|
} catch {
|
||||||
return Err.new(new Error(), 'An error has occurred')
|
return Err.new(new Error(), 'An error has occurred')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +67,9 @@ async function sendRequest<TResponse>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolveUrl(url: string): string {
|
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
|
const protocol = window.location.protocol
|
||||||
return `${protocol}//${get(location)}${url.startsWith('/') ? '' : '/'}${url}`
|
return `${protocol}//${get(apiLocation)}${url.startsWith('/') ? '' : '/'}${url}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy } from 'svelte'
|
import { onDestroy } from 'svelte'
|
||||||
import { location } from '$lib/stores'
|
import { apiLocation } from '$lib/stores'
|
||||||
|
|
||||||
let source = $state(`${$location}/api/camera/stream`)
|
let source = $state(`${$apiLocation}/api/camera/stream`)
|
||||||
|
|
||||||
onDestroy(() => (source = '#'))
|
onDestroy(() => (source = '#'))
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -59,8 +59,6 @@
|
|||||||
let gui_panel: GUI
|
let gui_panel: GUI
|
||||||
let Throttler = new throttler()
|
let Throttler = new throttler()
|
||||||
|
|
||||||
let feet_trace = new Array(4).fill([])
|
|
||||||
let trace_lines: BufferGeometry<NormalBufferAttributes>[] = []
|
|
||||||
let target: Object3D<Object3DEventMap>
|
let target: Object3D<Object3DEventMap>
|
||||||
|
|
||||||
let target_position = { x: 0, z: 0, yaw: 0 }
|
let target_position = { x: 0, z: 0, yaw: 0 }
|
||||||
@@ -179,7 +177,7 @@
|
|||||||
.addDirectionalLight({ x: 10, y: 20, z: 10, color: 0xffffff, intensity: 3 })
|
.addDirectionalLight({ x: 10, y: 20, z: 10, color: 0xffffff, intensity: 3 })
|
||||||
.addAmbientLight({ color: 0xffffff, intensity: 0.5 })
|
.addAmbientLight({ color: 0xffffff, intensity: 0.5 })
|
||||||
.addFogExp2(0xcccccc, 0.015)
|
.addFogExp2(0xcccccc, 0.015)
|
||||||
.addModel($model)
|
.addModel($model as URDFRobot)
|
||||||
.addTransformControls(sceneManager.model)
|
.addTransformControls(sceneManager.model)
|
||||||
.fillParent()
|
.fillParent()
|
||||||
.addRenderCb(render)
|
.addRenderCb(render)
|
||||||
@@ -193,32 +191,13 @@
|
|||||||
sceneManager.scene.add(target)
|
sceneManager.scene.add(target)
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
sceneManager.addDragControl(updateAngles)
|
sceneManager.addDragControl((angles: Record<string, number>) => {
|
||||||
|
Object.entries(angles).forEach(([name, angle]) => {
|
||||||
|
updateAngles(name, angle)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (sky) sceneManager.addSky()
|
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 = () => {
|
const calculate_kinematics = () => {
|
||||||
@@ -311,7 +290,6 @@
|
|||||||
|
|
||||||
const toes = getToeWorldPositions(robot)
|
const toes = getToeWorldPositions(robot)
|
||||||
|
|
||||||
renderTraceLines(toes)
|
|
||||||
update_camera(robot)
|
update_camera(robot)
|
||||||
update_gait()
|
update_gait()
|
||||||
calculate_kinematics()
|
calculate_kinematics()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Github } from '../icons'
|
import { Github } from '../icons'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
github: { url: string; version: string }
|
github: { url: string; version: string; active?: boolean; href?: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
let { github }: Props = $props()
|
let { github }: Props = $props()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { slide } from 'svelte/transition'
|
import { slide } from 'svelte/transition'
|
||||||
|
|
||||||
let chartElement: HTMLCanvasElement
|
let chartElement: HTMLCanvasElement
|
||||||
let chart: Chart<'line', number[], string>
|
let chart: Chart<'line', number[], number>
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
label: string
|
label: string
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ import { persistentStore } from '$lib/utilities'
|
|||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import { PUBLIC_VITE_USE_HOST_NAME } from '$env/static/public'
|
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', '')
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
servoAngles,
|
servoAngles,
|
||||||
servoAnglesOut,
|
servoAnglesOut,
|
||||||
socket,
|
socket,
|
||||||
location,
|
apiLocation,
|
||||||
useFeatureFlags,
|
useFeatureFlags,
|
||||||
walkGait
|
walkGait
|
||||||
} from '$lib/stores'
|
} from '$lib/stores'
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
const features = useFeatureFlags()
|
const features = useFeatureFlags()
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const ws = $location ? $location : window.location.host
|
const ws = $apiLocation ? $apiLocation : window.location.host
|
||||||
socket.init(`ws://${ws}/api/ws`)
|
socket.init(`ws://${ws}/api/ws`)
|
||||||
|
|
||||||
addEventListeners()
|
addEventListeners()
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import SettingsCard from '$lib/components/SettingsCard.svelte'
|
import SettingsCard from '$lib/components/SettingsCard.svelte'
|
||||||
import { WiFi } from '$lib/components/icons'
|
import { WiFi } from '$lib/components/icons'
|
||||||
import { location, socket } from '$lib/stores'
|
import { apiLocation, socket } from '$lib/stores'
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
const ws = $location ? $location : window.location.host
|
const ws = $apiLocation ? $apiLocation : window.location.host
|
||||||
socket.init(`ws://${ws}/api/ws/events`)
|
socket.init(`ws://${ws}/api/ws/events`)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<label class="label w-32" for="server">Address:</label>
|
<label class="label w-32" for="server">Address:</label>
|
||||||
<input class="input" bind:value={$location} />
|
<input class="input" bind:value={$apiLocation} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-primary" onclick={update}>Update</button>
|
<button class="btn btn-primary" onclick={update}>Update</button>
|
||||||
|
|||||||
@@ -2,7 +2,19 @@
|
|||||||
import { api } from '$lib/api'
|
import { api } from '$lib/api'
|
||||||
import Spinner from '$lib/components/Spinner.svelte'
|
import Spinner from '$lib/components/Spinner.svelte'
|
||||||
import type { CameraSettings } from '$lib/types/models'
|
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 getCameraSettings = async () => {
|
||||||
const result = await api.get<CameraSettings>('/api/camera/settings')
|
const result = await api.get<CameraSettings>('/api/camera/settings')
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleSettings = (data: Record<string, unknown>) => {
|
const handleSettings = (data: Record<string, unknown>) => {
|
||||||
settings = data
|
settings = data as PeripheralsConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
|||||||
@@ -195,8 +195,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($features.bmp) {
|
if ($features.bmp) {
|
||||||
updateChartData(tempChart, $imu.bmp_temp, 'Temperature')
|
updateChartData(tempChart, $imu.bmp_temp)
|
||||||
updateChartData(altitudeChart, $imu.altitude, 'Altitude')
|
updateChartData(altitudeChart, $imu.altitude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user