Skip to content

Commit 98b48f6

Browse files
committed
Fix turtle2 creating issue
1 parent 802a97b commit 98b48f6

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

electron_demo/turtle_tf2/main.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -601,26 +601,36 @@ ipcMain.on('spawn-turtle-request', async (event, data) => {
601601
const spawner = spawnerNode.createClient('turtlesim/srv/Spawn', 'spawn');
602602

603603
if (spawner.isServiceServerAvailable()) {
604-
const request = {
605-
x: x || 4.0,
606-
y: y || 2.0,
607-
theta: theta || 0.0,
608-
name: name || 'turtle2',
609-
};
610-
611-
console.log(`Attempting to spawn ${name} with request:`, request);
612-
const response = await spawner.sendRequest(request);
604+
// rclnodejs service calls expect individual arguments, not an object
605+
// For turtlesim Spawn service: x, y, theta, name
606+
const xPos = x || 4.0;
607+
const yPos = y || 2.0;
608+
const angle = theta || 0.0;
609+
const turtleName = name || 'turtle2';
610+
611+
console.log(
612+
`Attempting to spawn ${turtleName} at (${xPos}, ${yPos}, ${angle})`
613+
);
614+
615+
// Pass arguments individually instead of as an object
616+
const response = await spawner.sendRequest(
617+
xPos,
618+
yPos,
619+
angle,
620+
turtleName
621+
);
613622
console.log('Spawn response:', response);
614623

615-
if (response && response.name) {
616-
console.log(`Successfully spawned ${response.name}`);
624+
if (response) {
625+
const spawnedName = response.name || response || turtleName;
626+
console.log(`Successfully spawned ${spawnedName}`);
617627

618628
if (mainWindow) {
619629
mainWindow.webContents.send('turtle-spawned', {
620-
name: response.name,
621-
x: x || 4.0,
622-
y: y || 2.0,
623-
theta: theta || 0.0,
630+
name: spawnedName,
631+
x: xPos,
632+
y: yPos,
633+
theta: angle,
624634
});
625635
}
626636
}

0 commit comments

Comments
 (0)