CS452 - Real-Time Programming - Fall 2011

Lecture 23 - Calibration II

Public Service Annoucements

  1. Saturday November 5, 11.00 to 13.00. Open house for high school students.
  2. Information session on graduate studies: Tuesday, 8 November, 2011 at 16.30 in MC 2065
  3. First train control demo: 15 November, 2011.
  4. Final exam: Friday, 10 December, 2011, 10.30 to Saturday, 11 December, 2011.

Stage 1. Calibrating Stopping Distance

The simplest objective:

Sequence of events

  1. Train triggers sensor at t
  2. Application receives report at t + dt1
  3. You give command at t + dt1 + dt2
  4. Train receives and executes command at t + dt1 + dt2 + dt3
  5. Train slows and stops at t + dt1 + dt2 + dt3 + dt4

Questions you need to answer

This is very time-consuming!

Now make a table

Sensor 1 Sensor 2 ...
Speed 6
Speed 8

There are enough measurements in each cell of the table that you can estimate the random error. (Check with other groups to make certain that your error is not too big.)

Based on calibrations I have seen in previous terms you will find substantial variation with speed setting and train, little variation with sensor.

Group across cells that have the `same' value. Maybe all have the same value.

Hint. Interacting with other groups is useful to confirm that you are on track. Of course, simply using another group's calibration without saying so is `academic dishonesty'.

The Essence of Calibration

  1. You measure the time interval between two adjacent sensor reports.
  2. Knowing the distance between the sensors you calculate the velocity of the train

    Note that on average the lag mentioned above -- waiting for sensor read, time in train controller, time in your system before time stamp -- is unimportant.

  3. After many measurements you build a table

The Problems You Have to Solve

  1. The table is too big.
  2. The values you measure vary randomly.

The values you measure vary systematically

Stage 2. Calibrating Constant Velocity

An implicitly accepted fact about the world that is essential for calibration.

As long as the future is sufficiently like the past, which it almost always is, calibrations work just fine.

But when it isn't, all bets are off. You need something different disaster recovery. There are two rules of disaster recovery.

  1. Do no further harm.
  2. Start from the beginning.

Back to Calibration

If the future is like the past, then knowing the future is easy: understand the past. Understanding the past is easy in theory, but hard work in practice.

In Theory

  1. Measure
  2. Measure
  3. Measure
  4. ...
  5. Compile data into a useful form

In Practice

You need to figure out what to measure, and how much measurement to do.

  1. Estimate the calibration precision required by your task. E.g., stop within one train length
  2. Estimate the error in typical measurements. E.g.
  3. Make some measurements to test your estimates.
  4. As you make measurements continuously update the calibration.

You need to figure out the best way to structure measurement results so that they can be efficiently applied in doing the task.

  1. The set of tasks that provide calibration must
  2. How much of this should be done on-line? How much off-line?

Where the Steel Hits the Rail

These comments are essentially random.

  1. Measurement is costly.

    Therefore, you should never throw any data away.

  2. You are likely to use floating point.
  3. Each landmark requires a well-defined origin and clearances with respect to that origin. E.g.

Stage 3. Calibrating Acceleration and Deceleration

Physics of Acceleration and Deceleration

At the core is a relation, (x, t), which is a space-time point. The relation says that as time passes a train takes up successive positions x(t).


The first thing that we rule out is teleportation.

A train having infinite velocity is impossible in practice

No teleportation means that x(t) must be continuous.

Constant Velocity

Suppose you have a train at (x1, t1) and you have to get it to (x2, t2).

Two questions:

  1. Is it possible? If the maximum velocity is vmax, and vmax < (x2 - x1) / (t2 - t1), then it's impossible.
  2. How do you do it? If vmax > (x2 - x1) / (t2 - t1) then you might try
    1. Set v = (x2 - x1) / (t2 - t1) at t1
      • Use your velocity calibration for this!
    2. Set v = 0 at t2.

    Doesn't quite work.

    1. Because of acceleration you arrive at x2 after t2.
    2. Because of deceleration you don't stop until the stopping distance beyond x2.

    You could


    1. It's against the rules, because
    2. Your project would only be interesting to trees, and
    3. You would be unsuccessful because of stalling on curves.

More Fundamental

Infinite acceleration is impossible because the train would be crushed, if not vaporized!

This is true both in theory and in practice.

Constant Acceleration/Deceleration

Intuitively a good idea to minimize acceleration

  1. Accelerate at a from t1 to (t2 + t1) / 2
  2. Decelerate at -a from (t2 + t1) / 2 to t2
  3. At t2

But, what happens at t = t1, (t2 + t1) / 2, t2?

Constant Jerk

Third order curve for position, second order for velocity, linear acceleration. We usually go one better, and try to minimize jerk over the whole journey.

Minimize Jerk

Acceleration/Deceleration is continuous

The result is a fourth order curve in position, third order in velocity, which is what you try to achieve when you drive.

Is it Worth Having an Explicit Function?


  1. You can calculate position explicitly without having to do numerical integration.
  2. You can calculate the parameters of a function with less measurement. How?

    The idea is that the person who programmed acceleration/deceleration into the train was lazy, so there's probably one basic function used over and over again


  1. You need to check that the functional form you have is the right one, or a right-enough one.
  2. For practical purposes small look-up tables may be perfectly adequate.

Return to: