OpenDRO User's Guide

8.3 Lua Extensions

OpenDRO extends Lua with a number of built-in objectsthat make it easy to get status information and control the behavior of OpenDRO.  These extensions are summarized below. 

8.3.1 User Functions

OpenDRO supports up to ten user functions that are started from the DRO keypad.  The user functions are identified by functions at global scope named 'user0' through 'user9'.  After creating a user function, you run it by pressing the FUNC key twice followed by the number.  For example, suppose you create a user function to beep for 500ms.  Enter the function in the shell as follows:

OpenDRO> function user1() machine.beep(500) end

Now press FUNC-FUNC-1 and the DRO will beep (assuming you have the beeper on).  Note that on the second press of the FUNC key, the OpenDRO will prompt for the user function to execute.  If after making a selection the function has a run-time error, OpenDRO will display an error message on the display which you can clear by pressing any key.  You can then go back and correct your user function or try running it from the shell by typing the function name and empty parentheses (i.e. 'user1()').

8.3.2 Auto-Execute Script

OpenDRO can automatically execute a Lua script on boot up.  This script is stored in the non-volatile memory on the DRO and is used to initialize user functions, load programs off of the SD card, or to do anything else you like.  On the DPU-550, this is the only place to store permanent Lua code.  For the DRO-550, one can execute Lua scripts from the SD card in addition.  The auto-execute script is written by the luash.execwr() function and read by the luash.execrd() function.  See the OpenDRO object reference below for more information.

8.3.3 OpenDRO Types

The data types listed below are used by the OpenDRO object reference that follows this section.  These are not meant to represent official Lua data types and are simply used to clarify the expected type and range for the parameters passed to and returned from the OpenDRO objects.

  • FLOAT - A decimal floating point number.  For example, -1.23 or 5.78555.
  • INT - An integeral positive or negative number.
  • BOOL - A boolean value.  In Lua, 'nil' or 'false' are logically false, 'true' or any other value is logically false.
  • STRING - A textual string encapsulated inside of single or double quotes.  Most strings used by OpenDRO are not case sensitive.
  • TABLE - A Lua table which can represent an indexed array or an arbitrary set of data.
  • FILE - A string identify the complete path to a file on the SD card.  Either forward slash '/' or backward slash '\' may be used as directory separators.  The file path is not case sensitive.
  • AXIS - A string or number identifying an axis.  Mill axes are identified by 'X', 'Y', 'Z', 'W', or 'C' or by the numbers 1 through 5, respectively.  Lathe axes are identified by 'X', 'Z1', Z2', 'W', or 'C'.
  • LINE - A number from 1 through 3, or 1 through 5 if an LCD-200 is attached, that identifies a display line.  Lines 1 through 3 are displays X, Y, and Z, respectively, on the main DRO display.  Numbers 4 and 5 identify display lines W and C, respectively, on the LCD-200 display.
  • MENU - A number from 1 through 3 that identifies the top, middle, or bottom menu line on the display, respectively.
  • SCALE - A number from 1 through 5 that identifies a scale.

8.3.4 OpenDRO Objects

This section lists the OpenDRO objects added to Lua that enable you to control and report various aspects of its operation.  The tables following each object list the functions available inside of the object.


axis

Function Return Description
read(AXIS) FLOAT Returns the current axis reading.
preseta(AXIS,FLOAT) nil Set an incremental preset at an absolute position.
preseti(AXIS,FLOAT) nil Set an incremental preset at an incremental position.
zeroa(AXIS,FLOAT) nil Set an absolute zero at an absolute position.
zeroi(AXIS) nil Set an incremental zero at the current position.
save() nil Save the current axis settings to the non-volatile configuration.
show() nil Show the axis state for troubleshooting.

 

config

Function Return Description
save(FILE) nil Save the entire OpenDRO configuration to the SD card. (DRO-550 only)
load(FILE) nil Load the entire OpenDRO configuration from the SD card. (DRO-550 only)

 

display

Function Return Description
readset(LINE,FLOAT,INT,BOOL) nil Set a floating point reading on a display line.  The third integer parameter is the display precision in half digits. The fourth boolean parameter controls the display mark, which is the left-most decimal point that is used as an indicator for tool offsets and diameter mode.
readget(LINE) STRING Return the reading shown on the display line.
readblk(LINE) nil Blink the reading on the display line.
ind() BOOL TABLE Return a table of boolean values indicating the state of the LED indicators across the top of the DRO.  The indicators are in the following order starting at index 1: INCR, MM, ZERO, SET, and FUNC.
on() nil Turn the display on.
off() nil Turn the display off.
menuset(MENU,STRING) nil Set a text string on the menu line.
menuget(MENU) STRING Return the text string currently displayed on the menu line.
menuclr() nil Clear the entire menu display of text.
menustate() BOOL Return a boolean value that indicates the display state of the menu, true if the menu is currently displayed and false if it is not.
print(STRING) nil Display a text string across all three menu lines starting at the top.  This is convenient to easily display a longer message to the user without having to call menuset() multiple times.

 

func

Function Return Description
run(STRING,STRING) nil

Run a function from the menu where the first string identifies the group and the second identifies the function within the group.  The complete list of group and function names is shown below.

'positn' 'status' 'define' 'setup' 'sys'
'tool' 'tach' 'tool' 'mach' 'off'
'c-line' 'feed' 'boltho' 'axis' 'mach'
'boltho' 'calc' 'grid' 'scale' 'sndfst'
'grid'   'radius' 'disply' 'ver'
'radius'     'keypad' 'update'
'wspace'       'save'
'dia'       'load'
'compnd'       'erase'
tool(INT) nil Select a tool to use from 1 to the maximum allowed tool number.  Tool number 0 removes the current tool selection.
edge(STRING) nil Select an edge compensation side if a tool is in use.  The string is one of 'center', 'left', 'right', 'front' or 'rear'.
diameter(AXIS) nil Select an axis to apply diameter mode to.  If diameter mode is already applied, calling this function again will remove it regardless of the axis in the parameter.
compound(FLOAT) nil Set the lathe compound vectoring angle.  Setting an angle of 0 disables compound vectoring.
workspace(INT) nil Select a workspace from 1 to the maximum number supported.
tach(LINE,BOOL) nil Set the tach to show on a display line.  The second boolean parameter enables surface speed tach mode.  Calling this function again when the tach is already displayed will remove it regardless of the parameters.
feed(LINE,AXIS) nil Show the feed rate for an axis on a display line.  Calling this function again when a feed rate is already displayed will remove it regardless of the parameters.
save nil Save the current function settings to the non-volatile configuration.
show nil Show the function state for troubleshooting.

 

keypad

Function Return Description
press(STRING) nil Simulate the pressing of a key on the keypad.  The key names are as follows: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+-', '.', 'func', 'mminch', 'absincr', 'clear', 'enter', 'zero1', 'preset1', 'zero2', 'preset2', 'zero3', 'preset3', 'zero4', 'preset4', 'zero5', 'preset5'
get() STRING Get the next key pressed on the keypad.  The key names are the same as documented above.  If a key press is not available, then the function will wait until one is available and will stop processing readings.
wait() nil Wait until a key is pressed.  While waiting, readings are still processed.  Use this before get() to retrieve a key press without stopping reading update on the display.
float(MENU) FLOAT Get a floating point number that is edited on the indicated menu line.  Nil is returned if the user cancels entry.
number(MENU,INT, INT) INT Get a integral number that is edited on the indicated menu line.  The second parameter is the minimum allowed value and the third parameter is the maximum allowed value.  Nil is returned if the user cancels entry.
select(MENU,STRING TABLE) INT Select between a set of strings on the indicated menu line.  The integer index of the selection, starting at one for the first string, is returned.  Nil is returned if the user cancels entry.

 

luash

Function Return Description
automate(BOOL) nil Control automate mode.  If the parameter is true, then the line editing facilities of the shell are disabled and the characters are not echoed back.  This mode is meant for automated PC control such as with the VDRO-550 Windows application.
execrd() nil Display the auto-execute script.  The auto-execute script is a Lua script stored in the non-volatile memory that is executed every time OpenDRO boots.
execwr() nil Write the auto-execute script.  If automate mode is off, then line editing facilities may be used for each line entered.  To complete editing and save the script, hold down control and press the D key.
history() nil Display the lua shell command history.

 

machine

Function Return Description
active(INT) nil Set the active machine to 1 or 2.
inch() nil Set the machine to inch units.
mm() nil Set the machine to mm units.
abs() nil Set the machine to absolute mode.
inc() nil Set the machine to incremental mode.
on() nil Turn the machine on.
off() nil Turn the machine off.
stop() nil Stop processing readings.
beep(INT) nil Beep for the given number of milliseconds.
save() nil Save the current function settings to the non-volatile configuration.
show() nil Show the machine state for troubleshooting.

 

mem

Function Return Description
rb(INT) INT Read an 8-bit byte from memory at the given address.
rw(INT) INT Read a 32-bit word from memory at the given address.
wb(INT,INT) nil Write an 8-bit byte to memory.  The first parameter is the address and the second is the value.
ww(INT,INT) nil Write a 32-bit word to memory.  The first parameter is the address and the second is the value.
db(INT,INT) nil Display a range of 8-bit byte values from memory.  The first parameter is the address and the second is the number of bytes to display.
dw(INT,INT) nil Display a range of 32-bit word values from memory.  The first parameter is the address and the second is the number of words to display.
show() nil Display stack, heap, and Lua memory diagnostic information.

 

scale

Function Return Description
count(SCALE) INT Return the current counts for a scale.
cpi(SCALE) INT Get the counts per inch (CPI) setup for a scale.
show(SCALE) nil Show the scale state for troubleshooting.

 

sd

Function Return Description
show() nil Show the SD card state for troubleshooting.
dir(FILE) nil Display the files in the given subdirectory.
mkdir(FILE) nil Make a new subdirectory at the given location.
rename(FILE,FILE) nil Rename a file from the first to second parameter.
remove(FILE) nil Remove the given file and its contents.
read(FILE) nil Display the given file.
write(FILE) nil Write to the given file.  If automate mode is off, then line editing facilities may be used for each line entered.  To complete editing and save the file, hold down control and press the D key which sends the EOT character.
hd(FILE) nil Display a hexadecimal dump of the given file.

 

system

Function Return Description
reset() nil Reset the DRO hardware.
version() STRING Return a string of the form 'x.y.z' for the OpenDRO version.
hardware() STRING Return a string for the hardware type.
show() nil Display all diagnostic displays for all objects.

 

trace

Function Return Description
debug() nil Set the trace level to debug and above.
info() nil Set the trace level to info and above.
warning() nil Set the trace level to warning and above.
error() nil Set the trace level to error and above.
fatal() nil Set the trace level to fatal only.
level() STRING Return a string indicating the current trace level.