Skip to content

Commit 72a20da

Browse files
committed
Synchronize gamepad-drilling with Drill panel
1 parent 16a9644 commit 72a20da

4 files changed

Lines changed: 180 additions & 61 deletions

File tree

kalman_gs/node_project/src/common/gamepad-drilling.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ import { Topic } from 'roslib';
55
const RATE = 10;
66
const MAX_SPEED = 100;
77

8+
type DrillGamepadUpdate = {
9+
bridgeB?: number;
10+
bridgeC?: number;
11+
autonomy?: 0 | 1 | 2;
12+
weightRequest?: 0 | 1;
13+
};
14+
815
const clampSpeed = (value: number) => Math.max(-MAX_SPEED, Math.min(MAX_SPEED, Math.round(value * MAX_SPEED)));
916

17+
const dispatchDrillGamepadUpdate = (detail: DrillGamepadUpdate) => {
18+
window.dispatchEvent(new CustomEvent<DrillGamepadUpdate>('drill-gamepad-update', { detail }));
19+
};
20+
1021
window.addEventListener('ros-connect', () => {
1122
const drillBTopic = new Topic<{ data: number }>({
1223
ros,
@@ -43,10 +54,12 @@ window.addEventListener('ros-connect', () => {
4354

4455
if (bridgeB !== lastBridgeB) {
4556
drillBTopic.publish({ data: bridgeB });
57+
dispatchDrillGamepadUpdate({ bridgeB });
4658
lastBridgeB = bridgeB;
4759
}
4860
if (bridgeC !== lastBridgeC) {
4961
drillCTopic.publish({ data: bridgeC });
62+
dispatchDrillGamepadUpdate({ bridgeC });
5063
lastBridgeC = bridgeC;
5164
}
5265

@@ -58,19 +71,24 @@ window.addEventListener('ros-connect', () => {
5871

5972
if (stopButton > 0 && lastStopButton === 0) {
6073
drillAutonomyTopic.publish({ data: 0 });
74+
dispatchDrillGamepadUpdate({ autonomy: 0 });
6175
}
6276
if (drillButton > 0 && lastDrillButton === 0) {
6377
drillAutonomyTopic.publish({ data: 1 });
78+
dispatchDrillGamepadUpdate({ autonomy: 1 });
6479
}
6580
if (homeButton > 0 && lastHomeButton === 0) {
6681
drillAutonomyTopic.publish({ data: 2 });
82+
dispatchDrillGamepadUpdate({ autonomy: 2 });
6783
}
6884

6985
if (tareButton > 0 && lastTareButton === 0) {
7086
drillWeightReqTopic.publish({ data: 0 });
87+
dispatchDrillGamepadUpdate({ weightRequest: 0 });
7188
}
7289
if (weighButton > 0 && lastWeighButton === 0) {
7390
drillWeightReqTopic.publish({ data: 1 });
91+
dispatchDrillGamepadUpdate({ weightRequest: 1 });
7492
}
7593

7694
lastStopButton = stopButton;
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
.button {
2-
display: flex;
3-
justify-content: center;
4-
align-items: center;
5-
background-color: var(--interactive);
6-
padding: 3px;
7-
margin-top: 5px;
8-
margin-bottom: 5px;
9-
cursor: pointer;
10-
transition: background-color 0.1s;
11-
height: calc(1em + 4px);
12-
min-width: calc(1em + 4px);
13-
user-select: none;
14-
position: relative;
15-
overflow: hidden;
16-
text-wrap: nowrap;
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
background-color: var(--interactive);
6+
padding: 3px;
7+
margin-top: 5px;
8+
margin-bottom: 5px;
9+
cursor: pointer;
10+
transition: background-color 0.1s;
11+
height: calc(1em + 4px);
12+
min-width: calc(1em + 4px);
13+
user-select: none;
14+
position: relative;
15+
overflow: hidden;
16+
text-wrap: nowrap;
1717
}
1818

1919
.button:first-child {
20-
border-top-left-radius: 5px;
21-
border-bottom-left-radius: 5px;
22-
margin-left: 5px;
20+
border-top-left-radius: 5px;
21+
border-bottom-left-radius: 5px;
22+
margin-left: 5px;
2323
}
2424

2525
.button:last-child {
26-
border-top-right-radius: 5px;
27-
border-bottom-right-radius: 5px;
28-
margin-right: 5px;
26+
border-top-right-radius: 5px;
27+
border-bottom-right-radius: 5px;
28+
margin-right: 5px;
2929
}
3030

31-
.button:hover:not(.disabled) {
32-
background-color: var(--active);
31+
.button:hover:not(.disabled),
32+
.button.active {
33+
background-color: var(--active);
3334
}
3435

3536
.button:not(:last-child) {
36-
border-right: 1px solid var(--background);
37+
border-right: 1px solid var(--background);
3738
}
3839

3940
.button:active:not(.disabled) {
40-
background-color: var(--weak-foreground);
41-
transition: background-color 0s;
41+
background-color: var(--weak-foreground);
42+
transition: background-color 0s;
4243
}
4344

4445
.button.disabled {
45-
opacity: 0.5;
46-
cursor: not-allowed;
46+
opacity: 0.5;
47+
cursor: not-allowed;
4748
}

kalman_gs/node_project/src/components/button.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@ type Props = {
88
tooltip?: string;
99
onClick?: () => void;
1010
disabled?: boolean;
11+
active?: boolean;
1112
className?: string;
1213
style?: CSSProperties;
1314
};
1415

15-
export default function Button({ children, tooltip, onClick, disabled, className, style }: Props) {
16+
export default function Button({ children, tooltip, onClick, disabled, active, className, style }: Props) {
17+
const buttonClassName =
18+
styles['button'] +
19+
(className ? ` ${className}` : '') +
20+
(active ? ` ${styles['active']}` : '') +
21+
(disabled ? ` ${styles['disabled']}` : '');
22+
1623
if (tooltip === undefined || disabled) {
1724
return (
18-
<div
19-
className={styles['button'] + (className ? ` ${className}` : '') + (disabled ? ` ${styles['disabled']}` : '')}
20-
style={style}
21-
onClick={disabled ? undefined : onClick}
22-
>
25+
<div className={buttonClassName} style={style} onClick={disabled ? undefined : onClick}>
2326
{children}
2427
</div>
2528
);
2629
} else {
2730
return (
28-
<Tooltip
29-
text={tooltip}
30-
className={styles['button'] + (className ? ` ${className}` : '') + (disabled ? ` ${styles['disabled']}` : '')}
31-
style={style}
32-
onClick={disabled ? undefined : onClick}
33-
>
31+
<Tooltip text={tooltip} className={buttonClassName} style={style} onClick={disabled ? undefined : onClick}>
3432
{children}
3533
</Tooltip>
3634
);

0 commit comments

Comments
 (0)