EPICS Motor Module motor-R6-8-RC1_1-4
EPICS Motor Axis API

How use this API

This API is used to provide a general interface to motor controllers used by EPICS. To provide EPICS motor support the driver must implement the motor axis API by defining a table of function pointers of type motorAxisDrvSET_t. Most of the functions in this table correspond to operations that would normally be implemented to test a simple motor controller. In addition, existing examples of motor support can be copied for new motor controllers - good examples are the motor simulator (in directory MotorSimSrc), the Delta Tau (in pmacAsynMotor directory of the tpmac module) or the XPS controllers.

However, there are a couple of things that should be bourne in mind and these are outined in the following three subsections.

Locking and multi-thread considerations

The driver writer can assume that any call to this library will be in the context of a thread that can block for a reasonable length of time. Hence, I/O to the controller can be synchronous. However, you cannot assume that only one thread is active, so routines must lock data structures when accessing them.

This is particularly important when calling the callback routine. All asynchronous communication back to the upper level software is done through the callback function set by motorAxisSetCallback(). The rule is that the driver can assume that once this callback is completed all side effects have been handled by the upper level software. However, until it is called the driver must protect against updates.

The way this is normally implemented is that each axis has a mutex semaphore that is used to lock the following three operations together:

Note, in implementing this the upper level software makes sure that the motor API is never called in record processing context - so the axis mutex is always called before the dbScanLock mutex. Getting this out of order results in a deadlock.

Motor Parameters

Motor state information is accessed using the motor parameter motorAxisGetInteger(), motorAxisSetInteger(), motorAxisGetDouble(), motorAxisSetDouble() and motorAxisCallbackFunc() routines (the latter set with motorAxisSetCallback()). Parameters are identified by the #motorAxisParam_t enumerated type. Since this is common to all motors, the paramLib library is provided in the motor application for drivers to use. Using this is optional, but it generally saves effort. A specific drivers get and callback routines are typically just wrappers around the corresponding paramLib routines, and the set routines are also wrappers, but inevitably have some controller specific action to pass the parameter value down to the controller.

Background controller polling task.

All motor controllers will probably need a background polling task to update the state kept as parameters within the drivers. Typically, there is one task per controller, so multiple controllers can be polled simultaneously. The task typically If there is a state change this will result in upper level software being called back in the context this task, so may be a consideration in setting the task priority.

Using the motorAxisSetLog routine.

The motorAxisSetLog() routine is provided to hook into higher level EPICS reporting routines without compromising the EPICS independence of this interface. Implementing is done most easily by copying an existing driver.

History

For a long time EPICS motor support was either via the complex, and somewhat ill-defined motor record or via primitive record support. The two approaches were mutually incompatible and led to much anguish. People who adopted the motor record got a standard interface across all controllers, but it was inextensable. Those who wrote their own driver using primitive records could not port their databases to other motor controllers. Neither situation was very satisfactory.

After looking at this for some time, the reason became clear - the the interface between the generic software for the motor record and the underlying specific software for a given motor controller was very complex, poorly defined and very specific to the motor record. Hence, this interface defines a clean, extensible API for motor controller drivers to support, and (through asyn device and drive support) provides an interface with both motor records and other primitive records. We are providing drivers for OMS, Delta Tau and some Newport systems and hope others will adopt this approach.

To do this we have had to analyse the requirements needed to support the motor record, and the following is the results.

Analysis of commands that control hardware behaviour

All of these commands go through an interface with three routines implementing a transaction style interface: start_trans, build_trans and end_trans. The implication is that any build_trans commands issued between a start_trans and an end_trans happen atomically. Build_trans takes three parameters, the transaction type (an enumerated value), a pointer to an array of double parameters, and a pointer to the motor record itself.

build_trans commands that are only executed alone.

All of the commands in this section are only ever called alone, bracketed by a start_trans and an end_trans call. Hence, they could be re-implemented in a non-transaction based interface.

Commands that could be removed

Commands for which the return status is consulted.

These return an error if there is a problem with the demand value. On return, I think the demand value should be replaced by the permitted value (but I don't see this being used).

Other build_trans commands called singly

The return status is never checked when these transactions are built.

build_trans commands that are executed in groups

These commands are always executed in as part of a group of transactions intended to initiate motion of some kind. The consist of: SET_VEL_BASE, SET_VELOCITY, SET_ACCEL, JOG_VELOCITY, HOME_FOR, HOME_REV, MOVE_REL, MOVE_ABS, GO and JOG. They implement three different kinds of move:

The latter is an unfortunate name since I think the word Jog has multiple meanings in motion control context, but here we are dictated by the OMS definition where a jog is a constant velocity move. There is also two JOG commands, JOG and JOG_VELOCITY, the only difference in the OMS driver being that JOG clears the controller DONE flag for this axis before starting.

Homing sequence.

These five transactions are called as a set in lines 659-662 and also in lines 1719-1726 in motorRecord.cc. Only one of HOME_FOR or HOME_REV is called, dependent on the setting of the record homf or homr fields. (What happens if you don't find the home switch - can't the controller work out which way to attempt to home?). Note that no acceleration is specified.

Move sequence.

These six transactions are called as a set three times in motorRecord.cc (between lines 704-746, lines 778-798 and lines 2042-2102). Only one of MOVE_REL and MOVE_ABS is called depending on whether it is a relative move or an absolute move, and the parameter passed in this transaction is the actual move distance. SET_VEL_BASE is in parentheses because it is not called every time - but the reason for this is pretty unclear to me (I suspect it could be).

Jog sequences

There are two jog sequences:

I don't really understand the real difference between these two set - as far as I can see the only difference in the OMS driver is that the JOG transaction executes a CA to clear the axis done bit before running, whilst JOG_VELOCITY doesn't. I suspect that the two could be replaced by a single command in a new interface. I suspect one allows you to change the velocity whilst the motor is moving and the other doesn't, but I'm not sure.

Notes on the implementation of motion in the API.

In the API I have implemented these three collections of commands as three separate routines, not as multiple single parameter routines with a start/end buffering command. I have done this for simplicity to highlight the minimum functionality that needs to be provided to support the motor record, but this may be the wrong decision. Buffering could get complicated if multiple people wrote it in different ways. Note that if we did go down the buffering route, I see no need for either a GO command or a JOG and JOG_VELOCITY command. The former is implicit in the end_trans, and the latter should be amalgamated into a single command.

A third, compromise, route, which might be the best solution, is to implement primitive commands for the move parameters (acceleration, velocity etc), but define them such that they have an additional parameter which says (for example):

The latter could be used for the primitive record approach, and the former for the motor record.

Finally, in the PREM and the POST fields aren't seen in this implementation - This functionality is no longer supported through the motor record and should be done by linking to controller specific device support.

Analysis of commands that provide status information

As mentioned above, motor status is handled by issuing GET_INFO commands on a regular basis, and then calling pdset->update_values (which is actually motor_update_values in motordevCom.cc). This routine updates the:

There is also a certain amount of other updates done in device support, but I suspect these could possibly all be incorporated into a generic device support module if the driver API is sufficiently complete.

Other information flow.

There may be other paths of hidden information flow between the records and the controllers, but I haven't uncovered them.

How could this be documented as an acceptable interface.

There are a number of problems with the motor record as it stands.

As a result of this, I feel the first thing to do is to define an API that can be implemented by a person developing a motor controller, with the knowledge that if they provide this API, then they will have motor record support. We can then extend the API to provide support for other records, or the supporter of a particular motor controller can do it on his own. We will then write device support that links the API and the motor record, using the API as, effectively, a driver support entry table.

 All Classes Functions Variables