Robot Control
Robot control operations support abort signals for safe, cancellable movement. This is essential for emergency stops and responsive control.
Abort Signal Pattern
Many robot control methods accept an abortSignal option that allows you to cancel operations safely.
SDK Playground
In the SDK Playground, the abort signal is automatically provided by the execution environment. Simply use the global abortSignal variable:
// In SDK Playground - abortSignal is automatically available
await oloClient.core.moveFor({ linear: 0.5, angular: 0 }, 10000, {
abortSignal // Automatically provided by SDK Playground
}).catch(error => {
if (error.message === 'Aborted') {
console.log('Movement was safely cancelled by stop button');
}
});Standalone Applications
In standalone applications, you need to create your own abort mechanism:
// In standalone apps - create your own AbortController
const controller = new AbortController();
const abortSignal = controller.signal;
// Start a movement that can be cancelled
oloClient.core.moveFor({ linear: 0.5, angular: 0 }, 10000, {
abortSignal
}).catch(error => {
if (error.message === 'Aborted') {
console.log('Movement was safely cancelled');
}
});
// Cancel the movement (e.g., emergency stop button)
controller.abort();Safety Benefits:
- Emergency Stops - Immediately cancel dangerous movements
- Responsive Control - Cancel current action when starting new ones
- Timeout Safety - Prevent runaway robot behavior
- User Interruption - Allow users to stop operations safely
Complete Example:
// In SDK Playground, abortSignal is automatically provided
// In standalone apps, create your own: const controller = new AbortController(); const abortSignal = controller.signal;
try {
console.log('Starting robot control demo...');
// Check if already aborted (playground may have stopped script)
if (abortSignal.aborted) {
console.log('Script was aborted before starting');
return;
}
const cmdVelTopic = await oloClient.core.resolveCmdVelTopic();
// 1) Move forward for 3s (cancellable via stop button)
console.log('Moving forward...');
await oloClient.core.moveFor({ linear: 0.3, angular: 0 }, 3000, {
topicName: cmdVelTopic,
rateHz: 10,
abortSignal
});
// 2) Turn left for 2s (cancellable via stop button)
console.log('Turning left...');
await oloClient.core.moveFor({ linear: 0, angular: 0.5 }, 2000, {
topicName: cmdVelTopic,
rateHz: 10,
abortSignal
});
console.log('Movement demo completed!');
} catch (error) {
if (error.message === 'Aborted') {
console.log('Robot control demo was stopped by user');
} else {
console.error('Failed to control robot:', error);
}
} finally {
// Always ensure robot stops
await oloClient.core.stopRobot().catch(() => {});
}sendVelocity(topicName, velocity)
Send velocity command to robot.
Parameters:
topicName(string) - cmd_vel topic name (default: '/cmd_vel')velocity(object) - Velocity objectlinear(number) - Linear velocity in m/sangular(number) - Angular velocity in rad/s
Returns: Promise - Resolves when command is sent
// Move forward at 0.5 m/s
await oloClient.core.sendVelocity('/cmd_vel', { linear: 0.5, angular: 0 });
// Turn left at 0.3 rad/s
await oloClient.core.sendVelocity('/cmd_vel', { linear: 0, angular: 0.3 });moveFor(velocity, durationMs, options)
Move robot with specified velocity for a duration. Supports abort signals for safe cancellation.
Parameters:
velocity(object) - Velocity object with linear and angular componentsdurationMs(number) - Duration in millisecondsoptions(object, optional) - Movement optionstopicName(string) - cmd_vel topic namerateHz(number) - Publishing rate in HzabortSignal(AbortSignal) - Signal to abort movement safely
Returns: Promise - Resolves when movement completes or rejects if aborted
// Cancellable movement with abort signal
const controller = new AbortController();
try {
// Move forward for 3 seconds (cancellable)
await oloClient.core.moveFor({ linear: 0.3, angular: 0 }, 3000, {
topicName: '/cmd_vel',
rateHz: 10,
abortSignal: controller.signal
});
} catch (error) {
if (error.message === 'Aborted') {
console.log('Movement was safely cancelled');
}
}
// Cancel movement from anywhere (e.g., emergency stop button)
// controller.abort();startVelocityHold(velocity, options)
Start continuously publishing velocity until cancelled. Supports abort signals for safe cancellation.
Parameters:
velocity(object) - Velocity with linear and angular componentsoptions(object, optional) - Hold optionstopicName(string) - cmd_vel topic namerateHz(number) - Publishing rate in HzabortSignal(AbortSignal) - Signal to abort velocity holdstopOnCancel(boolean) - Stop robot when cancelled (default: true)
Returns: Promise<Object> - Velocity hold handle with stop() method
// Continuous movement with abort signal support
const controller = new AbortController();
const handle = await oloClient.core.startVelocityHold({ linear: 0.2, angular: 0 }, {
topicName: '/cmd_vel',
rateHz: 10,
abortSignal: controller.signal,
stopOnCancel: true
});
// Stop via handle
handle.stop();
// Or stop via abort signal (e.g., emergency stop)
controller.abort();stopRobot(topicName)
Stop robot movement.
Parameters:
topicName(string) - cmd_vel topic name (default: '/cmd_vel')
Returns: Promise - Resolves when stop command is sent
