Skip to content

Quickstart Tutorial: Python API for Real Actuator via USB

This page walks you through running a Real Actuator connected via USB, and controlling it via Python scripting using PULSAR HRI's Python API

👣 Step-By-Step Guide

  1. Make sure your actuator is set up and connected via USB, as per the Quickstart Tutorial: Set up Real Actuator and connect via USB

Tip

You are of course free to run this straight from the terminal and installing libraries globally, but for a better experience we do recommend to:

  1. Install the PULSAR HRI Python API (more details about it here)

    pip install --upgrade pcp_api
    

  2. Check USB communication via the CLI tool (more details about it here):

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

  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 via the PULSAR Python API! Now you can explore doing much more by:

Question

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