Skip to content

Commit c357041

Browse files
committed
subscribe to odom
1 parent 338ef2a commit c357041

5 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/pages/operator/tsx/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ function handleWebRTCMessage(message: WebRTCMessage | WebRTCMessage[]) {
208208
case "batteryVoltage":
209209
remoteRobot.sensors.setBatteryVoltage(message.message);
210210
break;
211+
case "odom":
212+
remoteRobot.sensors.setOdom(message.message);
213+
break;
211214
default:
212215
throw Error(`unhandled WebRTC message type ${message.type}`);
213216
}

src/pages/robot/tsx/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
ActionStateMessage,
2222
ROSBatteryState,
2323
BatteryVoltageMessage,
24+
ROSOdometry,
25+
OdomMessage,
2426
delay,
2527
} from "shared/util";
2628
import { AllVideoStreamComponent, VideoStream } from "./videostreams";
@@ -33,6 +35,7 @@ export const robot = new Robot({
3335
jointStateCallback: forwardJointStates,
3436
batteryStateCallback: forwardBatteryState,
3537
occupancyGridCallback: forwardOccupancyGrid,
38+
odomCallback: forwardOdom,
3639
moveBaseResultCallback: (goalState: ActionState) =>
3740
forwardActionState(goalState, "moveBaseState"),
3841
playbackPosesResultCallback: (goalState: ActionState) =>
@@ -183,6 +186,15 @@ function forwardBatteryState(batteryState: ROSBatteryState) {
183186
} as BatteryVoltageMessage);
184187
}
185188

189+
function forwardOdom(odom: ROSOdometry) {
190+
if (!connection) throw "WebRTC connection undefined";
191+
192+
connection.sendData({
193+
type: "odom",
194+
message: odom,
195+
} as OdomMessage);
196+
}
197+
186198
function forwardOccupancyGrid(occupancyGrid: ROSOccupancyGrid) {
187199
if (!connection) throw "WebRTC connection undefined";
188200

src/pages/robot/tsx/robot.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
StretchTool,
2424
getStretchTool,
2525
DiagnosticArray,
26+
ROSOdometry,
2627
} from "shared/util";
2728
import {
2829
rosJointStatetoRobotPose,
@@ -88,6 +89,7 @@ export class Robot extends React.Component {
8889
) => void;
8990
private batteryStateCallback: (batteryState: ROSBatteryState) => void;
9091
private occupancyGridCallback: (occupancyGrid: ROSOccupancyGrid) => void;
92+
private odomCallback: (odom: ROSOdometry) => void;
9193
private moveBaseResultCallback: (goalState: ActionState) => void;
9294
private playbackPosesResultCallback: (goalState: ActionState) => void;
9395
private amclPoseCallback: (pose: Transform) => void;
@@ -109,6 +111,7 @@ export class Robot extends React.Component {
109111
) => void;
110112
batteryStateCallback: (batteryState: ROSBatteryState) => void;
111113
occupancyGridCallback: (occupancyGrid: ROSOccupancyGrid) => void;
114+
odomCallback: (odom: ROSOdometry) => void;
112115
moveBaseResultCallback: (goalState: ActionState) => void;
113116
playbackPosesResultCallback: (goalState: ActionState) => void;
114117
amclPoseCallback: (pose: Transform) => void;
@@ -121,6 +124,7 @@ export class Robot extends React.Component {
121124
this.jointStateCallback = props.jointStateCallback;
122125
this.batteryStateCallback = props.batteryStateCallback;
123126
this.occupancyGridCallback = props.occupancyGridCallback;
127+
this.odomCallback = props.odomCallback;
124128
this.moveBaseResultCallback = props.moveBaseResultCallback;
125129
this.playbackPosesResultCallback = props.playbackPosesResultCallback;
126130
this.amclPoseCallback = props.amclPoseCallback;
@@ -254,6 +258,7 @@ export class Robot extends React.Component {
254258
this.subscribeToJointState();
255259
this.subscribeToJointLimits();
256260
this.subscribeToBatteryState();
261+
this.subscribeToOdom();
257262
this.subscribeToMode();
258263
this.subscribetoJointStateDiagnostics();
259264
this.subscribeToActionResult(
@@ -355,6 +360,19 @@ export class Robot extends React.Component {
355360
});
356361
}
357362

363+
subscribeToOdom() {
364+
const odomTopic: Topic<ROSOdometry> = new Topic({
365+
ros: this.ros,
366+
name: "/wheel_odom",
367+
messageType: "nav_msgs/msg/Odometry",
368+
});
369+
this.subscriptions.push(odomTopic);
370+
371+
odomTopic.subscribe((msg: ROSOdometry) => {
372+
if (this.odomCallback) this.odomCallback(msg);
373+
});
374+
}
375+
358376
subscribeToMode() {
359377
const modeTopic: Topic = new Topic({
360378
ros: this.ros,

src/shared/remoterobot.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ValidJoints,
2323
ROSPose,
2424
waitUntil,
25+
ROSOdometry,
2526
} from "shared/util";
2627
export type robotMessageChannel = (message: cmd) => void;
2728

@@ -240,6 +241,7 @@ class RobotSensors extends React.Component {
240241
private mode: string | undefined = undefined;
241242
private isHomed: boolean | undefined = undefined;
242243
private runStopEnabled: boolean = false;
244+
private odom: ROSOdometry | undefined = undefined;
243245
private functionProviderCallback?: (
244246
inJointLimits: ValidJointStateDict,
245247
inCollision: ValidJointStateDict
@@ -386,6 +388,10 @@ class RobotSensors extends React.Component {
386388
this.runStopFunctionProviderCallback(this.runStopEnabled);
387389
}
388390

391+
setOdom(odom: ROSOdometry) {
392+
this.odom = odom;
393+
}
394+
389395
/**
390396
* Records a callback from the function provider. The callback is called
391397
* whenever the battery voltage changes.

src/shared/util.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ export type WebRTCMessage =
102102
| MapPoseMessage
103103
| StopTrajectoryMessage
104104
| StopMoveBaseMessage
105-
106105
| BatteryVoltageMessage
107106
| ModeMessage
108107
| IsHomedMessage
109108
| IsRunStoppedMessage
110109
| StretchToolMessage
111110
| ActionStateMessage
111+
| OdomMessage
112112
| cmd;
113113

114114
interface StopTrajectoryMessage {
@@ -179,6 +179,11 @@ export interface BatteryVoltageMessage {
179179
message: number;
180180
}
181181

182+
export interface OdomMessage {
183+
type: "odom";
184+
message: ROSOdometry;
185+
}
186+
182187
export interface ROSPoint extends Message {
183188
x: number;
184189
y: number;
@@ -211,6 +216,22 @@ export interface ROSOccupancyGrid {
211216
data: number[];
212217
}
213218

219+
export interface ROSOdometry extends Message {
220+
header: string;
221+
child_frame_id: string;
222+
pose: {
223+
pose: ROSPose;
224+
covariance: number[];
225+
};
226+
twist: {
227+
twist: {
228+
linear: { x: number; y: number; z: number };
229+
angular: { x: number; y: number; z: number };
230+
};
231+
covariance: number[];
232+
};
233+
}
234+
214235
export const JOINT_LIMITS: { [key in ValidJoints]?: [number, number] } = {
215236
arm_joint: [0.001, 0.518],
216237
wrist_roll_joint: [-2.95, 2.94],

0 commit comments

Comments
 (0)