Communication Patterns Overview

HORUS provides two communication primitives that cover all robotics messaging needs:

PatternPurposeExample
TopicStreaming data (pub/sub)Sensor readings, motor commands, video frames
ActionLong-running tasks (goal/feedback/result)Navigation, arm motion, calibration

Both work locally (shared memory) and across machines (network transport via configuration).

Topic: Streaming Pub/Sub

Topic<T> is the primary communication primitive. It provides ultra-fast pub/sub with automatic optimization — ~3ns to ~167ns latency depending on topology.

use horus::prelude::*;

let pub_topic: Topic<f32> = Topic::new("sensor.temperature")?;
pub_topic.send(25.3);

let sub_topic: Topic<f32> = Topic::new("sensor.temperature")?;
if let Some(temp) = sub_topic.recv() {
    hlog!(info, "Temperature: {}", temp);
}
ScenarioLatency
Same thread~3ns
Same process~18-36ns
Cross-process~50-167ns

The backend is auto-selected based on topology and participant count. Communication paths upgrade transparently at runtime as participants join.

For full Topic API details, see Topic Communication.

Action: Long-Running Tasks

Actions handle tasks that take time to complete and benefit from progress feedback and cancellation. They follow the Goal / Feedback / Result pattern.

For full Action API details, see Actions.

When to Use What

ScenarioUseWhy
Sensor data streamingTopicContinuous data, latest value matters
Motor commandsTopicHigh frequency, low latency
Camera framesTopicStreaming, multiple consumers
Navigate to positionActionLong-running, needs progress feedback
Pick-and-placeActionMulti-step, cancellable
Calibration routineActionTakes time, reports progress
Emergency stopTopicMust be instantaneous, no handshake
Diagnostics broadcastTopicMany publishers, flexible topology

Rule of thumb: If it's a continuous stream of data, use Topic. If it's a task you'd want to start, monitor, and potentially cancel, use Action.

Composing Patterns

A typical robot system combines both patterns:

struct NavigationSystem {
    // Topics for streaming sensor data
    lidar_sub: Topic<LaserScan>,
    odom_sub: Topic<Odometry>,

    // Topics for publishing commands
    cmd_vel_pub: Topic<Twist>,
    status_pub: Topic<Status>,

    // Action server for goal-based navigation
    nav_server: ActionServerNode<NavigateToGoal>,
}

The navigation action server subscribes to sensor topics internally, computes a path, publishes velocity commands via topics, and reports progress back to the action client — all using the same underlying shared memory infrastructure.

Next Steps