Robot Foundations · Module 2: Describing a Robot with Numbers
Speed, Time and Small Steps
Take the pose now, the speed, and a short time step. Out comes the pose a moment later. Repeat.
Every robot simulator you will ever use, including the ones in the labs of this course, is built on a single piece of school arithmetic: distance equals speed multiplied by time. The trick is to apply it over a very short time, during which nothing changes much, and then to apply it again. This lesson shows you the whole method by hand.
What you will be able to do
- Use distance = speed × time for a robot moving in a straight line.
- Split a motion along a heading into its x part and its y part.
- Describe turning with a turning speed, and update a heading.
- Step a pose forward in time, one small step after another.
The idea
Speed and a time step
Speed says how much distance is covered in each second. Pip's top speed is 0.5 m/s: half a metre every second.
Distance is speed multiplied by time.
distance = speed × time
At 0.5 m/s for 4 s, Pip covers 0.5 × 4 = 2 m.
That formula is exact only while the speed stays the same. A robot speeds up, slows down and turns all the time. The way out is to cut time into slices so thin that the speed barely changes within one slice. Each slice is a time step, written dt ("delta t": a small change in time). You met it in the lesson on the robot loop: at 20 Hz, dt = 0.05 s.
Which way does the distance go?
A robot at heading 0° moves along x only. At 90° it moves along y only. In between, each step is shared between x and y, and two functions tell you the shares: cosine (cos) gives the share along x and sine (sin) gives the share along y. You do not need to compute them by hand. A calculator or a program does it. What you need is a feel for the values:
| Heading θ | cos θ (share along x) | sin θ (share along y) | In words |
|---|---|---|---|
| 0° | 1 | 0 | All of the motion is along x |
| 30° | 0.87 | 0.5 | Mostly along x |
| 45° | 0.71 | 0.71 | Equal shares |
| 60° | 0.5 | 0.87 | Mostly along y |
| 90° | 0 | 1 | All of the motion is along y |
| 180° | -1 | 0 | All along x, backwards |
So for a robot moving forward at speed v with heading θ, one time step changes its position like this:
The change in x is the distance moved times the cosine of the heading. The change in y is the distance moved times the sine of the heading.
new x = x + v × cos θ × dt
new y = y + v × sin θ × dt
v × dt is the distance moved in the step. Cosine and sine split it between the two axes.
Turning has a speed too
The heading changes at a turning speed, written ω (the Greek letter omega) and measured in radians per second. Positive ω is a left turn, matching the rule for angles. The update is the same idea once more:
The new heading is the old heading plus turning speed multiplied by the time step.
new θ = θ + ω × dt
A turning speed of 1 rad/s turns the robot about 57° every second.
Pose now, plus speeds times a small time step, gives the pose a moment later. That is the whole method.
These three lines are the robot's motion model: a rule that predicts the next pose from the current pose and the speeds. The pair (v, ω), forward speed and turning speed, is what you will command in the first lab.
Small steps make a curve
Each step is a short straight line. String enough of them together, turning a little between each, and they trace a curve.
The smaller the time step, the closer the chain of straight pieces follows the true curve. With dt = 0.05 s the pieces are a couple of centimetres long and the difference is too small to see. This is why simulators use small steps.
Words to know
- Speed (v)
- Distance covered per second, in m/s. Here: the forward speed. On Pip: up to 0.5 m/s.
- Turning speed (ω, "omega")
- How fast the heading changes, in radians per second. Left is positive. Also called angular velocity. On Pip: ω = 0 when driving straight.
- Time step (dt)
- A short slice of time over which the speeds are treated as constant. On Pip: 0.05 s.
- Cosine and sine (cos, sin)
- Two functions of an angle. For a heading, cos gives the share of motion along x and sin the share along y. Both lie between −1 and 1. On Pip: at 90°, cos is 0 and sin is 1: all the motion is along y.
- Motion model
- A rule that predicts the next pose from the current pose and the speeds. On Pip: the three update lines of this lesson.
- Velocity
- Speed together with its direction. In robotics the commands v and ω are often called "the velocity command". On Pip: the pair (v, ω).
A worked example: stepping a pose forward
Pip starts at the pose (1, 1, 0°). It is commanded v = 0.4 m/s and ω = 30° per second (which is 0.524 rad/s). Use a time step of dt = 0.5 s.
Step 1. The heading is 0°, so cos θ = 1 and sin θ = 0.
- new x = 1 + 0.4 × 1 × 0.5 = 1.2
- new y = 1 + 0.4 × 0 × 0.5 = 1
- new θ = 0° + 30° × 0.5 = 15°
Step 2. The heading is now 15°: cos θ = 0.966 and sin θ = 0.259.
- new x = 1.2 + 0.4 × 0.966 × 0.5 = 1.39
- new y = 1 + 0.4 × 0.259 × 0.5 = 1.05
- new θ = 15° + 15° = 30°
Carry on in the same way and you get the table below, which is the path in the figure.
| Step | Time (s) | x (m) | y (m) | θ |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0° |
| 1 | 0.5 | 1.2 | 1 | 15° |
| 2 | 1 | 1.39 | 1.05 | 30° |
| 3 | 1.5 | 1.57 | 1.15 | 45° |
| 4 | 2 | 1.71 | 1.29 | 60° |
| 5 | 2.5 | 1.81 | 1.47 | 75° |
| 6 | 3 | 1.86 | 1.66 | 90° |
Notice the order inside a step: the position was moved using the old heading, and the heading was updated afterwards. Other orders exist and give slightly different numbers. With a small time step the difference vanishes, but within one program you must pick an order and keep it.
Try it yourself
A robot is at (0, 0) facing 90° (along y). It is commanded v = 1 m/s and ω = 0. Use dt = 0.5 s. (a) Where is it after two steps? (b) Now give it ω = 90° per second with v = 0 for two steps. What changes?
Answer
(a) At 90°, cos θ = 0 and sin θ = 1. Each step adds 1 × 0 × 0.5 = 0 to x and 1 × 1 × 0.5 = 0.5 to y. After two steps it is at (0, 1), still facing 90°. (b) With v = 0 the position does not change. Each step adds 90 × 0.5 = 45° to the heading: after two steps the robot faces 180°. It has spun on the spot.
Common mistakes
"Sine goes with x and cosine with y."
The other way round, when the heading is measured from the x axis. A quick test: at θ = 0 the robot moves along x, and cos 0 = 1 while sin 0 = 0. So cos must go with x.
"I used ω in degrees per second and θ in radians."
Mixed units give a robot that turns 57 times too fast or too slow. Inside a program keep every angle in radians and every turning speed in radians per second.
"A big time step is fine, it just runs faster."
A big step assumes the heading is constant for a long time while the robot is in fact turning, so the computed path cuts corners and drifts away from the true one. Use a step that is short compared with how quickly the motion changes.
Remember this
- distance = speed × time, exact while the speed is constant.
- Over one small time step dt: new x = x + v cos θ dt, new y = y + v sin θ dt, new θ = θ + ω dt.
- Cosine gives the share of motion along x, sine the share along y.
- Repeating a small step traces any path. This rule is the motion model.
Check yourself
Three questions. Write an answer in your own words, then reveal the explanation. Nothing you type leaves your browser.
Question 1
A robot drives straight at 0.3 m/s for 12 s. How far does it go?
Explanation
distance = speed × time = 0.3 × 12 = 3.6 m. The formula applies directly because the speed is constant and the path is straight.
Question 2
A robot at (2, 1) faces 0° and moves at v = 0.5 m/s with ω = 0. What is its pose after one time step of 0.1 s?
Explanation
cos 0° = 1 and sin 0° = 0. new x = 2 + 0.5 × 1 × 0.1 = 2.05. new y = 1 + 0 = 1. The heading stays 0°. Pose: (2.05, 1, 0°).
Question 3
Why does a simulator take many small steps and not one large one?
Explanation
The update treats speed and heading as constant during a step. That is nearly true over a short time and badly false over a long one, during which the robot turns and changes speed. Many small steps keep each one accurate, and the errors of each step stay small.
What’s next
You can now predict where Pip goes. One more idea completes the toolkit: the same spot on the floor has different coordinates depending on who is describing it.
Where this goes on the site
Nothing below is needed to continue this course. These pages take the topic of this module further, and most assume more mathematics or Python than this course does.
- LaterVectors and Coordinates
Positions as vectors, with the algebra.
- LaterCoordinate Frames
Frames done properly, in two and three dimensions.