CS452 - Real-Time Programming - Spring 2012
Lecture 27 - Demos, Reservations
Public Service Annoucements
- Final exam date: 9.00 August 7 to 11.30 August 9
- The gold standard for milestone 2 is
- two trains on the track
- each receiving a new, random destination each time it reaches its
current destination
- running for five minutes or so
A Typical Reservation System
A reservation system is not the only way to keep trains from hitting one
another.
The reservation system described below is not the only reservation system
that works. I created it to illustrate the type of problems you must solve in
order to keep trains from colliding.
In past terms, students have succeeded using
- systems similar to the one described below
- systems that didn't break the track into blocks but gave out
reservations of arbitrary size
- systems that gave reservation that were areas covered by the track
rather than lines the length of the track..
Reducing the need for communication with the train controller by doing
more computation on the CPU consistenly outperform.
Hard Conditions
Needed to avoid collisions
- **Every train must have a reservation for the track it occupies.
- **Every train must travel at a low enough velocity that it can stop
before the end of the track it has reserved.
- **Every train should reserve enough to handle single sensor or
(exclusive) single switch errors.
- **No piece of track should ever be reserved by more than one train.
Soft Conditions
Needed to keep the trains moving
- Every train must release blocks it no longer occupies and will not
occupy in the immediate future.
- Every reservation held by a train must be contiguous
- Trains should release unneeded blocks in front of themselves if they
slow down or stop.
- A stopped train will hold either one or two blocks.
- Your system will behave perfectly well with only two trains if you
do not enforce this condition, but it will often spontaneously thaw
when a freeze occurs.
Who enforces these conditions?
- Nobody does so explicitly.
- There are constraints derived from the conditions above, such as
- The reservation server always gives out reservations that are
contiguous.
- The reservation server never gives out an already reserved piece of
track.
- The reservation server never revokes a reservation.
- The train always travels slowly enough that it can stop within its
current reservation if a request for extension is refused.
- And so on.
- Enforcement is provided by a protocol that every task obeys.
There is a situation in which the conditions cannot be enforced?
Here's how it works in theory
- Train gets a route from the route finder, and looks ahead along the
route.
- Train has a desired speed.
- Train asks reservation system for several blocks of track along the
route
- Blocks usually end at switches and/or sensors
- If you are ending blocks at switches you must know well enough
where the train is to be confident it is completely clear of the
switch.
- Reservation system grants the blocks if they are available
- Grants imply the condition that the train must travel so that it
can come to a complete stop without leaving any reserved block.
- Grants must be provided in the correct order
Here's one way for it to work in practice
- A train receives a reservation that will allow it to travel at its
desired speed for one or more blocks.
- The reservation includes enough track at the end of these blocks so
that the train can stop before reaching the end of its
reservation.
- Each time the train leaves a block it frees the reservation it had for
that block.
- Before reaching the end of the blocks on which it can travel at speed,
it requests an extention of its reservation.
- If the request is granted AND it can stop within the reservation, it
continues travelling at speed.
Reservation Implementation
You might decide that reservation negotiation will take place every time
the train receives a sensor report.
- Just requesting reservations whenever they're needed has a problem.
- Train drivers are likely to poll
- Polling is extremely priority-dependent.
- Priority-dependent bugs are hard to find, harder to fix.
Every time a train receives a sensor report it does its reservation
procedure
- Release the reservation just vacated
- Test stopping within the reservation at the next request time (sensor
report).
- If okay, finished
- If no, how much do I need beyond my current reservation?
- Request what's needed, possibly more
- Indicate the order in which you want the reservations
(contiguity).
- This depends on the direction in which you are travelling, which
it's not necessary for the reservation server to know.
- It could be deduced by the reservation server, but why bother.
- Reservation server gives as much as it can
- Train rechecks stopping condition using the complete reservation.
- If okay, finished
- If no, either
or
- slow down enough to satisfy the stopping condition
Comment. We like slowing down, which we consider to be a
more intelligent and aesthetic response to following a slow train than
stop-start driving.
Problems I Have Seen More than Once
Common Multi-train Tracking Problems
- Two trains waiting on the same sensor report
- Symptom: trains split and/or merge
- One is bound to get inconsistent state
- Should be solved by the reservation system
- Spurious sensor reports that a train is actually expecting.
- Most often for a secondary prediction,
- because the temporal window for a secondary prediction can
precede the time window for the primary one.
- Tightening temporal windows helps this
- Could look further ahead so that secondary predictions alway lag
behind primary ones
- Recover from such an error by back-tracking
- Permanently malfunctioning turn outs
- Can't be switched or always derails
- Alter track graph
- Important to be able to alter the track graph from the
prompt
- Partly for testing, but don't disable it in your demo version
because it can rescue a demo.
- Permanently malfunctioning sensors
- Usually fail on because of sticking
- Unstick by hand
- Alter track graph and mask reports
- See above for track graph
- Mask at as low a level as possible
Useful debugging aids
- Alter the track graph from the prompt.
- Simulate sensor-triggering from the prompt.
- From a low level log events that change track state.
- Are they consistent with the track state shown in your UI?
Common Reservation System Problems
- System freezes
- Reservations branch out ahead and cover a lot of the track
- Trains give back unneeded reservations as they slow down
- Reservations are not released.
- Usually shows itself only when the project is well advanced
- Looks as though there are phantom trains in the system
- Usually most of a reservation is released, but not all.
- Reservation leap-frogging
- Two trains are approaching one another; each gets a reservation
behind the other.
- Has also been seen when one train is following another.
- Ask for and/or give out reservations in the right order
Useful debugging aids
- Insert/remove reservations by hand from the prompt
- Query reservations (and who holds them) from the prompt
- Track map showing reservations in real-time.
- One partner watches the map while the other observes the trains
- Trains can get sensor reports only for sensors with the reservations
they hold.
- This is often the earliest symptom of a train getting lost.
(Editor's comment. It doesn't seem to me that `a train is getting
lost', but that `a train is lost'.)
- Enforce in the reservation server that all reservations must be
contiguous.
- Non-contiguous reservation requests are an early symptom of
reservation system failure.
Common Route-Finding/Following Bugs
- Train derails on turn-out after train changes direction
- Improve acceleration/deceleration calibration
- Switch turn-outs for both directions of travel
- Train derails on turn-out as turn-out switches
- Improve acceleration/deceleration calibration
- Improve train tracking
- Switch turn-outs too late
- Treat command latencies systematically
- Train collides with stationary train
- Be certain that stationary trains have reservations
- Insert/remove reservations by hand from the prompt
Useful debugging aids
All the above, plus
- Add/subtract switches, sections of track from graph by hand from the
prompt
- By modifying the route-finder you can confine all routes to a subset of
the tracks.
- This allows you to solve the common problems without being affetced
by uncommon ones.
Early Signs of Problems
Frequent train finding. (You should not be refinding trains every time
they stop.)
Return to: