Skip to main content

Unitree robot sdk version 2 for python

Project description

unitree_sdk2_python

Python interface for unitree sdk2

Installation

Dependencies

  • Python >= 3.8
  • cyclonedds == 0.10.2
  • numpy
  • opencv-python

Installing from source

Execute the following commands in the terminal:

cd ~
sudo apt install python3-pip
git clone https://github.com/unitreerobotics/unitree_sdk2_python.git
cd unitree_sdk2_python
pip3 install -e .

FAQ

1. Error when pip3 install -e .:
Could not locate cyclonedds. Try to set CYCLONEDDS_HOME or CMAKE_PREFIX_PATH

This error mentions that the cyclonedds path could not be found. First compile and install cyclonedds:

cd ~
git clone https://github.com/eclipse-cyclonedds/cyclonedds -b releases/0.10.x 
cd cyclonedds && mkdir build install && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install
cmake --build . --target install

Enter the unitree_sdk2_python directory, set CYCLONEDDS_HOME to the path of the cyclonedds you just compiled, and then install unitree_sdk2_python.

cd ~/unitree_sdk2_python
export CYCLONEDDS_HOME="~/cyclonedds/install"
pip3 install -e .

For details, see: https://pypi.org/project/cyclonedds/#installing-with-pre-built-binaries

Usage

The Python sdk2 interface maintains consistency with the unitree_sdk2 interface, achieving robot status acquisition and control through request-response or topic subscription/publishing. Example programs are located in the /example directory. Before running the examples, configure the robot's network connection as per the instructions in the document at https://support.unitree.com/home/en/developer/Quick_start.

DDS Communication

In the terminal, execute:

python3 ./example/helloworld/publisher.py

Open a new terminal and execute:

python3 ./example/helloworld/subscriber.py

You will see the data output in the terminal. The data structure transmitted between publisher.py and subscriber.py is defined in user_data.py, and users can define the required data structure as needed.

High-Level Status and Control

The high-level interface maintains consistency with unitree_sdk2 in terms of data structure and control methods. For detailed information, refer to https://support.unitree.com/home/en/developer/sports_services.

High-Level Status

Execute the following command in the terminal:

python3 ./example/high_level/read_highstate.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected,.

High-Level Control

Execute the following command in the terminal:

python3 ./example/high_level/sportmode_test.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected. This example program provides several test methods, and you can choose the required tests as follows:

test.StandUpDown() # Stand up and lie down
# test.VelocityMove() # Velocity control
# test.BalanceAttitude() # Attitude control
# test.TrajectoryFollow() # Trajectory tracking
# test.SpecialMotions() # Special motions

Low-Level Status and Control

The low-level interface maintains consistency with unitree_sdk2 in terms of data structure and control methods. For detailed information, refer to https://support.unitree.com/home/en/developer/Basic_services.

Low-Level Status

Execute the following command in the terminal:

python3 ./example/low_level/lowlevel_control.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected. The program will output the state of the right front leg hip joint, IMU, and battery voltage.

Low-Level Motor Control

First, use the app to turn off the high-level motion service (sport_mode) to prevent conflicting instructions. Execute the following command in the terminal:

python3 ./example/low_level/lowlevel_control.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected. The left hind leg hip joint will maintain a 0-degree position (for safety, set kp=10, kd=1), and the left hind leg calf joint will continuously output 1Nm of torque.

Wireless Controller Status

Execute the following command in the terminal:

python3 ./example/wireless_controller/wireless_controller.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected. The terminal will output the status of each key. For the definition and data structure of the remote control keys, refer to https://support.unitree.com/home/en/developer/Get_remote_control_status.

Front Camera

Use OpenCV to obtain the front camera (ensure to run on a system with a graphical interface, and press ESC to exit the program):

python3 ./example/front_camera/camera_opencv.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected.

Obstacle Avoidance Switch

python3 ./example/obstacles_avoid_switch/obstacles_avoid_switch.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected. The robot will cycle obstacle avoidance on and off. For details on the obstacle avoidance service, see https://support.unitree.com/home/en/developer/ObstaclesAvoidClient

Light and volume control

python3 ./example/vui_client/vui_client_example.py enp2s0

Replace enp2s0 with the name of the network interface to which the robot is connected.T he robot will cycle the volume and light brightness. The interface is detailed at https://support.unitree.com/home/en/developer/VuiClient

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unitree_sdk2py_dimos-1.0.2.tar.gz (39.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unitree_sdk2py_dimos-1.0.2-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file unitree_sdk2py_dimos-1.0.2.tar.gz.

File metadata

  • Download URL: unitree_sdk2py_dimos-1.0.2.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for unitree_sdk2py_dimos-1.0.2.tar.gz
Algorithm Hash digest
SHA256 904644326ec35216a705a036b7d321ef6014c0774b9aba0790c770930909cbe2
MD5 f6f952714359b8c77ce57c5a3ce39b7a
BLAKE2b-256 c41e4f334dc2cd11c31c9726bb8535e956ec07e795c2d8778c691585dc11567b

See more details on using hashes here.

File details

Details for the file unitree_sdk2py_dimos-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for unitree_sdk2py_dimos-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7dc80bc1a9ec3e08ba7b8d1613f52b017ca6d437863325c4a2ad95616585df65
MD5 da483a4f4bffbcf87ff3b274b32bbd04
BLAKE2b-256 9a4abee19c51a83ecb71a824c11db64c97986125218d0ec7896a5ac7c900eb82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page