- Please don't underestimate how hard it is to control a train.

A locomotive travels on the track at a given speed following the path created by directions of turn outs.

- As it travels it triggers sensors that give you feedback as to where it is.

How do you know where the locomotive is?

- sensor
- dead reckoning

Things can go wrong, such as

- A turn out switches while a locomotive is on top of it.
- Locomotives run off the ends of sidings.
- Locomotives stall because they pass over difficult parts of the track too slowly.
- Sensors fail to trigger, or trigger in the absence of a locomotive

The mapping between speed controls and train velocity is complex

- Velocity changes are not instantaneous. After the speed is changed the
train speeds up and slows down gradually.
- After the speed is changed the train speeds up and slows down gradually.
- `Tricks' that make the train stop instantly are not acceptable because they wear out the trains.

- The velocity decreases when travelling over turn outs or around curves.
- The smaller the radius of curvature the slower the velocity.

- Different locomotives travel at different velocities when set to the same speed.
- Velocity of a given locomotive decreases over time
- As the track gets dirty.
- As the time since the locomotive's last lubrication increases

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

- which locomotive you have
- which speed you set
- time since the last speed change
- the speed it was travelling at before the last speed change
- where it is on the track
- possibly on what type of track it is on

- how long since the track was cleaned
- how long since the locomotive was lubricated

- You measure the time interval between two adjacent sensor reports.
- knowing all the relevant conditions under which the measurement took place

- You calculate the velocity of the train
- velocity = distance / time interval
- measured in cm / sec.

- After many measurements you build a table
- Use the table to determine the current velocity
- Use the time since the last sensor report to calculate the distance beyond the sensor
- distance = velocity * time interval

- The table is too big.
- You need a ton of measurements

- The values you measure vary.
- You need to average and estimate error.

*We measure to build a calibration.**The calibration is used to predict the future.**The calibration needs only to be as precise as our need for future knowledge.*

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 |

- Some data is nominal:
- train number is just the name of the train;
- section number is just the name of an edge in your graph;
- section type is just the name of a type of section.

- Some data is ordinal:
- speed is ordered.
- You use the ordering of speed when you determine if the previous speed was higher or lower than the current one

- Some data is numerical:
- all times and the velocity.
- You may add and subtract these values.
- You may interpolate between these values.

- Data can be coded differently to move it from one category to another
- For example, time since locomotive maintenance (or track cleaning)
could be coded as
- just done
- recent
- eons ago

which is ordinal, not numerical.

- For example, time since locomotive maintenance (or track cleaning)
could be coded as

We call the givens, the

- the givens, train, speed, ..., section type, the independent variables
- what we measure, velocity, the dependent variable.

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

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

The basic method of data handling is simple.

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

The basic method in its full implementation is not feasible!

- Why?

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

- the ones that matter, and
- the ones that don't matter.

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

- Error. Some independent variables have effects that are smaller than the standard deviation measured above.
- 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.

We do the following off-line.

- We measure using as many different values of each independent variable as possible.
- On the measurements we do an analysis of variance (ANOVA), including interactions.
- We collapse the analysis across the variables that have no statistically significant effect
- We then get the estimated values for each cell, and look at differences across different values of a variable
- The differences map into differences of estimated position.
- 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

- we drive the locomotives all over the track for a while to update the static calibration.

To update

- In each cell of the table have
- the average velocity
- the variance of the average velocity

- After each measurement calculate
- new average velocity = \alpha * old average velocity + (1 - \alpha) * measurement
- new variance = \alpha * old variance + (1 - \alpha) * measurement * measurement
- 0.0 < \alpha < 1.0
- \alpha near 0.0 ignores old measurements
- \alpha near 1.0 makes old measurements dominant

Alternatively, you could average in a circular buffer.

While the project continues to run,

- use every measurement you make to update the table.

You might want to consider

- Using floating point for calculation. The easiest way to do this is to
have a single calibration task that
- receives measurements in fixed point,
- calculates internally in floating point, and
- provides current calibration parameters in fixed point.

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.

- Turning on optimization, but be careful .
- There are places where you have done register allocation by hand.
- Previously undiscovered critical races could appear, and even critical races associated with bus clocks.

- Size & align calibration tables by size & alignment of cache
lines
- linker command scripts

but only if access speed is a problem.

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

- Calibrating this correctly is essential.
- Calibrating this correctly is hard, or at least arduous.

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

Return to: