Programming the robot
pyCub supports three main programming workflows depending on your experience level and whether you want Studio’s integrated 3D interface or a standalone Python environment:
Workflow |
Entry API |
Units |
Simulation loop |
Best for |
|---|---|---|---|---|
Kid modes (Scratch & Kid Programming in Studio) |
|
Degrees |
Managed automatically |
Beginners, classrooms, quick experiments |
Studio Full Mode (Normal Mode IDE in Studio) |
|
Radians |
Explicit ( |
Full robot control, cameras, skin, course exercises |
Normal / Standalone Python (Terminal / PyCharm / VS Code) |
|
Radians ( |
Explicit ( |
Automated evaluation, headless runs, external Open3D/Web GUI |
(Note: inside .yaml world files, initial_joint_angles are always written in degrees, regardless of mode.)
Kid modes (icub_pybullet.kid_api)
The Kid modes inside pyCub Studio — Kid “Scratch” (Blocks) and Kid Programming (Python) — both run on top of icub_pybullet.kid_api.
How Kid execution works
Studio keeps an interactive physics worker running continuously in the background for the currently selected world (
with_ball.yaml,default.yaml,skin_test.yaml, or your custom.yamlworld in~/Documents/pyCub/worlds/).You do not instantiate
pyCub(...)and do not write awhile client.is_alive(): client.update_simulation()loop.Every movement command blocks until the motion finishes (or reaches its timeout), stepping the simulation smoothly and checking the Stop button cooperatively so infinite loops can always be interrupted immediately.
From Scratch blocks to Python
In Kid “Scratch”, snap movement, loop, logic, and sensor blocks together. Toggle Python Preview to watch the live Python translation as you edit blocks, save reusable projects as .pycub_blocks, or click Open as Python in Kid Programming to export the generated script directly into the text Python editor.
First program in Kid Programming
Select a world containing a ball (such as Table with a ball / with_ball.yaml) and run:
from icub_pybullet.kid_api import wave, shoulder_up, look_down, ball_touched, ball_distance
look_down(20)
wave("right")
shoulder_up("left", degrees=20, speed=1.5)
print("Touched:", ball_touched(), "Distance (cm):", ball_distance())
Studio automatically exposes all English and Czech kid_api commands for autocomplete and inline help, and both spellings share the exact same underlying controller. The equivalent Czech script is:
from icub_pybullet.kid_api import podívej_se_dolů, zamávej, zvedni_rameno, dotkl_se_míčku, vzdálenost_míčku
podívej_se_dolů(20)
zamávej("pravá")
zvedni_rameno("levá", degrees=20, speed=1.5)
print("Dotyk:", dotkl_se_míčku(), "Vzdálenost (cm):", vzdálenost_míčku())
Keyword arguments always use the Python parameter names (side, degrees, speed, target_degrees, delta_degrees, seconds).
Kid command groups
Preset actions:
wave(side="right"),left_wave(),right_wave(),both_arms_up(),both_arms_down(),look_center(),stand_straight(),reset_pose(),stop().Relative arm moves (degrees):
shoulder_up,shoulder_down,shoulder_out,shoulder_in,rotate_arm,bend_elbow,straighten_elbow,rotate_wrist. All acceptside("left"/"right"or"levá"/"pravá"),degrees=15.0, andspeed=1.5(rad/s).Relative head & torso moves (degrees):
turn_head,look_up,look_down,tilt_head,turn_body,bend_forward,bend_back,bend_sideways.Direct joint access & timing:
move_joint(joint_name, target_degrees, speed=1.5)for an absolute target angle,jog_joint(joint_name, delta_degrees, speed=1.5)for a signed relative offset,get_joint(joint_name)to read the current angle in degrees, andwait(seconds=1.0)to pause while physics keeps running.Sensors & telemetry:
ball_distance()(distance between ball and table in centimetres),ball_touched()(bool),ball_hits()(int), andskin_touched()(bool, active whenskin.use: True).
Click any entry in the Command Palette on the left to insert a working snippet at the cursor, or load a starter template from the toolbar. Syntax and runtime errors highlight the offending line in red and display a beginner-friendly hint in the console.
Studio Full Mode (Normal Mode IDE)
Normal Mode in pyCub Studio gives you the complete icub_pybullet.pycub.pyCub simulator API together with an embedded hardware-accelerated OpenGL 3D viewport, live console, eye cameras, and course exercise tools.
Running scripts in Studio Normal Mode
Edit
.pycontrollers and.yamlworld configs across multiple tabs and press F5 (or click Run Script) to execute the active tab.Each run starts in a clean isolated worker subprocess (
SimProcessSupervisor) whose rendering streams directly into Studio’s embedded 3D viewport—no separate Open3D window is opened.To code in PyCharm or VS Code while using Studio’s 3D viewport and camera panels, click Run External .py… and enable Auto-run external file on save, or launch Studio directly from the command line:
python -m studio.main --run-script path/to/your_controller.py
Minimal pyCub controller structure
In Full / Normal mode, your script creates the pyCub client, selects a world .yaml config, commands motions in radians, and keeps the simulation alive at the end until you click Stop:
from icub_pybullet.pycub import pyCub
client = pyCub(config="with_ball.yaml")
# Blocking joint motion (waits until target is reached or collision/timeout occurs)
client.move_position("neck_pitch", -0.25)
# Non-blocking joint motion: advance simulation manually in your own loop
client.move_position(["torso_pitch", "torso_yaw"], [0.30, -0.60], wait=False, velocity=2.0)
while not client.motion_done():
client.update_simulation()
# Keep the 3D view responsive after your routine finishes
while client.is_alive():
client.update_simulation()
Joint, velocity, and Cartesian control
Position control (
move_position): Pass a single joint name/ID or equal-length lists of joints and target angles in radians. Optional parameters:wait=True,velocity=1(rad/s),set_col_state=True,check_collision=True, andtimeout=None(seconds). Withwait=False, drive the simulation yourself withclient.update_simulation()untilclient.motion_done()returnsTrue, or callclient.wait_motion_done().Velocity control (
move_velocity): Command target angular speeds in radians per second for one joint or a list of joints.Reading joint state & stopping:
client.get_joint_state(joints=None)returns current joint positions in radians (defaulting to all movable joints);client.stop_robot(joints=None)halts active position or velocity targets.Cartesian control (
move_cartesian&Pose): Read the current end-effector pose withpose = client.end_effector.get_position(), adjustpose.pos([x, y, z]in metres) orpose.ori(quaternion[x, y, z, w]), and callclient.move_cartesian(pose, wait=True, velocity=1, check_collision=True, timeout=None). PyBullet computes the inverse kinematics solution and commands the movable joints automatically.
from icub_pybullet.pycub import pyCub, Pose
client = pyCub(config="with_ball.yaml")
cur = client.end_effector.get_position()
target = Pose(list(cur.pos), list(cur.ori))
target.pos[2] -= 0.15
target.pos[0] -= 0.10
client.move_cartesian(target, velocity=1.5)
Jacobians (
compute_jacobian): Compute the base-frame geometric Jacobian and active joint names for any kinematic chain ("left_arm","right_arm","left_leg","right_leg","torso","head"):
J, active_joints = client.compute_jacobian("right_arm", end="r_hand")
Eye cameras, tactile skin, and workspace tools
Eye cameras (
l_eye,r_eye): Toggle Left Eye (l_eye) or Right Eye (r_eye) in the Normal Mode toolbar, or seteyes.l_eye: True/eyes.r_eye: Truein your.yamlconfig. In Python, callclient.get_camera_images(eyes)for RGB arrays andclient.get_camera_depth_images(eyes)for depth arrays. Use Save RGB / Save Depth to export PNGs to~/Documents/pyCub/images/.Tactile skin: Set
skin.use: Truein your config (seeskin_test.yaml), step the simulation withclient.update_simulation(), and inspectclient.skin_activationsandclient.activated_skin_points.Examples & Course Exercises: Open the Examples & Exercises menu to load bundled scripts or copy Exercises
1–5into~/Documents/pyCub/exercises/. When an exercise file is open, click Run Exercise Tester to run its automated verification suite and view the HTML report.Extra packages & custom Python: Use Packages / Python in the top bar to install PyPI wheels into
~/Documents/pyCub/extra_packages/, attachsite-packagesfrom an existing virtual environment, or select an external Python executable for Normal Mode scripts.
Normal / Standalone Python mode (outside Studio)
You can also run any pyCub script directly from a terminal, PyCharm, or VS Code using an environment where icub_pybullet is installed (python3 -m pip install icub_pybullet or python3 -m pip install ./icub_pybullet), without launching Studio at all.
Visualizer backends (gui in .yaml)
When running outside Studio, pyCub reads the gui block of your .yaml config:
gui:
standard: True # Native Open3D 3D window
web: False # Browser-based visualizer (slower fallback)
Open3D desktop window (
standard: True, web: False): Default interactive 3D window when running locally.Browser visualizer (
standard: False, web: True): Serves an interactive view in your web browser—useful over remote sessions or if host OpenGL drivers conflict with Open3D.Headless mode (
standard: False, web: False): No 3D GUI is created. Best for automated tests, reinforcement learning, batch evaluation, and CI.
(Inside Studio Normal Mode, Studio automatically overrides these flags to route rendering into its embedded OpenGL viewport.)
Running kid_api scripts standalone
Scripts written for Kid Programming using icub_pybullet.kid_api also run directly as standard Python files:
python my_kid_script.py
On the first command call, get_robot() lazily creates pyCub(config="with_ball.yaml") and steps the simulation automatically.
Config resolution and running exercises from CLI
When you pass a relative config name such as pyCub(config="with_ball.yaml"), pyCub searches in order:
Direct / absolute path or relative to the current working directory.
Relative to the calling script’s directory (and a
configs/subfolder next to it).Your user workspace (
~/Documents/pyCub/worlds/,~/Documents/pyCub/configs/,~/Documents/pyCub/).Built-in
icub_pybullet/configs/(default.yaml,with_ball.yaml,skin_test.yaml).
Custom .yaml configs can inherit built-in settings via parent: with_ball.yaml and override only the fields you need (such as urdfs, eyes, skin, or end_effector).
To run an exercise tester directly from the command line outside Studio:
python exercises/exercise_1/exercise_1_tester.py
Inspecting calls in the editor
Both Kid Programming and Normal Mode in Studio include live Jedi-powered code inspection:
Hover documentation: Hover the mouse over a function or class name to read its signature and docstring without moving the cursor. Hover help formats
:param:entries and trailing inline parameter comments on separate lines.Signature & parameter hints: Pause with the cursor inside parentheses of a function call (or press Ctrl+Shift+Space) to view the active parameter and default values.
Go to Definition (
F12): Place the cursor on any symbol and press F12 to view its source definition and docstring—working for both unsaved functions in your current buffer andicub_pybulletlibrary code.
Motion, kinematics, and sensor reference
Quick comparison: Kid API vs Full pyCub API
Task |
Kid API ( |
Full |
|---|---|---|
Target joint angle |
|
|
Multi-joint move |
Call sequentially or loop |
|
Relative joint offset |
|
Read |
Joint velocity |
— |
|
Cartesian IK move |
— |
|
Read joint angle |
|
|
Camera RGB / Depth |
— |
|
Ball telemetry |
|
Inspect |
Tactile skin |
|
|
Step simulation |
Handled internally inside each command |
|
Key iCub joints and kinematic chains
Torso:
torso_pitch,torso_roll,torso_yawHead & eyes:
neck_pitch,neck_roll,neck_yaw,eyes_tilt,l_eye_pan_joint,r_eye_pan_jointLeft / right arms (
l_/r_):*_shoulder_pitch,*_shoulder_roll,*_shoulder_yaw,*_elbow,*_wrist_prosup,*_wrist_pitch,*_wrist_yaw, plus finger joints*_hand_*Left / right legs (
l_/r_):*_hip_pitch,*_hip_roll,*_hip_yaw,*_knee,*_ankle_pitch,*_ankle_rollKinematic chains (
CHAINS):"left_arm","right_arm","left_leg","right_leg","torso","head"
The bundled Example controllers and API reference document all classes, method signatures, and default parameters in detail.