Tuesday, May 21, 2013

Control interface design

I have been thinking of how the control interface would be like for the user. A user needs a few essentials:

1. An easy way to define inputs, outputs. So, in the same was you would join an ammeter output to an in-port, you need to be able to define such a connection and use the variable inside the code. Also, the output of a block should be connected to a controllable device. In case the controllable device has multiple controls, the user should be able to define which controls get what variables.

2. Time events: The simplest thing to do would be to define a constant sampling frequency but this would make multi-rate sampling impossible. Also, ideally, the user should be able to decide when the code will run next. As a reference, the user will be given the current simulation time as t_clock. Really, that is also not needed, because the user needs to define "after" how much time the control code will run again and not "at" what time the control code will run again.

3. The nature of the code: One of the reasons for using Python was to be able to combine some of the other efforts in signal processing, linear algebra etc that are happening and give the user the chance to write advanced control code. So the user can write anything that is valid code. For that matter I am not sure if it is possible to embed a C program/function within a Python program. But if that is possible, why not? Essentially, anything that you can do in Python in general.

So this is what the code I have written has designed so far.

1. Take from the user the name of the control files that he wants to use. For every control file, there will be a "descriptor" file with a _desc. This will be a CSV file. This file contains four keywords - "Input", "Output", "StaticVariable" and "TimeEvent".

2. As a framework, a sample of all these will be provided in every descriptor file. So there will be one of each to tell the user how to do the rest.

3. An "Input" will be from a meter. So the user will need to specify the name of the meter as in the circuit spreadsheet and the variable name by which they want to refer to it in the control code.
An "Output" will be at a controllable device and additionally a control tag to account for devices that have multiple control inputs and finally the variable name in the control code.
"StaticVariables" will be variables that will continue to be available with their latest values in the control code. So these will passed back and forth with the main program. All other variables used in the code will be temporary and will exist only in the control code (local variables).
"TimeEvent" will be when the code runs next. Here not fully sure what to do. Supposing there are multiple blocks of code the user wants to execute at different rates - say 100 microseconds and 145 microseconds. The user can define two time events. A simple way would be let the user take the simulation time in the form of "t_clock" and compare t_clock with the time events. A more elaborate way would be define any tevent as tevent=tevent+x. x could be constant or variable. And tevent can be initialized by the user.

4. With every control file, there will be a descriptor file. So there can be multiple control codes.

5. Once this is defined, the user writes the control code. The program takes the control code, embeds it inside a function and maps the inputs, outputs etc to variables passed from the main program. All this will be written automatically into another program with any import statements the user includes. This program will be imported by the main program and the functions will be executed automatically.

So this is the plan. Steps 1, 2, 3 and 4 are done. The code is almost ready and I need to think over it. Step 5 will then follow.

No comments:

Post a Comment