Scripting with GoQat - 2

Auto-exposure with GoQat - part 2

We've seen that we can pass a parameter to a script in GoQat's task queue to define a maximum image value and the script can analyse the image statistics to tell us if it's well exposed. But really we would like GoQat to do it all for us. We just want a well-exposed image without having to do any of the work! After all, when the ISS flies overhead, you don't want to be faffing around guessing the correct exposure length, right? We need a script to pass the exposure length back again to GoQat. Here's how...

Clear all the tasks by clicking the 'Clear tasks' button on the Tasks tab. Now click the 'Load tasks from file...' button in the task editing window, navigate to /usr/local/share/GoQat/data/examples and pick tasks3.txt. This loads the contents of tasks3.txt into the task queue. (If you installed GoQat in a non-standard location you will need to find the example files yourself). Here's what the task queue should look like:

SetParam 0 55000 SetParam 1 2 SetParam 3 1 While %3 Expose TARGET - %1 1 1 1000 1000 1 1 0.00 Exec /usr/local/share/GoQat/data/examples/ EndWhile

The first SetParam task sets the value of parameter 0 to the maximum value that we want in the exposure and the second SetParam task sets parameter 1 to the initial exposure length. The third SetParam task sets a flag (parameter 3) to the initial value of 1. The value of this flag governs the operation of the 'While...EndWhile' loop. If the flag is set to 1 the loop will be executed and if it's set to 0 then it won't be executed. When is called from the Exec task following the Expose task, it reduces the value of the exposure (parameter 1) by a fixed amount if the brightest pixel has a value higher than parameter 0 and sets parameter 3 to '1' so that the While loop executes again with the new exposure value. Otherwise, the exposure must be correct so it sets parameter 3 to '0' and the task queue stops executing after the EndWhile task.

You might want to change the values for parameter 0 or parameter 1, or adjust the exposure area which is set at 1000 pixels wide by 1000 pixels high. Fortunately, that's very easy to do in GoQat. Just right click anywhere on the task queue pane and GoQat will open an editor (gedit by default) and display the task queue. Make any changes you want, save the file and exit the editor. GoQat will re-load the new task queue. Note that this may not work if you already have the editor open editing another file - you may need to close any other instances of the editor first. You might also want to adjust the target camera temperature which is 0.00 C in this example, or you can ignore it altogether by choosing the 'Ignore cooling' option on GoQat's Camera tab. When you're done, click 'Play' on the Tasks tab and watch GoQat decrease the length of successive exposures until the brightest value is equal to parameter 0 or less. If GoQat tries to set an exposure shorter than allowed by your camera you may see some errors, so try to pick a level of illumination that isn't too bright.

Auto-exposure with GoQat - part 3

We can try to be a bit cleverer by calculating the expected exposure length to give a target brightness level. This is what the script does. Clear all the tasks by clicking the 'Clear tasks' button on the Tasks tab. Click the 'Load tasks from file...' button in the task editing window, navigate to /usr/local/share/GoQat/data/examples and pick tasks4.txt. This loads the contents of tasks4.txt into the task queue, which now looks like this:

SetParam 0 55000 SetParam 1 2 SetParam 3 1 While %3 Expose TARGET - %1 1 1 1000 1000 1 1 0.00 Exec /usr/local/share/GoQat/data/examples/ EndWhile Expose TARGET - %1 1 1 1000 1000 1 1 0.00

Parameter 0 is set to our target maximum value of 55000. Parameter 1 is the starting exposure length, set to 2 seconds. Parameter 3 is a flag that initially has the value 1. This is used in the While statement that follows; while parameter 3 is set to 1, the 'While ... EndWhile' sequence will continue to execute in a loop. If parameter 3 gets set to 0, then the loop will end and the final Expose task will be carried out. The script attempts to estimate the required exposure length based on the maximum value in the previous exposure and the current exposure, by reducing the exposure length in parameter 1 until neither the previous exposure nor the current one is saturated. When it has done that, it calculates the correct exposure length as parameter 1 and sets parameter 3 to '0' to break out of the While loop. The final Expose task should then give an exposure with a maximum of about 55000 - the value that we gave parameter 0 to start with.

For this to work, the script needs to remember the exposure length and maximum value of the previous exposure. So how does it do that? If you look at the script (which is installed by default in /usr/local/share/GoQat/data/examples) you will see that it passes back these values to GoQat to be stored in a 'workspace' variable. GoQat passes the workspace variable (a character string) to any script when the script is invoked. So the script gets the previous values passed in again next time it is called. GoQat remembers the contents of the workspace variable while the task queue is executing, so you can even use this as a way of passing values between scripts.

Here's an example of running the above task queue with - the maximum image value is 55029 for an exposure length of 0.784 seconds: