SCRIPTING/PRODUCING AND DIRECTING. FTP 101 SCRIPTING Synopsis
Scripting Reference Manual - Weiss Robotics · KMS Scripting Reference Manual Weiss Robotics GmbH &...
Transcript of Scripting Reference Manual - Weiss Robotics · KMS Scripting Reference Manual Weiss Robotics GmbH &...
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 2 of 34
© 2012 Weiss Robotics, all rights reserved
Contents
Contents 2
1 Introduction ...................................................................................................... 4
1.1 The LUA Scripting Language .......................................................................................... 4
1.2 The Scripting Environment ............................................................................................ 4
1.2.1 Using the Interactive Script Editor......................................................................................... 4
1.2.2 Uploading and downloading scripts ...................................................................................... 6
1.2.3 Automatically run a script on startup .................................................................................... 6
1.2.4 Accessing files from within a script ....................................................................................... 7
1.2.5 Restrictions ............................................................................................................................ 8
2 KMS-specific script extensions ........................................................................... 9
2.1 Generic Extensions ....................................................................................................... 9
2.1.1 Print a formatted string - printf() .......................................................................................... 9
2.1.2 Wait some time - sleep() ..................................................................................................... 10
2.1.3 Convert bytes into a LUA number - bton() .......................................................................... 11
2.1.4 Convert LUA number into bytes - ntob() ............................................................................. 12
2.1.5 Replace characters inside a string – replace() ..................................................................... 13
2.2 System ....................................................................................................................... 14
2.2.1 Get system information - system.info() .............................................................................. 14
2.2.2 Get firmware version – system.version() ............................................................................ 15
2.2.3 Get serial number – system.serial() ..................................................................................... 16
2.2.4 Get system type – system.id() ............................................................................................. 17
2.2.5 Get or set device tag - system.tag() ..................................................................................... 18
2.2.6 Get service tag - system.servicetag() ................................................................................... 19
2.2.7 Get temperature - system.temperature() ........................................................................... 20
2.2.8 Get system flags - system.flags() ......................................................................................... 21
2.3 Sensor and Data Acquisition ....................................................................................... 22
2.3.1 Acquire a single sensor data frame – daq.get() ................................................................... 22
2.3.2 Get or set filter – daq.filter() ............................................................................................... 23
2.3.3 Control sensor tare – daq.tare() .......................................................................................... 24
2.4 Calibration Settings .................................................................................................... 25
2.4.1 Get calibration matrix – calibration.matrix() ....................................................................... 25
2.4.2 Get calibration date and lifetime– calibration.date().......................................................... 26
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 3 of 34
© 2012 Weiss Robotics, all rights reserved
3 Interactive Scripting on the Command Interface ............................................... 27
3.1 Scripting vs. Command Interface ................................................................................. 27
3.2 Load custom function libraries .................................................................................... 27
3.3 Limitations ................................................................................................................. 28
3.4 Example ..................................................................................................................... 28
4 Appendix A: System State Flags ........................................................................ 30
5 Appendix B: Filter types ................................................................................... 32
6 Appendix C: Syntax Notation ............................................................................ 33
Parameters ..................................................................................................................... 33
Values 33
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 4 of 34
© 2012 Weiss Robotics, all rights reserved
1 Introduction
The KMS family of force/torque sensors includes a powerful scripting engine based on the LUA language
that enables you to implement application specific behavior of your sensor. The KMS includes the LUA
interpreter version 5.1.
1.1 The LUA Scripting Language
LUA is a lightweight and extensible programming language and was developed by a research group around
Roberto Ierusalimschy at Pontifical Catholic University of Rio de Janeiro, Brazil in 1993. This manual will not
give you a complete introduction in how to program LUA, but will focus on the sensor-specific extensions of
the programming language. A good source for learning LUA and for programming examples is the official
LUA Website at http://lua.org and the LUA User’s website at http://lua-users.org.
In addition, the following books will give you an introduction to the LUA programming language:
For beginners in programming, we recommend this book:
K. Jung, A. Brown: Beginning LUA Programming, 2007, ISBN 0-470-06917-1
If you are already familiar with programming, you may read instead:
R. Ierusalimschy: LUA 5.1 Reference Manual, August 2006, ISBN 85-903798-3-3
R. Ierusalimschy: Programming in LUA, March 2006, ISBN 85-903798-2-5
There is also a German edition of the latter one:
R. Ierusalimschy: Programmieren mit LUA, September 2006, ISBN 3-937514-22-8
1.2 The Scripting Environment
1.2.1 Using the Interactive Script Editor
For developing and testing scripts, the KMS contains an interactive script editor (see Figure 1) that is
accessible over its web interface. It consists of an editor with syntax highlighting and a console window to
display log messages from your script. To open the interactive script editor, go to the sensor’s website by
entering its IP address in your browser’s address line. Alternatively, you can use the symbolic name
http://kms40-00000000.local of your sensor, replacing the “00000000” by the serial number of your sensor
(this requires mDNS to be enabled on the sensor and an mDNS service like “Bonjour” running on your PC).
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 5 of 34
© 2012 Weiss Robotics, all rights reserved
This 8 digit number can be found on the type label located above the connectors. When accessing the
sensor’s web interface, you may have to log in first, depending on the security settings of the KMS.
You will need administrator rights to use the interactive script editor
Go to the interactive scripting page by choosing “Scripting -> Interactive Scripting” from the main menu.
You can now either write a new script or load one from the sensor’s SD-Card by pressing the “Open”
button. To run a script, it has to be saved first. Select a name that allows an easy identification of the script
by its function. The file extension has to be “.lua”. To abort a currently running script, press the “Stop”
button.
The editor supports common hotkeys, e.g. CTRL-C for copy, CTRL-P for paste and CRTL-S for save.
Figure 1: The Interactive Scripting Editor
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 6 of 34
© 2012 Weiss Robotics, all rights reserved
1.2.2 Uploading and downloading scripts
You can either copy your scripts to the SD card manually by placing the SD card into a compatible reader or
you can use the upload feature of the sensor’s web interface, see Figure 2.
Scripts must be located in the /user directory or any subdirectory and must end with “.lua” to be started.
You will need administrator rights to upload or download scripts
1.2.3 Automatically run a script on startup
Via the web interface of the KMS (go to the system settings page via “Settings -> System”), you may specify
any script from the /user directory to be automatically executed when the sensor starts up (see Figure 3).
Care should be taken that the script runs error-free. It is easy to imagine that you can seriously disturb the
normal operation of the sensor with an erroneous script. We recommend testing the script extensively
using the interactive scripting editor before using it as an autorun script.
Figure 2: Up-/Download Page
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 7 of 34
© 2012 Weiss Robotics, all rights reserved
In autorun mode, all console outputs are discarded, unless you open the web interface and go to the
interactive scripting editor page. There, you can see the currently running script.
Errors will be written to the system log.
Scripts must be located in the /user directory to be selectable as autostart script.
You will need administrator rights to configure the autostart feature
1.2.4 Accessing files from within a script
You can create and access files on the sensor’s integrated SD card. The default directory when starting a
script is /user. To read the content of a file, you can use the example code below. It accesses the file test.txt
Figure 3: Configuring an autostart script
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 8 of 34
© 2012 Weiss Robotics, all rights reserved
which is assumed to be located in the user directory on the SD card. For a complete “How To” on accessing
files from within LUA, please see the LUA Manual at http://lua.org.
Example
f = assert( io.open("test.txt", "r" ));
text = f:read( "*all" );
f:close();
print( text );
Care should be taken if accessing a file using an absolute path, as manipulation of system-related files
(outside the /user directory) may endanger the correct operation of the sensor!
1.2.5 Restrictions
Even if the KMS supports the complete functional range and syntax of the LUA programming language, the
following restrictions apply when running a script on the sensor hardware:
Arithmetic calculations are done using single precision floating point functions.
Environment variables are not available.
Console buffer does not block if full. Prints to the console (either via “print” or “printf”) are
internally buffered with a buffer of constant length. If the script constantly prints messages but
they are not polled by a client (i.e. the web interface’s console window is not active), the message
buffer may discard new messages if it is already full.
The script cannot read characters from the standard input (e.g. keyboard input).
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 9 of 34
© 2012 Weiss Robotics, all rights reserved
2 KMS-specific script extensions
2.1 Generic Extensions
2.1.1 Print a formatted string - printf()
Print a formatted string to the console. The format string follows the same rules as the ANSI C printf()
command. The following options/modifiers are not supported: *, l, L, n, p, h. For further details on
formatting strings, see the description of string.format in the LUA Reference Manual.
The console uses line buffering for printf() outputs. To force a line to be printed immediately, terminate it
using a carriage return ('\n') character.
The internal buffer of the console output will hold a limited number of characters. If no console window is
open or your script prints too much text, this buffer may become full and additional text may be lost!
Syntax
printf( fmt, […] )
Parameters
fmt
Format string
… (optional)
Optional list of parameters that are output using the format described in fmt.
Return Value
none
Example
printf( “Hello World!\n” ); -- outputs “Hello World” at the console
printf( “This is a %s: %d\n”, “ten”, 10 ); -- outputs “This is a ten: 10” at the console
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 10 of 34
© 2012 Weiss Robotics, all rights reserved
2.1.2 Wait some time - sleep()
Pauses the script execution for a given time.
Syntax
sleep( ms )
Parameters
ms (integer)
Time to wait in milliseconds. Negative values are treated as 0.
Return Value
none
Example
sleep( 1000 ); -- waits for 1 second
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 11 of 34
© 2012 Weiss Robotics, all rights reserved
2.1.3 Convert bytes into a LUA number - bton()
Converts a table with 4 bytes representing an IEEE 754 single precision floating point number into a LUA
number.
Syntax
<number> = bton( bytes )
Parameters
bytes <table>
Table containing four integers in the range of [0..255]. Byte addressing is little endian.
Return Value
floating point number
Example
number = bton( {164, 112, 157, 63} );
printf( “Number is %g\n”, number ); -- outputs “Number is 1.23” at the console
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 12 of 34
© 2012 Weiss Robotics, all rights reserved
2.1.4 Convert LUA number into bytes - ntob()
Interprets a LUA number as an IEEE 754 single precision floating point number and converts it into its byte
representation.
Syntax
<number> = ntob( number )
Parameters
number <number>
LUA Floating point number.
Return Value
Returns a table with four integers in the range of [0..255] that holds the binary representation of the
passed LUA number.
Example
bytes = {};
bytes = ntob( 1.23 );
print( bytes ); -- outputs “164 112 157 63” at the console
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 13 of 34
© 2012 Weiss Robotics, all rights reserved
2.1.5 Replace characters inside a string – replace()
Replace all occurrences of the old character inside a string by a new character.
Syntax
<string> = replace( str, oldch, newch )
Parameters
str (string)
String where the characters should be replaced.
oldch (string)
Character to be replaced. This string must only contain one character.
newch (string)
Replacement character. This string must only contain one character.
Return Value
Returns a copy of the given string where the characters have been replaced.
Example
-- Replace all points by commas:
s = "These are numbers: 1.234 and 3.45";
print( replace( s, ".", "," )); -- -> produces "These are numbers: 1,234 and 3,45"
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 14 of 34
© 2012 Weiss Robotics, all rights reserved
2.2 System
2.2.1 Get system information - system.info()
Returns a table containing the system information and the sensor-specific physical limits.
Syntax
<table> = system.info()
Parameters
none
Return Value
Table containing the system information:
<table>.serial_number = <int> Serial Number
<table>.hw_revision = <int> Hardware revision
<table>.sw_version = <string> Software version
<table>.bl_version = <string> Bootloader version
<table>.type = <string> System type, e.g. "KMS 40"
<table>.macaddr = <string> The sensor’s MAC address
Example
info = {};
info = system.info();
printf( "type: %s mm\n", info.type ); -- outputs: “type: KMS 40”
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 15 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.2 Get firmware version – system.version()
Get the firmware version string.
This function is the scripting equivalent of the command interface’s V() command.
Syntax
<string> = system.version()
Parameters
none
Return Value
String containing the firmware version.
Example
version =system.version();
printf( "version: %s\n", version ); -- outputs something like: “version: 1.0.0”
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 16 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.3 Get serial number – system.serial()
Get the sensor serial number.
This function is the scripting equivalent of the command interface’s SN() command.
Syntax
<integer> = system.serial()
Parameters
none
Return Value
Integer value containing the sensor’s serial number.
Example
serial =system.serial();
printf( "serial: %d\n", serial ); -- outputs something like: “serial: 12345678”
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 17 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.4 Get system type – system.id()
Get the system type string. This can be used for example to distinguish between different devices
manufactured by Weiss Robotics that support the scripting interface.
This function is the scripting equivalent of the command interface’s ID() command.
Syntax
<string> = system.id()
Parameters
none
Return Value
String containing the system type.
Example
type =system.type();
printf( "type: %s\n", type ); -- outputs something like: “type: KMS 40”
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 18 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.5 Get or set device tag - system.tag()
Sets and/or returns the system tag. The system tag is a string that can be set to any value. You can write
e.g. application specific data or the sensor location to it. The system tag can be accessed via the command
interface, too.
This function is the scripting equivalent of the command interface’s D() command.
Syntax
<string> = system.tag( [value] )
Parameters
value (string), optional
If this parameter is passed, it defines the new value for the tag.
Return Value
Current tag value.
Example
system.tag( "Example" ); -- Set the system tag to "Example"
printf( "System tag is %s\n", system.tag()); -- outputs: "System tag is Example"
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 19 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.6 Get service tag - system.servicetag()
Return the service tag of the sensor. The service tag is an alphanumeric string that is used to identify the
device for service purposes.
Syntax
<string> = system.servicetag()
Parameters
none
Return Value
String containing the service tag of the device
Example
tag = system.servicetag();
printf("The system service tag is %s\n", tag );
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 20 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.7 Get temperature - system.temperature()
Return the temperature of the device.
This function is the scripting equivalent of the command interface’s T() command.
Syntax
<number> = system.temperature()
Parameters
none
Return Value
Temperature in degrees celsius
Example
t = system.temperature();
printf("The current system temperature is %f degC\n", t );
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 21 of 34
© 2012 Weiss Robotics, all rights reserved
2.2.8 Get system flags - system.flags()
Return the current system flags value. The returned value is the decimal representation of a bit vector of 32
bit length, encoded as an integer value. A return value of 12 (binary 1100), for example, indicates that bit 2
and bit 3 are set, which means that the flags SF_FILTER_EN and SF_TARA are enabled.
Chapter 4 gives an overview of the available flags.
This function is the scripting equivalent of the command interface’s FLAGS() command.
Syntax
<integer> = system.flags()
Parameters
none
Return Value
System flags value
Example
f = system.flags();
printf( "The current system flag value is %d\n", f );
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 22 of 34
© 2012 Weiss Robotics, all rights reserved
2.3 Sensor and Data Acquisition
2.3.1 Acquire a single sensor data frame – daq.get()
Get a single sensor data frame that contains the currently measured values as well as a time stamp.
This function is the scripting equivalent of the command interface’s F() command.
Syntax
<table>, <int> = daq.get()
Parameters
none
Return Value
Returns a table holding the six measured force/torque values (floating point) and an integer value holding a
timestamp.
The first three numbers in the table indicate the forces Fx, Fy and Fz (in this order) in Newton (N). The three
following numbers indicate the torque values Mx, My and Mz in Newton meters (Nm). The timestamp value
is given in 1/10 Milliseconds (ms).
Example 1
f, ts = daq.get(); -- returns frame f and timestamp ts
Example 2
f = daq.get(); -- returns frame f only
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 23 of 34
© 2012 Weiss Robotics, all rights reserved
2.3.2 Get or set filter – daq.filter()
Get or set the type of filter that is currently used or should be used for filtering the sensor values. Several
types of filters are available. If a parameter is given, the function will return the state after the parameter
has been applied. The returned value should never be different from the given parameter’s value.
This function is the scripting equivalent of the command interface’s FLT() command.
Please note that this value will not be saved persistently, i.e. it will be lost when power-cycling the device.
Use the sensor’s web interface to change the default value that is loaded at boot time.
Syntax
<integer> = daq.filter( [id] )
Parameters
id (integer), optional
If given, the filter with this ID will be used for filtering. A value of 0 means that filtering is turned off.
Return Value
The function returns the ID of the filter currently in use.
Example
filter = daq.filter (); -- returns current filter id
if not filter == 0 then -- if filtering is not disabled at the moment
daq.filter(3); -- set filter to filter 3
end;
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 24 of 34
© 2012 Weiss Robotics, all rights reserved
2.3.3 Control sensor tare – daq.tare()
Tare or untare the sensor and/or return if it is currently tared. If taring is selected, the sensor will record a
number of measured values over a short time period and calculate average values that will be subtracted as
an offset value from all future measured values, making the currently measured value become 0. If untaring
is selected, this offset value will be cleared.
This function is the scripting equivalent of the command interface’s TARE() command.
Please note that this value will not be saved permanently, i.e. it will be lost when power-cycling the device.
Syntax
<boolean> = daq.tare( [enable] )
Parameters
enable (boolean), optional
If true, the sensor will be tared. If false, the sensor will be untared.
Return Value
The function returns the current taring state, detected after the given parameter has been applied.
Example
daq.tare( true ); -- tare the sensor
for i=1,10 do
x = daq.get(); -- acquire 10 frames and print them to stdout
print( x );
end;
daq.tare( false ); -- untare the sensor
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 25 of 34
© 2012 Weiss Robotics, all rights reserved
2.4 Calibration Settings
2.4.1 Get calibration matrix – calibration.matrix()
Get the sensor’s calibration matrix.
This function is the scripting equivalent of the command interface’s CALMATRIX() command.
Syntax
<table> = calibration.matrix()
Parameters
none
Return Value
The function returns a nested table of 6 x 6 values of type number holding the sensor’s calibration matrix.
Example
matrix = calibration.matrix(); -- get calibration matrix
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 26 of 34
© 2012 Weiss Robotics, all rights reserved
2.4.2 Get calibration date and lifetime– calibration.date()
Get the sensor’s calibration date as a UNIX-like timestamp1 and the calibration lifetime in seconds.
This function is the scripting equivalent of the command interface’s CALDATE() command.
You may use the function os.date() to convert the timestamp value into a human-readable formatted
date string.
Syntax
<integer>, <integer> = calibration.date()
Parameters
none
Return Value
The function returns two integer values. The first value represents a UNIX-like timestamp that indicates the
sensor’s calibration date. The second value represents the calibration lifetime in seconds.
Example
date, lifetime = calibration.date(); -- get calibration date and lifetime
print( os.date( “%x”, date ) ); -- convert date to human-readable string and print it
print( os.date( “%x”, date + lifetime ) ); -- calculate calibration timeout date and print it
1 Number of seconds passed since Jan. 1, 1970 0:00 h
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 27 of 34
© 2012 Weiss Robotics, all rights reserved
3 Interactive Scripting on the Command Interface
The KMS offers scripting extensions not only by executing program files from its web interface but also on
the default command interface as it is described in the Command Set Reference Manual. The command
strings submitted to the sensor will be interpreted as chunks of LUA code, offering a wide range of
possibilities e.g. by using control structures like loops or conditional branches in conjunction with the
commands described above or in the Command Set Reference Manual.
Opening the sensor’s command interface with a standard telnet client will provide an interactive scripting
console, ready to type in some code.
3.1 Scripting vs. Command Interface
You may have already noticed that some of the sensor-specific commands are available on the command
interface as well as on the scripting engine. The Command Set Reference Manual for example describes the
command F(), acquiring a single data frame, whereas the scripting command daq.get() does
practically the same.
The difference between the two commands is that F() outputs the result as a string to the command
interface while daq.get() does not. However, both functions return the same value that can be assigned
to a variable, so it depends solely on your intention which command should be preferred.
Examples
F() -- outputs something like
-- F={949732,-329790,-5681618,239,-8883,4742},472416
f, ts = daq.get() -- outputs nothing, just assigns return values to variables f and ts
PRINT( daq.get() ) -- outputs something like
PRINT={949732,-329790,-5681618,239,-8883,4742},472496
f, ts = F() -- assigns return values and prints result
3.2 Load custom function libraries
The functionality of the command interface can be extended by using your own LUA function libraries on
the command interface. To load these libraries, make them available in the file autoexec.lua that can be
found in the /user directory. If you saved your functions for example to /user/myfunctions.lua, you can
include them by adding the line
require “myfunctions.lua”
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 28 of 34
© 2012 Weiss Robotics, all rights reserved
to the appropriate section of /user/autoexec.lua.
Note that the file autoexec.lua must always be present. If it is deleted, a new empty file will be created
automatically at boot time.
Errors in autoexec.lua or in included files will be noted in the sensor’s log files.
3.3 Limitations
Interactive scripting on the command interface has some limitations compared to standard LUA. Most
important, there is no standard output to the interface, which means the common functions printf()
and print() are not available. Instead, there is the command interface’s PRINT() command that can
be used to output the values of variables. Please refer to the sensor’s Command Set Reference Manual for
further details on this command.
Another limitation is that a scripting chunk that should be executed at once must fit into one single line. For
complex operations, this may lead to a pretty confusing code structure. In this case, it may be a good idea
to put your code into a function library on the sensor’s SD card and to make these functions available on
the command interface using the autoexec.lua file as described in section 3.2.
3.4 Example
The following code example shows step by step how to acquire 10 data frames in a row, calculating the
average of each measured value and printing the result.
First of all, create a LUA table that should hold the intermediate result of the data acquisition by typing
frame = { 0, 0, 0, 0, 0, 0 }
followed by <Enter>. As this code chunk will not cause any output, we can check what happened by typing
PRINT( frame )
again followed by <Enter>. Note that the default LUA functions printf() and print() are not available on the
command interface. Instead, the special PRINT() command must be used.
Now let’s get the 10 frames in a row and sum up the measured values by using LUA’s for-loops. Type:
for i=1,10 do f = daq.get(); for j=1,6 do frame[j] = frame[j] + f[j]; end; end
and press <Enter>. Note that the whole string must be sent in one line to work.
Again, this string should be accepted without returning any response. Once more, we can check the result
by typing
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 29 of 34
© 2012 Weiss Robotics, all rights reserved
PRINT( frame )
which should return the sum vector of the acquired sensor values.
As final step, we can calculate the average values by using a for-loop again:
for j=1,6 do frame[j] = frame[j] / 10 end
and print the final result with
PRINT( frame )
We can also put the complete example code into a single line, of course, executing all the steps at once.
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 30 of 34
© 2012 Weiss Robotics, all rights reserved
4 Appendix A: System State Flags
The System State Flags are arranged as a 32-bit wide integer value that can be read using the function
system.state() (see chapter 2.3.1). Each bit has a special meaning listed below.
Bit No. Flag Name Description
D31 reserved These bits are currently unused but may be used in a
future release of the KMS firmware.
D30 SF_SCRIPT_FAILURE
Script Error.
An error occurred while executing a script and the script
has been aborted. This flag is reset whenever a script is
started.
D29 SF_CMD_FAILURE Command Error.
The last command returned an error.
D28 SF_POWER_FAULT Power Fault.
The power supply is out of range.
D27 SF_TEMP_FAULT
Temperature Fault.
The sensor hardware has reached a critical temperature limit.
D26 SF_CAL_FAULT Calibration Fault.
Calibration fault.
D25 SF_OV_MZ Overrun Mz.
Overrun for Mz value.
D24 SF_OV_MY Overrun My.
Overrun for My value.
D23 SF_OV_MX Overrun Mx.
Overrun for Mx value.
D22 SF_OV_FZ Overrun Fz.
Overrun for Fz value.
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 31 of 34
© 2012 Weiss Robotics, all rights reserved
D21 SF_OV_FY Overrun Fy.
Overrun for Fy value.
D20 SF_OV_FX Overrun Fx.
Overrun for Fx value.
D19..12 reserved These bits are currently unused but may be used in a future release of the KMS firmware.
D11 SF_TEMP_WARNING
Temperature Warning.
The sensor hardware will soon reach a critical temperature level.
D10 SF_CAL_EXPIRED Calibration expired.
Sensor calibration has expired
D9..6 reserved These bits are currently unused but may be used in a future release of the KMS firmware.
D5 SF_SCRIPT_RUNNING Script running.
A script is currently running.
D4 SF_DAQ_RUNNING
Data acquisition running.
Data acquisition is running. Frames are submitted using the command interface.
D3 SF_FILTER_EN Filtering enabled.
Filtering of sensor values is enabled.
D2 SF_TARA The sensor is tared.
Set if the sensor is tared.
D1 SF_STABLE Values stable.
The sensor measured values are stable.
D0 SF_CAL_VALID Calibration valid.
Sensor calibration is valid.
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 32 of 34
© 2012 Weiss Robotics, all rights reserved
5 Appendix B: Filter types
The sensor offers seven predefined filter settings of different frequency range to filter the acquired data.
The following diagram and table indicate the filter characteristics.
ID Filter Cutoff Frequency (-3 dB)
1 Filter 1 5 Hz
2 Filter 2 15 Hz
3 Filter 3 35 Hz
4 Filter 4 65 Hz
5 Filter 5 120 Hz
6 Filter 6 170 Hz
7 Filter 7 240 Hz
-30
-20
-10
0
0 50 100 150 200 250
Dam
pin
g [d
B]
Frequency [Hz]
Filter characteristics
Filter 1
Filter 2
Filter 3
Filter 4
Filter 5
Filter 6
Filter 7
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 33 of 34
© 2012 Weiss Robotics, all rights reserved
6 Appendix C: Syntax Notation
The following command syntax notation is used throughout this document:
Parameters
a Denotes a mandatory parameter
[a] Denotes an optional parameter
{a, b, c} Denotes a selection of mandatory parameters (exactly one must be present)
[{a, b, c}] Selection of optional parameters (either exactly one or none must be present)
Values
<integer> An integer value
<number> A floating point value
<string> A string literal
<table> A table
<var> variable type
KMS Scripting Reference Manual
Weiss Robotics GmbH & Co. KG In der Gerste 2 71636 Ludwigsburg, Germany
For updates and further information, please visit http://www.weiss-robotics.com
Page 34 of 34
© 2012 Weiss Robotics, all rights reserved
Weiss Robotics GmbH & Co. KG In der Gerste 2
D-71636 Ludwigsburg, Germany
e-mail: [email protected]
For further information and other products from Weiss Robotics, please visit our homepage at http://www.weiss-robotics.com. _________________________________________________________________________________________ © 201212 Weiss Robotics, all rights reserved. All technical data mentioned in this data sheet can be changed to improve our products without prior notice. Used trademarks are the property of their respective trademark owners. Our products are not intended for use in life support systems or systems whose failure can lead to personal injury.