Skip to content

3. Tasks and robots

The tasks

name id robot (default) goal observation reward
joint_reach Redysim/JointReach-v0 three_link (planar arm, 3 joints) joint angles within ±1.2 rad q, dq, q_goal − q −‖q_goal − q‖ − 0.01 ‖dq‖² − 0.001 ‖a‖², +1 within 0.05 rad
task_reach Redysim/TaskReach-v0 three_link (planar arm, 3 joints) a point in space q, dq, p, v, p_goal − p −‖p_goal − p‖ − 0.01 ‖dq‖² − 0.001 ‖a‖², +1 within 2 cm
acrobot_swing_up Redysim/AcrobotSwingUp-v0 two_link, only the elbow is driven tip above 0.9 of the full reach, both joints slower than 0.5 rad/s cos q, sin q of both joints, dq (6 values) h − 0.002 ‖dq‖² − 0.001 u², h = height of the tip over the shoulder in full reaches (−1 hanging, +1 up), +3 at every step the arm is up and slow
cartpole_balance Redysim/CartPoleBalance-v0 pr (a cart on a rail with a pole on it), only the cart is driven keep the pole upright and the cart near the middle of the rail; the episode ends when the pole tips past 0.5 rad or the cart leaves ±2.4 m x, cos θ, sin θ, dx, dθ (5 values) cos θ − 0.1 x² − 0.01 (dx² + dθ²) − 0.001 u², +1 at every step the pole is within 0.1 rad of upright and the cart within 0.5 m of the middle, −10 on a fall
cartpole_swing_up Redysim/CartPoleSwingUp-v0 pr, only the cart is driven; the pole starts hanging down swing the pole up and hold it there (within 0.2 rad, slower than 1 rad/s, cart near the middle); the episode ends only when the cart leaves ±2.4 m x, cos q, sin q, dx, dq (5 values, as cartpole_balance) (1 + cos θ) − 0.1 x² − 0.001 ‖d‖² − 0.001 u², +3 while held up, −10 when the cart leaves the rail
platform_reach Redysim/PlatformReach-v0 three_rrr (the 3-RRR parallel robot: three motors, two closed loops; action mode pd_target, motor limit 50 N m) the centre of the triangle to a goal point and its rotation to a goal angle; each goal is the pose after the motors are turned by up to 0.6 rad and the loops closed (about 10 cm from the start) the motor angles from the start pose and speeds, the goal minus the platform pose (x, y, angle) and the platform velocity (12 values) −‖p_goal − p‖ − 0.2 |φ_goal − φ| − 0.01 ‖dq‖² − 0.001 ‖a‖², +1 within 1 cm and 0.05 rad
space_reach Redysim/SpaceReach-v0 satellite with a 7-joint arm (default), or seven-link planar space robot (six joints, two hands, separate position goals) a point in space 41 values: q, dq, base position, rotation matrix and velocity, tip p, v, p_goal − p (details) as task_reach
quadruped_velocity Redysim/QuadrupedVelocity-v0 quadruped on the ground a commanded velocity 45 values: gravity direction, base angular velocity, command, joint q and dq, previous action (details) velocity tracking, tilt and action penalties, −10 on a fall
wheeled_nav Redysim/WheeledNav-v0 Pioneer-size differential-drive robot a point, between obstacles 26 values: goal in the heading frame, speeds, wheel speeds, previous action, 16 range-finder rays (details) 5 × progress to the goal, +20 at the goal, −20 on a collision
car_parking Redysim/CarParking-v0 the four-wheel car (four_wheel_car, Ackermann steering; action mode car_drive: a speed and a steering angle) reverse into a gap of two car lengths between two parked cars and stop in its middle, parallel to the street 14 values: the pose in the frame of the gap, the gap in the frame of the car, speeds, the two steering angles, previous action, the gap 5 × progress of a position and heading error (the heading counts only near the gap), +20 when parked, −20 on a collision, −0.05 a step

a is the action in [−1, 1], u the force on the elbow in N m (limit 1 N m, below what holds the arm up: the shoulder has no motor, so the arm has to pump itself up), p and v the position and velocity of a point of the last link (its tip by default), q and dq the positions and velocities of the actuated joints. The goal of task_reach is reachable: it is the position of the point at a random pose of the arm.

Defaults of the arm tasks: control step 20 ms, 200 steps per episode, force limit 20 N m per joint, joint limits ±3 rad (a joint is stopped there), speed cap 10 rad/s. All of them can be set when the environment is made:

import redysim_rl

env = redysim_rl.make_vec(
    "joint_reach", num_envs=16,
    dt=0.01,                      # control step (s)
    max_episode_steps=300,        # truncation
    tau_limit=15.0,               # force limit of every actuated joint (N m)
    dq_limits=6.0,                # speed cap (rad/s)
    include_previous_action=True, # append the last action to the observation
)
print(env.single_observation_space.shape, env.unwrapped.dt)

Configuring a task

A task is an object whose arguments set the goal range, the tolerance and the reward weights:

from redysim_rl import JointReach, RedysimVectorEnv

task = JointReach(goal_range=0.6, tol=0.03, w_vel=0.05, bonus=2.0, terminate_on_success=True)
env = RedysimVectorEnv(task, num_envs=32, robot="kinova_gen3lite")
obs, info = env.reset(seed=0)

With terminate_on_success=True an episode ends (terminated) when the goal is reached; otherwise it runs to its time limit (truncated). TaskReach(link=2, point=[0.1, 0, 0]) follows another point.

Robots

robot= takes:

  • nothing: the task's default, a bundled model: three_link for the reach tasks (three links in a vertical plane, so gravity has to be held up). Open it in the GUI like any other model. redysim_rl.planar_arm(n, length, mass, vertical) makes other arms;
  • the name of a bundled model, robot="kinova_gen3lite", "three_link", "kuka", ... (open chains only); the GUI offers three_link and kinova_gen3lite (6 joints, gravity along −z, shown in a 3D replay) for joint_reach and task_reach. The Kinova starts at its zero pose (the arm stands straight up), its goals are drawn round that pose, a zero action holds it, and its joint limits (±3 rad) are a window round it;
  • a redysim.Robot of your own, from a model file or built in Python;
  • redysim_rl.pendulum(length, mass, gravity).

Joints with aj = 0 in the model are passive: they are not observed as actions and get no force. A robot with closed loops (a four-bar, the 3-RRR parallel robot) is simulated with its loops closed: its home pose is the start pose of its model file (fordyn.q0, where the loops close), every reset closes the loops again keeping the motor angles, the actions drive its motors, and only the motors have stops (a limit on a passive joint would fight the loop). A start that cannot be closed ends that robot's episode as a failure. Give the motors enough force to carry the mechanism: the 3-RRR needs about 50 N m against gravity (tau_limit=50), the limit of platform_reach. Some bundled models are poor learning problems, for example a long chain whose links differ greatly in mass, because its inertia matrix is badly conditioned; the default arm is proportioned for learning.

Episodes, goals and randomisation

  • env.reset(seed=...) seeds one random generator that draws every goal, starting pose and randomisation, so the same seed gives the same episodes.
  • options fix them: env.reset(options={"q": ..., "dq": ..., "goal": ...}), one row per robot (for the floating base also "qb", "dqb").
  • randomise={"mass": 0.2} multiplies the mass and inertia of every link of a robot by a factor in [0.8, 1.2], drawn again at every reset of that robot, so that a policy sees a family of arms:
import redysim_rl

env = redysim_rl.make_vec("task_reach", num_envs=64, randomise={"mass": 0.2})
env.reset(seed=0)
masses = [robot.m for robot in env.unwrapped.backend.robots]
print(masses[0], masses[1])
  • info carries distance (or angle_error), is_success and failed for every robot. A step that cannot be completed numerically ends that robot's episode with reward failure_penalty (−10) and leaves the others running.