ROBOTICS FIELD NOTESENGLISH EDITION / 8 October 2026
Guides

Robot programming for beginners

Start with a small Python and MuJoCo control exercise, then learn where ROS 2 messages fit into a robot software system.

Start with a measurable movement

Program a single simulated hinge to reach a requested angle. This keeps the first exercise small enough to inspect. You will define the mechanism, set a target, advance time and read the resulting position. There is no walking policy to train and no physical robot to purchase.

MuJoCo provides a CPU physics engine with Python bindings. Its interactive renderer and its GPU simulation backends are separate pieces. The exercise below uses no viewer, camera rendering, MJX or CUDA. A supported Python environment is enough to attempt this small CPU simulation; performance on a particular computer still depends on that machine. [1]

Create an isolated Python environment

Make a folder for the exercise and run the following command in its terminal. Use a Python interpreter supported by the current MuJoCo package. The official Python documentation for MuJoCo explains that its pip package includes the simulation library. [2]

python -m venv robot-lab

On Linux or macOS, install into that environment with robot-lab/bin/python -m pip install mujoco. On Windows, use robot-lab\Scripts\python.exe -m pip install mujoco. Keep the interpreter path when running the exercise so installation and execution use the same environment.

Move a hinge to half a radian

Save this original exercise as one_joint.py. The XML defines a half-kilogram capsule on a vertical hinge and a position actuator. Its target is 0.5 radians. The actuator applies feedback as the simulated joint moves. The timestep is 0.002 seconds, so 1,000 steps cover two seconds of simulated time. [3]

import mujoco

scene = """
<mujoco model="one_joint">
  <option timestep="0.002" integrator="implicitfast"/>
  <worldbody>
    <body>
      <joint name="turn" type="hinge" axis="0 0 1" damping="0.1"/>
      <geom type="capsule" fromto="0 0 0 0.3 0 0" size="0.03" mass="0.5"/>
    </body>
  </worldbody>
  <actuator>
    <position joint="turn" kp="5" kv="0.5"/>
  </actuator>
</mujoco>
"""
model = mujoco.MjModel.from_xml_string(scene)
state = mujoco.MjData(model)
state.ctrl[0] = 0.5
for step in range(1000):
    mujoco.mj_step(model, state)
print(f"time={state.time:.2f}s angle={state.qpos[0]:.3f}rad")

Run robot-lab/bin/python one_joint.py on Linux or macOS, or robot-lab\Scripts\python.exe one_joint.py on Windows. Here state.ctrl[0] holds the requested angle, while state.qpos[0] holds the simulated joint angle. Each mj_step call advances the simulated state by the configured timestep. The program should print time=2.00s angle=0.500rad. [2] [1]

After the hinge exercise, inspect the 29-actuator G1 model. The next tutorial records joint and sensor data from a floating humanoid model.

Change one parameter at a time

  • Change the target to 0.2 radians and rerun from the initial state.
  • Print the angle every 100 steps to see the path to the target.
  • Reduce the actuator gain and compare how long the joint takes to settle.
  • Keep a table of target, final angle, gain and timestep.

The controller responds to the difference between the target and measured angle. The position gain sets its response to that error, while the velocity gain damps the motion. Studying that error is more informative than checking that a script exited. This exercise has one fixed-base joint and no contact task, perception or balancing. A humanoid adds those coupled problems.

Add ROS 2 when programs need to communicate

ROS 2 introduces nodes, publishers and subscribers so separate parts of a robot system can exchange messages. Its DDS design documents explain the communication model. For a later version of this exercise, put the target generator and the state logger in separate nodes. Send the target in one topic and the measured position in another. [4]

Use the official ROS 2 documentation for the release installed on your computer. Complete its beginner node and topic material before combining a simulator, camera driver and controller. The documentation repository links to the maintained manuals. [5]

Sources and verification

  1. MuJoCo engine overview ↗Google DeepMind / MuJoCo · Read 8 October 2026

    Separates the CPU simulation engine, OpenGL rendering and GPU backends.

  2. MuJoCo Python bindings ↗Google DeepMind / MuJoCo · Read 8 October 2026

    Official installation and MjModel, MjData and mj_step API documentation.

  3. MuJoCo MJCF reference ↗Google DeepMind / MuJoCo · Read 8 October 2026

    Hinge joint, position actuator and integration settings used in the original exercise.

  4. ROS on DDS design document ↗ROS 2 project · Read 8 October 2026

    Historical design source for nodes, publishers, subscribers and message transport. Not used for current installation commands.

  5. ROS 2 official documentation source ↗ROS 2 project · Read 8 October 2026

    Official documentation repository and supported documentation entry point. Tutorials must match the installed ROS release.

Article history

Explained the target, simulated joint angle and position and velocity gains used by the runnable one-joint exercise.

Added a contextual link to the simulation series for the next engineering step.

Report a correction