Skip to content

Quickstart Tutorial: Python API for a Real Actuator via USB

This page walks you through running a real actuator connected via USB and controlling it with Python using PULSAR HRI's Python API.

👣 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

You can run this directly from the terminal and install libraries globally, but for a better experience we recommend the following:

  1. Install the PULSAR HRI Python API:

    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. Run the following script. The actuator should rotate at a constant speed for 5 seconds:

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

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.