Skip to main content

Perl Interface move_right Example

Dan's picture
Posted in

Hi There,

I have a few questions regarding how to use the perl interface commands.

1.)In the move_right.pl example included in the download there is a sub routine command which I am curious about.

 get_output($port); It's used several times in the example but I can not seem to find anything in your docs about it. Would you mind explaining it's significance?

2.) Is the any order of execution requirements when using the following commands in a perl script?:
# camera(CONTROL)
# program_control(TYPE)
# set_camera(TYPE, VALUE)
# set_motor(MOTOR, TYPE, VALUE)
# set_alt_in(TYPE, PREDEL, VALUE, MOTOR, DIR)
# set_alt_out(TYPE, PREDEL, TIME)
# delete_action(POSITION)
# add_action(TYPE, POSITION, COMMAND, VALUE, MOTOR, DIR)
# add_keyframe(TYPE, POSITION, VALUE, ACTION_POS, MOTOR)

so for example: does it matter if I put

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

before

 # set intervalometer to 5 seconds

 if( ! $moco_obj->set_camera('cycle', 5) ) {
         die( $moco_obj->error() );
 }

in a perl script, will it make any difference to the final result?

I am writing a command line promt script that essentially asks you to input all of the relevant values for a shot. It stores them all as variables and uses them as arguments for sub routine versions of the code above and then starts the move.

I'm beginning to think I should just stick with the action example in the synopsis for this kind interface and just give the user access to input some arguments for an just an action to begin with. I know this is locking them out of many other features, but I'm new to perl and I don't wan't to get too in over my head.

Dan.

Dan, As to (1) : The

Dan,

As to (1) :

The get_output() subroutine is defined within the script its self, it just reads anything that comes back from the serial interface, and prints that out.

I added that, as during testing I would add a lot of Serial.print()'s to the arduino side for debugging purposes, and that let me read the output. It's largely non-operative with the standard engine distribution.

It's funny you mention a command-line interface, I'm actually working on one written in perl that provides a scripting and interactive mode. I.e. you can enter commands one-at-a-time at an interactive prompt, load scripts from a file, or go completely non-interactive, and just run pre-scripted commands from a text file.

The commands are largely analogous to the API commands, so you could say things like:

Command> port COM8
[port] Com port set to 'COM8'
Command> connect
[connect] Connected to the OpenMoco engine
Command> camera cycle 5
[camera] Set parameter 'cycle' to value '5'
Command> start
[start] Start request sent
...

It's not ready for prime-time, and in fact, still has a lot of work left to do, but I could send over what I have to you if you want, it might make it easier to build on. Or, we could work together to complete it. It's designed to handle the differences between unix and windows distributions, etc. Mind you, it's completely un-tested at this point *grin*

(2):

As to whether the order of commands makes any difference - nope. You can even change the parameters while it's running, and it will use the new setting for the parameter immediately.

The only important thing to note is that if you issue a start command (via the start api call, or the program control api call) it will immediately start executing with whatever parameters it had in memory. So, generally, that should be the last thing you call if you're worried about anything default or previously set messing w/ your program.

!c

Thanks for the

Dan's picture

Thanks for the answers,

That's sounds great! It sounds much more thought out than what I had in mind. I'm not sure how much I can help out with this, being a newbie to perl and programming in general. But I would be happy to test it out as you work on it if you interested.

Dan.