A trajectory is a path with timing
A trajectory is a path for a robot hand together with when it is at each point along it. A robot that jumps straight to a target would throw the load it carries, so it follows a planned path in many small steps.
In this lesson you plan a straight line by interpolation and use a speed limit to decide how many steps it takes.
By the end of this lesson
Note
I can plan a straight path between two points with a number of steps and a speed limit.
Key words
| Word | What it means |
|---|---|
| Path | the line of points the hand passes through |
| Trajectory | a path together with the time at each point |
| Interpolation | finding the points in between two known points |
| Waypoint | one point on a path |
| Speed limit | the fastest the hand may move |
The cells students fill in are left blank in this preview.
Interpolation finds points between two ends
To move from a start to an end, split the move into equal steps. At step k of n, you are a fraction k divided by n of the way there.
Each coordinate is start plus fraction times (end minus start). Do that for x and for y. The points fall on a straight line, equally spaced.
Worked example: a diagonal path
| Step | Fraction | x | y |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1/4 | 1 | 0.5 |
| 2 | 2/4 | 2 | 1 |
| 3 | 3/4 | 3 | 1.5 |
| 4 | 4/4 | 4 | 2 |
The cells students fill in are left blank in this preview.
Make five points with NumPy
docker exec jupyter python3 -c "import numpy as np; print(np.linspace([0, 0], [4, 2], 5))"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
NumPy can space the points for you
The Run above prints five rows, the points of the table: (0, 0), (1, 0.5), (2, 1), (3, 1.5) and (4, 2). np.linspace does the interpolation, and the 5 is the number of points, not steps.
Plain Python needs a loop, as in the next block, and gives the same points.
Interpolate in plain Python
start = [0, 0]
end = [4, 2]
steps = 4
for step in range(steps + 1):
fraction = step / steps
x = start[0] + (end[0] - start[0]) * fraction
y = start[1] + (end[1] - start[1]) * fraction
print("step", step, "point", [x, y])
# Change steps to 8 and press Run.
# There are more points, and each one is closer to the last.
Path length is the sum of gaps
The length of a path is the sum of the distances between neighbouring points. Each gap is a Pythagoras sum on the change in x and the change in y.
For a straight path all gaps are equal, so the length is just the distance from start to end. For (0, 0) to (4, 2) that is the square root of 20, about 4.472.
A speed limit sets the number of steps
The hand may move at most a maximum speed. If each step lasts dt seconds, one step may cover at most max speed times dt.
Divide the distance by that and round up. For 10 units at 3 units a second with 0.5 second steps, 10 divided by 1.5 is 6.67, so 7 steps.
Worked example: a speed limit
| Quantity | Working | Result |
|---|---|---|
| Most per step | 3 times 0.5 | 1.5 units |
| Steps, unrounded | 10 divided by 1.5 | 6.67 |
| Steps, rounded up | round 6.67 up | 7 |
| Real distance per step | 10 divided by 7 | 1.429 units |
| Real speed | 1.429 divided by 0.5 | 2.857 a second, below the limit |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think four steps gives four points. A step is the gap between two points, so n steps makes n + 1 points, counting both ends. Loop from 0 to n inclusive, or the target is never reached.
Count the steps for a speed limit
import math
distance = 10
max_speed = 3
dt = 0.5
steps = math.ceil(distance / (max_speed * dt))
per_step = distance / steps
print("steps:", steps)
print("distance each step:", round(per_step, 3))
print("speed:", round(per_step / dt, 3))
# Change max_speed to 5. How many steps now, and is the speed below the limit?
Going further
In start.ipynb, plan a path from (3, 0) to (0, 3) in 6 steps. Feed each point through the inverse kinematics from lesson 3 for links 3 and 2.
Print the angles of each point. Do the joint angles change evenly, even though the hand moves evenly?