# Controlling a Train

## Types of Control

#### Summary

The sensors give us large granularity feedback control.

Between the sensors we must use ballistic control,

• which depends on integrating the train speed over time.

## Calibration

Based on

• using knowledge of the past to predict the future

Methodology

• Measure the train's speed
• Assume that the future will be like the past
• Then the speeed of the train under the same condition will be the same in the future

#### Measuring Speed

The easy part

• Get time at sensor N
• Get time at sensor N+1
• Calculate speed between the sensors using
• distance between sensors
• difference between times

Collect many such measurements

#### Using a Calibration

The other easy part

1. Arrive at sensor N at time t
• Use clock server to label sensor event with time
2. Look up velocity to use in calibration table
3. Position at time t' is sensor position + velocity x (t' - t)

#### Building a Calibration Table

The hard part.

Two things are hard.

1. Dealing with measurement error
• Two categories of error
1. Systematic = controllable

Examples,

• measurement lag
• Assume average lag is always the same
• Calculating time intervals works fine
• Calculating actual position at a specific time needs a lag added
• How do you find out the lag?

curved versus straight

Solution

• Subdivide the data
• But not too much
2. Random = uncontrollable

Examples,

• variations in measurement lag

Level of random error determines ultimate accuracy of calibration

Solution

• Take more measurements
• But without consuming much time

Rule of thumb

• Many measurements, simple algorithm works better than
• Few measurements, complex algorithm
2. Determining what state is relevant

State is has many potentially relevant aspects

• train speed
• which train it is
• curved versus straight versus switch
• previous speed
• time since last speed change
• cleanliness of track
• time since last maintenance of train

### Practical Issues

1. You are already doing a whole lot of measurements
2. Average in a circular buffer
3. Size & align table by size & alignment of cache lines