Skip to content

Part 2: Make your own robot

A robot is described in a model file: a short text file ending in .yaml. You can write it in any text editor. This part builds a small robot step by step; every complete model file shown here can be copied and run as it is.

2.1 The idea

  • The robot is a set of links, numbered 1, 2, 3, ... Link 1 is the body (the trunk). It has no joint: it is free to move and turn, and the program computes how.
  • Every other link is attached to an earlier link by a joint that turns about the z axis of the link's own frame. Legs are chains of such links.
  • Every leg link is a rod along its own x axis. Both ends of every leg link can touch the ground. The body does not.
  • The ground is a soft surface at height 0: a spring and a damper push a leg end up when it goes below 0, and friction holds it back sideways.

To start from a working file, copy one of the examples and change it:

redysim-floating --export biped my_robot.yaml
redysim-floating fordyn my_robot.yaml

The ready-made files are also in the my_models folder.

Each link is one entry of the list links:, in order. Here are the first two links of a hopper, a body with one leg:

links:
- {link: 1, parent: 0, length: 0.4, tip: 0.2, mass: 5, inertia: [0.01, 0.0708, 0.0708, 0, 0, 0]}
- {link: 2, parent: 1, dh: {alp: 0, a: 0, b: 0}, length: 0.5, tip: 0.5, mass: 1,
   com: [0.25, 0, 0], inertia: [0, 0.0208, 0.0208, 0, 0, 0]}
key meaning
link the link number (optional; the program checks it against the position in the list)
parent the link this one is attached to; 0 for the body. A parent always has a smaller number.
joint R for a revolute joint (the default), which turns; P for a prismatic joint, which slides
dh where the joint is, see below. The body has none.
length, tip the link is a rod from tip - length to tip along its x axis (in metres)
mass kilograms
com centre of mass [x, y, z] in the link's frame (default [0, 0, 0])
inertia [Ixx, Iyy, Izz, Ixy, Iyz, Izx] about the centre of mass, in the link's frame (kg m²)

Where the joint is: dh

The joint of link i is placed relative to its parent with three numbers (the modified Denavit-Hartenberg parameters):

  • a: the distance along the x axis of the parent from the parent's origin to the joint;
  • b: the distance along the z axis (the joint axis);
  • alp: a twist of the joint axis about the parent's x axis, in radians. It is 0 for a robot that moves in a plane, and pi/2 (1.5708) for a joint that turns about a perpendicular axis.

Frame convention for the modified DH parameters

In the picture, link i hangs from its parent p: a is measured along the parent's X axis, b along the joint axis Z of link i, and alp is the angle between the two Z axes. (For a robot in a plane all joint axes are parallel and alp is 0.)

The joint angle itself is not in the model: it is what the simulation computes. When the angle is 0, link i's x axis is parallel to its parent's x axis. Lengths are in metres, angles in radians. Any number in a model file may also be written with pi or radians(): alp: -pi/2 or alp: radians(-90) is the same as alp: -1.5707963267948966. Only arithmetic (+ - * /, brackets) is allowed.

Sliding joints (joint: P). A prismatic joint slides along its axis Z instead of turning about it, like a telescopic leg. Its variable is then the distance along Z (it takes the place of b, so the b you write is not used), and the link does not turn relative to its parent: a fixed angle about Z can be given as th in the same block, e.g. - {link: 3, parent: 2, joint: P, dh: {a: 0.5, th: 0}, ...}. Its start value in q0 is then a distance in metres, and its motor gives a force (N) instead of a torque.

Several links on one parent (phi and h). The parent's x axis is the common normal to the joint axis of one child only. Another child (another leg on the body, say) may need the parent frame turned first by an angle phi about the parent's z axis and moved by a distance h along it; its alp and a are then measured from that turned x axis. Add them to the same block, e.g. dh: {alp: 1.5708, a: 0.2, b: 0, phi: 1.5708, h: 0.1}. Both are 0 when left out.

Branch angle and branch offset of a further child

In the figure, link #β has two children, #i and #j (two legs, say); the joints are the grey cylinders on their axes (dash-dot). xβ is the common normal from zβ to the joint axis zi of the first child, whose numbers are read from xβ as usual. For the further child #j, the frame is first shifted by hj along zβ and turned by φj about it (from the dashed copy of xβ), to x′β, the common normal from zβ to zj; then aj and αj are read from x′β.

When alp is 0 you can also put h into b instead, as the example quadruped does for its hips.

Mass and inertia

For a uniform rod of mass m and length L with its centre of mass in the middle, the centre of mass is at com: [L/2, 0, 0] and the inertia about it is [0, mL²/12, mL²/12, 0, 0, 0]. The leg of the hopper (m = 1 kg, L = 0.5 m) gives [0, 0.0208, 0.0208, 0, 0, 0]. A body that is a box of mass m and sides l, w has Izz = m(l² + w²)/12.

A leg link is a rod along its x axis

Where the touch points are

A leg link touches the ground with two points: the end at x = tip - length and the end at x = tip. For the hopper's leg (length: 0.5, tip: 0.5) these are the joint (x = 0) and the foot (x = 0.5). A link with length: 0 (a massless connecting link) touches the ground at its origin.

2.3 The ground and gravity

Two more entries describe the world:

gravity: [0, -9.81, 0]
ground: {stiffness: 3000, damping_factor: 0.3}

Gravity points along −Y: Y is up, and the ground is the plane Y = 0. The ground keys:

key meaning default
stiffness spring constant of the ground, N/m. Larger is harder. 3000
damping_factor how strongly the ground damps the landing. 1 is the damping that would stop the whole robot on one spring without bouncing; below 1 it bounces. Give exactly one damping setting: damping_factor, damping_ratio (per foot) or damping. 10
friction friction coefficient 0.7

Hunt–Crossley contact. The keys above are the original spring-damper contact (contact: original, the default). The bundled biped, quadruped and hexapod use a more physical one, contact: hunt_crossley: the force starts at zero at touchdown and never pulls, and its damping grows with the penetration, so a landing neither bounces nor sticks. It has its own keys:

key meaning default
equivalent_stiffness or stiffness the ground spring (give exactly one of them). equivalent_stiffness is the linear spring in N/m that the contact should match none
exponent 1 is a linear spring, 1.5 is a Hertzian contact 1
restitution how much of the impact speed comes back, between 0 and 1 0.5
reference_speed the impact speed, in m/s, at which restitution applies 1

friction, friction_slope and axes work as before. The damping keys of the original contact (damping_factor, damping_ratio, damping, rebound_speed) cannot be combined with it. For example:

ground: {contact: hunt_crossley, exponent: 1.5, equivalent_stiffness: 2500, restitution: 0.5}

A robot that has to stand still needs a fixed step of 2 ms or smaller; 4 ms is enough only for walking that tracks a command (the friction makes a standing robot creep at larger steps).

A very hard ground makes the simulation slow. For the other keys of the original contact (rebound_speed, friction_slope, axes, damping) see the example files.

ground: none removes the ground, for a robot in space (section 2.8).

Wheels instead of legs

A robot that rolls has no leg ends to touch the ground. Give it a wheels: list instead, set ground: none, and the ground is again the plane Y = 0 (wheel_axes changes that). Each wheel is a link on a joint that turns about its axle; the list says where the wheel touches:

ground: none
wheels:
  - {link: 2, radius: 0.0825, axle: [0, 0, 1]}                     # a driven wheel: the axle is the
                                                                   # axis the link turns about
  - {link: 1, radius: 0.025, point: [-0.2, -0.0575, 0], lateral: 20, friction: 0.1}   # a caster ball
key meaning default
link, radius the link that carries the wheel, and the wheel radius in m required
point where the hub is, in the frame of the link [0, 0, 0]
axle the line the wheel turns about, in the frame of the link; leave it out for a ball none
stiffness, damping the normal spring (N/m) and damper (N s/m) of the tyre 30000, 300
longitudinal, lateral how hard the tyre resists slipping along the rolling direction and sideways, N per m/s 2000, 2000
friction the tyre force never exceeds this times the normal force 0.8

The tyre is a soft force, not a rule that the wheel cannot slip: a stiff lateral keeps the wheel from sliding sideways, and the motor torque on the joint drives the robot. Give the wheel the inertia it has with its motor and gearbox (about 0.02 kg m² about the axle for a small robot); a bare wheel makes the simulation chatter. The ready-made pioneer is a complete example, and its controller diff_drive follows a forward speed and a turn rate (section 2.5).

2.4 A first simulation: the drop test

A complete model file. The hopper stands with its leg straight down, 5 cm above the ground, and is dropped:

name: One-legged hopper (drop test)
gravity: [0, -9.81, 0]
ground: {stiffness: 3000, damping_factor: 0.3}
links:
- {link: 1, parent: 0, length: 0.4, tip: 0.2, mass: 5, inertia: [0.01, 0.0708, 0.0708, 0, 0, 0]}
- {link: 2, parent: 1, dh: {alp: 0, a: 0, b: 0}, length: 0.5, tip: 0.5, mass: 1,
   com: [0.25, 0, 0], inertia: [0, 0.0208, 0.0208, 0, 0, 0]}
fordyn:
  base: {qb0: [0, 0.55, 0, 0, 0, 0], dqb0: [0, 0, 0, 0, 0, 0]}
  q0: [-1.5708]
  dq0: [0]
  time: [0, 1.0]
  step: 0.005
  torque: {free: {}}

Save it as hopper.yaml and run redysim-floating fordyn hopper.yaml. The fordyn: section says how to start and run:

key meaning
base: {qb0, dqb0} the body's start: [x, y, z, phi, theta, psi], its position (in metres; y is up) and its three angles (radians), and the rates of these six numbers
q0, dq0 the start value and rate of every joint (links 2, 3, ...), one value each: an angle in radians, or for a prismatic joint a distance in metres
time: [start, end] in seconds
step the spacing of the saved results, in seconds
torque what drives the joints; free: {} means no motor at all
external forces and moments on links, such as a thruster or a push (section 2.8)

The leg hangs straight down because the joint angle is −1.5708 (−90°): the link's x axis then points down. Link 2 is a leg, so the body is 0.55 m high and the foot is at 0.55 − 0.5 = 0.05 m.

What to expect: the hopper falls, the foot touches the ground at about 0.1 s, the ground spring compresses and pushes back, the hopper bounces a few times and settles. At rest the foot sinks into the ground by the weight divided by the stiffness: 6 kg × 9.81 / 3000 = 0.02 m, so the body ends 0.5 − 0.02 = 0.48 m high. Look at the Energy plot: the total stays flat, while the ground takes energy out of the motion. This drop test is the best first test of any new robot: if the Total energy is flat and the robot behaves as you expect, the model is entered correctly.

2.5 Moving the joints

The joints are moved by a trajectory (the motion you want) and a controller (the motor that tries to follow it). Add both:

name: One-legged hopper (leg swing in the air)
gravity: [0, -9.81, 0]
ground: {stiffness: 3000, damping_factor: 0.3}
links:
- {link: 1, parent: 0, length: 0.4, tip: 0.2, mass: 5, inertia: [0.01, 0.0708, 0.0708, 0, 0, 0]}
- {link: 2, parent: 1, dh: {alp: 0, a: 0, b: 0}, length: 0.5, tip: 0.5, mass: 1,
   com: [0.25, 0, 0], inertia: [0, 0.0208, 0.0208, 0, 0, 0]}
trajectory:
  cycloidal: {q0: [-1.5708], qf: [-0.7854], duration: 0.5}
fordyn:
  base: {qb0: [0, 3, 0, 0, 0, 0], dqb0: [0, 0, 0, 0, 0, 0]}
  time: [0, 0.5]
  step: 0.005
  torque: {computed_torque: {kp: 49, kd: 14}}

The hopper is now 3 m above the ground, so it is in free fall while its leg swings from straight down (−1.5708) to 45° (−0.7854) in 0.5 s. The joint angles are not given in fordyn: any more: by default they start where the trajectory starts (q0: from_trajectory).

Run it and look at the Base motion plot. The motor swings the leg, and nothing holds the body, so the body turns the other way: by the end its angle phi is about −0.4 rad. This is the recoil of a robot in the air, and it is why a free-floating body needs a simulation like this.

Trajectories (trajectory:):

name motion
cycloidal a smooth move from q0 to qf in duration seconds, starting and ending at rest
joint_waypoints a smooth joint motion through schedule: [[time, q_link2, ...], ...]; each interval starts and ends at rest, suitable for driving wheels before moving an arm
mobile_manipulator_motion a compact wheel angular speed with start/stop ramps, followed by a smooth arm pose move; see mobile_manipulator.yaml
wheel_leg_motion a compact slow-roll and knee-bend motion: a wheel angular speed, smooth start/stop times, and hip/knee bend amounts; see wheel_legged.yaml
constant hold the joint values q
biped_gait, quadruped_gait, hexapod_gait the walking motions of the ready-made robots (section 2.6)

Controllers (torque:):

name what it does
computed_torque computes the motor torques from the robot's dynamics so that the joints follow the trajectory very closely. The gains kp, kd (default 49 and 14) set how fast an error dies out.
pd a simple spring-damper on each joint angle, without knowing the robot. Lags behind when the robot is heavy.
free no motors
constant fixed torques, tau: [..]
diff_drive for a two-wheeled robot: follow: trajectory regulates the wheel speeds from the Motion tab; it can also use a forward speed v and turn rate w, or a schedule: [[time, v, w], ..]; the wheel radius and track are read from the model
mobile_manipulator regulates wheel speed under drive and arm position under arm; follow: trajectory takes both targets from the shared Motion-tab trajectory; see mobile_manipulator.yaml
car_drive regulates rear wheel speeds and front steering angles; follow: trajectory takes targets from car_path in the Motion tab, or use a separate speed and steering schedule
wheel_leg holds four three-joint legs at a stand or crouch stance while driving two wheels per side; see the bundled wheel_legged model
quad_flight drives one free body with four rotor thrusts to position and yaw waypoints; see the bundled quadcopter model

Type redysim-floating --types to list them.

Inverse dynamics

With a trajectory, you can also ask the opposite question: what torques are needed for this motion? Add an invdyn: section to the file above (save it as hopper_swing.yaml) and run redysim-floating invdyn hopper_swing.yaml:

invdyn:
  base: {qb0: [0, 3, 0, 0, 0, 0], dqb0: [0, 0, 0, 0, 0, 0]}
  time: [0, 0.5]
  step: 0.005

The joints follow the trajectory exactly, and tor.dat and the torque plot show the torques.

2.6 Walking robots

Walking needs the motion of every leg joint at every moment. For the biped, the quadruped and the hexapod, ReDySim computes it for you from a few numbers:

trajectory:
  biped_gait: {step_time: 1.0, stride: 0.3, foot_height: 0.1, hip_height: 0.96, hip_x0: -0.15}
key meaning
step_time seconds per step
stride step length, metres
foot_height how high the swinging foot is lifted
hip_height height of the hip above the ground while walking. It must be smaller than thigh + shank.
hip_x0 where the hip is, relative to the planted foot, at the start of a step

The thigh and shank lengths come from the model: they are the tip of the thigh and shank links (links 2 and 3 of the biped, 3 and 4 of the quadruped, 2 and 3 of the hexapod), and all legs must have the same lengths. Change a leg length in the link table and the gait follows.

Because the motion is made for one layout of links, change the numbers of the ready-made robots (masses, lengths, stride, ground) rather than their structure. A gait only exists for the biped (7 links) and the quadruped and hexapod (13 links each).

The walking robots start from the gait: the section

fordyn:
  base:
    from_gait: {axes: [x, z, y], offset: [0.0, 0.25, 0.0]}
    euler: [-1.5708, 0.0, 0.0]

places the body on the hip of the gait at time 0. The gait lives in its own frame (x forward, y sideways, z up) while the simulation has Y up, so axes says which gait direction becomes the simulation's X, Y and Z. Leave it as in the example for the same kind of robot.

A robot that may turn over (a tumbling space robot, a jump, a fall) should add attitude: euler_parameters to the base: section. The simulation then carries the base attitude as four Euler parameters instead of three Euler angles, which are singular when the base pitch theta reaches 90°. You still give the start pose as Euler angles; it is converted once. The state then has one more column (qb has 7 values), and the result's euler gives Euler angles for plotting. The default stays Euler angles, as in the MATLAB program.

2.7 What to change in the examples

  • Make it walk faster: shorter step_time, longer stride.
  • Softer or harder ground: stiffness, damping_factor (with the Hunt–Crossley contact: equivalent_stiffness, restitution).
  • Slippery ground: a smaller friction.
  • A heavier body: the mass and inertia of link 1.
  • A different gain: kp and kd of the controller. Larger values follow the motion more closely, but a very large value makes the simulation slow.
  • A longer walk: time: [0, 6].

After every change, run the robot and look at the Energy plot first.

2.8 A robot floating in space

Without ground and gravity the robot only moves because its own joints move. The space_robot example is a heavy base with two arms of three links each (three joints an arm: a hand can be given a position and an orientation in the plane; the MATLAB program's robot, with two links an arm, is space_robot_matlab):

gravity: [0, 0, 0]
ground: none

The centre of mass of the whole robot then stays exactly where it is: when the arms swing, the base moves the other way. Run redysim-floating fordyn space_robot and look at the animation. The model file is in my_models/space_robot.yaml.

A body without joints

A model may have only one link, the base. It has no joint, so there are no torques, no joint angles to give and no joint plots. Use it for a free object, such as a payload or a satellite without arms:

name: Payload, a body without joints
gravity: [0, 0, 0]
ground: none
links:
- {link: 1, parent: 0, length: 1.0, tip: 0.5, mass: 100, com: [0, 0, 0],
   inertia: [10, 12, 14, 0, 0, 0]}
fordyn:
  base: {qb0: [0, 0, 0, 0, 0, 0], dqb0: [0.1, 0, 0, 0, 0, 0.2]}
  time: [0, 5]
  step: 0.1

With no force on it, the body keeps moving and turning as it started.

A force or a moment from outside, such as a thruster or a push, is written under fordyn: as external:, a list with one entry for each force. All forces act together.

key meaning
link the number of the link the force acts on (1 is the body)
force [x, y, z] in newtons, in the fixed frame of the world (frame: link: in the frame of the link, so that it turns with the link, like a thruster)
moment [x, y, z] in newton metres, in the same frame as the force
point where the force acts, [x, y, z] in metres in the link's own frame (default: the link's origin). A force away from the centre also turns the link.
from, to the force acts only from from to to, in seconds (default: always)

Here a thruster pushes the payload from the side of its end for the first two seconds. It speeds up and starts to spin, and then it coasts:

name: Payload with a thruster
gravity: [0, 0, 0]
ground: none
links:
- {link: 1, parent: 0, length: 1.0, tip: 0.5, mass: 100, com: [0, 0, 0],
   inertia: [10, 12, 14, 0, 0, 0]}
fordyn:
  base: {qb0: [0, 0, 0, 0, 0, 0]}
  time: [0, 5]
  step: 0.1
  external:
    - {link: 1, point: [0, 0.5, 0], force: [20, 0, 0], frame: link, from: 0, to: 2}

In invdyn: the same list can be given. The joint torques are then those needed besides these forces. Your own function of time can be named instead of a force (custom: with file and function, as for controllers, section 2.6) and needs --allow-python; it returns the forces of all links. A force that depends on another robot, such as a grasp, needs a few lines of Python: see Appendix B.

2.9 Checking a model

  1. Run the drop test (free joints, as in section 2.4). The body must fall as you expect and the Total energy must be flat.
  2. Make the robot stand still with the constant trajectory and computed_torque, and check that it does not sink through the ground.
  3. Read the error messages. The program names the place in the file, for example links[3].parent: the parent of link 3 must be a link with a smaller number.

Common mistakes:

symptom cause
the robot falls through the floor stiffness too small for the weight, or the robot starts below Y = 0
the robot explodes (non-finite) a link with no mass or inertia at the end of a chain; or a very hard ground with a large step
a leg is drawn in the wrong place the start values q0 and the link's a, b, alp do not match what you meant
the gait is for a robot with 13 links a gait was used on a robot of a different structure

2.10 Quick reference

# the entries of a model file, in the usual order
name: text
gravity: [0, -9.81, 0]
ground: {stiffness: 3000, damping_factor: 10, friction: 0.7}   # or: ground: none
links:
- {link: 1, parent: 0, length: .., tip: .., mass: .., com: [..], inertia: [6 values]}
- {link: 2, parent: 1, dh: {alp: .., a: .., b: ..}, length: .., tip: .., mass: .., com: [..], inertia: [..]}
trajectory: {cycloidal: {..}}            # or constant, biped_gait, quadruped_gait, hexapod_gait
wheels: [{link: 2, radius: .., axle: [..]}]   # optional, instead of legs: see section 2.3
scene: {legs: [[2, 3], [4, 5]], trunk: true}   # how the animation draws the robot (optional)
fordyn:
  base: {qb0: [6 values], dqb0: [6 values]}
  q0: [..]                               # or from_trajectory
  time: [0, 2]
  step: 0.01
  solver: ode15s                         # ode15s (default, for walking), ode45, ode5
  rtol: 1.0e-4
  atol: 1.0e-6
  torque: {computed_torque: {kp: 49, kd: 14}}
invdyn:
  base: {qb0: [6 values], dqb0: [6 values]}
  time: [0, 2]
  step: 0.01

scene lists the chains of links to draw as legs (legs), and trunk: true also draws link 1 as a line; without a scene the program draws every branch of the robot as a leg.

Mobile manipulator controller

The bundled mobile_manipulator demonstrates a light arm on a Pioneer-size base. Its mobile_manipulator_motion entry in the Motion tab commands both wheels at 3 rad/s after a short ramp, stops them, then moves the arm smoothly from its elbow-up start to a second pose. Wheel angle is the integral of speed. follow: trajectory makes the forward controller track wheel velocity only under drive: and arm position under arm:. The same motion supplies joint positions, speeds and accelerations to inverse dynamics, which computes the required torques. The example has no gripper or payload.

Wheel-legged controller

The bundled wheel_legged model has four wheels in wheels: and ground: none. Its wheel_leg controller can use schedule rows [time, forward_speed, turn_rate, crouch_fraction] or follow: trajectory. The latter follows the same joint motion shown in the GUI Motion tab for both dynamics modes. stand and crouch are the leg poses in schedule mode; the bundled model uses follow: trajectory and reads its pose from the Motion tab. left and right list the driven wheel links. kp and kd control the legs, while wheel_kp, wheel_kd and tau_max control the wheels. Radius, track and rolling direction come from the model; optional overrides warn if they differ. It rolls only, with no walking gait.

The bundled wheel_leg_motion trajectory commands the four wheels at a low angular speed of -0.5 rad/s after a short start ramp, then stops them smoothly. It bends the knees by 0.1125 rad from 2 to 3 s, holds for 1 s, and straightens them from 4 to 5 s. The motion supplies wheel angle by integrating that speed; the forward controller regulates wheel speed only (wheel_kp: 0) and leg position. Inverse dynamics uses the same derived joint motion to compute torques. Their free-base paths can differ slightly because the forward controller and wheel contact affect tracking.

The bundled quadcopter is a single free rigid body with attitude: euler_parameters, gravity, and no ground contact. Its quad_flight controller accepts four rotors rows [x, y, z, spin] in the body frame, where spin is -1 or 1. The schedule rows are [time, x, y, z, yaw] in the inertial frame. kp_pos and kd_pos set the position loop; kp_att and kd_att set the attitude loop. yaw_drag is the yaw moment per unit rotor thrust, and max_thrust limits each rotor. The controller mixes total thrust and body moments into four nonnegative thrusts. Its scene.rotors discs are visual only: this teaching model has no rotor dynamics, aerodynamic drag, or ground effect. A timed external: force supplies the wind gust.