Part 2: Make your own robot¶
You describe a robot in a model file: a plain text file ending in .yaml. You can write
it in any text editor (Notepad, TextEdit, VS Code, Gedit). Save it as plain text with a
name that ends in .yaml: in TextEdit (macOS) choose Format > Make Plain Text before
saving, and in Notepad (Windows) choose Save as type: All files, otherwise the file may be
saved as my_robot.yaml.txt.
Every ready-made robot is also a model file: open any file in the my_models folder (next
to this manual) in your editor to see a complete, working example.
YAML in two minutes¶
The model file is written in a format called YAML. You do not need to learn it; these few rules are all you need.
| rule | example |
|---|---|
One setting per line, as name: value. Put a space after the colon. |
gravity: [0, -9.81, 0] |
| A list of numbers goes in square brackets, separated by commas. | q0: [0, 0, 0] |
| A few named values can be grouped in curly brackets. | dh: {alp: 0, a: 0.3, b: 0, th: 0} |
A line starting with - is one item of a list. There is one for each link. |
- link: 1 |
| Lines at the same level start in the same column. Indent with spaces, never with the Tab key. | two spaces for each level |
Text after # is a comment and is ignored. |
# this is a note |
Write numbers, not formulas: 1.5708, not pi/2. Use a decimal point, not a comma. Very small numbers are written 4.2e-6. |
th: 1.5708 |
true and false switch things on and off. |
actuated: false |
A piece of a file, with the rules marked:
links: # "links" is a list: each link starts with "-"
- link: 1 # name, colon, space, value
parent: 0
joint: R
dh: {alp: 0, a: 0.3, b: 0, th: 0} # curly brackets group named values
mass: 0.5
com: [0.15, 0, 0] # square brackets: a list of numbers
inertia: [4.2e-6, 3.75e-3, 3.75e-3, 0, 0, 0]
If you break a rule, ReDySim stops and tells you where:
| what you did | what you see |
|---|---|
| used the Tab key | found character '\t' that cannot start any token, with the line number |
forgot the space after a colon (gravity:[0, 0, 0]) |
could not find expected ':', with the line number |
| forgot a closing bracket | expected ',' or ']', with the line number |
| indented a line wrongly | expected <block end>, with the line number |
wrote a formula or a decimal comma (pi/2, 0,4) |
could not convert string to float: 'pi/2' |
| gave a list the wrong number of values | for example fordyn.q0: expected 2 values, got 3 |
The line number is the line in your file. Look at it, and at the line above it.
2.1 Start from an example¶
This writes the two-link arm to my_robot.yaml in your current folder. Run it:
You get the same result as redysim fordyn two_link. From now on you only edit
my_robot.yaml. Other examples such as kuka and robotic_gripper can serve as templates in
the same way (closed-loop robots are covered in section 2.8).
Results go to output/fordyn/my_robot/; the folder name is the file name.
2.2 What is in the file¶
A model file has a few parts. Here is a short one, a two-link arm:
name: My 2-Link Arm
gravity: [0, -9.81, 0]
links:
- link: 1
parent: 0
joint: R
dh: {alp: 0, a: 0.0, b: 0, th: 0}
mass: 0.5
com: [0.15, 0, 0]
inertia: [4.2e-6, 3.75e-3, 3.75e-3, 0, 0, 0]
- link: 2
parent: 1
joint: R
dh: {alp: 0, a: 0.3, b: 0, th: 0}
mass: 0.4
com: [0.125, 0, 0]
inertia: [3.3e-6, 2.08e-3, 2.08e-3, 0, 0, 0]
fordyn:
q0: [0, 0]
time: [0, 3]
step: 0.01
| part | meaning |
|---|---|
name |
a title shown on the plots |
gravity |
gravity vector [x, y, z]. [0, -9.81, 0] pulls down along the y axis. Use [0, 0, 0] to switch gravity off. |
links |
the robot, one entry per link, in order from the base outwards |
cuts |
closed loops only: where the loop is cut (section 2.8) |
base_pos |
optional: where the links attached to the ground start (below) |
fordyn |
settings for redysim fordyn |
invdyn |
settings for redysim invdyn |
base_pos is needed only when several links are attached to the ground at different
places, as in the parallel robot three_rrr. It gives the position of the origin of each
such link, by link number:
Without it, a link attached to the ground starts at its own modified DH offset from the ground origin. With it, the link starts at the point you give (and a ground link that you do not list starts at the ground origin). For a closed loop the positions matter: the loop can only close if the arms really start where the cuts expect them.
2.3 Describing a link¶
Each entry under links describes one link together with the joint that moves it.
| key | meaning |
|---|---|
link |
the number of the link (1, 2, 3, ...). Optional, but it helps you to read the file; the program checks that it matches the link's position in the list. |
parent |
the link this one is attached to. Links are numbered 1, 2, 3, ... in the order they are listed. 0 means the fixed ground. |
joint |
R for a revolute (turning) joint, P for a prismatic (sliding) joint |
dh |
the four modified DH parameters of the link, as {alp: ..., a: ..., b: ..., th: ...}. Any you leave out are zero. Section 2.4 explains them. |
mass |
mass of the link (kg) |
com |
position of the link's centre of mass, [x, y, z], in the link's own frame (m) |
inertia |
[Ixx, Iyy, Izz, Ixy, Iyz, Izx], the inertia of the link about its centre of mass (kg m²) |
tip |
optional. A point of the link in its own frame, [x, y, z], such as the end of the link or a tool point. The animation draws the link out to it, also when other links are attached to this one (the link then has one more rod, to the tip); a platform (a link with two or more cut points of a closed loop) is drawn as a filled polygon instead, with a dot at its tip (put the tip at the centre of the platform). If you leave it out for a terminal link, one that no other link is attached to (the end of a chain or of a branch), ReDySim uses twice the centre of mass. Every other link is drawn from its joint to the next joint automatically, so it needs no tip unless you want it extended. A link that ends at a tip of its own is also drawn out to each cut point of a closed loop that is not that tip, so the loop stays connected: the hoken_fourbar extends its coupler, link 3, beyond its joint with link 2 by the length it already has, with tip: [-0.1152, 0, 0], and traces that tip. |
trace |
optional. The points of this link whose path is drawn in the animation when you run with --trace (in the GUI, with Trace paths): true or tip for the link's tip (a link with children needs its own tip), origin for the origin of the link's frame, a point [x, y, z] of the link's frame, or a list of these, such as [tip, origin]. If no link has trace, the tips of all terminal links are traced, which suits a robot arm or a gripper. In a closed loop, name the point you care about (the foot of the robotic_leg, the platform of the stewart), so that only its path is drawn. The robotic_leg is a pantograph: link 6 is extended to tip: [0.3, 0, 0] and traced, and that point draws the foot's path four times larger. A point given as [x, y, z] that is not a tip also gets a small dot, in the colour of its path. |
actuated |
is the joint driven by a motor? Default true. |
In a flat arm the twist alp, the offset b and the angle th are all zero, so dh: {a: 0.3}
is enough. For a revolute joint, th is the joint variable and what you write is ignored
(section 2.4).
Chains and branches. In a simple chain, each link's parent is the previous link
(parent: 0, 1, 2, ...). In a branched robot such as a gripper, several links can share one
parent. A parent must always be listed before its children.
Many identical links. A chain of identical links does not need to be written out link by
link. A repeat entry stands for that many links, each attached to the one before:
name: A 30-link chain
gravity: [0, -9.81, 0]
links:
- repeat: 30 # thirty identical links
each:
joint: R
dh: {a: 0.1}
mass: 0.2
com: [0.05, 0, 0]
inertia: [1e-6, 1.7e-4, 1.7e-4, 0, 0, 0]
fordyn:
q0: {fill: 0} # the same value for every joint
time: [0, 1]
step: 0.02
eachis an ordinary link, withoutlink:andparent:(they are filled in).- The first copy is attached to the link before the
repeatentry. To attach it somewhere else, writeparent: 3next torepeat(it applies to the first copy only). repeatentries can be mixed with ordinary links, as many times as you like. The link numbers then count every copy, so afterrepeat: 30the next link is number 31 (if you writelink:numbers at all; you can leave them out).q0: {fill: 0}means the same number for every joint.fillworks wherever a list with one value for each joint is expected:q0,dq0,q_d,guess,qf,tau, and so on. Where the list has one value for each motor (a trajectory in a closed loop), it gives one value for each motor.
A chain of 1000 links is written the same way. The file loads instantly, and one second of its motion simulates in a few seconds (on the test computer, 2.7 s).
Numbers for a uniform bar. If a link is a thin, uniform bar of mass mass and length L
lying along its own x axis, then
For a 0.3 m bar of 0.5 kg this gives Iyy = Izz = 0.5 * 0.3^2 / 12 = 0.00375, the value in
the file above. If it is the last link of a chain, its far end is tip: [0.3, 0, 0], which is what
ReDySim assumes when you leave tip out. For a real link, take the numbers from your CAD software or measure them.
2.4 Placing the frames: modified DH parameters¶
The numbers alp, a, b and th place each link relative to its parent. They are the
modified Denavit-Hartenberg (DH) parameters of Khalil and Kleinfinger, also used by
Craig. For a flat arm you can ignore most of this section (section 2.3 is enough), but for
a robot that moves in three dimensions you need it.
The frames¶
Every link k gets a coordinate frame with its origin Ok and axes Xk, Yk, Zk, fixed to the link. The frame of the fixed ground is frame 0.
- Z axis. Zk is along the axis of joint k: the line a revolute joint turns about, or the line a prismatic joint slides along. Joint k connects link k to its parent.
- X axis. Xk-1 is along the common normal of Zk-1 and Zk: the shortest line between the two axes. If the axes cross or are parallel, any direction at right angles to both is fine; choose the simplest.
- Origin. Ok-1 is the point where that common normal meets Zk-1.
- Y axis. Yk-1 completes a right-handed frame (X × Y = Z). You never type Y in the file.
The four numbers¶
The position and orientation of frame k relative to frame k-1 are given by four numbers. Look at the figure while you read them.
| key | name | definition |
|---|---|---|
alp |
twist angle αk | the angle from Zk-1 to Zk, turning about Xk-1 |
a |
link length ak | the distance from Zk-1 to Zk, along Xk-1 |
b |
joint offset bk | the distance from Xk-1 to Xk, along Zk |
th |
joint angle θk | the angle from Xk-1 to Xk, turning about Zk |
Angles are in radians and distances in metres. A positive angle is a right-handed turn
(counter-clockwise when seen from the tip of the axis).
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.
Only one of the four is the joint variable q, the number that changes as the robot
moves: th for a revolute joint, b for a prismatic joint. For that parameter, the value
written in the file is ignored, because the program uses q instead. So:
- For a revolute joint, leave
thout (or0). The joint angle isq, and you give its starting value inq0underfordyn(or in the trajectory underinvdyn).q = 0means that Xk lies along Xk-1. If your robot starts with the joint turned by 90 degrees, you writeq0: [..., 1.5708, ...], notth: 1.5708. - For a prismatic joint, leave
bout (or0). The sliding distance isq.this then a fixed turn of the frame, andbis not used.
The other three numbers are fixed lengths and angles of the link, and you write them as
they are. This is also the rule in the MATLAB version, where th is replaced by the joint
variable.
Which frame is the parent?¶
The four numbers of link k are measured relative to the frame of its parent, the link
named by parent. For link 1 the parent is the ground (parent: 0), and its numbers are
measured relative to the ground frame. In a branched robot, each child has its own four
numbers relative to the same parent frame.
More than one link on the same parent: phi and h¶
Call the parent β (in the figure below it is link #β). Its frame has only one x axis,
xβ, and it is the common normal to the joint axis of one child, the first. A further
child j, whose joint axis zj is somewhere else, usually has its common normal
x′β in another direction and at another height along zβ. Two more numbers, written in
the same dh: block, take frame β there first:
| key | name | definition |
|---|---|---|
phi |
branch angle φj | the angle from xβ to x′β, turning about zβ |
h |
branch offset hj | the distance from xβ to x′β, along zβ |
In the figure, link #β has two children, #i and #j; 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′β.
The other four numbers of the child are then read from x′β instead of xβ. Both are zero (and can be left out) for the first child and for every link of a serial chain. In matrix form the transform from the parent frame to frame j is
Rot(zβ, φj) Trans(zβ, hj) Rot(x′β, αj) Trans(x′β, aj) Trans(zj, bj) Rot(zj, θj).
For example, a link that leaves the side of its parent, a quarter turn away from the first
child and 0.15 m further along the parent's joint axis, is written
dh: {alp: 1.5708, a: 0.2, b: 0.3, phi: 1.5708, h: 0.15}.
When alp is 0, h can equally be added to b (both are along the same axis), and when
alp and a are both 0, phi only shifts the zero of the joint angle (for a prismatic
joint it can be added to th); older models do this, and they still work. In every other
case you need phi and h.
A recipe¶
- Number the links 1, 2, ..., n from the base outwards, and draw the axis of every joint.
- Draw the ground frame so that Z0 and X0 are convenient: usually Z along a vertical or a joint axis.
- For each link in turn, draw Zk along its joint axis and the common normal Xk-1 from Zk-1 to Zk.
- Read off the four numbers for the link from the definitions above, and write them as
the link's
dh:block. - Mark the centre of mass and give its position
comin frame k, and the inertia about the centre of mass in the axes of frame k.
Example 1: a flat arm¶
The parameters of every example robot are listed in Appendix A (the Example robots page).
In the two-link arm all joint axes point out of the page (Z along the page's normal) and are parallel, so the twist is zero. Link 1's joint is at the ground origin. Link 2's joint is 0.3 m along X from link 1's joint.
| link | alp |
a |
b |
th |
why |
|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 0 | joint 1 is at the origin of the ground frame, axes parallel |
| 2 | 0 | 0.3 | 0 | 0 | joint 2 is 0.3 m from joint 1 along X1 |
Example 2: the KUKA KR5 arm (6 joints)¶
Values from my_models/kuka.yaml. All joints are revolute.
| link | alp |
a |
b |
th |
what it says |
|---|---|---|---|---|---|
| 1 | 0 | 0 | 0.4 | 0 | joint 1 axis is vertical (gravity is along -z); frame 1 is 0.4 m above the ground frame, along Z1 |
| 2 | 90° (1.5708) | 0.18 | 0 | 0 | axis 2 is turned 90° from axis 1 and 0.18 m away from it |
| 3 | 0 | 0.6 | 0 | 0 | axis 3 is parallel to axis 2 and 0.6 m away |
| 4 | 90° (1.5708) | 0.12 | 0.62 | 0 | axis 4 is turned 90° from axis 3, 0.12 m on, with a 0.62 m offset along itself |
| 5 | -90° (-1.5708) | 0 | 0 | 0 | the wrist axes cross, so no length or offset |
| 6 | 90° (1.5708) | 0 | 0 | 0 | the same |
Check your frames before you simulate¶
Set every joint angle to zero (q0: [0, 0, 0, ...]) and run redysim fordyn with
gravity: [0, 0, 0] and a very short run, then look at the animation at the first frame.
The robot should be in the pose you expect for all joints at zero. If it is not, the
frames (the four numbers) are wrong, and the dynamics will be wrong too. Fix them before
you change anything else. The most common mistakes are:
- a sign error in
alp(try its negative), aandbswapped (ais along X,bis along Z),- Zk not along the real joint axis.
2.5 Worked example: build a three-link arm¶
We extend the two-link arm by a third link and make it move.
Step 1. Export the two-link arm and give it a new name:
The file contains the robot and two sets of settings, fordyn and invdyn, each written for
the two joints.
Step 2. Run it and look at the plots, so you know what a working file looks like:
Step 3. Change one thing. In the first link, change mass: 0.5 to mass: 1.5 and run again.
The arm swings differently, because the first link is now heavier.
Step 4. Add a third link at the end of the links list. The new link hangs from link 2
(parent: 2), and its joint is at the far end of link 2, which is 0.25 m long (a: 0.25
in its dh block). We make it a 0.2 m, 0.3 kg bar and number it link: 3:
- link: 3
parent: 2
joint: R
dh: {alp: 0, a: 0.25, b: 0, th: 0}
mass: 0.3
com: [0.1, 0, 0]
inertia: [3.0e-6, 1.0e-3, 1.0e-3, 0, 0, 0]
Step 5. The robot now has three joints, so everything that lists joint values needs
three numbers. Change q0 in fordyn to q0: [0, 0, 0], and in the invdyn section
change the trajectory to three values: cycloidal: {q0: [0, 0, 0], qf: [1.0, 0.5, 0.3]}.
(If you forget one of them, ReDySim stops with a message about the wrong number of values.)
Run redysim fordyn arm3.yaml again. The arm now falls under gravity with three links.
Your file should now look like this:
name: My 3-Link Arm
gravity: [0, -9.81, 0]
links:
- link: 1
parent: 0
joint: R
dh: {alp: 0, a: 0.0, b: 0, th: 0}
mass: 0.5
com: [0.15, 0, 0]
inertia: [4.2e-6, 3.75e-3, 3.75e-3, 0, 0, 0]
- link: 2
parent: 1
joint: R
dh: {alp: 0, a: 0.3, b: 0, th: 0}
mass: 0.4
com: [0.125, 0, 0]
inertia: [3.3e-6, 2.08e-3, 2.08e-3, 0, 0, 0]
- link: 3
parent: 2
joint: R
dh: {alp: 0, a: 0.25, b: 0, th: 0}
mass: 0.3
com: [0.1, 0, 0]
inertia: [3.0e-6, 1.0e-3, 1.0e-3, 0, 0, 0]
fordyn:
q0: [0, 0, 0]
time: [0, 3]
step: 0.01
invdyn:
time: [0, 10]
step: 0.05
trajectory:
cycloidal: {q0: [0, 0, 0], qf: [1.0, 0.5, 0.3]}
(The exported file also lists dq0, solver and the tolerances; they are optional and can
stay.)
Step 6. Make the arm go somewhere. Add a torque section under fordyn so that a
controller drives the joints to the angles q_d (in radians):
Run again. The joints now settle near q_d. kp is how hard the controller pulls towards
the target; kd damps the motion. A larger kp is stiffer, and a larger kd removes
oscillation.
Step 7. Ask the opposite question: what torques would move the arm there? The file
already has an invdyn section, which moves the arm smoothly from q0 to qf in 10 seconds
(cycloidal means a smooth move from rest to rest). Run it:
The plots show the torque each joint needs. They are also in
output/invdyn/arm3/tor.dat. Change the end time in time to 3 (time: [0, 3]) and run again: the same move in less
time needs larger torques.
2.6 The simulation settings¶
fordyn (for redysim fordyn):
| key | meaning |
|---|---|
q0 |
starting joint positions: angles in radians, sliding joints in metres. One number per joint. |
dq0 |
starting joint velocities (default all zero) |
time |
[start, end] in seconds |
step |
time between stored results |
solver |
ode45 (default), ode15s for stiff problems, or ode5 (fixed step) |
rtol, atol |
the accuracy of the solver: relative (default 0.0001) and absolute (default 1e-6). Smaller numbers are more accurate and slower. |
torque |
the controller that drives the joints (below). If left out, the joints are free and the robot moves under gravity only. |
external |
forces and moments on links, such as a push or a load (below) |
invdyn (for redysim invdyn):
| key | meaning |
|---|---|
time: [start, end] |
start and end time in seconds (as in fordyn); the trajectory runs from 0 to the end time |
step |
time between stored results |
trajectory |
the motion to follow (below) |
guess |
closed loops only: the starting guess for the passive joints (section 2.8) |
external |
forces and moments on links; the joint forces are then those needed besides them (below) |
A trajectory and a controller are chosen by name: you write the name, and its settings
after it. A list with the same number for every joint can be written {fill: 0.5}. The tables below list the available ones, and redysim --types prints the same
list. Where a closed loop is concerned, the lists in a trajectory (q0, qf, ...) have one
value for each motor, not for each joint.
Trajectories (invdyn: trajectory:)¶
| name | the motion | settings |
|---|---|---|
cycloidal |
smooth move from rest to rest | q0, qf |
quintic |
smoother move from rest to rest (zero acceleration at both ends) | q0, qf |
trapezoidal |
speeds up, cruises at a constant speed, slows down | q0, qf, accel_fraction (more than 0, at most 0.5; default 0.25: the share of the time spent speeding up, and again slowing down) |
constant_speed |
every joint turns at a constant speed | rpm |
sine |
an oscillation, offset + amplitude * sin(2 pi * frequency * t + phase) |
amplitude, frequency (hertz; one number, or one for each joint), offset, phase (both optional) |
waypoints |
stops at each of a list of positions, one after the other | points (a list of joint positions), durations (seconds for each part; by default the duration is divided equally) |
For example:
invdyn:
time: [0, 4]
step: 0.05
trajectory:
waypoints:
points: [[0, 0], [1.0, 0.5], [0.2, -0.3]]
durations: [1.5, 2.5]
The moves between rest positions (cycloidal, quintic, trapezoidal, waypoints) start and
end at rest. A tool path in task space has its own types (pose, circle, section 2.7).
Controllers (fordyn: torque:)¶
| name | what it does | settings |
|---|---|---|
pd |
a spring and a damper towards a target: the force is kp * (target - q) + kd * (target rate - dq) |
kp, kd, and either q_d (the target positions) or follow: trajectory (the invdyn trajectory of the same file). dq_d: optional target rates. |
pd_gravity |
pd plus gravity compensation, so the robot holds a pose without sagging. Open chains only. |
the same as pd |
computed_torque |
model-based: uses the robot's dynamics to give exactly the motion asked for, so it follows a trajectory almost exactly. Open chains only. | the same as pd |
constant |
fixed joint forces | tau (one value for each joint, or for each motor) |
kp and kd are single numbers. A larger kp pulls harder towards the target, and a larger
kd damps the motion.
A complete example: a two-link arm follows a smooth move with computed_torque. Run it
with redysim fordyn tracking.yaml, then change computed_torque to pd and compare the
plots: with only pd the joints lag behind the path.
name: Tracking a quintic move
gravity: [0, -9.81, 0]
links:
- link: 1
parent: 0
joint: R
dh: {alp: 0, a: 0.0, b: 0, th: 0}
mass: 0.5
com: [0.15, 0, 0]
inertia: [4.2e-6, 3.75e-3, 3.75e-3, 0, 0, 0]
- link: 2
parent: 1
joint: R
dh: {alp: 0, a: 0.3, b: 0, th: 0}
mass: 0.4
com: [0.125, 0, 0]
inertia: [3.3e-6, 2.08e-3, 2.08e-3, 0, 0, 0]
fordyn:
q0: [0, 0]
time: [0, 2]
step: 0.01
torque:
computed_torque: {kp: 100, kd: 20, follow: trajectory}
invdyn:
time: [0, 2]
step: 0.05
trajectory:
quintic: {q0: [0, 0], qf: [1.0, 0.5]}
External forces (external:)¶
A force or a moment from outside, such as a push or a load carried on the tip, is written under
fordyn: (or invdyn:) 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 |
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) |
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) |
from, to |
the force acts only from from to to, in seconds (default: always) |
A complete example: a free two-link arm in space (no gravity, no motors) is pushed on its tip for half a second, then left alone:
name: Arm pushed on the tip
gravity: [0, 0, 0]
links:
- link: 1
parent: 0
joint: R
dh: {alp: 0, a: 0.0, b: 0, th: 0}
mass: 0.5
com: [0.15, 0, 0]
inertia: [4.2e-6, 3.75e-3, 3.75e-3, 0, 0, 0]
- link: 2
parent: 1
joint: R
dh: {alp: 0, a: 0.3, b: 0, th: 0}
mass: 0.4
com: [0.125, 0, 0]
inertia: [3.3e-6, 2.08e-3, 2.08e-3, 0, 0, 0]
fordyn:
q0: [0, 0]
time: [0, 2]
step: 0.01
external:
- {link: 2, point: [0.25, 0, 0], force: [0, 0.5, 0], from: 0.2, to: 0.7}
In invdyn: the joint forces are those needed besides the external forces. Your own function
of time can be named instead of a force (custom: with file and function, as below) and
needs --allow-python; it returns an array of forces for all links (see Appendix B). A force
that depends on another robot, such as a grasp, needs a few lines of Python: see Appendix B.
Your own Python function¶
If none of the types fits, you can write your own function in a Python file and name it in the
model file. The same custom entry works for a controller, a joint trajectory and a task
trajectory:
The file my_controls.py must be in the same folder as the model file (or below it):
import numpy as np
def my_torque(t, tf, robot, q, dq, k=10.0):
"""The force for each joint at time t."""
return k * (np.array([0.5, 0.3]) - q) - 0.5 * dq
The function must have these arguments, and return this:
| used for | the function | returns |
|---|---|---|
a controller (fordyn: torque:) |
f(t, tf, robot, q, dq): the time, the end time, the robot, the joint positions and rates |
one force for each joint |
a joint trajectory (invdyn: trajectory:) |
f(t, dof, Tp): the time, the number of motors, the duration |
(q, dq, ddq), each with one value for each motor |
a task trajectory (invdyn: task: trajectory:) |
f(t, dof, Tp) |
(x, dx, ddx), the task coordinates and their rates and accelerations |
Whatever you write under params is handed to your function as keyword arguments (here k),
so one function can serve several files.
Because your function is Python code that ReDySim runs, ReDySim refuses to run it unless you
allow it, with --allow-python:
Allow it only for files that you wrote or that you trust: a model file from someone else could otherwise run anything on your computer. A file name that points outside the model file's folder is refused, even with the flag.
2.7 More advanced robots¶
For these, start from a ready-made file and change it, rather than writing from scratch.
The my_models folder has the complete files for the advanced examples. Copy one, rename
it and edit the copy.
| to model | start from |
|---|---|
| a robot with sliding joints | redysim --export rp my_robot.yaml |
| a branched robot (fingers, legs) | redysim --export robotic_gripper my_robot.yaml |
| a closed-loop mechanism (four-bar, slider-crank, parallel robot) | redysim --export fourbar my_robot.yaml |
| a tool that follows a path in space | redysim --export kuka_tool my_robot.yaml |
--export writes the complete ready-made file of the example: the robot, the cuts of a
closed loop, and the fordyn and invdyn settings. The same files are in my_models/.
One example, spatial_biped, has no ready-made file (its walking motion comes from
equations that a model file cannot hold); for it --export writes the robot and the
fordyn settings only.
Appendix A (the Example robots page) lists the modified DH parameters, masses and inertias of all the examples, including these.
Closed loops have their own section, 2.8.
Tool path. Instead of joint motion, invdyn can follow the position and orientation of
a point on the robot. Open the exported file and look at its invdyn: section. It
contains a task: section with a targets entry (which link and which point, in that link's
own frame) and a trajectory (a straight move with a turn, or a circle). If a target leaves
out point and its link has a tip (section 2.3), the tip is the point that is moved; if the
link has no tip, it is the link's origin. The position of the tool at every time step is
written to tip.dat, so you can check that it follows the path.
The settings of a task:
| key | meaning |
|---|---|
targets |
what to move: a list of {link, point, dirs, angle, orientation}. dirs is the directions followed (xy, xyz, ...), angle: true adds the flat rotation angle of the link, orientation: true adds its full 3-D orientation. |
trajectory |
the path: one of the three below |
guess |
optional: starting joint values for the inverse kinematics |
| path | the motion | settings |
|---|---|---|
pose |
a straight move of the point with a turn about a fixed axis, from rest to rest (for one target with dirs: xyz and orientation: true) |
the start, as start_joints (joint values) or as position and rotvec; move (the displacement [x, y, z]), axis (default [0, 0, 1]), angle (radians) |
circle |
a point on a circle in the plane (for one target with dirs: xy) |
center, radius, speed (radians per second), phase (optional) and, if the target has angle: true, the fixed angle |
cycloidal |
a smooth move of the task coordinates from rest to rest (not for 3-D orientations) | x0, x1: the start and end values of the task coordinates |
The task must be square: the number of task coordinates (plus the rows of a closed loop) must equal the number of joints, so that the joint motion is unique. Run it with:
2.8 Closed-loop mechanisms¶
A mechanism such as a four-bar, a slider-crank or a parallel robot has links that form a closed loop. A link in the loop has two neighbours, so the "each link has one parent" description of the earlier sections does not fit directly. The trick is to cut the loop at one joint:
- Cutting opens the loop, and what remains is an ordinary tree of links, which you describe as before.
- You then tell ReDySim that the two ends of the cut must meet again. From that, it works out the motion of the whole mechanism.
The steps¶
- Choose a joint to cut. Any joint in the loop will do. Choose one that leaves a simple tree of links, usually one far from the ground.
- Describe the open tree. Number the links, give each a
parentand fill in the modified DH parameters, masses and inertias as in sections 2.3 to 2.5. The cut joint itself is not part of the tree. - Describe the cut under
cuts:. Each cut says that a point of one link must meet a point of another:
| key | meaning |
|---|---|
a, pa |
link a, and the point on it, [x, y, z] in link a's own frame |
b, pb |
link b, and the point on it in its own frame. b: 0 is the ground, and then pb is a fixed point in the ground frame. |
dirs |
the directions in which the points must agree: xy for a flat loop, xyz for a ball joint |
- Say which joints have motors. Mark each joint that has a motor with
actuated: true(the default) and every other joint withactuated: false. ReDySim counts the motors for you: a four-bar has one. At least one joint must be passive. - Nothing else to switch on. Having
cutsis what makes the model a closed loop. - Trajectories and PD gains name the motors only. A four-bar has one motor, so
q_d: [1.0]has one value, not three. - Give a starting guess for the passive joints if you use
invdyn, withguess:underinvdyn. It has one value for each joint, in the order of the links. The default isq0fromfordyn, so you can often skip it.
How to choose a cut¶
A cut replaces a pin joint that you have taken out of the loop. To fill in cuts: for your
own mechanism:
- Pick the pin you want to cut, in the loop. Look at the two links it joins and note
their numbers from the tree you described. Call one
aand the otherb. A pin between a link and the ground hasb: 0. - Find the pin in link
a. Measure its position in link a's own frame: the frame you used for its modified DH parameters, with its origin at the link's joint and x normally along the link. A pin at the far end of a 0.1 m link ispa: [0.1, 0, 0]. - Find the pin in link
bin the same way, in link b's own frame, and call itpb. Ifb: 0, givepbas a fixed point in the ground frame. - Set
dirs:xyfor a flat mechanism,xyzfor a ball joint. - Check it on paper. Draw the mechanism at one pose, with the two points on top of each other. If they cannot meet in your drawing, a number or a link is wrong.
In the picture, the blue point is pb on link 1 and the orange point is pa on link 3.
They are drawn apart so that you can see both; in the mechanism they always coincide.
Some rules of thumb:
- Which link is
aand which isbdoes not matter. If you swap them, the motion and the motor torque stay exactly the same. Only the sign of the constraint-force columns intor.datis reversed (section 2.8, worked example). - One cut for each independent loop. A four-bar has one loop and one cut. The 3-RRR robot has two cuts and the walking leg three.
- Cut a pin, not a link. A cut always replaces a joint between two links.
- This manual covers flat pins (
xy) and ball joints (xyz). A spatial pin that also locks the orientation of the two links is not described by one point cut, and the manual does not cover it.
Worked example: the four-bar¶
The four-bar has a crank (link 1), a follower (link 2) and a coupler (link 3).
The figure above shows this mechanism.
- Link 1, the crank, turns about the ground origin and is driven by a motor. It is 0.05 m long.
- Link 2 turns about a ground point 0.15 m from the origin (
a: 0.15). It is 0.13 m long. - Link 3 is attached to the tip of link 2 (
parent: 2,a: 0.13) and is 0.1 m long. - The coupler's free end must meet the tip of the crank. That is the cut: point
[0.1, 0, 0]of link 3 meets point[0.05, 0, 0]of link 1.
The whole file (it is the bundled my_models/fourbar.yaml with rounded inertias):
name: My Four-bar
gravity: [0, -9.81, 0]
cuts:
- {a: 3, pa: [0.1, 0, 0], b: 1, pb: [0.05, 0, 0], dirs: xy}
links:
- link: 1
parent: 0
joint: R
dh: {alp: 0, a: 0.0, b: 0, th: 0}
mass: 1.5
com: [0.025, 0, 0]
inertia: [1.25e-5, 3.125e-4, 3.125e-4, 0, 0, 0]
- link: 2
parent: 0
joint: R
dh: {alp: 0, a: 0.15, b: 0, th: 0}
mass: 5.0
com: [0.065, 0, 0]
inertia: [4.17e-5, 7.04e-3, 7.04e-3, 0, 0, 0]
actuated: false
- link: 3
parent: 2
joint: R
dh: {alp: 0, a: 0.13, b: 0, th: 0}
mass: 3.0
com: [0.05, 0, 0]
inertia: [2.5e-5, 2.5e-3, 2.5e-3, 0, 0, 0]
actuated: false
fordyn:
q0: [0, 2.28, 2.28]
time: [0, 1.33]
step: 0.01
invdyn:
time: [0, 1.33]
step: 0.01
guess: [0, 2.28, 2.28]
trajectory:
constant_speed: {rpm: 45}
Run it:
What to notice:
fordynlets the mechanism move freely under gravity fromq0.q0has one angle for each of the three joints. The start pose does not have to close exactly, because ReDySim closes the loop for you before it starts and keeps the motor angle.invdyngives the motor a motion (here a turn at 45 rpm) and finds the torque it needs. The passive joints (2 and 3) are solved so that the loop stays closed.guess: [0, 2.28, 2.28]is the starting guess forinvdyn. The motor angle is given by the trajectory, but the passive joints (2 and 3) cannot be told where to go, so ReDySim searches for them. It starts from these values and then follows the motion step by step, which keeps the mechanism in the same shape. Choose values near a pose in which the loop is closed (a rough sketch is good enough). If you leaveguessout, ReDySim starts fromq0offordyn. With neither, it would start from zero angles, andinvdynusually stops with "loop closure did not converge".tor.dathas three columns: the motor torque, followed by the two components (x and y) of the force that holds the cut together. The plots show both. (Swappingaandbin the cut reverses the sign of these two columns, and nothing else.)
More examples¶
| file | what it adds |
|---|---|
my_models/slider_crank.yaml |
a sliding joint in the loop (its joint variable is a distance, not an angle) |
my_models/three_rrr.yaml |
a parallel robot: seven links, three motors (on links 1, 4 and 6) and two cuts |
my_models/stewart.yaml |
a spatial parallel robot: 21 links, six motors (the prismatic leg joints) and five cuts with dirs: xyz; leg 1 carries the platform through a spherical joint (three revolute links), the other five legs are closed by cuts on it |
my_models/robotic_leg.yaml |
a walking leg linkage: seven links, one motor and three cuts |
my_models/hoken_fourbar.yaml |
another four-bar, with different link lengths (one a is negative: the joint lies on the other side) |
Appendix A lists their modified DH parameters and cut points.
If something goes wrong¶
| message | what it means and what to do |
|---|---|
a closed loop needs passive joints: every joint is marked as driven |
you wrote cuts but no joint has actuated: false. Mark the joints without a motor. |
loop closure did not converge: singular configuration or unreachable pose |
the two points of a cut can never meet, or the starting guess is too far away. Check the link numbers and the points in cuts (are they in the link's own frame?), check the link lengths, and set q0 and invdyn: guess close to a closed pose. |
the initial state violates the loop closure (position error ...) |
a warning. It appears only with close_loops: false, which switches off the automatic closing of the start pose. Remove that line. |
| the mechanism "flips" to a different shape | the same link lengths can assemble in two ways. Start (q0 and guess) near the one you want. |
A good check before you trust the results is to run fordyn and watch the animation. The
links should stay connected at the cut for the whole run.
2.9 When something goes wrong¶
ReDySim checks your file and stops with a message. The last line says what is wrong.
| message | what it means and how to fix it |
|---|---|
Unknown example 'xyz'. Use --list. |
the name is not an example, and no file by that name exists. Check the spelling, and include .yaml for your own file. |
my_robot.yaml has no 'invdyn' section. |
you ran redysim invdyn on a file that has no invdyn: part. Add one (section 2.6). |
m: masses must be non-negative |
a mass is negative. Check every mass. |
link 2: 'link: 3' does not match its position in the list |
the optional link: number disagrees with the link's place in the list. Renumber, or delete the link: line. |
link 1: ['a'] given twice |
the same value is written both inside dh and directly in the link (or as both m and mass). Keep one. |
link 1: dh: unknown keys ['x'] |
a misspelt key inside dh. Only alp, a, b and th are allowed. |
bt: every parent must have a lower link number than its child |
a link's parent is the link itself or a later link. List parents first, and check every parent. |
fordyn.torque: unknown keys ['pdd']; allowed: [...] (or the same for invdyn.trajectory) |
the name of a controller or trajectory is misspelt. The message lists the names that exist; redysim --types does too. |
invdyn.trajectory: give exactly one of ... |
you wrote two trajectory types (or none). Keep one. |
fordyn.torque.pd_gravity: needs an open-loop robot |
pd_gravity and computed_torque work only for open chains. Use pd for a closed loop. |
...runs your Python function ... add --allow-python |
the file uses custom:. Run it with --allow-python (section 2.6). |
links[2].repeat: give a positive whole number |
the number after repeat must be a whole number of at least 1. |
... a mapping here must be {fill: number} |
only {fill: 0.5} is allowed where a list is expected; give a list [...] or one number in fill. |
| a message about the wrong number of values | q0, q_d or qf has a different number of entries than the robot has joints. |
an error mentioning yaml or mapping values |
a formatting mistake: a Tab character, a missing space after a colon, or a missing bracket. Compare with the examples in this manual. |
| the simulation stops because values became not finite | the motion blew up. Try a smaller step, solver: ode15s, a smaller kp, and check masses and inertias. |
| problem | fix |
|---|---|
redysim: command not found |
activate the environment first (section 1.1) |
| no window opens | your computer has no display. Look for the saved plot*.png files in the output folder. |
an animation file .mp4 fails |
only .gif is supported without extra software. Use --save-anim name.gif. |
2.10 A checklist for a new robot¶
- Start from an example with
redysim --export. - Run it unchanged first.
- Change one thing at a time and run again after each change.
- Count the joints. Every list of joint values needs one number per joint.
- Check units: metres, kilograms, seconds and radians.
- Watch the animation: it is a stick figure (section 1.3), so look at the joints and the directions of the links, not at their shapes.
- If it misbehaves, switch gravity off (
gravity: [0, 0, 0]) and use a smallerstepto see whether the problem is the model or the settings.
If you know some Python and want to run many simulations or make your own graphs, see Appendix B (Using Python). It is optional.
A force that acts on a link from outside, such as a contact or a grasp, and several robots in one simulation are also done from Python: see section B.5 of Appendix B.