Skip to content

Quickstart

Multiple physical actuators over CAN FD with Pulsar SDK

Use one USB-to-CAN adapter to control several physical actuators on one CAN FD bus using Pulsar Python SDK (3.1.0) or Pulsar Rust SDK (1.1.0).

Prepare the bus

Before writing code:

  1. securely mount and power every actuator;
  2. confirm actuator firmware is 2.2.5 or newer (see Firmware compatibility);
  3. wire the CAN bus with termination at both physical ends;
  4. connect the Pulsar USB-to-CAN adapter;
  5. confirm every actuator has a unique CAN address;
  6. read CAN FD connectivity.

Find actuator addresses

After installing the SDK, scan the bus:

pixi run pulsar-cli scan
pixi run pulsar-rs-cli scan

When several Pulsar serial devices are connected, pass --port /dev/ttyACM0 (Linux) or --port COM3 (Windows).

Configure and command one group

Replace the example addresses below with the addresses reported by scan:

from time import sleep

from pulsar_sdk import (
    ActuatorGroup,
    ControlConfiguration,
    ControlParams,
    Mode,
    PcpOverCan,
    PulsarActuatorReal,
)

can = PcpOverCan()
arm = ActuatorGroup(
    "arm",
    {
        "shoulder": PulsarActuatorReal(can, address=23),
        "elbow": PulsarActuatorReal(can, address=24),
    },
)

with arm:
    arm.configure(
        ControlConfiguration(Mode.VELOCITY, control_rate_hz=50.0)
    )
    arm.enable()

    for _ in range(100):  # 2 s at 50 Hz
        arm.set_commands({
            "shoulder": {ControlParams.COMMAND: 0.2},
            "elbow": {ControlParams.COMMAND: -0.2},
        })
        sleep(0.02)

    arm.disable()
use std::collections::BTreeMap;
use std::thread::sleep;
use std::time::Duration;

use pulsar_rs_sdk::{
    ActuatorGroup, ControlConfiguration, ControlParam, Mode, PcpOverCan,
    PulsarActuatorReal,
};

fn main() -> pulsar_rs_sdk::Result<()> {
    let can = PcpOverCan::new()?;
    let shoulder = PulsarActuatorReal::on_can(&can, 23)?;
    let elbow = PulsarActuatorReal::on_can(&can, 24)?;

    let arm = ActuatorGroup::new(
        "arm",
        [
            ("shoulder".into(), shoulder.actuator().clone()),
            ("elbow".into(), elbow.actuator().clone()),
        ],
    )?;

    arm.connect()?;
    let config = ControlConfiguration::new(Mode::Velocity, [], 0.0)?
        .with_control_rate_hz(50.0)?;
    arm.configure(&config)?;
    arm.enable()?;

    let batch = BTreeMap::from([
        ("shoulder".into(), BTreeMap::from([(ControlParam::Command, 0.2)])),
        ("elbow".into(), BTreeMap::from([(ControlParam::Command, -0.2)])),
    ]);
    for _ in 0..100 {
        arm.set_commands(&batch)?;
        sleep(Duration::from_millis(20));
    }

    arm.disable()?;
    arm.disconnect()?;
    Ok(())
}

PcpOverCan automatically selects the port when only one Pulsar USB-to-CAN adapter is connected. With several adapters, inspect PcpOverCan.list_ports() / PcpOverCan::list_ports() and pass the port explicitly (PcpOverCan(port) / PcpOverCan::with_port(port)).

The SDK validates the complete selected batch before the first write. Member writes are sequential, so a later transport failure can occur after an earlier actuator was updated.

Next steps