Skip to content

Pulsar SDK

Telemetry and callbacks

Pulsar SDK supports on-demand snapshot reads, per-actuator telemetry callbacks, synchronized group control callbacks, and platform-wide callback registration.

Configure periodic telemetry

from pulsar_sdk import ControlConfiguration, Mode, TelemetryItems

configuration = ControlConfiguration(
    mode=Mode.POSITION,
    telemetry_items=(
        TelemetryItems.POSITION,
        TelemetryItems.VELOCITY,
        TelemetryItems.TORQUE_ESTIMATE,
        TelemetryItems.TIMESTAMP_MS,
    ),
    telemetry_rate_hz=500,
    control_rate_hz=500,
)
use pulsar_rs_sdk::{ControlConfiguration, Mode, TelemetryItem};

let configuration = ControlConfiguration::new(
    Mode::Position,
    [
        TelemetryItem::Position,
        TelemetryItem::Velocity,
        TelemetryItem::TorqueEstimate,
        TelemetryItem::TimestampMs,
    ],
    500.0,
)?
.with_control_rate_hz(500.0)?;
  • Configure at most 12 unique telemetry items.
  • Check actual_telemetry_rate_hz for the exact firmware 20 kHz divider rate.
  • Use canonical telemetry names (POSITION / TelemetryItem::Position, VELOCITY / TelemetryItem::Velocity); duplicate *_ACTUAL aliases were removed in 3.1.0 / 1.1.0.

Read a snapshot

Snapshot reads work in CONFIG_AND_TELEM or DRIVE_ACTIVE:

telemetry = actuator.read_telemetry((
    TelemetryItems.POSITION,
    TelemetryItems.VELOCITY,
))
let telemetry = actuator.read_telemetry(&[
    TelemetryItem::Position,
    TelemetryItem::Velocity,
])?;
let pos = telemetry[&TelemetryItem::Position].as_f64();

Standalone actuator telemetry callback

def on_telemetry(address, telemetry):
    print(address, telemetry[TelemetryItems.POSITION])

actuator.set_telemetry_callback(on_telemetry)
# Later, to remove:
actuator.set_telemetry_callback(None)
use std::sync::Arc;

actuator.set_telemetry_callback(Some(Arc::new(|address, telemetry| {
    if let Some(pos) = telemetry.get(&TelemetryItem::Position) {
        println!("{address:?}: {:.3} rad", pos.as_f64());
    }
})))?;
// Later, to remove:
actuator.set_telemetry_callback(None)?;

One worker per execution domain invokes user callbacks off the transport reader thread. At most one callback runs while one newest pending packet waits; inspect dropped_telemetry_packets if your callback runs slower than the telemetry rate.

Group control callback

A group control callback executes once one fresh sample has arrived from every actuator in the group, and its returned command batch is validated and transmitted immediately:

from pulsar_sdk import ControlParams, TelemetryItems

def controller(metadata, telemetry):
    return {
        name: {ControlParams.COMMAND: values[TelemetryItems.POSITION]}
        for name, values in telemetry.items()
    }

arm.set_control_callback(controller)
use std::collections::BTreeMap;
use std::sync::Arc;

use pulsar_rs_sdk::{ControlParam, TelemetryItem};

arm.set_control_callback(Some(Arc::new(|_metadata, telemetry| {
    let mut batch = BTreeMap::new();
    for (name, values) in telemetry {
        if let Some(pos) = values.get(&TelemetryItem::Position) {
            batch.insert(name, BTreeMap::from([(ControlParam::Command, pos.as_f64())]));
        }
    }
    Some(batch)
})))?;

Telemetry and control callback sequence

In Rust, cross-thread callbacks require Send + Sync + 'static, so share mutable state across the main thread and callback via Arc<Mutex<_>> or atomics.

Platform control callback

Platform.set_control_callback registers the same callback on every group. Each group still invokes the callback independently on its own domain worker — inspect metadata.group_name to distinguish groups (for example "left_arm" vs "right_arm").

Performance & control-loop best practices

  • Keep callbacks short and non-blocking: avoid file I/O, plotting, or sleeping inside control callbacks. Push samples into a bounded queue / ring buffer and log or render on another thread.
  • Request only the telemetry items you use: smaller telemetry packets reduce CAN FD bus utilization and allow higher control rates.
  • Callback-driven vs. external loop:
  • Use set_control_callback for low-jitter closed-loop control synchronized to incoming telemetry (the SDK automatically collects complete group batches and enforces stale-telemetry and deadline watchdogs).
  • Use separate telemetry callback + timed host loop (calling set_commands) when your control cadence is driven by an external clock (e.g. a planner, GUI, or simulator loop). Always set control_rate_hz in ControlConfiguration to match your actual command rate.

Timeouts and removal

ActuatorGroup enforces two independent host-side watchdogs during active callback control:

  • telemetry_timeout_s (default 0.1 s): triggers STALE_TELEMETRY if a member stops reporting.
  • controller_timeout_s (default 1.0 s, or None to disable): triggers CONTROLLER_TIMEOUT if the callback exceeds its deadline.

Removing a callback from another thread waits cleanly for the currently executing invocation to finish. A diagnostic callback cannot replace itself while running (ResourceBusyError).