🎲 Adds all gait planners for internal kinematics
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
import { lerp, degToRad } from 'three/src/math/MathUtils';
|
import { lerp, degToRad } from 'three/src/math/MathUtils';
|
||||||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
||||||
import Kinematic, { type body_state_t } from '$lib/kinematic';
|
import Kinematic, { type body_state_t } from '$lib/kinematic';
|
||||||
import {EightPhaseWalkState, FourPhaseWalkState, StandState} from '$lib/gait'
|
import {EightPhaseWalkState, FourPhaseWalkState, IdleState, RestState, StandState} from '$lib/gait'
|
||||||
import { radToDeg } from 'three/src/math/MathUtils.js';
|
import { radToDeg } from 'three/src/math/MathUtils.js';
|
||||||
import type { URDFRobot } from 'urdf-loader';
|
import type { URDFRobot } from 'urdf-loader';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
@@ -36,8 +36,13 @@
|
|||||||
let target_position = {x: 0, z: 0, yaw: 0}
|
let target_position = {x: 0, z: 0, yaw: 0}
|
||||||
|
|
||||||
let kinematic = new Kinematic()
|
let kinematic = new Kinematic()
|
||||||
let gaitPlanner = new FourPhaseWalkState()
|
let planners = {
|
||||||
let standState = new StandState()
|
[ModesEnum.Idle]: new IdleState(),
|
||||||
|
[ModesEnum.Rest]: new RestState(),
|
||||||
|
[ModesEnum.Stand]: new StandState(),
|
||||||
|
[ModesEnum.Crawl]: new EightPhaseWalkState(),
|
||||||
|
[ModesEnum.Walk]: new FourPhaseWalkState()
|
||||||
|
}
|
||||||
const dir = [1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1]
|
const dir = [1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1]
|
||||||
const Lp = [
|
const Lp = [
|
||||||
[1, -1, 1, 1],
|
[1, -1, 1, 1],
|
||||||
@@ -244,10 +249,15 @@
|
|||||||
h: controlData[5],
|
h: controlData[5],
|
||||||
s: controlData[6],
|
s: controlData[6],
|
||||||
};
|
};
|
||||||
let planner = get(mode) === ModesEnum.Walk ? gaitPlanner : standState
|
body_state.ym = ((data.h + 128) * 0.75) / 100;
|
||||||
|
let planner = planners[get(mode)]
|
||||||
body_state = planner.step(body_state, data);
|
body_state = planner.step(body_state, data);
|
||||||
|
|
||||||
|
settings.omega = body_state.omega
|
||||||
|
settings.phi = body_state.phi
|
||||||
|
settings.psi = body_state.psi
|
||||||
settings.xm = body_state.xm
|
settings.xm = body_state.xm
|
||||||
|
settings.ym = body_state.ym
|
||||||
settings.zm = body_state.zm
|
settings.zm = body_state.zm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-3
@@ -36,7 +36,7 @@ export abstract class GaitState {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static get default_height() {
|
protected get default_height() {
|
||||||
return 0.5;
|
return 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ export abstract class GaitState {
|
|||||||
console.log('Ending', this.name);
|
console.log('Ending', this.name);
|
||||||
}
|
}
|
||||||
step(body_state: body_state_t, command: ControllerCommand, dt: number = 0.02) {
|
step(body_state: body_state_t, command: ControllerCommand, dt: number = 0.02) {
|
||||||
console.log('Stepping', this.name);
|
return body_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
map_command(command: ControllerCommand): gait_state_t {
|
map_command(command: ControllerCommand): gait_state_t {
|
||||||
@@ -66,6 +66,21 @@ export class IdleState extends GaitState {
|
|||||||
protected name = 'Idle';
|
protected name = 'Idle';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class RestState extends GaitState {
|
||||||
|
protected name = 'Rest';
|
||||||
|
|
||||||
|
step(body_state: body_state_t, command: ControllerCommand, dt: number = 0.02) {
|
||||||
|
body_state.omega = 0;
|
||||||
|
body_state.phi = 0;
|
||||||
|
body_state.psi = 0;
|
||||||
|
body_state.xm = 0;
|
||||||
|
body_state.ym = this.default_height / 2;
|
||||||
|
body_state.zm = 0;
|
||||||
|
body_state.feet = this.default_feet_pos;
|
||||||
|
return body_state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class StandState extends GaitState {
|
export class StandState extends GaitState {
|
||||||
protected name = 'Stand';
|
protected name = 'Stand';
|
||||||
|
|
||||||
@@ -75,7 +90,7 @@ export class StandState extends GaitState {
|
|||||||
body_state.psi = command.ry / 8;
|
body_state.psi = command.ry / 8;
|
||||||
body_state.xm = command.ly / 2 / 100;
|
body_state.xm = command.ly / 2 / 100;
|
||||||
body_state.zm = command.lx / 2 / 100;
|
body_state.zm = command.lx / 2 / 100;
|
||||||
body_state.ym = ((command.h + 128) * 0.75) / 100;
|
body_state.feet = this.default_feet_pos;
|
||||||
return body_state;
|
return body_state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const jointNames = persistentStore('joint_names', []);
|
|||||||
|
|
||||||
export const model = writable();
|
export const model = writable();
|
||||||
|
|
||||||
export const modes = ['idle', 'rest', 'stand', 'walk'] as const;
|
export const modes = ['idle', 'rest', 'stand', 'Crawl', 'walk'] as const;
|
||||||
|
|
||||||
export type Modes = (typeof modes)[number];
|
export type Modes = (typeof modes)[number];
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ export enum ModesEnum {
|
|||||||
Idle,
|
Idle,
|
||||||
Rest,
|
Rest,
|
||||||
Stand,
|
Stand,
|
||||||
|
Crawl,
|
||||||
Walk
|
Walk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user