🐾 Updates controller to have command
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
let right: nipplejs.JoystickManager;
|
let right: nipplejs.JoystickManager;
|
||||||
|
|
||||||
let throttle_timing = 40;
|
let throttle_timing = 40;
|
||||||
let data = new Int8Array(7);
|
let data = new Int8Array($outControllerData.length);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
left = nipplejs.create({
|
left = nipplejs.create({
|
||||||
@@ -46,13 +46,14 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateData = () => {
|
const updateData = () => {
|
||||||
data[0] = 0;
|
data[0] = 1;
|
||||||
data[1] = toInt8($input.left.x, -1, 1);
|
data[1] = 0;
|
||||||
data[2] = toInt8($input.left.y, -1, 1);
|
data[2] = toInt8($input.left.x, -1, 1);
|
||||||
data[3] = toInt8($input.right.x, -1, 1);
|
data[3] = toInt8($input.left.y, -1, 1);
|
||||||
data[4] = toInt8($input.right.y, -1, 1);
|
data[4] = toInt8($input.right.x, -1, 1);
|
||||||
data[5] = toInt8($input.height, 0, 100);
|
data[5] = toInt8($input.right.y, -1, 1);
|
||||||
data[6] = toInt8($input.speed, 0, 100);
|
data[6] = toInt8($input.height, 0, 100);
|
||||||
|
data[7] = toInt8($input.speed, 0, 100);
|
||||||
|
|
||||||
outControllerData.set(data);
|
outControllerData.set(data);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export type Modes = (typeof modes)[number];
|
|||||||
|
|
||||||
export const mode: Writable<Modes> = writable('idle');
|
export const mode: Writable<Modes> = writable('idle');
|
||||||
|
|
||||||
export const outControllerData = writable(new Int8Array([0, 0, 0, 0, 0, 70, 0]));
|
export const outControllerData = writable(new Int8Array([0, 0, 0, 0, 0, 0, 70, 0]));
|
||||||
|
|
||||||
export const input: Writable<ControllerInput> = writable({
|
export const input: Writable<ControllerInput> = writable({
|
||||||
left: { x: 0, y: 0 },
|
left: { x: 0, y: 0 },
|
||||||
|
|||||||
+30
-13
@@ -209,13 +209,14 @@ const updateAngles = (angles) => {
|
|||||||
|
|
||||||
const bufferToController = (buffer) => {
|
const bufferToController = (buffer) => {
|
||||||
return {
|
return {
|
||||||
stop: buffer[0],
|
command: buffer[0],
|
||||||
lx: buffer[1],
|
stop: buffer[1],
|
||||||
ly: buffer[2],
|
lx: buffer[2],
|
||||||
rx: buffer[3],
|
ly: buffer[3],
|
||||||
ry: buffer[4],
|
rx: buffer[4],
|
||||||
h: buffer[5],
|
ry: buffer[5],
|
||||||
s: buffer[6],
|
h: buffer[6],
|
||||||
|
s: buffer[7],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -276,15 +277,31 @@ const stand = (client) => {
|
|||||||
// https://www.hindawi.com/journals/cin/2016/9853070/
|
// https://www.hindawi.com/journals/cin/2016/9853070/
|
||||||
|
|
||||||
const step = (model, controller, tick) => {
|
const step = (model, controller, tick) => {
|
||||||
const y1 = -100 * Math.sin(-0.05 * tick) - 150;
|
const arc_height = controller.h;
|
||||||
const y2 = -100 * Math.sin(-0.05 * tick + Math.PI) - 150;
|
const speed = (controller.s + 128) / 255 / 4;
|
||||||
const x1 = Math.abs((tick % 120) - 60) - 60;
|
|
||||||
|
const T_stride_s = 500 / 1000;
|
||||||
|
const overlay = 10 / 100;
|
||||||
|
|
||||||
|
const T_stance_s = T_stride_s * (0.5 + overlay);
|
||||||
|
const T_swing_s = T_stride_s * (0.5 - overlay);
|
||||||
|
|
||||||
|
const x = Math.abs((tick % 200) - 100);
|
||||||
|
|
||||||
|
const y1 = Math.min(
|
||||||
|
Math.max(-arc_height * Math.sin(-speed * tick) - 150, -200),
|
||||||
|
-100
|
||||||
|
);
|
||||||
|
const y2 = Math.min(
|
||||||
|
Math.max(-arc_height * Math.sin(-speed * tick + Math.PI) - 150, -200),
|
||||||
|
-100
|
||||||
|
);
|
||||||
const Lp = [
|
const Lp = [
|
||||||
// -50 is minimum
|
// -50 is minimum
|
||||||
[100, y1, 100, 1],
|
[100, y1, 100, 1],
|
||||||
[100, y2, -100, 1],
|
[100, y2, -100, 1],
|
||||||
[-100, y2, 100, 1],
|
[-65, y2, 100, 1],
|
||||||
[-100, y1, -100, 1],
|
[-65, y1, -100, 1],
|
||||||
];
|
];
|
||||||
|
|
||||||
model.servos.angles = kinematic
|
model.servos.angles = kinematic
|
||||||
@@ -336,7 +353,7 @@ const handelController = (ws, buffer) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleBufferMessage = (ws, buffer) => {
|
const handleBufferMessage = (ws, buffer) => {
|
||||||
if (buffer.length === 6) {
|
if (buffer.length === 8) {
|
||||||
handelController(ws, buffer);
|
handelController(ws, buffer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user