×

Well Test - RA Logix

For the Demo, the automation piece is a Studio 5000 project. The project has a single task which runs at 200ms with two structured text programs in that task. The entire project is available for download in the Well Test - Downloads section. The project sections are described in detail below.
 
Studio 5000 Logic
 

User Defined Types

The project includes User Defined Types (UDTs) for each PLC Shift app, plus control, configuration and status objects. UDTs are generated directly from PLC Shift Manager using the Logix UDT Export functionality.
 
Gas Flow Top Level UDT
 

Controller and Program Level Tags

Controller level tags are used to start and stop and stop tests, switch between manual and auto and manual mode, view the status of the well test program and to update the well configurations. Program level tags are used internally within the program. These tags should not be manipulated directly and the controller level tags should be used instead.
 
Controller level tags that start with WellTest_Cfg are used to upload a new well configuration to the program. Tags that start with WellTest_control are used to control the program. Tags that start with WellTest_Status are used to view the status of the program.
 
Controller Level Tags
 

Well Test Configuration

The 'WellTestWroker' structured text program contains five hard coded well configurations. This makes it easy to test the program, and to get started, but it is not useful for a real application. In a real well testing application, it's important to be able to load well configurations from an external source, like SCADA or a local HMI.
 
Use the tags that start with WellTest_Cfg to load a new configuration into the program. First set the configuration to update using the 'WellTest_cfg_CfgToUpdate' tag. Internally, the program has an array of 32 well configurations allocated, so this number must be between 1 and 32. Next, set the configuration values as needed. Finally, set the 'WellTest_Cfg_UpdateCfg' tag to true. When the ST program sees this value as true, it will move the configuration values from the objects into the group in the right structures in the internal array.
 

Well Test Control

Use tags in this group to control the well test application.
 
  • The 'WellTest_Control_ManualAutoMode' tag is used to choose between Manual and Auto modes. 0 = Manual mode and 1 = Auto mode. In Manual mode, the well on test is selected by the user and well tests are started manually. In automatic mode, the program will cycle through all the configured wells automatically, and put the next well on test when the current test is complete.
 
Control Tags
 
  • The 'WellTest_Control_WellOnTestIn' tag is used to select the well on test. This is only needed in Manual mode.
  • The 'WellTest_Control_StartTest' tag is used to start a well test when in Manual mode.
  • The 'WellTest_Control_StopTest' tag is used to stop a test when in Manual mode. Note that a stop command will always take priority over a start command if both are set at the same time.
     

    Well Test Status

    Use tags in these groups to see that status of the well test application. Note that each flow run provides comprehensive status information and this group only shows a small subset of the available information. For example, previous tests results are not shown, even though they are available from the flow computers in the form of batch history tags.
     
    Status Tags
     

Logic

The MainTask is set to execute every 200ms and contains two programs.
 
Tasks and Routines
 

Simulate Inputs

The 'SimulateInputs' program is used to simulate inputs to the flow computers so that real IO is not required to start. This program should be deleted in a real system.
 

Well Test

The 'WellTest' program is the main program for this demo. This is where we actually control the well test. This program has a few different sections, which are explained at a high level below.
 
 
Well Configurations
At the bottom of WellTest there is a large chunk of code that defines configurations for 5 different wells. These are populated into the 'WellConfigurations' variable when the 'LoadConfigurations' variable is set. Note that the configuration for well 3, at index 2, has an invalid gas composition. The sum of the hexanes+ components is out of range for AGA 8 1994. This is used to show what happens when the configuration of a flow run fails validation.
 
The configuration for well 3, at index 2, is purposefully invalid.
 
When a well test is started, we take the well on test variable from the 'WellTest_Control_WellOnTestIn' tag, which ranges from 1 to 5, subtract 1, to get a number from 0 to 4, and then use that number as an index for the 'WellConfigurations' array to retrieve the configuration for the well on test.
 
Adding more wells can be done by increasing the size of the 'WellConfigurations' array. This is configured to hold 32 well configurations, but we have only populated 5.
 

Main State Machine

The bulk of the work for the program is done in the main state machine. This is a large IF THEN ELSE structure that moves between the various states as defined in the 'TestStates' enumeration. The code and the state transitions are well documented, so we won't get into the details here.
 

Additional Code

Outside of the main state machine, there are various small chunks of helper code.
 
  • Get Inputs. This code maps external tags into internal variables.
  • Connection State. This code checks that the applications execution counts are always changing. When the counts are changing we can be sure that PLC Shift apps are working and connected to the PLC.
  • Write Outputs. This code moves internal variables to external tags.
  • Copy Configs. This code moves configuration values from external tags into the internal configuration array.
  • Alarms Active. This code determines whether any flow computer alarms and active and if alarms are active, the HMI is updated.