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
- 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:
-
use an IDE such as Visual Studio Code
-
up a virtual environment using tools such as venv or pipenv or poetry or uv
-
Install the PULSAR HRI Python API (more details about it here)
-
Check USB communication via the CLI tool (more details about it here):
You should see your actuator's ID and connection info. -
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:
-
checking out more example scripts starting with this one
-
trying other communication methods beyond direct USB enabling the control of multiple actuators, such as CAN
-
get intimate with the Python API code reference starting from understanding the actuator classes and methods
-
If you're interested in simulating PULSAR actuators without needing hardware, explore how to create Virtual Actuators with the AUGUR Digital Twin.
Question
Need help or something doesn’t work? Head over to the Support page: we’ve got your back.