|
|
Python external function examples: Wing angle depth control |
This topic is intended to be read in conjunction with the main external function documentation, and the example source code.
This ZIP file contains all of the Python external function examples, with each example contained in the appropriately named sub-folder.
This example illustrates how external function parameters specified in the OrcaFlex model can be read by the external function and used in the calculations.
This example comprises OrcaFlex file: WingAngleDepthControl.dat and Python script WingAngleDepthControl.py.
The example implements control of the gamma angle of two wings attached to a towed fish, in order to maintain level flight at a specified depth. Active control only starts once a specified simulation time (ControlStartsAtTime) has been reached, and this time, the target depth and other parameters, are all specified in the object tags on the Towed Fish data form.
The external function Initialise method reads these parameters, and its Calculate method checks if the simulation time has reached the ControlStartsAtTime, and if so calculates the new wing gamma angle. Before that time the Calculate method leaves the function value unchanged, so the wing gamma angles remain at the initial value that is specified on the variable data form in OrcaFlex, which is 90 degrees in this example. When the time ControlStartsAtTime is reached the control system becomes active and the wing gamma angles are controlled to make the towed fish dive to and then remain at the target depth.
The control system is a very basic proportional control, i.e. the wing angle is set to a constant multiplied by the error signal (the error signal being the difference between the actual and the target depth). Because the wings are independently controlled, each wing seeks out the target depth, and this gives roll control of the towed fish as well as depth control. A real control system would be more sophisticated than this basic example.
Using object tags to provide information to your external function is recommended over the use of the external function info parameters field. However, older external functions did not have object tags available for use, and so we demonstrate the previous method in this example, in order that anyone maintaining or receiving an old model can still understand the associated code.