Skip to main content

Perl Interface: OpenMoco::Interface::TimeLapse

 


 


NAME

OpenMoco::Interface::TimeLapse - Perl module for interfacing with the OpenMocotime-lapse engine.

 


VERSION

Version 0.1

 


DESCRIPTION

OpenMoco::Interface::TimeLapse provides a high-level interface to the serial communication protocol used by the OpenMoco time-lapse engine. This module is designed to be used in applications and scripting for configuring and controlling a device running the OpenMoco time-lapse engine software.

This module is intended to support the rapid development or prototypeing of applications designed to interface with an OpenMoco engine.

For more information, see www.openmoco.org

 


AUTHOR

c. a. church

 


SYNOPSIS

 
 use OpenMoco::Interface::TimeLapse;
   # $serial is a valid, connected serial object of
   # Win32::SerialPort or Device::SerialPort
   
    my $moco_obj = OpenMoco::Interface::TimeLapse->new('serial_obj' => $serial);
        # add an action to be used later
        
         if( ! $moco_obj->add_action( 'camera', 0, 'interval', 5 ) ) {
         die( $moco_obj->error() );
         }
        
        # start program execution 
         if( ! $moco_obj->start() ) {
         die( $moco_obj->error() );
         }
         else {
         print "Started Engine\n";
         }

 


COPYING

This package is licensed under the PERL Artistic License. You may modify and distribute this package under the same terms as PERL its self.

 


METHODS

 

 

new(HREF)

Creates a new instance of the class. Accepts an optional HASHREF of initialization arguments. Returns a blessed instance of the class upon success, undef upon error.

The HREF argument can contain any keys of the following values:

 'serial_obj'   : A valid Win32::SerialPort or Device::SerialPort object

The serial object must be connected with the engine, and the engine must be operating properly for this module to be used.

Example:

 my $moco_obj = OpenMoco::Interface::TimeLapse->new( { 'serial_obj' => $serial } );

 

serial_obj(SERIAL_OBJECT)

Sets or returns the currently in-use serial object. If called with no arguments, returns the object currently in use. If called with a valid Win32::SerialPort or Device::SerialPort object, it sets that object as the one in-use and returns it back.

If you do not pass the 'serial_obj' parameter in the new() method, then you must call this method with a valid serial object before using any other method.

Example:

 $serial = $moco_obj->serial_obj( $serial );

 

error()

Returns the last set error message. Takes no arguments.

Example:

 my $err = $moco_obj->error();

 

stop()

Sends a stop/clear program control to the openmoco engine.

Takes no arguments. Returns true on success, returns undef and sets the error message on error.

Synonymous with clear()

Example:

 if( ! $moco_obj->stop() ) {
         die( $moco_obj->error() );
 }

 

start()

Sends a start program control to the openmoco engine.

Takes no arguments. Returns true on success, returns undef and sets the error message on error.

Example:

 if( ! $moco_obj->pause() ) {
         die( $moco_obj->error() );
 }

 

pause()

Sends a pause program control to the openmoco engine.

Takes no arguments. Returns true on success, returns undef and sets the error message on error.

Example:

 if( ! $moco_obj->pause() ) {
         die( $moco_obj->error() );
 }

 

clear()

Sends a stop/clear program control to the openmoco engine.

Takes no arguments. Returns true on success, returns undef and sets the error message on error.

Synonymous with stop()

Example:

 if( ! $moco_obj->clear() ) {
         die( $moco_obj->error() );
 }

 

camera(CONTROL)

Turns camera intervalometer on or off. Takes a single scalar argument: a string that indicates whether to turn on or off the camera. Possible argument values are:

   'on'  : turn on the camera intervalometer
   'off' : turn off the camera intervalometer

Returns true on success, returns undef and sets the error message on error.

Example:

 if( ! $moco_obj->camera('on') ) {
         die( $moco_obj->error() );
 }
 
 
 if( ! $moco_obj->camera('off') ) {
         die( $moco_obj->error() );
 }

 

program_control(TYPE)

Sends a program control to the engine. Takes a single scalar argument: a string that identifies the control to send. Possible argument values are:

  'start'   : start the program running
  'stop'    : stop/clear the program running
  'pause'   : pause the running program
  'cam_on'  : turn on the camera intervalometer
  'cam_off' : turn off the camera intervalometer

Note: there are short-hand methods provided for each of these controls. See start(), stop(), clear(), pause(), and camera().

Returns true on success, returns undef and sets the error message on error.

Example:

 if( ! $moco_obj->program_control('start') ) {
         die( $moco_obj->error() );
 }

 

set_camera(TYPE, VALUE)

Sets a camera control value. Takes two arguments: a scalar TYPE argument that defines the control to set, and a scalar VALUE argument that specifies the value for the given control.

The following are the possible controls, and their maximum values:

  'cycle'    : Set the interval time between shots, in seconds.
               Max = 65536
  'exposure' : Set the exposure time, or shutter trigger time, in mS
               Max = 4294967295
  'tap'      : Set the pre-focus tap time, in mS
               Max = 65536
  'shots'    : Set the maximum number of shots
               Max = 65535
  'post'     : Set the post-exposure delay, in mS
               Max = 65535

Returns true on success, returns undef and sets the error message on error.

Example:

 # set intervalometer to 5 seconds
 if( ! $moco_obj->set_camera('cycle', 5) ) {
         die( $moco_obj->error() );
 }

 

set_motor(MOTOR, TYPE, VALUE)

Sets a motor control value for a specified motor. Takes three arguments: a numeric motor argument that defines the motor to set the control for, a scalar argument that defines the control to set, and a scalar valueargument that specifies the value for the given control.

Motors are indexed at zero, and the possible motor values are 0-2.

The following are the possible controls, and their maximum values:

  'steps'    : Set the number of steps between shots.
               Max = 65536
    
  'max_step' : Set the maximum step count for the motor
               Max = 4294967295
     
  'ramp'     : Set the ramp rate for the motor
               Value = 1-255
     
  'dir'      : Set the direction of travel
               Value = 0-1

Returns true on success, returns undef and sets the error message on error.

Example:

 # set motor movement to 10 steps
 
 if( ! $moco_obj->set_motor(0, 'steps', 10) ) {
         die( $moco_obj->error() );
 }

 

set_alt_in(TYPE, PREDEL, VALUE, MOTOR, DIR)

Sets the alt in/out as an input, and specifies what to execute when triggered.

It takes three required arguments, TYPE, PREDEL, and VALUE, and up to two more optional arguments, based on TYPE.

The type argument is a scalar string, specifying what type of action to take when triggered, and determines the meaning of value. PREDEL defines how many milliseconds to delay after the trigger is recognized before executing the action.

The following types are supported:

  'camera' : fires the camera when triggered, value is the
             length of the exposure in mS from 1-65535
  'motor'  : Moves the specified MOTOR in the specified
             DIR, for the value specified steps.  value
             is from 1-8191
 
The MOTOR and DIR arguments are only used with the 'motor' type.

Returns true on success, returns undef and sets the error message on error.

Example:

 
 if( ! $moco_obj->set_alt_in('camera', 0, 1000) ) {
         die( $moco_obj->error() );
 }
 if( ! $moco_obj->set_alt_in('motor', 50, 100, 0, 1) ) {
         die( $moco_obj->error() );
 }

 

set_alt_out(TYPE, PREDEL, TIME)

Sets the alt in/out as an output, and specifies what type of trigger will cause it to run.

It takes three required arguments: type is a scalar string specifying what type of trigger will cause the alt output to go logic high, predel is a number of mS to delay before bringing the output high, and time is the time in mS to keep the output high for.

The output may be configured to trigger before or after the
camera or before or after the motors.
The following types are supported:
  'pre_cam'    : triggers the alt out before the camera fires
  'post_cam'   : triggers the alt out after the camera fires
  'pre_mot'    : triggers the alt out after motors move
  'post_mot'   : triggers the alt out before motors move
Returns true on success, returns undef and sets the error message
on error.

Example:

 
 if( ! $moco_obj->set_alt_out('pre_cam', 0, 1000) ) {
         die( $moco_obj->error() );
 }

 

delete_action(POSITION)

Deletes the action stored in the given position.

Returns true on success, returns undef and sets the error message on error.

Example:

 
 if( ! $moco_obj->delete_action(3) ) {
         die( $moco_obj->error() );
 }

 

add_action(TYPE, POSITION, COMMAND, VALUE, MOTOR, DIR)

Adds an action to memory, which can be executed later via a keyframe. There are three required arguments type, position, and command, and up to three more based on the values of the type and command arguments.

The position argument indicates the position of the action, from 0-7. If you add an action where one already exists, it will be written over.

The following combinations of options are allowed:
  type = camera
    command = enable
      value = n/a
    command = disable
      value = n/a
    command = interval
      value = new interval value
    command = exp_mult
      value = exposure multiplier (1-255)
    command = exp_div
      value = exposure divider (1-255)
  type = motor
    command = enable
      value = 0
      motor = motor # (0-2)
      dir   = direction (0-1)
    command = disable
      value = 0
      motor = motor # (0-2)
      dir   = direction (0-1)
   command = set_move (set # of steps between shots)
      value = # of steps (1-255)
      motor = motor # (0-2)
      dir   = direction (0-1)
   command = ramp (trigger down ramp)
      value = 0
      motor = motor # (0-2)
      dir   = direction (0-1)
  type = program
    command = stop
      value = n/a
    command = start
      value = n/a
    command = pause
      value = n/a
                
Returns true on success, returns undef and sets the error message
on error.

Example:

 
 if( ! $moco_obj->add_action('program', 0, 'stop') ) {
         die( $moco_obj->error() );
 }
 
        # start ramping down motor 2, set direction to 1
        
 if( ! $moco_obj->add_action('motor', 3, 'ramp', 0, 2, 1) ) {
         die( $moco_obj->error() );
 }

 

add_keyframe(TYPE, POSITION, VALUE, ACTION_POS, MOTOR)

Adds a keyframe of the specified type. There are four required arguments, the type of keyframe, the keyframe index (position) for that type, and which action index (action pos) to trigger. For the type of 'motor', the motor number may also be specified.

The following types are supported, and their maximum values:
  'camera' : # of shots (0-8192)
  'motor'  : # of steps (0-134217728)
  'time'   : # of mS (0-536870912)

A keyframe triggers when the specified value for the type of keyframe has been exceeded. If you add a keyframe to an index position of an existing keyframe for that type, it will be overwritten.

Keyframes are removed on the engine once executed.

Returns true on success, returns undef and sets the error message on error.

Example:

 # add keyframe at index zero for camera, to trigger
 # action at index 1 when 500 shots are exceeded
 
 if( ! $moco_obj->add_keyframe('camera', 0, 500, 1) ) {
         die( $moco_obj->error() );
 }
 
        # add keyframe at index 1 for motor, (monitoring motor 0)
        # to trigger action at index 2 after 13,000 steps
        
 if( ! $moco_obj->add_keyframe('motor', 1, 13000, 2, 0) ) {
         die( $moco_obj->error() );
 }