Skip to content

Commit 12484e5

Browse files
committed
temp fix for reversed axies
1 parent 566a3e1 commit 12484e5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

frontend/src/js/frontendConsts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const EMOJI_MAP = ["🏔", "🏎", "🚃", "🕤", "🐔", "🛤", "🚖"
1919
export const MEMORABLE_PEER_ID_OFFSET = 74646;
2020

2121
export const PING_INTERVAL = 1000 // 1 second in ms
22-
export const MOVE_MSG_TIMEOUT = 800 // 0.8 seconds in ms
22+
export const MOVE_MSG_TIMEOUT = 300 // 0.8 seconds in ms
2323

2424
export enum ConnectionState {
2525
connecting = "Connecting",

frontend/src/js/rovActions.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { calculateDesiredMotion } from "./rovUtil";
88
import type { buttonChangeDetails } from "virtual-gamepad-lib";
99
import { ConnectionStates } from "./shared/consts";
1010
import type { FlightMode } from "./shared/mavlink2RestMessages";
11-
import { GPAD_STANDARD_BUTTON_INDEX, GPAD_STANDARD_BUTTON_INDEX_TO_MAVLINK_INDEX, MOVE_MSG_TIMEOUT } from "./frontendConsts";
11+
import { GPAD_STANDARD_BUTTON_INDEX, GPAD_STANDARD_BUTTON_INDEX_TO_MAVLINK_INDEX, MOVE_MSG_TIMEOUT, PING_INTERVAL } from "./frontendConsts";
1212

1313
class RovActionsClass {
1414

@@ -32,6 +32,8 @@ class RovActionsClass {
3232
const BTN_Y = GPAD_STANDARD_BUTTON_INDEX.Y
3333
const BTN_LT = GPAD_STANDARD_BUTTON_INDEX.LT
3434
const BTN_RT = GPAD_STANDARD_BUTTON_INDEX.RT
35+
const BTN_RB = GPAD_STANDARD_BUTTON_INDEX.RB
36+
const BTN_LB = GPAD_STANDARD_BUTTON_INDEX.LB
3537

3638
if (buttonsChangedMask[BTN_A] && buttonsChangedMask[BTN_A].released) {
3739
this.takeControl()
@@ -47,7 +49,8 @@ class RovActionsClass {
4749
// do something with throttle
4850
}
4951

50-
const rawExcludedButtons = [BTN_A, BTN_B, BTN_LT, BTN_RT];
52+
// FIXME: this is a hack to get the buttons to work with the mavlink message
53+
const rawExcludedButtons = [BTN_A, BTN_B, BTN_LT, BTN_RT, BTN_LB, BTN_RB];
5154
const pressedButtons = buttonsChangedMask.map((val, index) => {
5255
if (val === false) return false;
5356
if (rawExcludedButtons.includes(index)) return false;
@@ -90,7 +93,7 @@ class RovActionsClass {
9093
this.requiredMsgsLoopIntervalId = Number(setInterval(() => {
9194
if (frontendConnMngr.connectionState.get() != ConnectionStates.connected) return;
9295
const now = Date.now();
93-
if (now - this.lastPingTime > MOVE_MSG_TIMEOUT) {
96+
if (now - this.lastPingTime > PING_INTERVAL) {
9497
frontendRovMsgHandler.sendRovMessage({ Ping: { Time: Date.now() } }, null);
9598
this.lastPingTime = now;
9699
}
@@ -132,13 +135,15 @@ class RovActionsClass {
132135
}
133136

134137
moveRov(VelocityX, VelocityY, VelocityZ, AngularVelocityYaw, btnBitmask: number = -1) {
138+
// FIXME: this is a hack to get the buttons to work with the mavlink message
135139
const ButtonBitmask = btnBitmask === -1 ? this.lastMove.ButtonBitmask : btnBitmask;
136140
const movementDelta = (VelocityX - this.lastMove.VelocityX) + (VelocityY - this.lastMove.VelocityY) + (VelocityZ - this.lastMove.VelocityZ) + (AngularVelocityYaw - this.lastMove.AngularVelocityYaw);
137141
const totalMovement = Math.abs(VelocityX) + Math.abs(VelocityY) + Math.abs(VelocityZ) + Math.abs(AngularVelocityYaw);
138-
const timeSinceLastMoveCmd = Date.now() - this.lastMovementTime;
139-
if (totalMovement > 0.1 && movementDelta < 0.01 && timeSinceLastMoveCmd < 400) return;
140-
frontendRovMsgHandler.sendRovMessage({ Move: { VelocityX, VelocityY, VelocityZ, AngularVelocityYaw } }, null);
141-
this.lastMove = { VelocityX, VelocityY, VelocityZ, AngularVelocityYaw, ButtonBitmask };
142+
// const timeSinceLastMoveCmd = Date.now() - this.lastMovementTime;
143+
// if (totalMovement > 0.1 && movementDelta < 0.01 && timeSinceLastMoveCmd < 400) return;
144+
const move = { VelocityX: VelocityY * 2, VelocityY: VelocityX, VelocityZ, AngularVelocityYaw, ButtonBitmask }
145+
frontendRovMsgHandler.sendRovMessage({ Move: move }, null);
146+
this.lastMove = move;
142147
this.lastMovementTime = Date.now();
143148
}
144149

0 commit comments

Comments
 (0)