✨ Refactors and adds new mode concept
This commit is contained in:
+11
-2
@@ -1,11 +1,20 @@
|
||||
export type vector = { x: number; y: number };
|
||||
|
||||
export interface ControllerInput {
|
||||
left: vector;
|
||||
right: vector;
|
||||
height: number;
|
||||
speed: number;
|
||||
}
|
||||
|
||||
export type angles = number[] | Int16Array;
|
||||
|
||||
type AnglesData = {
|
||||
export type AnglesData = {
|
||||
type: 'angles';
|
||||
data: angles;
|
||||
};
|
||||
|
||||
type LogData = {
|
||||
export type LogData = {
|
||||
type: 'log';
|
||||
data: string;
|
||||
};
|
||||
|
||||
@@ -39,7 +39,9 @@ class SocketService {
|
||||
}
|
||||
|
||||
public addPublisher(store: Writable<WebsocketOutData>, type?: string) {
|
||||
store.subscribe((data) => this.send(type ? JSON.stringify({ type, data }) : data));
|
||||
const publish = (data: WebsocketOutData) =>
|
||||
this.send(type ? JSON.stringify({ type, data }) : data);
|
||||
store.subscribe(publish);
|
||||
}
|
||||
|
||||
private handleConnected(): void {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './socket-store';
|
||||
export * from './logging-store';
|
||||
export * from './model-store';
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import type { ControllerInput } from '$lib/models';
|
||||
import { persistentStore } from '$lib/utilities';
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
|
||||
export const emulateModel = writable(true);
|
||||
|
||||
export const input = writable({
|
||||
export const jointNames = persistentStore('joint_names', []);
|
||||
|
||||
export const model = writable();
|
||||
|
||||
export const modes = ['idle', 'stand', 'walk'] as const;
|
||||
|
||||
export type Modes = (typeof modes)[number];
|
||||
|
||||
export const mode: Writable<Modes> = writable('idle');
|
||||
|
||||
export const outControllerData = writable(new Int8Array([0, 0, 0, 0, 0, 70, 0]));
|
||||
|
||||
export const input: Writable<ControllerInput> = writable({
|
||||
left: { x: 0, y: 0 },
|
||||
right: { x: 0, y: 0 },
|
||||
height: 70,
|
||||
speed: 0
|
||||
});
|
||||
|
||||
export const outControllerData = writable(new Int8Array([0, 0, 0, 0, 0, 70, 0]));
|
||||
|
||||
export const jointNames = persistentStore('joint_names', []);
|
||||
|
||||
export const model = writable();
|
||||
@@ -5,7 +5,7 @@ export const toUint8 = (number: number, min: number, max: number) => {
|
||||
};
|
||||
|
||||
export const toInt8 = (number: number, min: number, max: number) => {
|
||||
number = Math.max(min, Math.min(max, number));
|
||||
let scaled = ((number - min) / (max - min)) * 255 - 128;
|
||||
return Math.max(-128, Math.min(127, Math.round(scaled))) | 0;
|
||||
};
|
||||
number = Math.max(min, Math.min(max, number));
|
||||
let scaled = ((number - min) / (max - min)) * 255 - 128;
|
||||
return Math.max(-128, Math.min(127, Math.round(scaled))) | 0;
|
||||
};
|
||||
|
||||
@@ -3,3 +3,7 @@ export const humanFileSize = (size: number): string => {
|
||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||
return Number((size / Math.pow(1024, i)).toFixed(2)) * 1 + units[i];
|
||||
};
|
||||
|
||||
export const capitalize = (str: string): string => {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user