Skip to content

Protobuf C++/Python SDK Manual

All product guides

1. Introduction

1.1. Feature

This SDK acquires joint angles or quaternion data of the hand based on the Protobuf transmission format, supporting both Windows and Linux environments.

1.2. Download

Language OS OS Version Description Download Link Package Name Format
CPP Windows / / Download HandDriver_Win_x64_Cpp_Protobuf_src_yyyymmddhhmm
CPP Ubuntu 22&24, amd / Download HandDriver_Linux_Cpp_Protobuf_src_yyyymmddhhmm
CPP Ubuntu 22&24, amd Requires compilation before use. Download HandDriver_Linux_Cpp_Protobuf_src_yyyymmddhhmm
CPP Ubuntu 20 amd Requires compilation before use. Download HandDriver_Linux_Cpp_Protobuf_src_yyyymmddhhmm
Python Windows
Ubuntu
/ / Download HandDriver_Py_Protobuf_src_yyyymmddhhmm

1.3. HandDriver Configuration

  • Check "Data Transmission" to turn on the data transmission.
  • Select the Format: Protobuf.
  • Choose the Content: Euler or Quater. (Typically, the robotics field prefers Euler.)
  • Options: To transmit IMU data (only supported for gloves with IMU sensors), check the IMU option; otherwise, IMU data will not be transmitted.
  • The Old Plugin does not apply here.
  • Select the FPS, which supports 120Hz, 90Hz, and 60Hz. The default FPS is 120Hz.
  • In the target address section, click the "+" icon, then enter the IP address and port number of the receiving end to enable data transmission. (For local transmission, enter 127.0.0.1.)
  • Multiple target addresses can be set.
  • After completing the settings, click the "Apply" button to save.

2. Coordinate System and Data Definitions

2.1. Coordinate System and Data Description

Hand Model and Data Specification

2.2. Protocol Buffer Definition File

The Protocol Buffer definition file is as follows:

handdriver_teleop.proto

syntax = "proto3";

package HandDriver;

import "handdriver_algebra.proto";

// Index description for joints array (Angle)
enum JointsIndex_Angle
{
    THUMB_DISTAL_PITCH = 0;         // Thumb Distal Pitch
    THUMB_INTERMEDIATE_PITCH = 1;   // Thumb Intermediate Pitch
    THUMB_PROXIMAL_PITCH = 2;       // Thumb Proximal Pitch
    THUMB_PROXIMAL_YAW = 3;         // Thumb Proximal Yaw
    INDEX_DISTAL_PITCH = 4;         // Index Distal Pitch
    INDEX_INTERMEDIATE_PITCH = 5;   // Index Intermediate Pitch
    INDEX_PROXIMAL_PITCH = 6;       // Index Proximal Pitch
    INDEX_PROXIMAL_YAW = 7;         // Index Proximal Yaw
    MIDDLE_DISTAL_PITCH = 8;        // Middle Distal Pitch
    MIDDLE_INTERMEDIATE_PITCH = 9;  // Middle Intermediate Pitch
    MIDDLE_PROXIMAL_PITCH = 10;     // Middle Proximal Pitch
    MIDDLE_PROXIMAL_YAW = 11;       // Middle Proximal Yaw
    RING_DISTAL_PITCH = 12;         // Ring Distal Pitch
    RING_INTERMEDIATE_PITCH = 13;   // Ring Intermediate Pitch
    RING_PROXIMAL_PITCH = 14;       // Ring Proximal Pitch
    RING_PROXIMAL_YAW = 15;         // Ring Proximal Yaw
    PINKY_DISTAL_PITCH = 16;        // Pinky Distal Pitch
    PINKY_INTERMEDIATE_PITCH = 17;  // Pinky Intermediate Pitch
    PINKY_PROXIMAL_PITCH = 18;      // Pinky Proximal Pitch
    PINKY_PROXIMAL_YAW = 19;        // Pinky Proximal Yaw
    THUMB_PROXIMAL_ROLL = 20;       // Thumb Proximal Roll
    INDEX_PROXIMAL_ROLL = 21;       // Index Proximal Roll
    PINKY_PROXIMAL_ROLL = 22;       // Pinky Proximal Roll
}

// Index description for joints array (Quat)
enum JointsIndex_Quat{
    INDEX_PROXIMAL = 0;       // Index Proximal
    INDEX_INTERMEDIATE = 1;   // Index Intermediate
    INDEX_DISTAL = 2;         // Index Distal
    MIDDLE_PROXIMAL = 3;      // Middle Proximal
    MIDDLE_INTERMEDIATE = 4;  // Middle Intermediate
    MIDDLE_DISTAL = 5;        // Middle Distal
    RING_PROXIMAL = 6;        // Ring Proximal
    RING_INTERMEDIATE = 7;    // Ring Intermediate
    RING_DISTAL = 8;          // Ring Distal
    PINKY_PROXIMAL = 9;       // Pinky Proximal
    PINKY_INTERMEDIATE = 10;  // Pinky Intermediate
    PINKY_DISTAL = 11;        // Pinky Distal
    THUMB_PROXIMAL = 12;      // Thumb Proximal
    THUMB_INTERMEDIATE = 13;  // Thumb Intermediate
    THUMB_DISTAL = 14;        // Thumb Distal
}

message JointPose{
    string name = 1;
    Vec3 globalPosition = 2;
    Quat globalRotation = 3;
}

message GloveHandDataAngle{
  string serialNumber = 1;      // Device Serial Number
  int32 battery = 2;            // Battery Level
  int32 calibrationState = 3;   // Calibration State
  bool aButton = 4;             // A Button State
  bool bButton = 5;             // B Button State
  bool menuButton = 6;          // Menu Button State
  bool joyButton = 7;           // Joystick Button State
  Vec2 joyPosition = 8;         // Joystick Position
  Quat imu = 9;                 // Hand IMU Orientation
  repeated float joints = 10;   // Joint Angles
  int32 gesture = 11;           // Recognized Gesture Index
}

message GloveHandDataQuat{
  string serialNumber = 1;      // Device Serial Number
  int32 battery = 2;            // Battery Level
  int32 calibrationState = 3;   // Calibration State
  bool aButton = 4;             // A Button State
  bool bButton = 5;             // B Button State
  bool menuButton = 6;          // Menu Button State
  bool joyButton = 7;           // Joystick Button State
  Vec2 joyPosition = 8;         // Joystick Position
  Quat imu = 9;                 // Hand IMU Orientation
  repeated Quat joints = 10;    // Joint API Rotations
  int32 gesture = 11;           // Recognized Gesture Index
}

message GloveHandDataPose{
  string serialNumber = 1;
  int32 battery = 2;
  int32 calibrationState = 3;
  bool aButton = 4;
  bool bButton = 5;
  bool menuButton = 6;
  bool joyButton = 7;
  Vec2 joyPosition = 8;
  Quat imu = 9;
  repeated JointPose pose = 10;
  int32 gesture = 11;
  repeated float joints = 12;
}

message TeleopDataAngle
{
  int64 TimeStamp = 1; // Milliseconds
  uint64 FrameIndex = 2; // Frame index at start of transmission
  string RoleName = 3;         // User Role Name
  GloveHandDataAngle LeftHand = 4;  // Left Hand Data
  GloveHandDataAngle RightHand = 5; // Right Hand Data
}

message TeleopDataQuat
{
  int64 TimeStamp = 1; // Milliseconds
  uint64 FrameIndex = 2; // Frame index at start of transmission
  string RoleName = 3;         // User Role Name
  GloveHandDataQuat LeftHand = 4;   // Left Hand Data
  GloveHandDataQuat RightHand = 5;  // Right Hand Data
}

message TeleopDataPose
{
  int64 TimeStamp = 1;
  uint64 FrameIndex = 2;
  string RoleName = 3;
  GloveHandDataPose LeftHand = 4;
  GloveHandDataPose RightHand = 5;
}

handdriver_algebra.proto

syntax = "proto3";

package HandDriver;

message Vec2 {
  float x = 1;
  float y = 2;
}

message Vec3 {
  float x = 1;
  float y = 2;
  float z = 3;
}

message Quat {
  float x = 1;
  float y = 2;
  float z = 3;
  float w = 4;
}

2.3. Angle Value Reception Notes

Regarding the received angle values, please refer to the data page in the HandDriver. The data displayed on that page is consistent with the data received by the SDK:

  • Sign conventions are consistent.
  • Specific numerical values are displayed as integers in HandDriver.
  • For detailed explanations, please refer to:

Hand Model and Data Specification

2.4. Pose Data Description

The pose data uses the wrist as the origin in global coordinates, with a left-handed coordinate system where Z points forward and Y points upward. \ Example pose data is as follows:

Received 2765 bytes from ('127.0.0.1', 53413)
Teleop Header: TimeStamp=1780908276819, FrameIndex=5031, RoleName=teleop
LeftHand:
serialNumber: "ABSTCE5GH006666L_AHST006666D"
battery: 5
calibrationState: 3
joyPosition {
  x: -0.6460064
  y: -0.43769968
}
imu {
}
pose {
  name: "LeftWrist"
  globalPosition {
  }
  globalRotation {
    w: 1.0
  }
}
pose {
  name: "LeftThumbProximal"
  globalPosition {
    x: 0.017914
    y: 0.029178
    z: 0.025298
  }
  globalRotation {
    x: -0.6689547
    y: 0.14353934
    z: 0.6163418
    w: -0.3898961
  }
}
pose {
  name: "LeftThumbIntermediate"
  globalPosition {
    x: 0.009871995
    y: 0.056357574
    z: 0.054094575
  }
  globalRotation {
    x: -0.6756838
    y: -0.1074957
    z: 0.71550316
    w: -0.1412495
  }
}
pose {
  name: "LeftThumbDistal"
  globalPosition {
    x: 0.011400047
    y: 0.058206744
    z: 0.086523205
  }
  globalRotation {
    x: -0.6625688
    y: -0.17060609
    z: 0.7256205
    w: -0.07328782
  }
}
pose {
  name: "LeftThumbEnd"
  globalPosition {
    x: 0.014789092
    y: 0.054559436
    z: 0.11657778
  }
  globalRotation {
    x: -0.6625688
    y: -0.17060609
    z: 0.7256205
    w: -0.07328782
  }
}
pose {
  name: "LeftIndexProximal"
  globalPosition {
    x: -0.01104
    y: 0.037389
    z: 0.085647
  }
  globalRotation {
    x: 0.36210546
    y: 0.49686828
    z: -0.66516364
    w: 0.423744
  }
}
pose {
  name: "LeftIndexIntermediate"
  globalPosition {
    x: 0.0053505264
    y: 0.04621408
    z: 0.124726675
  }
  globalRotation {
    x: 0.20350446
    y: 0.55708617
    z: -0.79788154
    w: 0.10782433
  }
}
pose {
  name: "LeftIndexDistal"
  globalPosition {
    x: 0.030626608
    y: 0.044668518
    z: 0.13730581
  }
  globalRotation {
    x: 0.046504833
    y: 0.5931449
    z: -0.7895216
    w: -0.15057325
  }
}
pose {
  name: "LeftIndexEnd"
  globalPosition {
    x: 0.05258345
    y: 0.038982347
    z: 0.1347819
  }
  globalRotation {
    x: 0.04277485
    y: 0.6634037
    z: -0.7355003
    w: -0.13078794
  }
}
pose {
  name: "LeftMiddleProximal"
  globalPosition {
    x: -0.016369
    y: 0.009461
    z: 0.08573
  }
  globalRotation {
    x: 0.53729814
    y: 0.48057202
    z: -0.50287634
    w: 0.47694513
  }
}
pose {
  name: "LeftMiddleIntermediate"
  globalPosition {
    x: -0.017763132
    y: 0.007877586
    z: 0.12878667
  }
  globalRotation {
    x: 0.5416414
    y: 0.51296073
    z: -0.47487786
    w: 0.46689066
  }
}
pose {
  name: "LeftMiddleDistal"
  globalPosition {
    x: -0.018317329
    y: 0.0066357614
    z: 0.16202517
  }
  globalRotation {
    x: 0.530094
    y: 0.4881408
    z: -0.5093769
    w: 0.47037682
  }
}
pose {
  name: "LeftMiddleEnd"
  globalPosition {
    x: -0.018434599
    y: 0.00564339
    z: 0.18789749
  }
  globalRotation {
    x: 0.530094
    y: 0.4881408
    z: -0.5093769
    w: 0.47037682
  }
}
pose {
  name: "LeftRingProximal"
  globalPosition {
    x: -0.009701
    y: -0.013209
    z: 0.081339
  }
  globalRotation {
    x: 0.51560634
    y: 0.49414393
    z: -0.46716434
    w: 0.5212767
  }
}
pose {
  name: "LeftRingIntermediate"
  globalPosition {
    x: -0.0127317505
    y: -0.014117249
    z: 0.121545605
  }
  globalRotation {
    x: 0.52337396
    y: 0.5240717
    z: -0.4350181
    w: 0.51204324
  }
}
pose {
  name: "LeftRingDistal"
  globalPosition {
    x: -0.014873557
    y: -0.014758674
    z: 0.14994739
  }
  globalRotation {
    x: 0.51560634
    y: 0.49414393
    z: -0.46716434
    w: 0.5212767
  }
}
pose {
  name: "LeftRingEnd"
  globalPosition {
    x: -0.016559508
    y: -0.015264551
    z: 0.17230827
  }
  globalRotation {
    x: 0.51560634
    y: 0.49414393
    z: -0.46716434
    w: 0.5212767
  }
}
pose {
  name: "LeftPinkyProximal"
  globalPosition {
    x: 0.00147
    y: -0.034467
    z: 0.076123
  }
  globalRotation {
    x: 0.4686218
    y: 0.55040336
    z: -0.40766224
    w: 0.55790794
  }
}
pose {
  name: "LeftPinkyIntermediate"
  globalPosition {
    x: -0.0003741461
    y: -0.036289483
    z: 0.10588492
  }
  globalRotation {
    x: 0.44247153
    y: 0.5875495
    z: -0.36825535
    w: 0.56867623
  }
}
pose {
  name: "LeftPinkyDistal"
  globalPosition {
    x: -0.0014843073
    y: -0.037386145
    z: 0.12379582
  }
  globalRotation {
    x: 0.32238728
    y: 0.594398
    z: -0.32184738
    w: 0.66270053
  }
}
pose {
  name: "LeftPinkyEnd"
  globalPosition {
    x: -0.0025962326
    y: -0.038484804
    z: 0.1417457
  }
  globalRotation {
    x: 0.46862188
    y: 0.55040336
    z: -0.40766236
    w: 0.55790806
  }
}
gesture: -1
joints0: -10.8
joints1: -42.3
joints2: 10.0
joints3: 25.0
joints4: -34.5
joints5: -43.2
joints6: -25.0
joints7: -17.6
joints8: -0.7
joints9: -0.9
joints10: -0.3
joints11: 3.7
joints12: 0.0
joints13: 0.0
joints14: 0.0
joints15: 1.5
joints16: 0.0
joints17: 0.0
joints18: 0.0
joints19: 1.5
joints20: -1.0
joints21: 0.0
joints22: 0.0

2.5. Coordinate System Conversion Instructions

The HandDriver's default output coordinate system is a left-handed coordinate system, with the wrist as the origin, +Y as up, +Z as forward, and a unit scale of 1. The corresponding parameters are left, +y, zfrom, 1. Coordinate system conversion is used to map quaternion or pose data received by the SDK to the coordinate system required by the target application.

Coordinate system parameters are uniformly specified in the following format:

handedness, up, view, unitScale

Example: left, +y, zfrom, 1

Meaning: handedness = left, up = +y, view = zfrom, unitScale = 1.

Field Descriptions:

Field Allowed Values Descriptions
handedness left, right Specifies whether the target coordinate system is left-handed or right-handed.
up +x, -x, +y, -y, +z, -z Specifies the "up" axis in the target coordinate system.
view xfrom, yfrom, zfrom, xto, yto, zto Specifies the "forward / view direction" axis in the target coordinate system; from indicates that the positive direction of that axis points forward, while to indicates that the negative direction points forward.
unitScale Numeric value, e.g., 1, 0.01, 0.001 Specifies the scaling factor for position units; 1 means meters, 0.01 means centimeters, and 0.001 means millimeters.

Conversion Scope:

Data Type Convert? Conversion Content
angle No Angle values are output directly without coordinate system conversion.
quat Yes Converts left‑hand and right‑hand IMU quaternions and joint quaternions.
pose Yes Converts left‑hand and right‑hand IMU quaternions, as well as globalRotation and globalPosition for each joint; unitScale is applied to position data.

Usage Recommendations: Typically, keep --source-coord at its default value and only specify the target coordinate system via --target-coord. If the target engine or robot control system uses different axes or units, you can adapt it using up, view, and unitScale.

Example: Convert Pose data to a left‑handed coordinate system with +Z as up, +X as forward, while keeping the unit scale unchanged:

./udp_receiver --type pose --target-coord "left,+z,xfrom,1"

Angle data are joint angles and are not subject to coordinate system conversion. When conversion is enabled for quat and pose data, the rotation data of IMUs and joints are converted; additionally, pose data also convert the globalPosition of each joint.

3. C++ SDK Windows

This project is a C++ application designed for real-time reception and parsing of hand data. It utilizes Windows Socket (Winsock2) for UDP communication and integrates Google Protocol Buffers (Protobuf) for serialized data parsing.

3.1. Overview

This program operates as a UDP server, listening for broadcast or unicast data packets on a specified port.

Core Features:

  • UDP Communication: Based on the UDP protocol to ensure low-latency data transmission.
  • Protobuf Parsing: Supports parsing two core data packet types:
  • TeleopDataAngle: Data based on joint angles (suitable for robotic hand control).
  • TeleopDataQuat: Data based on quaternions (suitable for 3D rendering/Unity/UE).
  • TeleopDataPose: Data based on pose.
  • Cross-Platform Design: The core logic is compatible with Linux, while the network layer is adapted for Windows using Winsock2.

3.2. Structure

d:/udp_receiver_cpp/
├── CMakeLists.txt              # CMake build script, managing dependencies and compilation rules
├── main.cpp                    # Main program entry point, containing Socket logic and data printing
├── handdriver_teleop.proto     # Core data protocol definitions (hand data, telemetry packets)
├── handdriver_algebra.proto    # Basic mathematical type definitions (vectors, quaternions)
├── build/                      # (Auto-generated) CMake build directory
   └── Release/                # Output directory for compiled Release executable files

3.3. Environment Setup and Compilation

This project relies on CMake for build management and vcpkg for third-party library (Protobuf) management.

3.3.1. Dependency Preparation

  1. Install Visual Studio: Ensure the "Desktop development with C++" workload is included.
  2. Install CMake: Version 3.10 or higher is recommended.
  3. Install vcpkg: * Download vcpkg and run bootstrap-vcpkg.bat. * Install the Protobuf library: powershell vcpkg install protobuf:x64-windows

3.3.2. Compilation Steps

We provide two compilation modes: Release (recommended, better performance) and Debug (for debugging purposes).

Generate Project Files

In the project root directory, use CMake to configure the project. Please ensure you replace the path with your local vcpkg path.

# Replace <path_to_vcpkg> with the actual path, for example C:/vcpkg.
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release

Execute Compilation

cmake --build build --config Release

Compilation Output:

After successful compilation, the executable file udp_receiver.exe and its required DLLs (libprotobuf.dll, abseil_dll.dll) will be automatically generated in the build/Release directory.

3.4. Execution and Parameter Description

The program is a command-line tool that supports flexible configuration through parameters.

3.4.1. Startup Method (Choose One of Two)

  1. Method 1: Startup command format (Supports Port, Type, and Coordinate Conversion Parameters)
./udp_receiver.exe [--port port_number] [--type data_type]
./udp_receiver.exe [--port port_number] [--type data_type][--target-coord "handedness,up,view,unitScale"]

Parameter Details

Parameter Short Form Required Default Type Description
--port -p No 5555 Integer The local UDP port the program listens on. Ensure this port is not blocked by the firewall.
--type -t No angle String Specifies the protocol to parse:
angle: Parses joint angle data.
quat: Parses joint quaternion data.
pose: Parses joint pose data.
--target-coord / No / String Specifies the target coordinate system; coordinate conversion is enabled when this parameter is provided. Only affects position/quaternion data in pose and quat.
--coord-help / / Switch Prints the coordinate system parameter format description and exits.

Coordinate System Reference Format:

handedness,up,view,unitScale
left,+y,zfrom,1
handedness=left,up=+y,view=zfrom,unit=0.01
Field Allowed Values Descriptions
handedness left, right Specifies whether the target coordinate system is left-handed or right-handed.
up +x, -x, +y, -y, +z, -z Specifies the "up" axis in the target coordinate system.
view xfrom, yfrom, zfrom, xto, yto, zto Specifies the "forward / view direction" axis in the target coordinate system; from indicates that the positive direction of that axis points forward, while to indicates that the negative direction points forward.
unitScale Numeric value, e.g., 1, 0.01, 0.001 Specifies the scaling factor for position units; 1 means meters, 0.01 means centimeters, and 0.001 means millimeters.
  1. Method 2: Double-click the exe program to start (Coordinate conversion is not supported)

Follow the on-screen prompts to enter the data mode, then press Enter to start running.

Select receive data type:
  1. angle - TeleopDataAngle, joint angle data
  2. quat  - TeleopDataQuat, joint quaternion data
  3. pose  - TeleopDataPose, hand pose data
Enter type [1/2/3 or angle/quat/pose, default pose]:

3.4.3. Execution Examples

  • Scenario 1: Default Execution

Listens on port 5555 and parses angle data.

build\Release\udp_receiver.exe
  • Scenario 2: Receive quat data from HandDriver client

Assume HandDriver sends quat data to port 6666.

build\Release\udp_receiver.exe -p 6666 -t quat 
  • Scenario 3: Receive pose data from HandDriver client

Assume HandDriver sends pose data to port 6666.

build\Release\udp_receiver.exe -p 6666 -t pose
  • Scenario 4: Receive pose data from the HandDriver client and convert it to a left‑handed coordinate system with Z up and X forward, using the default unit scale.

Assume that the HandDriver sends pose data to port 6666.

build\Release\udp_receiver.exe -p 6666 -t pose --target-coord “left,+z,xfrom,1”

3.5. Code Logic Analysis

The core flow of main.cpp is as follows:

  1. Initialize Winsock: Call WSAStartup to initialize the Windows network library.
  2. Parse Arguments: Parse command-line arguments to obtain the port and data type.
  3. Create Socket: Establish a UDP socket (SOCK_DGRAM).
  4. Bind Port (Bind): Bind the socket to INADDR_ANY and the specified port, allowing it to receive traffic from all network interfaces.
  5. Receive Loop (While Loop): * recvfrom: Block and wait until a data packet is received. * Deserialization: Select the TeleopDataAngle, TeleopDataQuat or TeleopDataPose object according to --type, and call ParseFromString() to parse the binary data. * Data Processing: If parsing is successful, call the print_*_data function to print the string representation (DebugString()) of the data content.
  6. Resource Cleanup: Close the socket and clean up Winsock.

3.6. Secondary Development Guide

If you need to write your own code to read the data, please refer to the following C++ example:

Include Header Files

#include "handdriver_teleop.pb.h" // Auto-generated header files

Parsing Logic

// Assuming buffer is the received char* data and n is its length
std::string raw_data(buffer, n);
HandDriver::TeleopDataAngle packet;

if (packet.ParseFromString(raw_data)) {
    // 1. Get the timestamp
    long long ts = packet.timestamp();

    // 2. Get the bending degree of the left thumb tip
    // Access path: TeleopData -> LeftHand -> Joints Array -> Index 0
    float thumb_bend = packet.lefthand().joints(0); 

    // 3. Get the wrist pose
    auto imu = packet.lefthand().imu();
    printf("Wrist Quat: x=%.2f, y=%.2f\n", imu.x(), imu.y());
}

4. C++ SDK Linux

4.1. Overview

This project is a C++-based UDP network receiver program, specifically designed to receive and parse glove data serialized via Google Protocol Buffers (Protobuf). The program supports three primary data transmission modes: Angle mode, Quaternion mode and Pose mode.

4.2. Compilation and Build

This project uses CMake for build management.

4.2.1. Environment Dependency Installation

This project runs in a Linux (Ubuntu/Debian) environment. Please follow the steps below to install the required dependencies:

Update the Software Source

sudo apt-get update

Install Basic Build Tools

Install the C++ compiler (g++) and the CMake build tool:

sudo apt-get install -y build-essential cmake

Install Protocol Buffers

This project relies on Google Protocol Buffers for data serialization. It requires the installation of the compiler (protoc) and the C++ development library (libprotobuf-dev):

sudo apt-get install -y protobuf-compiler libprotobuf-dev

4.2.2. Compilation Steps

Please execute the following commands in the project's root directory:

# 1. Generate the build files
cmake .

# 2. Compile the executable
make

After successful compilation, the executable file udp_receiver will be generated in the current directory.

4.3. Usage Instructions

The program is configured via command-line parameters, supporting custom listening ports and data types.

4.3.1. Parameter Description

Parameter Short Form Required Default Type Description
--port -p No 5555 Integer The local UDP port the program listens on.
--type -t No angle String angle: Parses joint angle data.
quat: Parses joint quaternion data.
pose: Parses joint pose data.
--target-coord / No / String Specifies the target coordinate system; coordinate conversion is enabled when this parameter is provided. Only affects position/quaternion data in pose and quat.
--coord-help / / Switch Prints the coordinate system parameter format description and exits.

Coordinate System Reference Format:

handedness,up,view,unitScale
left,+y,zfrom,1
handedness=left,up=+y,view=zfrom,unit=0.01
Field Allowed Values Descriptions
handedness left, right Specifies whether the target coordinate system is left-handed or right-handed.
up +x, -x, +y, -y, +z, -z Specifies the "up" axis in the target coordinate system.
view xfrom, yfrom, zfrom, xto, yto, zto Specifies the "forward / view direction" axis in the target coordinate system; from indicates that the positive direction of that axis points forward, while to indicates that the negative direction points forward.
unitScale Numeric value, e.g., 1, 0.01, 0.001 Specifies the scaling factor for position units; 1 means meters, 0.01 means centimeters, and 0.001 means millimeters.

4.3.2. Execution Examples

  1. Run with default settings (Listens on port 5555, parses Angle data):
./udp_receiver
  1. Specify port and type (Listens on port 6000, parses Quat data):
./udp_receiver --port 6000 --type quat
  1. Specify port and type (Listens on port 6000, parses Pose data):
./udp_receiver --port 6000 --type pose
  1. Specify port and type with coordinate conversion (Listen on port 6000, parse Pose data, and convert to a left‑handed coordinate system with Z up, X forward, and default unit scale):
./udp_receiver --port 6000 --type pose --target-coord "left,+z,xfrome,1"

4.4. Code Logic and Interfaces

4.4.1. Main Program Flow (main.cpp)

  1. Parameter Parsing: Uses getopt_long to parse command-line arguments port and type.
  2. Socket Initialization: Creates a UDP socket and binds it to the specified port (INADDR_ANY).
  3. Reception Loop:
  • recvfrom blocks and receives a UDP data packet.
  1. Protobuf parsing: Based on the type argument, selects the corresponding Protobuf message type (TeleopDataAngle, TeleopDataQuat or TeleopDataPose) for deserialization (ParseFromString).
  2. Coordinate conversion:
  • Pose: When conversion is enabled, call ConvertTeleopDataPoseInPlace() to convert the left‑hand and right‑hand IMU data, as well as the globalPosition and globalRotation of each joint.
  • Quat: When conversion is enabled, call ConvertTeleopDataQuatInPlace() to convert the left‑hand and right‑hand IMU quaternions and the joint quaternions.
  • Angle: No coordinate conversion is performed; the raw angle data is output directly.
  1. Output printing:
  • On successful parsing, call the corresponding print function.
  • On parsing failure, output an error message and continue to the next loop iteration.

4.4.2. Coordinate System Conversion API (coordinate_system.h)

Namespace: HandDriver::CoordinateSystem

Main Types:

enum class Side { Left, Right };
enum class AxisPolarity { NegativeZ, NegativeY, NegativeX, PositiveX, PositiveY, PositiveZ };
enum class AxisView { ZFromViewer, YFromViewer, XFromViewer, XToViewer, YToViewer, ZToViewer };

struct CoordinateSystemVUH {
    AxisView view = AxisView::ZFromViewer;
    AxisPolarity up = AxisPolarity::PositiveY;
    Side handedness = Side::Left;
    float unitScale = 1.0f;
};

Main Functions:

Function Description
HandDriverDefaultCoordinateSystem() Returns the HandDriver default coordinate system left,+y,zfrom,1.
IsCoordinateSystemValid() Validates whether the coordinate system configuration is valid.
ParseCoordinateSystemVUH() Parses a string coordinate system configuration into a CoordinateSystemVUH.
ToString() Formats the coordinate system configuration as a readable string.
CoordinateSystemSpecHelp() Returns the help text for coordinate system parameters.
ConvertPosition() Converts a Vec3 position, including axis mapping and unit scaling.
ConvertRotation() Converts a Quat quaternion rotation.
ConvertJointPose() Converts the globalPosition and globalRotation of a single JointPose.
ConvertGloveHandDataPoseInPlace() In‑place conversion of Pose data for a single hand.
ConvertTeleopDataPoseInPlace() In‑place conversion of Pose data for both left and right hands in TeleopDataPose.
ConvertGloveHandDataQuatInPlace() In‑place conversion of Quat data for a single hand.
ConvertTeleopDataQuatInPlace() In‑place conversion of Quat data for both left and right hands in TeleopDataQuat.

5. Python SDK - Linux/Win

This SDK supports both Windows and Linux.

This tool listens on a specified port via the UDP protocol, receives binary data packets, and uses Google Protocol Buffers (Protobuf) to deserialize them according to the specified data type (angle, quat or pose), finally printing the parsed data to the console.

5.1. Environment Dependencies

  • Python 3.x
  • Protobuf library

Install dependencies:

pip install protobuf==3.20.3

5.2. Interface Description and Data Access

5.2.1. Communication Protocol

  • Protocol: UDP
  • Default Port: 5555
  • Data Format: Protobuf-serialized binary stream

5.2.2. Reception Process (Python)

  1. Create Socket: Establish a UDP socket.
  2. Bind Port: Bind to a specified IP (0.0.0.0) and port.
  3. Reception Loop: Use recvfrom to receive data packets.
  4. Deserialization: * If the data type is angle, use TeleopDataAngle.ParseFromString(data). * If the data type is quat, use TeleopDataQuat.ParseFromString(data). * If the data type is pose, use TeleopDataPose.ParseFromString(data).
  5. Data Access: Access fields of the parsed object (e.g., msg.LeftHand.joints[0]).

5.3. Usage Demo

The script udp_receiver.py provides a simple command-line interface.

5.3.1. Parameter Description

Parameter Required Default Description
--port No 5555 The local UDP port the program listens on.
--type No angle angle: Parses joint angle data.
quat: Parses joint quaternion data.
pose: Parses joint pose data.
--source-coord No left,+y,zfrom,1 Specifies the source coordinate system of the input data; usually keep the default.
--target-coord No / Specifies the target coordinate system; coordinate conversion is enabled when this parameter is provided. Only affects position/quaternion data in pose and quat.
--coord-help / Prints the coordinate system parameter format description and exits.

View coordinate system parameter help:

python udp_receiver.py --coord-help

5.3.2. Example 1: Receiving Angle Data (Default)

python udp_receiver.py

Or specify explicitly:

python udp_receiver.py --port 5555 --type angle

5.3.3. Example 2: Receiving Quaternion Data

If the sender is transmitting data in quaternion format:

python udp_receiver.py --port 5555 --type quat

5.3.4. Example 3: Receiving Pose Data

If the sender is transmitting data in pose format:

python udp_receiver.py --port 5555 --type pose

5.3.5. Example 4: Changing the Listening Port

To listen on port 6000:

python udp_receiver.py --port 6000

5.3.6. Example 5: Receive pose data and convert it to a left-handed coordinate system, with Z up, X forward, and default unit scaling.

python udp_receiver.py --port 5555 --type pose --target-coord "left,+z,xfrome,1"