Skip to content

Quickstart Tutorial: Python API for a Real Actuator via USB

This page walks you through the fastest way to run a real actuator connected via USB and control it with Python. It installs the Python API globally so you can test quickly from a terminal.

For best-practice project setup, dependency management, and reusable examples, start with Install Python API, then follow the Python API Examples repository README, beginning with the quickstart examples.

👣 Step-by-Step Guide

  1. Make sure your actuator is set up and connected via USB, as described in the Quickstart Tutorial: Set Up a Real Actuator and Connect via USB.

Tip

This quickstart is optimized for speed, not long-term project hygiene. For normal development, use the installation workflow in Install Python API and run the maintained quickstarts and tutorials from Python API Examples.

  1. Install the PULSAR HRI Python API:

    python -m pip install --upgrade pcp-api
    

  2. Check USB communication using the CLI tool:

    pulsar-cli scan
    
    You should see your actuator's ID and connection information.

  3. Copy and paste the following command into your terminal. The actuator should rotate at a constant speed for 5 seconds:

    python - <<'PY'
    from time import sleep
    
    from pcp_api import PcpOverUsb, PulsarActuatorReal
    
    # Auto-detect the USB port and create the adapter
    port = PcpOverUsb.get_port()
    adapter = PcpOverUsb(port)
    
    # Connect to actuator at address 0 (USB)
    actuator = PulsarActuatorReal(adapter, 0)
    actuator.connect()
    
    # Set control mode and target speed
    actuator.change_mode(PulsarActuatorReal.Mode.SPEED)
    actuator.change_setpoint(1.0)  # rad/s
    
    # Start and run for 5 seconds
    actuator.start()
    sleep(5)
    actuator.disconnect()
    adapter.close()
    PY
    

Success

You’ve just sent your first command using the PULSAR Python API! You can now do much more with it:

Question

Need help or something doesn’t work? Head over to the Support page: we’ve got your back.