Creating a Python Controller

The Python API enables control engineers to control a wind turbine in Ashes from Python. The control system retrieves periodic updates about the state of the wind turbine and can then provide control values for Ashes. The developed control system can either directly be programmed in Python or can be routed through Python from an environment of Choice. Control systems have already been designed in Python, Matlab, Simulink and Labview and were used to control the simulated model in Ashes.

This video provides  adetailed explanation on how to get started with Python controllers: https://www.youtube.com/watch?v=RJ3yznaAkNc

1 Connecting to Ashes

The connection to Ashes is handled by the Simis package as described in Python API in Ashes. The DataStore class handles the connection of control systems with Ashes. The connection is initialized once the start_connection() function is called on the DataStore.

2  Creating a Controller

Each controller has to subclass either the Listener class or the RNAController class to automatically register itself with the DataStore. 
  • Listener: Registers itself with the DataStore but does not provide additional funcitonality. Also serves as an interface so that the notify method is implemented in every Subclass.
  • RNAController: Abstract Subclass of RNAController that also takes a RNA number as parameter. If only one RNA is in the model ignore this parameter.
The DataStore then notifies all registered controllers every time it receives data from the Ashes environment. The order of these notifications is determined by the order of instantiation of the controllers.

Such a notification contains the Model from Ashes that is provided on the API and the results can directly be written back into this model. For more details check the corresponding tables in Python API in Ashes

Example controllers can be found in C:\Users\UserName\Documents\Ashes X.xx\Python examples .

3  Additional Requirements for running Controllers automatically

If a controller is to be run automatically by Ashes on Simulation-Start, then all user-defined files that are imported by the script have to reside in the same folder.

Additionally, you have to make sure that all imports are called directly with the file-name and do not include the parent directory. 

For example lets assume that the file structure in the project looks something like this:
1
2
3
4
5
6
7
proj\
    controller1\
               run_controller1.py
               extra_import1.py
    controller2\
               run_controller2.py
               extra_import2.py


If we now configure Ashes to automatically run the first controller (run_controller1.py) then the following has to considdered:
  • run_controller1.py is not allowed to import file outside of folder controller1 (e.g. run_controller2 nor extra_import2).
  • run_controller1.py max import extra_import1 but only explicitly. For example: 
    1
    from extra_import1 import extra
  • The import must not include the parent directory. Therefore do NOT use: 
    1
    2
    3
    from controller1.extra_import1 import extra
    # or 
    from proj.controller1.extra_import1 import extra


  • The imported file is not allowed to import files outside of the folder controller1 (Same rules as for run_controller1.py)