@ebowwa/unitree-g1
v0.1.2
Published
TypeScript bindings for Unitree G1 SDK2 - Control Unitree G1 humanoid robot from Node.js/Bun
Maintainers
Readme
@ebowwa/unitree-g1
TypeScript bindings for Unitree G1 SDK2 - Control Unitree G1 humanoid robot from Node.js/Bun.
Installation
bun add @ebowwa/unitree-g1Prerequisites
libunitree_sdk2.so- Unitree SDK2 shared library- CycloneDDS (
libddsc.so) - DDS middleware - Network connection to robot (Ethernet)
Usage
Basic Setup
import { init, release, G1Loco, FsmModeType } from '@ebowwa/unitree-g1';
// Initialize SDK with domain ID and network interface
init(0, 'eth0');
try {
// Create locomotion client
const loco = new G1Loco();
// Check current mode
const mode = loco.getFsmMode();
console.log('Current mode:', mode);
// Set to walking mode
loco.setFsmMode(FsmModeType.WalkRun);
// Move forward at 0.5 m/s
loco.setVelocity(0.5, 0, 0);
// Wait 2 seconds
await new Promise(r => setTimeout(r, 2000));
// Stop
loco.stop();
// Set to passive mode
loco.setFsmMode(FsmModeType.Passive);
} finally {
// Release resources
release();
}Arm Actions
import { init, release, G1Arm, ARM_ACTIONS } from '@ebowwa/unitree-g1';
init(0, 'eth0');
const arm = new G1Arm();
// Execute predefined action by ID
arm.executeAction(ARM_ACTIONS.SHAKE_HAND);
// Execute action by name
arm.executeActionByName('wave');
// Stop custom action
arm.stopAction();
// Get available actions
const actionList = arm.getActionList();
console.log('Available actions:', actionList);
release();Using G1Robot Helper
import { G1Robot } from '@ebowwa/unitree-g1';
// Create robot with default config (domain 0, eth0)
const robot = new G1Robot(0, 'eth0');
// Get locomotion client
const loco = robot.loco();
// Get arm client
const arm = robot.arm();API Reference
Functions
init(domainId: number, networkInterface: string)- Initialize SDKrelease()- Release SDK resourcesisInitialized(): boolean- Check if SDK is initialized
Classes
G1Loco
getFsmMode(): FsmModeType- Get current FSM modesetFsmMode(mode: FsmModeType)- Set FSM modesetVelocity(linearX, linearY, angularZ)- Set velocity commandstop()- Stop the robot
G1Arm
executeAction(actionId: number)- Execute action by IDexecuteActionByName(name: string)- Execute action by namestopAction()- Stop current actiongetActionList(): string- Get available actions (JSON)
Constants
// FSM Modes
FsmModeType.Last = 0
FsmModeType.Passive = 1
FsmModeType.WalkRun = 2
// Arm Actions
ARM_ACTIONS.RELEASE = 99
ARM_ACTIONS.TWO_HAND_KISS = 11
ARM_ACTIONS.SHAKE_HAND = 27
ARM_ACTIONS.WAVE = 28
ARM_ACTIONS.THUMBS_UP = 29
// Channel Names
CHANNELS.LOW_STATE = 'rt/lowstate'
CHANNELS.LOW_COMMAND = 'rt/lowcmd'
CHANNELS.VELOCITY_COMMAND = 'rt/velocitycmd'
// API IDs
LOCO_API.SET_VELOCITY = 7105
LOCO_API.SET_FSM_MODE = 7003Building from Source
# Build Rust crate
cd unitree-sdk && cargo build --release
# Build napi bindings
cd ../unitree-ts && bun run buildLicense
MIT
