Automation Update

New Galil firmware supports function parameters

The latest version of Galil’s firmware for their Accelera controllers has a few new features, including parameters for subroutines. This makes a big difference when trying to write compact, readable and easy to maintain code for the Galil. Read on to learn how to pass parameters to subroutines running on the new firmware.

Galil’s controllers use a simple but powerful two-letter command language. For example, a program to move a motor 5000 encoder counts and then set an output might look something like this:

SH;      ' Enable servo motor
PR 5000; ' Set up a 5000 count relative move
BG;      ' Begin the move
AM;      ' Wait for the move to complete
SB 2;    ' Turn on digital output 2

The Galil language has always supported subroutines to help break complicated tasks into simpler, more reusable parts. For example, the code below puts the move code above into a routine called “MOVE”, and runs the move every time it sees digital input 1 go high.


#LOOP
AI 1;     ' Wait for input 1 to go high
JS #MOVE; ' Jump to the return subroutine (and return when it finishes)
JP #LOOP; ' Start loop all over again
#MOVE
PR 5000;  ' Set up a 5000 count relative move
BG;       ' Begin the move
AM;       ' Wait for the move to complete
SB 2;     ' Turn on digital output 2
EN

That works fine as long as you’re always going to move the same distance. But now imagine you want to move 5000 counts if digital input 1 goes high, and 10000 counts if digital input 2 goes high. One solution would be to write two different functions: MOVE1 and MOVE2 for example. With the new Accelera feature for subroutine parameters, there’s a better solution: write a subroutine that takes a parameter telling it how far to move. The code might look something like this:


#LOOP
JS #MOVE(5000), @IN[1]=1;  ' Move 5000 counts if input 1 is high
JS #MOVE(10000), @IN[2]=1; '
Move 10000 counts if input 2 is high
JP #LOOP;                  ' Keep on looping
#MOVE;  ' Move function. Parameter ^a is distance
PR ^a;  ' Set up a move based on the parameter passed to the function
BG;     ' Begin the move
AM;     ' Wait for the move to complete
SB 2;   ' Turn on digital output 2
EN

As the code shows, the subroutine’s parameters are named ^a, ^b, etc. Eight parameters are allowed (^a through ^h). If a ^a-^h variable isn’t used as a parameter, it can be used as a local variable that is only visible in that subroutine. Variables can be passed by value or by reference.

To read more about the new Accelera features, check out the April edition of Galil’s ServoTrends newsletter and the DMC-4000 command reference.

Share:
  • Print
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Twitter
  • email
Posted in: Motion Geek | Topics: , ,
Comments closed

Request Information


Copyright 2008 — 2009 Automation Solutions. All Rights Reserved.   |   Home   |   SiteMap   |   Privacy Policy   |   Contact Us

Providers of automation and motion control components including servo motors, gearboxes, actuators, stages, motion controllers, PLCs, and sensors. Offices in Masschusetts, Connecticut, New Jersey, Virginia, North Carolina & South Carolina.