Skip to content

Commit 16a9644

Browse files
committed
Update gamepad-drilling to follow new logic
1 parent 9a4fc5f commit 16a9644

1 file changed

Lines changed: 68 additions & 13 deletions

File tree

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

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,80 @@ import { ros } from './ros';
33
import { Topic } from 'roslib';
44

55
const RATE = 10;
6+
const MAX_SPEED = 100;
7+
8+
const clampSpeed = (value: number) => Math.max(-MAX_SPEED, Math.min(MAX_SPEED, Math.round(value * MAX_SPEED)));
69

710
window.addEventListener('ros-connect', () => {
8-
const sendDrillData = new Topic({
9-
ros: ros,
10-
name: '/science/drill/cmd',
11-
messageType: 'kalman_interfaces/Drill'
11+
const drillBTopic = new Topic<{ data: number }>({
12+
ros,
13+
name: '/science/drill/b',
14+
messageType: 'std_msgs/Int8'
15+
});
16+
const drillCTopic = new Topic<{ data: number }>({
17+
ros,
18+
name: '/science/drill/c',
19+
messageType: 'std_msgs/Int8'
20+
});
21+
const drillAutonomyTopic = new Topic<{ data: number }>({
22+
ros,
23+
name: '/science/drill/autonomy',
24+
messageType: 'std_msgs/UInt8'
25+
});
26+
const drillWeightReqTopic = new Topic<{ data: number }>({
27+
ros,
28+
name: '/science/drill/weight/request',
29+
messageType: 'std_msgs/UInt8'
1230
});
1331

32+
let lastBridgeB = 0;
33+
let lastBridgeC = 0;
34+
let lastStopButton = 0;
35+
let lastDrillButton = 0;
36+
let lastHomeButton = 0;
37+
let lastTareButton = 0;
38+
let lastWeighButton = 0;
39+
1440
setInterval(() => {
15-
// let armAxis = readGamepads('left-y', 'drill') ;
16-
let rackAxis = readGamepads('right-y', 'drill');
17-
let drilling = (readGamepads('right-trigger', 'drill') + readGamepads('left-trigger', 'drill')) * 0.5;
41+
const bridgeB = clampSpeed(readGamepads('right-y', 'drill'));
42+
const bridgeC = clampSpeed(readGamepads('left-x', 'drill'));
43+
44+
if (bridgeB !== lastBridgeB) {
45+
drillBTopic.publish({ data: bridgeB });
46+
lastBridgeB = bridgeB;
47+
}
48+
if (bridgeC !== lastBridgeC) {
49+
drillCTopic.publish({ data: bridgeC });
50+
lastBridgeC = bridgeC;
51+
}
52+
53+
const stopButton = readGamepads('b-button', 'drill');
54+
const drillButton = readGamepads('a-button', 'drill');
55+
const homeButton = readGamepads('y-button', 'drill');
56+
const tareButton = readGamepads('left-shoulder', 'drill');
57+
const weighButton = readGamepads('right-shoulder', 'drill');
58+
59+
if (stopButton > 0 && lastStopButton === 0) {
60+
drillAutonomyTopic.publish({ data: 0 });
61+
}
62+
if (drillButton > 0 && lastDrillButton === 0) {
63+
drillAutonomyTopic.publish({ data: 1 });
64+
}
65+
if (homeButton > 0 && lastHomeButton === 0) {
66+
drillAutonomyTopic.publish({ data: 2 });
67+
}
1868

19-
// if(Number.isNaN(armAxis)) armAxis = 0;
20-
if (Number.isNaN(rackAxis)) rackAxis = 0;
21-
if (Number.isNaN(drilling)) drilling = 0;
69+
if (tareButton > 0 && lastTareButton === 0) {
70+
drillWeightReqTopic.publish({ data: 0 });
71+
}
72+
if (weighButton > 0 && lastWeighButton === 0) {
73+
drillWeightReqTopic.publish({ data: 1 });
74+
}
2275

23-
// const drillData = { arm: armAxis, rack: rackAxis, drill: drilling };
24-
const drillData = { rack: rackAxis, drill: drilling };
25-
sendDrillData.publish(drillData);
76+
lastStopButton = stopButton;
77+
lastDrillButton = drillButton;
78+
lastHomeButton = homeButton;
79+
lastTareButton = tareButton;
80+
lastWeighButton = weighButton;
2681
}, 1000 / RATE);
2782
});

0 commit comments

Comments
 (0)