Skip to content

7. Legged robots

quadruped_velocity is a robot standing on the ground: the bundled 12 kg quadruped (a trunk and four legs of three joints, 12 actuated joints) must hold a stance and walk at a commanded velocity. Unlike the space robot, it has a ground, a stiff spring, which changes how the environment is stepped.

Status

The environment is complete and tested, but no learned policy walks properly yet.

  • After 3 million steps of PPO the forward speed did not follow the command, and the policy did no better than doing nothing: a zero action, which just holds the standing pose with the PD law, already survives every 500-step episode (velocity error 0.265 m/s; the trained policy 0.276 m/s), so staying up is not evidence of learning. Random actions survive only 3 %.
  • After 10 million steps with a sharper tracking kernel (sigma=0.25, commands 0.2 to 0.5 m/s) the speed does follow the command (0.21, 0.31, 0.39 and 0.45 m/s for commands of 0.2, 0.3, 0.4 and 0.5; error 0.072 m/s; no falls), but not as a gait. One foot is held in the air permanently, two feet slide on the ground at about 0.55 m/s, the fourth taps about ten times a second, and the trunk is crouched at 0.34 m instead of 0.48 m. The default reward does not penalise foot slip or an unnatural pose, so the policy found a way around them; the optional terms below address that.

The robot always starts upright, so there is no get-up task, and no push or recovery test has been done. Walking needs far longer training than the arm tasks (see Training).

This task needs the floating-base package (see Install).

import numpy as np
import redysim_rl

env = redysim_rl.make_vec("quadruped_velocity", num_envs=8)       # PD-target actions by default
command = np.tile([0.3, 0.0, 0.0], (8, 1))                        # forward speed, sideways, yaw rate
obs, info = env.reset(seed=0, options={"command": command})
for _ in range(25):                                               # a zero action holds the stance
    action = np.zeros(env.action_space.shape, dtype=np.float32)
    obs, reward, terminated, truncated, info = env.step(action)
print(obs.shape, info["height"].mean().round(2), int(info["fell"].sum()))

What the policy sees and does

An episode lasts 500 control steps (10 s) at 50 Hz. The observation has 45 values, and none of them needs more than an IMU and the joint encoders:

values content
3 direction of gravity in the base frame (zero tilt gives (0, −1, 0))
3 angular velocity of the base, in the base frame (scaled by 0.25)
3 the command: forward speed, sideways speed, yaw rate
12 joint positions relative to the standing pose
12 joint velocities (scaled by 0.05)
12 the previous action

There is deliberately no linear velocity and no base position. The action is a joint target within 0.5 rad of the standing pose; a PD law (kp 80, kd 2, force limit 20 N m) turns it into forces. A zero action holds the standing pose. With impedance actions the previous action has 36 values, so the observation has 69.

Commands and reward

A command (v_forward, v_left, yaw rate) is drawn at every reset, in the heading frame: the base's forward axis (its z axis for the bundled model), flattened onto the ground. By default only the forward speed varies (0 to 0.5 m/s). Per step the reward is

  • + 1.0 · exp(−|v − v_cmd|² / σ²) for the horizontal velocity (σ = 0.5 m/s), and + 0.5 · exp(−(ω − ω_cmd)² / σ²) for the yaw rate; With yaw_gate (0 to 1, default 0) the yaw term is multiplied by 1 − yaw_gate · (1 − speed term), so it is only paid in proportion to how well the speed is tracked. Without it, a robot that stands still, or walks in a circle at the right body-frame speed, collects the yaw reward (or, with w_ang = 0, nothing stops the circling);
  • − 2.0 · tilt (the squared horizontal part of gravity in the base frame);
  • − 0.01 · squared change of the action, − 10⁻⁴ · squared joint velocities;
  • − 10 when the robot falls, which ends the episode: the base lower than half the standing height, or tilted by more than 1 rad.

Optional terms shape a gait; each is off (weight 0) by default:

  • w_pose · exp(−mean((q − q_nominal)²) / pose_sigma²) keeps the legs near the standing pose;
  • − w_slip · squared horizontal speed of every foot in contact, − w_torque · squared joint forces of the PD law;
  • − w_knee · number of knees on the ground (knee_fall=True ends the episode like a fall);
  • w_air · (time a foot was in the air − air_min), capped at air_max − air_min, paid when it touches down while the commanded speed exceeds 0.1 m/s, and − w_up · seconds (up to 1) a foot has been up beyond air_max;
  • − w_pitch · absolute pitch of the trunk.
from redysim_rl import RedysimVectorEnv
from redysim_rl.legged import QuadrupedVelocity

task = QuadrupedVelocity(vx_range=(0.2, 0.5), wz_range=(-0.3, 0.3), sigma=0.25, w_rate=0.1)
env = RedysimVectorEnv(task, num_envs=4)
obs, info = env.reset(seed=0)
print(env.unwrapped.task.cmd.round(2))

info reports velocity_error, yaw_error, height, fell, is_success (not fallen) and is_tracking (up, and the speed within tol_speed of the command). The ReDySim RL GUI also asks for the mean turn-rate error to be below tol_yaw (default 0.3 rad/s) before it counts a test robot as a success. The same settings can be given by name: make_vec("quadruped_velocity", task_kwargs={"sigma": 0.25}).

Why it is slower than the arm tasks

The ground is a stiff contact, so the physics needs a small step, and the step the task uses depends on the robot's ground. The bundled quadruped has the Hunt-Crossley ground: the task steps it with the semi-implicit method at 2 ms, 10 steps in every 50 Hz control step (decimation=10, method="semi_implicit"). On a 1 s walk the trunk follows a fine-step run to a few millimetres up to 8 ms, but a robot holding its pose creeps along the ground because of the friction: 108 mm/s at 4 ms, 13 mm/s at 2 ms (about the 11 mm/s of the MATLAB ground at 1 ms) and 1 mm/s at 1 ms, so 2 ms is the default (see the floating-base manual, Modelling, the bundled models). With the MATLAB-damped quadruped_matlab (robot="quadruped_matlab") the task uses RK4 at 1 ms, 20 steps per control step, as before. Both choices apply to every action mode (even the torque mode) and can be overridden with decimation and method. RK4 at a fixed step is erratic on the Hunt-Crossley ground, so keep the semi-implicit method with it.

The earlier measurements were on the MATLAB ground: with 1,024 robots about 11,000 to 13,000 control steps per second in every action mode (one environment about 700 to 970), and the larger steps tried there (RK4 at 2 ms) still stood with a larger droop, while the semi-implicit method at 1 ms lost some stability (3 of 256 robots fell while standing) and diverged from 2 ms. They were measured on a busy machine, so only the ordering is reliable. No policy has been trained on the Hunt-Crossley ground beyond a 0.1M-step test run.

Other legged robots

robot= takes another floating-base model, but then give q_nominal (the standing pose) and base_height; without them the task refuses a robot other than the bundled quadruped. The Spot-like model bundled with the floating-base package does not stand with the gains and steps tried here, so it is not supported. Mass randomisation works as for every task (randomise={"mass": 0.1}).