diff --git a/app/src/lib/gait.ts b/app/src/lib/gait.ts index 6948cfa..81dc894 100644 --- a/app/src/lib/gait.ts +++ b/app/src/lib/gait.ts @@ -1,7 +1,7 @@ import { get } from 'svelte/store' import type { body_state_t } from './kinematic' import { currentKinematic } from './stores/featureFlags' -import { HumanInputData, WalkGaits } from './platform_shared/message' +import { ControllerData, WalkGaits } from './platform_shared/message' export interface gait_state_t { step_height: number @@ -53,7 +53,7 @@ export abstract class GaitState { end() { console.log('Ending', this.name) } - step(body_state: body_state_t, command: HumanInputData, dt: number = 0.02) { + step(body_state: body_state_t, command: ControllerData, dt: number = 0.02) { this.map_command(command) this.body_state = body_state this.dt = dt / 1000 @@ -70,7 +70,7 @@ export abstract class GaitState { return body_state } - map_command(command: HumanInputData) { + map_command(command: ControllerData) { const kin = this.kinematic this.gait_state = { step_height: command.s1 * kin.max_step_height, @@ -85,7 +85,7 @@ export abstract class GaitState { export class IdleState extends GaitState { protected name = 'Idle' - step(body_state: body_state_t, command: HumanInputData) { + step(body_state: body_state_t, command: ControllerData) { super.step(body_state, command) return body_state } @@ -94,7 +94,7 @@ export class IdleState extends GaitState { export class CalibrationState extends GaitState { protected name = 'Calibration' - step(body_state: body_state_t, _command: HumanInputData) { + step(body_state: body_state_t, _command: ControllerData) { super.step(body_state, _command) body_state.omega = 0 body_state.phi = 0 @@ -110,7 +110,7 @@ export class CalibrationState extends GaitState { export class RestState extends GaitState { protected name = 'Rest' - step(body_state: body_state_t, _command: HumanInputData) { + step(body_state: body_state_t, _command: ControllerData) { super.step(body_state, _command) body_state.omega = 0 body_state.phi = 0 @@ -126,7 +126,7 @@ export class RestState extends GaitState { export class StandState extends GaitState { protected name = 'Stand' - step(body_state: body_state_t, command: HumanInputData) { + step(body_state: body_state_t, command: ControllerData) { super.step(body_state, command) const kin = this.kinematic body_state.omega = 0 @@ -189,7 +189,7 @@ export class BezierState extends GaitState { super.end() } - step(body_state: body_state_t, command: HumanInputData, dt: number = 0.02) { + step(body_state: body_state_t, command: ControllerData, dt: number = 0.02) { super.step(body_state, command, dt) const kin = this.kinematic this.body_state.ym = kin.min_body_height + command.height * kin.body_height_range diff --git a/app/src/lib/stores/model-store.ts b/app/src/lib/stores/model-store.ts index 9addc4e..0ecbb52 100644 --- a/app/src/lib/stores/model-store.ts +++ b/app/src/lib/stores/model-store.ts @@ -1,6 +1,6 @@ import Kinematic from '$lib/kinematic' import { - HumanInputData, + ControllerData, KinematicData, ModeData, ModesEnum, @@ -24,8 +24,8 @@ export const walkGait: Writable = writable( export const kinematicData = writable(KinematicData.create()) -export const input: Writable = writable( - HumanInputData.create({ +export const input: Writable = writable( + ControllerData.create({ left: { x: 0, y: 0 }, right: { x: 0, y: 0 }, height: 0.7, diff --git a/app/src/routes/+layout.svelte b/app/src/routes/+layout.svelte index 9a1caa9..524781a 100644 --- a/app/src/routes/+layout.svelte +++ b/app/src/routes/+layout.svelte @@ -23,7 +23,7 @@ import { AnglesData, DownloadOTAData, - HumanInputData, + ControllerData, KinematicData, ModeData, RSSIData, @@ -48,7 +48,7 @@ addEventListeners() input.subscribe(data => - throttler.throttle(() => socket.sendEvent(HumanInputData, data), 100) + throttler.throttle(() => socket.sendEvent(ControllerData, data), 100) ) mode.subscribe(data => socket.sendEvent(ModeData, data)) walkGait.subscribe(data => socket.sendEvent(WalkGaitData, data)) diff --git a/esp32/include/communication/proto_helpers.h b/esp32/include/communication/proto_helpers.h index cb0eb6d..3f7004c 100644 --- a/esp32/include/communication/proto_helpers.h +++ b/esp32/include/communication/proto_helpers.h @@ -32,7 +32,7 @@ DEFINE_MESSAGE_TRAITS(KinematicData, kinematic_data) DEFINE_MESSAGE_TRAITS(IMUCalibrateData, imu_calibrate) DEFINE_MESSAGE_TRAITS(I2CScanData, i2c_scan) DEFINE_MESSAGE_TRAITS(PeripheralSettingsData, peripheral_settings) -DEFINE_MESSAGE_TRAITS(HumanInputData, human_input_data) +DEFINE_MESSAGE_TRAITS(ControllerData, controller_data) DEFINE_MESSAGE_TRAITS(WalkGaitData, walk_gait) DEFINE_MESSAGE_TRAITS(IMUCalibrateExecute, imu_calibrate_execute) DEFINE_MESSAGE_TRAITS(I2CScanDataRequest, i2c_scan_data_request) diff --git a/esp32/include/message_types.h b/esp32/include/message_types.h index 356d959..91ce651 100644 --- a/esp32/include/message_types.h +++ b/esp32/include/message_types.h @@ -5,7 +5,7 @@ struct CommandMsg { float lx, ly, rx, ry, h, s, s1; - void fromProto(const socket_message_HumanInputData& data) { + void fromProto(const socket_message_ControllerData& data) { lx = data.has_left ? data.left.x : 0; ly = data.has_left ? data.left.y : 0; rx = data.has_right ? data.right.x : 0; diff --git a/esp32/include/motion.h b/esp32/include/motion.h index 50ba4a0..1b9c148 100644 --- a/esp32/include/motion.h +++ b/esp32/include/motion.h @@ -23,7 +23,7 @@ class MotionService { void handleAngles(const socket_message_AnglesData& data); - void handleInput(const socket_message_HumanInputData& data); + void handleInput(const socket_message_ControllerData& data); void handleWalkGait(const socket_message_WalkGaitData& data); diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index a6a3f4b..d88fb14 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -136,8 +136,8 @@ void setupServer() { } void setupEventSocket() { - socket.on( - [&](const socket_message_HumanInputData &data, int clientId) { motionService.handleInput(data); }); + socket.on( + [&](const socket_message_ControllerData &data, int clientId) { motionService.handleInput(data); }); socket.on([&](const socket_message_ModeData &data, int clientId) { servoController.setMode(SERVO_CONTROL_STATE::ANGLE); diff --git a/esp32/src/motion.cpp b/esp32/src/motion.cpp index 11f4304..dfab08f 100644 --- a/esp32/src/motion.cpp +++ b/esp32/src/motion.cpp @@ -18,7 +18,7 @@ void MotionService::setState(MotionState* newState) { } } -void MotionService::handleInput(const socket_message_HumanInputData& data) { +void MotionService::handleInput(const socket_message_ControllerData& data) { command.fromProto(data); if (state) state->handleCommand(command); } diff --git a/platform_shared/message.proto b/platform_shared/message.proto index d2578c8..a8a62c0 100644 --- a/platform_shared/message.proto +++ b/platform_shared/message.proto @@ -139,7 +139,7 @@ message DownloadOTAData { string status = 1; int32 progress = 2; string error = message SonarData { string dummy_field = 1; } -message HumanInputData { +message ControllerData { Vector left = 10; Vector right = 11; float height = 20; float speed = 21; float s1 = 22; } @@ -198,7 +198,7 @@ message Message { ServoPWMData servo_pwm = 210; ServoStateData servo_state = 211; WifiSettingsData wifi_settings = 240; - HumanInputData human_input_data = 250; + ControllerData controller_data = 250; RSSIData rssi = 260; } }