Scripting

Basic

In this lesson you will write a script that sets the lights and takes an image set.

You'll learn to...

  • Set environmental effects
  • Time events
  • Take image sets

Before you start

The start of a script

This may seem a little silly, but always start out your script with a comment describing what this script is intended to do. This means other people reading the script (and you in a month when you forget) know what it's for.

/**
 * Scripting Basics
 *
 * Shows new users how to give the chamber commands to set environmental
 *    conditions and take image sets over a period of time.
 *
 * made: 2017-03-07
 * by:   William A. Norman
 */

Turning on the lights

Now lets make the chamber do something. Lets start by turning the lights to 250.

set_intensity(250)

Hold it...

That should turn on the lights! Before we do something else (like turn them off), lets wait for at least 30 seconds. This wouldn't be a very interesting experiment if the lights only flashed on for a second.

wait("30sec")

Now, nothing will happen for 30 seconds.

Image sets

To actually do science with this chamber, we need to take some images. We need to start by creating a CameraProtocol describing the image set we want taken. Creating protocols is a little more complex, and will be covered in later lessons. For now, just use the protocol here.

var example_protocol = new CameraProtocol ("example_protocol_1")
    example_protocol.setAnalysisID        ("f0fm")
    example_protocol.setSensorGroupID     ("*")
    example_protocol.setSensors           ("*")
    example_protocol.setNumberLoops       ( 6 )
    example_protocol.setFramesPerLoop     ([ 5, 5, 5, 5, 5, 5 ])
    example_protocol.setMeasuringLight    ([ 1, 1, 1, 0, 0, 0 ])
    example_protocol.setSaturationFlash   ([ 0, 1, 0, 0, 1, 0 ])
    example_protocol.setExposure          ([ "50us" ])
    example_protocol.setFrameInterval     ([ "70ms" ])

Notice how you are saving the protocol to a variable. You need to do this in order to use it, like so:

run_camera_protocol(example_protocol)

If you run this, you'll have taken real images. Nice!

Cleanup

Finally, lets turn the lights back off. If you don't, the chamber will continue with its last intensity settings until some further action changes it.

set_intensity(0)

Put together

The final script all put together should look like this. It turns the lights on to 250 for 30 seconds, takes a single image, and turns the lights back off.

/**
 * Scripting Basics
 *
 * Shows new users how to give the chamber commands to set environmental
 *    conditions and take image sets over a period of time.
 *
 * made: 2017-03-07
 * by:   William A. Norman
 */

set_intensity(250)

wait("30sec")

var example_protocol = new CameraProtocol ("example_protocol_1")
    example_protocol.setAnalysisID        ("f0fm")
    example_protocol.setSensorGroupID     ("*")
    example_protocol.setSensors           ("*")
    example_protocol.setNumberLoops       ( 6 )
    example_protocol.setFramesPerLoop     ([ 5, 5, 5, 5, 5, 5 ])
    example_protocol.setMeasuringLight    ([ 1, 1, 1, 0, 0, 0 ])
    example_protocol.setSaturationFlash   ([ 0, 1, 0, 0, 1, 0 ])
    example_protocol.setExposure          ([ "50us" ])
    example_protocol.setFrameInterval     ([ "70ms" ])

run_camera_protocol(example_protocol)

set_intensity(0)