Skip to content

4. Action modes

The policy outputs numbers in [−1, 1], one set per robot; the action mode turns them into forces on the actuated joints. Choose it with action_mode=:

mode action per joint force
"torque" a a · tau_max
"pd_target" a kp (q* − q) − kd dq with fixed gains; q* is the action scaled onto q_range (absolute) or q + a · delta_max (delta)
"impedance" a_q, a_kp, a_kd the same law, with kp and kd read from the action on a logarithmic scale between limits
"diff_drive" (two numbers for the robot) v, w a differential-drive robot: forward speed and turn rate, turned into wheel speeds and a speed law kd (target - speed) per wheel, see Wheeled robots

The force is always clipped to the force limit (tau_limit).

import numpy as np
import redysim_rl

for mode in ("torque", "pd_target", "impedance"):
    env = redysim_rl.make_vec("joint_reach", num_envs=4, action_mode=mode)
    env.reset(seed=0)
    print(mode, env.action_space.shape)          # 3, 3 and 9 numbers per robot

PD targets and impedance

action_kwargs sets the arguments of the mode:

import redysim_rl

env = redysim_rl.make_vec(
    "joint_reach", num_envs=4, action_mode="pd_target",
    action_kwargs={"target": "delta", "delta_max": 0.2, "kp": 40.0, "kd": 3.0},
)
  • target="absolute" (default): the action selects a position inside q_range (±π by default, or (low, high)); "delta": the action moves the target away from the current position by at most delta_max rad.
  • "impedance" takes kp_range and kd_range (each (low, high), a number or one value per joint). With the default gains the range is 0.25 to 4 times the automatic gains below.

A task may choose its own default mode, decimation and gains: the arm tasks default to torque, while quadruped_velocity defaults to PD targets within 0.5 rad of its standing pose (kp 80, kd 2, 20 physics steps per control step). Arguments you give always win.

Automatic gains and decimation

A force that is held over a whole control step makes a stiff PD law unstable for a light arm: a damping of 2 N m s/rad on a link of 0.015 kg m² diverges at a step of 20 ms. Two things keep the PD modes stable on any robot:

  • decimation. The law is recomputed decimation times inside every control step (5 by default for the PD modes, 1 for "torque", whose force is held over the whole step); the simulator step is the control step divided by it. Set it with decimation=.
  • Gains from the robot. Unless you give kp, kd (or the ranges), they are computed from the inertia matrix of the robot at 64 random poses: the stiffness is scaled so that the fastest mode of M⁻¹K has the frequency 0.3 / h (h the physics step), the damping is critical for the smallest joint inertia and then limited so that h times the fastest rate of M⁻¹D is at most 0.5. They are conservative on purpose: the arm is sluggish rather than unstable.

The gains are available for inspection and reuse:

from redysim_rl import planar_arm
from redysim_rl.robots import auto_gains

kp, kd = auto_gains(planar_arm(3), act=[0, 1, 2], h=0.004)
print(kp.round(1), kd.round(2))

Gravity

A PD law without gravity compensation leaves a steady offset on a vertical arm (gravity torque / kp). The policy learns to bias its targets; the impedance mode, which can also raise the stiffness, learns this fastest (see Training).