Pipe & Filter
Abstraction
Since this implementation uses filters, no
transformation is necessary for the input or output data streams. Five
primitive components of type Filter are used within the Cruise Control
composite filter. Since each filter is an independent process, no driver
component is necessary. This design differs from the Ford Pipe and Filter
system as described in [CKS95] in that accelerator value is not
a system input and system functionality was partitioned differently. System
state processing was removed from CalculateThrottleSetting. The
output value from CalculateDesiredSpeed is based on system state.
Implementation
Each of the filters output data only when
a current output value differs from the previously written value. This
reduced the volume of data and also eliminated the timing concerns between
the data producers and the data consumers.
The filter SystemState determines the overall status of the Cruise Control system. If the engine is on and the Cruise Control is turned on then the system status is On, otherwise the system status is Off.
Within an actual Cruise Control system, Clock pulses would count the signals on its input stream and periodically output a pulse rate. In this configuration, however, a numerical value for the pulse rate is read and simply written to the output stream. The current pulse rate information is required by both the CalculateDesiredSpeed and the CalculateThrottleSetting components. To satisfy both components’ requirements, component Split was built to copy it’s input stream to two output streams.
CalculateDesiredSpeed determines the current desired speed. It uses the output of SystemState to determine overall system status. If the system was inactive and the SystemState now indicates that the system is active, CalculateDesiredSpeed captures the current speed as the desired speed. If active, CalculateDesiredSpeed checks the brake (which, if applied, causes the system to be paused) and updates Desired Speed with the Cruise Delta (if any). When paused, CalculateDesiredSpeed checks for Cruise Resume to reactivate the system. The desired speed is compared with the previously written value, and when it changes, it is written to the output stream.
CalculateThrottleSetting uses the output of CalculateDesiredSpeed and Current Speed to calculate a new throttle setting. The formula used to calculate the throttle setting is the same as in the Procedure Call system (see Figure 6). The new throttle setting is compared with the previously written value, and when it changes, is written to the output stream.The following formula is used to calculate a new throttle setting:
ThrottleSetting = (int) (((double)(DesiredSpeed - PulsesPerSecondData) / (double)DesiredSpeed) * 10.0);