CS452 - Real-Time Programming - Fall 2010

Lecture 23 - Calibration I

Public Service Announcements

  1. Open house, November 9, 2010
  2. Velocity/speed

Train Properties

The Velocity of a Train

In general the velocity of a locomotive may be a function of many variables

  1. which locomotive you have
  2. which speed you set
  3. time since the last speed change
  4. the speed it was travelling at before the last speed change
  5. where it is on the track
  6. how long since the track was cleaned
  7. how long since the locomotive was lubricated

Important. Some of these effects are matter; some don't. It's part of your task to find out which is which.

The Essence of Calibration

  1. You measure the time interval between two adjacent sensor reports.
  2. You calculate the velocity of the train
  3. After many measurements you build a table


Independent Variable. A quantity the value of which is determined solely by the application.

Dependent Variable. A quantity the value of which is determined directly by the values of the independent variables.

Calibration Table. A set of rows, one for each combination of values of all relevant independent variable, together with an estimate of all relevant dependent variables for the combination of values. You find out the current value of an independent variable by looking it up in the table.

Data Point. Measured value(s) of dependent variable(s) for a combination of independent variables.

Cell. A bin in which data points for the same set of dependent variables were used. Estimated values of dependent variables are usually the result of averaging the data points in a cell.

Collapsing a Table. Merging cells across the different values of a dependent variable. This is normally done after you have determined that there is no variation of dependent variable value that you care about when an independent variable is changed.

The Problems You Have to Solve

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

Building a Calibration Table

Remember the goal


Each measurement produces a data record

Train Speed Section Previous Speed Time since speed change (seconds) Time since locomotive maintenance (hours) Time since track cleaning (hours) Section type Velocity (cm/sec)
25 8 31 10 23 76 36 curved 8.9


  1. Some data is nominal:
  2. Some data is ordinal:
  3. Some data is numerical:
  4. Data can be coded differently to move it from one category to another

Dealing with Data

We call the givens, the

The idea is that we expect what we measure, velocity, to be different when the dependent variables are different.

Remember the goal

We measure to build a calibration. The calibration is used to predict the future.

The basic method of data handling is simple.

  1. Gather together all measurements that have the same dependent variables.
  2. Calculate the mean and standard deviation of the measurements.
  3. Use the mean when estimating how far the train travels in a given time.
  4. Use the standard deviation to calculate how far away from your estimate the train might be.
  5. The more measurements in your collection the smaller the standard deviation.

The basic method in its full implementation is not feasible!

To make it more reasonable we sort the dependent variables into two categories:

  1. the ones that matter, and
  2. the ones that don't matter.

We omit the variables that don't matter. There are two ways of `not mattering'.

  1. Error. Some independent variables have effects that are smaller than the standard deviation measured above.
  2. Effect on your project. Sometimes the effect greated by an independent variable is too small to change the results of your project.

In either case the independent variable is omitted.

In a perfect world, which has infinite computing in zero time, and infinite availability of the tracks,

We do the following off-line.

  1. We measure using as many different values of each independent variable as possible.
  2. On the measurements we do an analysis of variance (ANOVA), including interactions.
  3. We collapse the analysis across the variables that have no statistically significant effect
  4. We then get the estimated values for each cell, and look at differences across different values of a variable
  5. The differences map into differences of estimated position.
  6. Differences in estimated position that are smaller than what you need for your project are used as a criterion for dropping more independent variables.

This provides a reasonable initial calibration table.

At the beginning of each run of the project, we run the locomotives we will be using all over the track for a while

To update

  1. In each cell of the table have
  2. After each measurement calculate

Alternatively, you could average in a circular buffer.

While the project continues to run,

Unfortunately, the world isnot perfect.

Practical Issues

You might want to consider

  1. Using floating point for calculation. The easiest way to do this is to have a single calibration task that

    If more than one task uses fixed point you must change your context switch if any access to the floating point processor is non-atomic.

  2. Turning on optimization, but be careful .
  3. Size & align calibration tables by size & alignment of cache lines

    but only if access speed is a problem.

Each train has a built-in velocity profile used when the train slows or stops.

You can create your own profile by a succession of speed commands.

Return to: