Skip to content

Commit 781a3ce

Browse files
committed
test autonav restart
1 parent cba8dd1 commit 781a3ce

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/lib/ros2CommandCentre.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,44 @@ export class ROS2CommandCentreClient {
991991
console.log('Rover launch completed successfully');
992992
}
993993

994+
/**
995+
* Restart autonomous navigation without waypoints
996+
* Used when returning to autonomous mode after manual control
997+
*/
998+
async restartAutonomousNavigation(): Promise<void> {
999+
// Set navigation state
1000+
this._isNavigating = true;
1001+
this.notifyStateChange();
1002+
1003+
// Send the LaunchRover command without waypoints
1004+
await this.sendCommand({
1005+
type: 'LaunchRover',
1006+
params: {
1007+
waypoint_count: 0,
1008+
launch_mode: 'autonomous'
1009+
}
1010+
});
1011+
1012+
console.log('Waiting for autonomous navigation nodes to restart...');
1013+
1014+
// Wait for required nodes to be running (based on Python autonomous_nodes)
1015+
const requiredNodes = ['gps', 'obstacle_detection', 'auto_nav', 'serial_motor_imu', 'usb_camera', 'csi_camera_1', 'csi_camera_2']
1016+
const nodesStarted = await this.waitForNodesRunning(requiredNodes, 45000); // 45 second timeout
1017+
1018+
if (!nodesStarted) {
1019+
console.error('Failed to restart all required nodes for autonomous navigation');
1020+
this._isNavigating = false;
1021+
this.notifyStateChange();
1022+
throw new Error('Required nodes failed to restart for autonomous navigation');
1023+
}
1024+
1025+
console.log('Autonomous navigation restarted successfully');
1026+
1027+
// Store required nodes and start health monitoring
1028+
this._requiredNodes = requiredNodes;
1029+
this.startNodeHealthCheck();
1030+
}
1031+
9941032
/**
9951033
* Switch to manual control mode
9961034
*/

src/routes/rovers/[id]/[pathId]/+page.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,19 @@
343343
: commandCenterClient.connect({ enableCSICamera: true, enableUSBCamera: true, enableCSI2Camera: true });
344344
345345
ensureConnection
346-
.then(() => {
346+
.then(async () => {
347347
setupCommandCenterClient();
348+
349+
// Restart autonomous navigation when returning from manual control
350+
// This ensures the auto_nav node is restarted
351+
if (commandCenterClient) {
352+
try {
353+
await commandCenterClient.restartAutonomousNavigation();
354+
console.log('Autonomous navigation restarted successfully');
355+
} catch (error) {
356+
console.error('Failed to restart autonomous navigation:', error);
357+
}
358+
}
348359
})
349360
.catch((err) => {
350361
console.error('Failed to connect to ROS2 Command Center:', err);

0 commit comments

Comments
 (0)