Complete guide for controlling robots in RoboSpace
# 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]}")get_num_actuators() - Get number of actuatorsget_actuator_names() - Get actuator namesget_actuator_ranges() - Get control limitsset_control(ctrl) - Set control valuesget_control() - Get current controlget_qpos() - Get joint positionsget_qvel() - Get joint velocitiesget_time() - Get simulation timereset() - Reset simulationstep() - Step simulation forwardReturns 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_actuatorsSets 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 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)