by hvengel » Fri May 02, 2014 10:16 pm
The lead computer code is very plain Jane procedural code and is an almost direct translation of the original 1974 FORTRAN code although I did try to make the names of various things more meaningful than the 3 and 4 character names used in the original code. At the time the original code was written OO and design patterns and the like did not exist. In addition, the original FORTRAN code was doing some things math wise that likely would not be done now days by using very close approximations to reduce computer cycle times (that is substituting low computational cost very close approximations for computationally expensive but exact operations) and this was retained in the translation.
It was intended to be a single instance per aircraft. This lead computer is a fixed gun lead computer meaning that it does not have the hooks needed for a turret gun (IE. variable elevation and azimuth) as it assumes that the guns and sight point in a fixed direction. There are configuration parameters that tell the lead computer where the gun is located relative to the sight line, how much the gun's bore is elevated relative to alpha (IE. the guns have a single known position and direction of fire that is more or less parallel to the flight path) and at what range the bullets path intersects the sight line. I don't know of any aircraft that uses fixed guns that has more than one gun sight. So I don't think supporting multiple instances makes sense for the type of gun sight this computer supports.
For turret guns there will either have to be a different solution or this one will need to be extended to allow for gun azimuth and elevation corrections as the gun is moved by the gunner. This will be non-trivial. In addition all of the math/physics in the paper that the original code came from is for fixed guns and does not include the additional factors needed for a turret gun. By the time this paper was written turret guns were very rare in actual service and were considered obsolete. It will be necessary to find additional reference materials to implement a turret gun sight and this might prove difficult. A turret gun lead computer should be setup to support multiple instances since most aircraft with turret guns will have more than one. For example a B-17 had three turret guns and some of these on later models had lead computing sights that were USN-MK18 derivatives which were specifically for turret guns.
Of the approx 350 lines of code a significant part of that is initialization code and stuff that interfaces with FlightGear to get or calculate data it needs (true air speed, normal acceleration, q-body, p-body, r-body, air temperature, air density,,,). The actual computational part that gets executed with each iteration of the computer is only perhaps 140 lines and some of this is related to interfacing to prevent bad property tree data from causing the computer to become unstable or to recover the computer if something extreme, like a spin, causes the computer to become unstable. There is also code in the main loop that clamps the elevation and azimuth to the physical limits of the gun sight which are setup as part of the lead computer configuration.