RoboSpace API Documentation

Complete guide for controlling robots in RoboSpace

Getting Started

Quick Start

# Quick Start

# Get basic information
n = get_num_actuators()
print(f"Robot has {n} actuators")

# Set control values
control = [0.5] * n
set_control(control)

# Get current state
pos = get_qpos()
vel = get_qvel()
print(f"Position: {pos[:3]}")
print(f"Velocity: {vel[:3]}")

Available Functions

  • get_num_actuators() - Get number of actuators
  • get_actuator_names() - Get actuator names
  • get_actuator_ranges() - Get control limits
  • set_control(ctrl) - Set control values
  • get_control() - Get current control
  • get_qpos() - Get joint positions
  • get_qvel() - Get joint velocities
  • get_time() - Get simulation time
  • reset() - Reset simulation
  • step() - Step simulation forward

Core Functions

get_num_actuators()

get_num_actuators() → int

Returns the total number of actuators in the current robot model.

# Get number of actuators
n_actuators = get_num_actuators()
print(f"Number of actuators: {n_actuators}")

# Create control array with correct size
control = [0.0] * n_actuators

set_control(ctrl)

set_control(ctrl: list[float]) → None

Sets control values for all actuators. Input can be a list or numpy array.

# Set all actuators to neutral
control = [0.0] * get_num_actuators()
set_control(control)

# Sine wave control
import math
t = get_time()
control = [0.5 * math.sin(t + i*0.5) for i in range(get_num_actuators())]
set_control(control)

get_qpos() & get_qvel()

get_qpos() → numpy.array
get_qvel() → numpy.array

Get joint positions and velocities respectively.

# PD Controller example
import numpy as np

def pd_controller(target, kp=10.0, kd=1.0):
    qpos = get_qpos()
    qvel = get_qvel()
    n = get_num_actuators()
    
    # Calculate errors
    pos_error = np.array(target) - qpos[:n]
    vel_error = -qvel[:n]
    
    # PD control law
    control = kp * pos_error + kd * vel_error
    set_control(control.tolist())
    
    return np.linalg.norm(pos_error)