-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scriptable Motor Controller #79
Conversation
I not able to build the ScriptMotor support dynamically on windows (win32-x86 & windows-x64)
|
Just updated the Lua module to fix windows shared library functionality, after pulling from master was able to compile on my machine. |
I was able to build the ScriptMotor support against the latest version of the lua module (epics-modules/lua@58f1a16). I had to create the following files in the lua/configure directory to build for debug architectures on Windows: CONFIG_SITE.Common.win32-x86-debug |
Original pull request accidentally got merged when I was trying to fix build issues.
This pull request adds a Model 3 driver that runs functions from a lua scripting language file.
Having a single motor driver than can run code from an easily modifiable text file grants a lot of benefits.
How it works
A ScriptMotorController is created by calling the iocsh function
ScriptControllerConfig
. It takes as its parameters; the name of the asyn port to create, the number of axes this controller will control, the name of the lua file that contains the commands to run the support, and an optional set of parameters defined in the xxx=yyy format that will become global parameters for all the axes that are defined by this controller. The driver searches for the file by using the LUA_SCRIPT_PATH environment variable, a semicolon separated list of folders that may contain the script. Once found, the controller will compile the file into a bytecode state and each axis of the controller gets a copy of said state. The polling rate of this controller is set by the variablesIdlePollPeriod
andMovingPollPeriod
, either setting them in the parameter list, or by setting them in the lua script itself.Further parameters can then be supplied to each individual axis by using the
ScriptAxisConfig
function. It takes in the controller's port name, the axis you are supplying parameters to, and another set of parameters to become global variables for the lua state of that motor axis.Whenever one of the asynMotorAxis commands is called, the driver attempts to find the same function defined in the script and call it with the same parameters that it was given. So, for example, when the move command is issued to the motor driver, it looks for a function named 'move' in the lua script and then calls it with the position, relative movement, minimum velocity, maximum velocity, and acceleration parameters.
Inside each of these functions, control of the motor record can be accomplished by setting asyn parameters and processing callbacks. The relevant functions are
asyn.getXXXXParam
,asyn.setXXXXParam
, andasyn.callParamCallbacks
. They each take as their first two parameters the port name that refers to the ScriptMotorController driver and the axis number of the motor running the code. Both are conveniently provided as global variables DRIVER and AXIS. The get and set param functions next take the string name of a parameter that the motor controller provides. And the set param function will then take a value to set that parameter to, while the get param function will return the value of the parameter. A small snippet of code using all of these would be:Control of the motor itself is usually done by sending and receiving data across an asyn port. The methods included to allow that are:
where data is a string to sent to an asyn port, and PORT is the name of the port itself. Usually PORT will be supplied to the script through the parameter system noted above. These functions use a set of parameters to control their functionality. These parameters are the same as the ones from the stream module:
which can all either be set by just assigning a value to said variable or using a set function:
Examples of using all of this is provided with the vmc.lua script.
In addition, there are the epics.get and epics.put functions that replicate caget and caput to allow the script to read and write to any PV. The softMotor.lua script provides an example of using these functions to create a motor wrapper around a drive value and a readback value.
Note
This pull request works using the epics-modules/lua module, which isn't a standard part of synApps yet. RELEASE has been changed to note that it is necessary and ScriptMotorController does not build by default.