Publishing messagesΒΆ

Publish with one-shot calls or create a reusable publisher for repeated messages. Relative topic names resolve against the robot namespace; leading / marks an absolute topic.

from olo import Client
from olo.core import TopicInfo

with Client() as client:
    robot = client.robot()

    # Publish a message on the status topic. Relative names resolve to
    # /<robot namespace>/status.
    status = TopicInfo("status", "std_msgs/msg/String")
    robot.core.publish(status, {"data": "Hello from the OLO SDK"}, timeout=1.0)

    # ...or create a persistent publisher which can be reused.
    status_pub = robot.core.publisher(status)
    status_pub.publish({"data": "Hello again"}, timeout=1.0)

    # Leading slash in the topic name will publish in the global namespace.
    fleet_status = TopicInfo("/fleet/status", "std_msgs/msg/String")
    robot.core.publish(fleet_status, {"data": "fleet-wide"}, timeout=1.0)
import { connect } from "olo/web";
import type { TopicInfo } from "olo/core";

const client = connect();
const robot = await client.robot();

// Publish a message on the status topic. Relative names resolve to
// /<robot namespace>/status.
const status: TopicInfo = { name: "status", msgType: "std_msgs/msg/String" };
await robot.core.publish(status, { data: "Hello from the OLO SDK" }, { timeoutMs: 1000 });

// ...or create a persistent publisher which can be reused.
const statusPublisher = robot.core.publisher(status);
await statusPublisher.publish({ data: "Hello again" }, { timeoutMs: 1000 });

// Leading slash in the topic name will publish in the global namespace.
const fleetStatus: TopicInfo = { name: "/fleet/status", msgType: "std_msgs/msg/String" };
await robot.core.publish(fleetStatus, { data: "fleet-wide" }, { timeoutMs: 1000 });