Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
5689402375 | |||
2a7934b8d6 | |||
3071e402b2 | |||
dd0610fd99 | |||
c7936191d9 | |||
3ec83b115e | |||
bfda809257 | |||
76a91d4a2f | |||
228bcf7fd7 | |||
db03ffea0e | |||
4c3254687d | |||
eb94379efe | |||
1dd132c709 | |||
7729eceb28 | |||
828e9bc59c | |||
f26d1bb612 | |||
bed245b010 | |||
ca7bede4b7 | |||
d3307db987 | |||
591509bd43 | |||
5854d2c9d0 | |||
f134a61649 | |||
49be84068f | |||
e92a867189 | |||
8bc6109e2a | |||
c06cf8e76c | |||
f14ac66971 | |||
b6e0f03a17 | |||
5946563372 | |||
da96b4b973 | |||
61087d2e44 | |||
26754e608d | |||
a866023957 | |||
8008ece919 | |||
dbe031ca79 | |||
be9f3b0d76 | |||
86006e408a | |||
6656841a01 | |||
682325de7d | |||
97e80814e3 | |||
a4943f3fe4 |
@ -1,6 +1,6 @@
|
||||
default:
|
||||
image: docker.psi.ch:5000/sinqdev/sinqepics:latest
|
||||
|
||||
|
||||
stages:
|
||||
- lint
|
||||
- build
|
||||
@ -24,16 +24,6 @@ formatting:
|
||||
tags:
|
||||
- sinq
|
||||
|
||||
# clangtidy:
|
||||
# stage: lint
|
||||
# script:
|
||||
# - curl https://docker.psi.ch:5000/v2/_catalog
|
||||
# # - dnf update -y
|
||||
# # - dnf install -y clang-tools-extra
|
||||
# # - clang-tidy sinqEPICSApp/src/*.cpp sinqEPICSApp/src/*.c sinqEPICSApp/src/*.h -checks=cppcoreguidelines-*,cert-*
|
||||
# # tags:
|
||||
# # - sinq
|
||||
|
||||
build_module:
|
||||
stage: build
|
||||
script:
|
||||
@ -48,4 +38,4 @@ build_module:
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
tags:
|
||||
- sinq
|
||||
- sinq
|
||||
|
13
Makefile
13
Makefile
@ -6,14 +6,16 @@ BUILDCLASSES=Linux
|
||||
EPICS_VERSIONS=7.0.7
|
||||
ARCH_FILTER=RHEL%
|
||||
|
||||
# additional module dependencies
|
||||
REQUIRED+=asynMotor
|
||||
# Specify the version of asynMotor we want to build against
|
||||
asynMotor_VERSION=7.2.2
|
||||
|
||||
# Source files to build
|
||||
SOURCES += src/msgPrintControl.cpp
|
||||
SOURCES += src/sinqAxis.cpp
|
||||
SOURCES += src/sinqController.cpp
|
||||
|
||||
# Headers which allow using this library in concrete driver implementations
|
||||
HEADERS += src/msgPrintControl.h
|
||||
HEADERS += src/sinqAxis.h
|
||||
HEADERS += src/sinqController.h
|
||||
|
||||
@ -21,6 +23,9 @@ HEADERS += src/sinqController.h
|
||||
TEMPLATES += db/asynRecord.db
|
||||
TEMPLATES += db/sinqMotor.db
|
||||
|
||||
USR_CFLAGS += -Wall -Wextra # -Werror
|
||||
# This file registers the motor-specific functions in the IOC shell.
|
||||
DBDS += src/sinqMotor.dbd
|
||||
|
||||
# MISCS would be the place to keep the stream device template files
|
||||
USR_CFLAGS += -Wall -Wextra -Weffc++ -Wunused-result # -Werror
|
||||
|
||||
# MISCS would be the place to keep the stream device template files
|
||||
|
260
README.md
260
README.md
@ -2,46 +2,266 @@
|
||||
|
||||
## Overview
|
||||
|
||||
This library offers base classes for EPICS motor drivers (`sinqAxis` and `sinqController`) of PSI SINQ. These classes are extensions of the classes `asynMotorAxis` and `asynMotorController` from the `asynMotor` framework (https://github.com/epics-modules/motor/tree/master/motorApp/MotorSrc) and bundle some common functionalities.
|
||||
This library offers base classes for EPICS motor drivers (`sinqAxis` and `sinqController`) of PSI SINQ. These classes are extensions of the classes `asynMotorAxis` and `asynMotorController` from the `asynMotor` framework (https://github.com/epics-modules/motor/tree/master/motorApp/MotorSrc) and bundle some common functionality.
|
||||
|
||||
## Features
|
||||
## User guide
|
||||
|
||||
### Architecture of EPICS motor drivers at SINQ
|
||||
|
||||
The asyn-framework offers two base classes `asynMotorAxis` and `asynMotorController`. At SINQ, we extend those classes by two children `sinqAxis` and `sinqController` which are not complete drivers on their own, but serve as a framework extension for writing drivers. The concrete drivers are then created as separated libraries, an example is the TurboPMAC-driver: https://git.psi.ch/sinq-epics-modules/turboPmac.
|
||||
|
||||
The full inheritance chain for two different motor drivers "a" and "b" looks like this:
|
||||
`asynController -> sinqController -> aController`
|
||||
`asynAxis -> sinqAxis -> aAxis`
|
||||
|
||||
`asynController -> sinqController -> bController`
|
||||
`asynAxis -> sinqAxis -> bAxis`
|
||||
|
||||
Those inheritance chains are created at runtime by loading shared libraries. These libraries must be compatible to each other (see next section).
|
||||
|
||||
### Versioning
|
||||
|
||||
In order to make sure the shared libraries are compatible to each other, we use the "require" framework extension for EPICS (https://github.com/paulscherrerinstitute/require). If a shared library has another library as a dependency, it is checked whether the latter is already loaded. If yes, the loaded version is considered compatible if:
|
||||
|
||||
1) no specific version was required by the former library
|
||||
2) the already loaded version matches the required version exactly
|
||||
3) major and minor numbers are the same and already loaded patch number is equal to the required one or higher
|
||||
4) major numbers are the same and already loaded minor number is higher than the required one
|
||||
5) the already loaded version is a test version and the required version is not a test version
|
||||
These rules are in complicance with the SemVer standard (https://semver.org/lang/de/)
|
||||
|
||||
If the dependency hasn't been loaded yet, it is loaded now. In case no specific version is required, the latest numbered version is used.
|
||||
|
||||
Because these rules are checked sequentially for each required dependency and no unloading is performed, it is important to consider the order of required libraries. Consider the following example:
|
||||
|
||||
```
|
||||
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
|
||||
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
|
||||
```
|
||||
`require` first checks the dependencies of `libDriverA` and sees that `sinqMotor 1.2` is required. It therefore load `sinqMotor 1.2` and then `libDriverA`. Now the next `require` starts analyzing the dependencies of `libDriverB` and sees that `sinqMotor 1.0` is required. Since `sinqMotor 1.2` is already loaded, rule 4) is applied and `libDriverB` is assumed to be compatible with `sinqMotor 1.2` as well (which it should be according to SemVer).
|
||||
|
||||
When the order is inverted, the following happens:
|
||||
```
|
||||
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
|
||||
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
|
||||
```
|
||||
`require` first checks the dependencies of `libDriverB` and sees that `sinqMotor 1.0` is required. It therefore load `sinqMotor 1.0` and then `libDriverB`. Now the next `require` starts analyzing the dependencies of `libDriverA` and sees that `sinqMotor 1.2` is required. Since `sinqMotor 1.0` is already loaded, `require` cannot load `sinqMotor 1.2`. Therefore the IOC startup is aborted with an error message.
|
||||
|
||||
In order to make the setup script more robust, it is therefore recommended to explicitly add a dependency version which is compatible to all required libraries:
|
||||
|
||||
```
|
||||
require "sinqMotor", "1.2"
|
||||
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
|
||||
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
|
||||
```
|
||||
The IOC startup now succeeds because we made sure the higher version is loaded first.
|
||||
|
||||
Please see the README.md of https://github.com/paulscherrerinstitute/require for more details.
|
||||
|
||||
To find out which version of sinqMotor is needed by a driver, refer to its Makefile (line `sinqMotor_VERSION=x.x.x`, where x.x.x is the minimum required version).
|
||||
|
||||
### IOC startup script
|
||||
|
||||
An EPICS IOC for motor control at SINQ is started by executing a script with the IOC shell. In its simplest form, an IOC for two controllers is a file looking like this:
|
||||
```
|
||||
#!/usr/local/bin/iocsh
|
||||
|
||||
# Load libraries needed for the IOC
|
||||
require sinqMotor, 1.0.0
|
||||
require actualDriver, 1.2.0
|
||||
|
||||
# Define environment variables used later to parametrize the individual controllers
|
||||
epicsEnvSet("TOP","/ioc/sinq-ioc/sinqtest-ioc/")
|
||||
epicsEnvSet("INSTR","SQ:SINQTEST:")
|
||||
|
||||
# Include other scripts for the controllers 1 and 2
|
||||
< actualDriver.cmd
|
||||
< actualDriver.cmd
|
||||
|
||||
iocInit()
|
||||
```
|
||||
The first line is a so-called shebang which instructs Linux to execute the file with the executable located at the given path - the IOC shell in this case. The controller script "mcu1.cmd" looks like this:
|
||||
The script for controller 1 ("turboPmac1.cmd") for a Turbo PMAC (see https://git.psi.ch/sinq-epics-modules/turboPmac) has the following structure. The scripts for other controller types can be found in the README.md of their respective repositories.
|
||||
|
||||
```
|
||||
# Define the name of the controller and the corresponding port
|
||||
epicsEnvSet("DRIVER_PORT","actualDriver1")
|
||||
epicsEnvSet("IP_PORT","p$(DRIVER_PORT)")
|
||||
|
||||
# Create the TCP/IP socket used to talk with the controller. The socket can be adressed from within the IOC shell via the port name
|
||||
drvAsynIPPortConfigure("$(IP_PORT)","172.28.101.24:1025")
|
||||
|
||||
# Create the controller object with the defined name and connect it to the socket via the port name.
|
||||
# The other parameters are as follows:
|
||||
# 8: Maximum number of axes
|
||||
# 0.05: Busy poll period in seconds
|
||||
# 1: Idle poll period in seconds
|
||||
# 1: Socket communication timeout in seconds
|
||||
actualDriverController("$(DRIVER_PORT)", "$(IP_PORT)", 8, 0.05, 1, 1);
|
||||
|
||||
# Define some axes for the specified motor controller at the given slot (1, 2 and 5). No slot may be used twice!
|
||||
actualDriverAxis("$(DRIVER_PORT)",1);
|
||||
actualDriverAxis("$(DRIVER_PORT)",2);
|
||||
actualDriverAxis("$(DRIVER_PORT)",5);
|
||||
|
||||
# Set the number of subsequent timeouts
|
||||
setMaxSubsequentTimeouts("$(DRIVER_PORT)", 20);
|
||||
|
||||
# Configure the timeout frequency watchdog: A maximum of 10 timeouts are allowed in 300 seconds before an alarm message is sent.
|
||||
setThresholdComTimeout("$(DRIVER_PORT)", 300, 10);
|
||||
|
||||
# Parametrize the EPICS record database with the substitution file named after the motor controller.
|
||||
epicsEnvSet("SINQDBPATH","$(sinqMotor_DB)/sinqMotor.db")
|
||||
dbLoadTemplate("$(TOP)/$(DRIVER_PORT).substitutions", "INSTR=$(INSTR)$(DRIVER_PORT):,CONTROLLER=$(DRIVER_PORT)")
|
||||
epicsEnvSet("SINQDBPATH","$(actualDriver_DB)/turboPmac.db")
|
||||
dbLoadTemplate("$(TOP)/$(DRIVER_PORT).substitutions", "INSTR=$(INSTR)$(DRIVER_PORT):,CONTROLLER=$(DRIVER_PORT)")
|
||||
dbLoadRecords("$(sinqMotor_DB)/asynRecord.db","P=$(INSTR)$(DRIVER_PORT),PORT=$(IP_PORT)")
|
||||
```
|
||||
|
||||
### Substitution file
|
||||
|
||||
The substitution file is a table containing axis-specific information which is used to create the axis-specific PVs.
|
||||
To work with sinqMotor, "mcu1.substitutions" needs to look like this (the order of columns does not matter):
|
||||
```
|
||||
file "$(SINQDBPATH)"
|
||||
{
|
||||
pattern
|
||||
{ AXIS, M, DESC, EGU, DIR, MRES, MSGTEXTSIZE, ENABLEMOVWATCHDOG, LIMITSOFFSET, CANSETSPEED, ADAPTPOLL }
|
||||
{ 1, "lin1", "Linear motor doing whatever", mm, Pos, 0.001, 200, 1, 1.0, 1, 1 }
|
||||
{ 2, "rot1", "First rotary motor", degree, Neg, 0.001, 200, 0, 1.0, 0, 1 }
|
||||
{ 3, "rot2", "Second rotary motor", degree, Pos, 0.001, 200, 0, 0.0, 1, 0 }
|
||||
{ 5, "rot3", "Surprise: Third rotary motor", degree, Pos, 0.001, 200, 1, 2.0, 0, 0 }
|
||||
}
|
||||
```
|
||||
The variable `SINQDBPATH` has been set in "mcu1.cmd" before calling `dbLoadTemplate`.
|
||||
|
||||
#### Mandatory parameters
|
||||
|
||||
- `AXIS`: Index of the axis, corresponds to the physical connection of the axis to the MCU.
|
||||
- `M`: The full PV name is created by concatenating the variables INSTR, DRIVER_PORT and M. For example, the PV of the first axis would be "SQ:SINQTEST:mcu1:lin1".
|
||||
- `EGU`: Engineering units. For a linear motor, this is mm, for a rotaty motor, this is degree.
|
||||
- `DIR`: If set to "Neg", the axis direction is inverted.
|
||||
- `MRES`: This is a scaling factor determining the resolution of the position readback value. For example, 0.001 means a precision of 1 um. A detailed description can be found in section [Motor record resolution MRES](#motor-record-resolution-mres).
|
||||
|
||||
#### Optional parameters
|
||||
The default values for those parameters are given for the individual records in db/sinqMotor.db
|
||||
- `DESC`: Description of the motor. This field is just for documentation and is not needed for operating a motor. Defaults to the motor name.
|
||||
- `MSGTEXTSIZE`: Buffer size for the motor message record in characters. Defaults to 200 characters
|
||||
- `ENABLEMOVWATCHDOG`: Sets `setWatchdogEnabled` during IOC startup to the given value. Defaults to 0.
|
||||
- `LIMITSOFFSET`: If the motor limits are read out from the controller, they can
|
||||
be further reduced by this offset in order to avoid errors due to slight overshoot
|
||||
on the motor controller. For example, if this value is 1.0 and the read-out limits
|
||||
are [-10.0 10.0], the EPICS limits are set to [-9.0 9.0]. This parameter uses engineering units (EGU). Defaults to 0.0.
|
||||
- `CANSETSPEED`: If set to 1, the motor speed can be modified by the user. Defaults to 0.
|
||||
- `ADAPTPOLL`: If set to any value other than 0, adaptive polling is enabled for this particular axis. Adaptive polling is designed to reduce the communication load in case some axis is moving. By default, if at least one axis is moving, all axes are polled using the busy / moving poll period (see [IOC startup script](#ioc-startup-script)). Adaptive polling modifies this behaviour so that the affected axis is only polled with the busy / moving poll period if it itself is moving. Defaults to 1.
|
||||
|
||||
### Motor record resolution MRES
|
||||
|
||||
The motor record resolution (index motorRecResolution_ in the parameter
|
||||
library, MRES in the motor record) is NOT a conversion factor between
|
||||
user units (e.g. mm) and motor units (e.g. encoder steps), but a scaling
|
||||
factor defining the resolution of the position readback field RRBV. This
|
||||
is due to an implementation detail of EPICS described here:
|
||||
https://epics.anl.gov/tech-talk/2018/msg00089.php
|
||||
https://github.com/epics-modules/motor/issues/8
|
||||
|
||||
Basically, the position value in the parameter library is a double which
|
||||
is then truncated to an integer in devMotorAsyn.c (because it was
|
||||
originally meant for converting from engineering units to encoder steps,
|
||||
which are by definition integer values). Therefore, if we want a
|
||||
precision of 1 millimeter, we need to set MRES to 1. If we want one of
|
||||
1 micrometer, we need to set MRES to 0.001. The readback value needs to
|
||||
be multiplied with MRES to get the actual value.
|
||||
|
||||
In the driver, we use user units. Therefore, when we interact with the
|
||||
parameter library, we need to account for MRES. This means:
|
||||
- When writing position or speed to the parameter library, we divide the
|
||||
value by the motor record resolution.
|
||||
- When reading position or speed from the parameter library, we multiply
|
||||
the value with the motor record resolution.
|
||||
|
||||
Index and motor record field are coupled as follows:
|
||||
The parameter motorRecResolution_ is coupled to the field MRES of the
|
||||
motor record in the following manner:
|
||||
- In sinqMotor.db, the PV (motor_record_pv_name) MOTOR_REC_RESOLUTION
|
||||
is defined as a copy of the field (motor_record_pv_name).MRES .
|
||||
- The PV name MOTOR_REC_RESOLUTION is coupled in asynMotorController.h
|
||||
to the constant motorRecResolutionString
|
||||
- ... which in turn is assigned to motorRecResolution_ in
|
||||
asynMotorController.cpp This way of making the field visible to the
|
||||
driver is described here:
|
||||
https://epics.anl.gov/tech-talk/2020/msg00378.php This is a one-way
|
||||
coupling, changes to the parameter library via setDoubleParam are NOT
|
||||
transferred to (motor_record_pv_name).MRES or to
|
||||
(motor_record_pv_name):Resolution.
|
||||
|
||||
### Additional records
|
||||
|
||||
`sinqMotor` provides a variety of additional records. See `db/sinqMotor.db` for the complete list and the documentation.
|
||||
|
||||
## Developer guide
|
||||
|
||||
### Base classes
|
||||
|
||||
sinqMotor offers a variety of additional methods for children classes to standardize certain patterns (e.g. writing messages to the IOC shell and the motor message PV). For a detailed description, please see the respective function documentation in the .h-files. All of these functions can be overwritten manually if e.g. a completely different implementation of `poll` is required. Some functions are marked as virtual, because they are called from other functions of sinqMotor and therefore need runtime polymorphism. Functions without that marker are not called anywhere in sinqMotor.
|
||||
|
||||
### sinqController
|
||||
- `stringifyAsynStatus`: Convert the enum `asynStatus` into a human-readable string.
|
||||
- `errMsgCouldNotParseResponse`: Write a standardized message if parsing a device response failed.
|
||||
#### sinqController.h
|
||||
- `couldNotParseResponse`: Write a standardized message if parsing a device response failed.
|
||||
- `paramLibAccessFailed`: Write a standardized message if accessing the parameter library failed.
|
||||
- `stringifyAsynStatus`: Convert the enum `asynStatus` into a human-readable string.
|
||||
- `checkComTimeoutWatchdog`: Calculates the timeout frequency (number of timeouts in a given time) and informs the user if a specified limit has been exceeded.
|
||||
- `setThresholdComTimeout`: Set the maximum number of timeouts and the time window size for the timeout frequency limit.
|
||||
- `checkMaxSubsequentTimeouts`: Check if the number of subsequent timeouts exceeds a specified limit.
|
||||
- `setMaxSubsequentTimeouts`: Set the limit for the number of subsequent timeouts before the user is informed.
|
||||
|
||||
### sinqAxis
|
||||
- `atFirstPoll`: This function is executed once before the first poll. If it returns anything but `asynSuccess`, it retries.
|
||||
- `setWatchdogEnabled`: Enables / disables the watchdog. This function is also available in the IOC shell.
|
||||
- `checkMovTimeoutWatchdog`: Manages a watchdog mechanism for movement operations. This watchdog compares the actual time spent in a movement operation with an expected time, which is calculated based on the distance of the current and the target position.
|
||||
#### sinqAxis.h
|
||||
- `enable`: This function is called if the `$(INSTR)$(M):Enable` PV from db/sinqMotor.db is set.
|
||||
This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `reset`: This function is called when the `$(INSTR)$(M):Reset` PV from db/sinqMotor.db is set.
|
||||
It calls `doReset` and performs some fast polls after `doReset` returns.
|
||||
- `doReset`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `move`: This function sets the absolute target position in the parameter library and then calls `doMove`.
|
||||
- `doMove`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `home`: This function sets the internal status flags for the homing process and then calls doHome.
|
||||
- `doHome`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `poll`: This is a wrapper around `doPoll` which performs some bookkeeping tasks before and after calling `doPoll`:
|
||||
|
||||
Before calling `doPoll`:
|
||||
- Try to execute `atFirstPoll` once during the lifetime of the IOC (and retry, if that failed)
|
||||
- Reset the status problem flag, the communication error flag and the error message.
|
||||
|
||||
After calling `doPoll`:
|
||||
- Call `checkMovTimeoutWatchdog`. If the movement timed out, create an error message for the user
|
||||
- Update the readback-value for the axis enablement.
|
||||
- Reset `motorStatusProblem_`, `motorStatusCommsError_` and `motorMessageText_` if `doPoll` returned `asynSuccess`
|
||||
- Run `callParamCallbacks`
|
||||
- Return the status of `doPoll`
|
||||
- `doPoll`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `move`: This function sets the absolute target position in the parameter library and then calls `doMove`.
|
||||
- `doMove`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `home`: This function sets the absolute target position in the parameter library and then calls `doHome`. The target position is assumed to be the high limit, if the distance of the current position to it is larger than that to the low limit, and the low limit otherwise.
|
||||
- `doHome`: This is an empty function which should be overwritten by concrete driver implementations.
|
||||
- `motorPosition`: Returns the parameter library value of the motor position, accounted for the motor record resolution (see section "Motor record resolution MRES")
|
||||
- `setMotorPosition`: Writes the given value into the parameter library, accounted for the motor record resolution (see section "Motor record resolution MRES")
|
||||
- `setVeloFields`: Populates the motor record fields VELO (actual velocity), VBAS (minimum allowed velocity) and VMAX (maximum allowed velocity) from the driver.
|
||||
- `setAcclField`: Populates the motor record field ACCL from the driver.
|
||||
- `startMovTimeoutWatchdog`: Starts a watchdog for the movement time. This watchdog compares the actual time spent in a movement operation with an expected time, which is calculated based on the distance of the current and the target position.
|
||||
- `checkMovTimeoutWatchdog`: Check if the watchdog timed out.
|
||||
- `setWatchdogEnabled`: Enables / disables the watchdog. This function is also available in the IOC shell.
|
||||
- `setOffsetMovTimeout`: Set a linear offset for the expected movement time. This function is also available in the IOC shell.
|
||||
- `setScaleMovTimeout`: Set a scaling factor for the expected movement time. This function is also available in the IOC shell.
|
||||
|
||||
## Versioning
|
||||
#### msgPrintControl.h
|
||||
In addition to the two extension classes this library also includes a mechanism which prevents excessive repetitions of the same error message to the IOC shell via the classes `msgPrintControl` and `msgPrintControlKey`. A detailed description of the mechanism can be found in the docstring of `msgPrintControl`. The implementation of the `poll` function of `sinqAxis` also contains an example how to use it. Using this feature in derived drivers is entirely optional.
|
||||
|
||||
### Versioning
|
||||
|
||||
The versioning is done via git tags. Git tags are recognized by the PSI build system: If you tag a version as 1.0, it will be built into the directory /ioc/modules/sinqMotor/1.0. The tag is directly coupled to a commit so that it is always clear which source code was used to build which binary.
|
||||
|
||||
All existing tags can be listed with `git tag` in the sinqMotor directory. Detailed information (author, data, commit number, commit message) regarding a specific tag can be shown with `git show X.X`, where X.X is the name of your version. To create a new tag, use `git tag X.X`. If the tag `X.X` is already used by another commit, git will show a corresponding error.
|
||||
All existing tags can be listed with `git tag` in the sinqMotor directory. Detailed information (author, data, commit number, commit message) regarding a specific tag can be shown with `git show x.x.x`, where `x.x.x` is the name of your version. To create a new tag, use `git tag x.x.x`. If the tag `x.x.x` is already used by another commit, git will show a corresponding error.
|
||||
|
||||
## How to build it
|
||||
### How to build it
|
||||
|
||||
The makefile in the top directory includes all necessary steps for compiling a shared library together with the header files into `/ioc/modules` (using the PSI EPICS build system).Therefore it is sufficient to run `make install -f Makefile` from the terminal.
|
||||
This library is based on the PSI version of the EPICS motor record, which can be found here: `https://git.psi.ch/epics_driver_modules/motorBase`. We use a branch with a bugfix which is currently not merged into master due to resistance of the PSI userbase: `https://git.psi.ch/epics_driver_modules/motorBase/-/tree/pick_fix-lockup-VAL-HOMF-VAL`. This library can be build with the following steps, assuming GCC and make are available:
|
||||
- `git clone https://git.psi.ch/epics_driver_modules/motorBase/-/tree/pick_fix-lockup-VAL-HOMF-VAL`
|
||||
- `cd motorBase`
|
||||
- `git tag 7.2.2`. The latest version on master is currently 7.2.1, hence we increment the bugfix version counter by one
|
||||
- `make install`
|
||||
|
||||
To use the library when writing a concrete motor driver, include it in the makefile of your application /library the same way as other libraries such as e.g. `asynMotor` by adding `REQUIRED+=sinqMotor` to your Makefile.
|
||||
To build sinqMotor itself, the makefile in the top directory includes all necessary steps for compiling a shared library together with the header files into `/ioc/modules` (using the PSI EPICS build system). Therefore it is sufficient to clone this repository to a suitable location (`git clone https://git.psi.ch/sinq-epics-modules/sinqmotor/-/tree/main`). Afterwards, switch to the directory (`cd sinqmotor`) and run `make install`.
|
||||
|
||||
To use the library when writing a concrete motor driver, include it in the makefile of your application / library the same way as other libraries such as e.g. `asynMotor` by adding `REQUIRED+=sinqMotor` to your Makefile. The version can be specified with `sinqMotor_VERSION=x.x.x.`
|
||||
|
@ -1,9 +1,9 @@
|
||||
record(asyn,"$(P)$(R)")
|
||||
record(asyn,"$(P)")
|
||||
{
|
||||
field(DTYP,"asynRecordDevice")
|
||||
field(PORT,"$(PORT)")
|
||||
field(ADDR,"$(ADDR)")
|
||||
field(OMAX,"$(OMAX)")
|
||||
field(IMAX,"$(IMAX)")
|
||||
field(ADDR,"0")
|
||||
field(OMAX,"80")
|
||||
field(IMAX,"80")
|
||||
}
|
||||
|
||||
|
418
db/sinqMotor.db
418
db/sinqMotor.db
@ -1,126 +1,324 @@
|
||||
record(motor,"$(P)$(M)")
|
||||
# The main asyn motor record. Some fields are populated from the substitution
|
||||
# files via macros:
|
||||
# - INSTR: Name of the instrument, e.g. "SQ:SINQTEST:"
|
||||
# - M: Name of the motor in EPICS, e.g. "lin1"
|
||||
# - DESC: Short description of the motor. If not given, this is equal to M
|
||||
# - DIR: This value is usually set to "Pos". If the motor axis direction
|
||||
# should be inverted, this value can be set to "Neg"
|
||||
# - CONTROLLER: Name of the motor controller, e.g. "mcu1"
|
||||
# - AXIS: Number of the axis, e.g. "1"
|
||||
# - MRES: Motor record resolution. See the README.md for a detailed discussion
|
||||
# - EGU: Engineering units. In case of a rotary axis, this is "degree", in
|
||||
# case of a linear axis this is "mm".
|
||||
# - RTRY: The maximum number of times the motor record will try again to move to
|
||||
# the desired position. When the retry limit is reached, the motor record will
|
||||
# declare the motion finished. If the desired position was not reached, the
|
||||
# field MISS will be set to 1 and NICOS will emit a warning "Did not reach
|
||||
# target position". If this value is set to 0, the retry deadband is never
|
||||
# applied and therefore MISS will always be 0. The error message "Did not reach
|
||||
# target position" will therefore never appear.
|
||||
# - RDBD: Retry deadband: When the motor has finished a complete motion,
|
||||
# possibly including backlash takeout, the motor record will compare its current
|
||||
# position with the desired position. If the magnitude of the difference is
|
||||
# greater than RDBD, the motor will try again, as if the user had requested a
|
||||
# move from the now current position to the desired position. Only a limited
|
||||
# number of retries will be performed (see RTRY). If the given value is smaller
|
||||
# than MRES, it is set to MRES. In this version of the record, we set RDBD to a
|
||||
# very high value in order to suppress both retries and the NTM (new target
|
||||
# monitor) logic from issuing stop commands during overshoots (see
|
||||
# https://epics.anl.gov/bcda/synApps/motor/motorRecord.html#Fields_misc).
|
||||
record(motor,"$(INSTR)$(M)")
|
||||
{
|
||||
field(DESC,"$(DESC)")
|
||||
field(DTYP,"$(DTYP)")
|
||||
field(DIR,"$(DIR)")
|
||||
field(VELO,"$(VELO)")
|
||||
field(VBAS,"$(VBAS)")
|
||||
field(ACCL,"$(ACCL)")
|
||||
field(BDST,"$(BDST)")
|
||||
field(BVEL,"$(BVEL)")
|
||||
field(BACC,"$(BACC)")
|
||||
field(OUT,"@asyn($(PORT),$(ADDR))")
|
||||
field(DESC,"$(DESC=$(M))")
|
||||
field(DTYP,"asynMotor")
|
||||
field(DIR,"$(DIR=Pos)")
|
||||
field(OUT,"@asyn($(CONTROLLER),$(AXIS))")
|
||||
field(MRES,"$(MRES)")
|
||||
field(PREC,"$(PREC)")
|
||||
field(EGU,"$(EGU)")
|
||||
field(INIT,"$(INIT)")
|
||||
field(PINI, "NO")
|
||||
field(INIT,"")
|
||||
field(PINI,"NO")
|
||||
field(DHLM, "$(DHLM=0)")
|
||||
field(DLLM, "$(DLLM=0)")
|
||||
field(TWV,"1")
|
||||
field(RDBD,"$(RDBD)")
|
||||
field(RTRY, "0")
|
||||
field(RTRY,"0")
|
||||
field(RDBD, "$(RDBD=10e300)") # Suppress retries and overshoot stop commands
|
||||
field(BDST, "0")
|
||||
field(RMOD,"3") # Retry mode 3 ("In-Position"): This suppresses any retries from the motor record.
|
||||
}
|
||||
|
||||
# The message text
|
||||
record(waveform, "$(P)$(M)-MsgTxt") {
|
||||
# This PV reads out the 10th bit of the MSTA field of the motor record, which
|
||||
# is the "motorStatusProblem_" bit.
|
||||
record(calc, "$(INSTR)$(M):StatusProblem")
|
||||
{
|
||||
field(INPA, "$(INSTR)$(M).MSTA CP")
|
||||
field(CALC, "A >> 9")
|
||||
}
|
||||
|
||||
# If the value of this PV is 0, the according axis is currently disconnected from the controller.
|
||||
# Trying to give commands to a disconnected axis will result in an error message in the IOC shell
|
||||
# This record is coupled to the parameter library via motorConnected_ -> MOTOR_CONNECTED.
|
||||
record(longin, "$(INSTR)$(M):Connected")
|
||||
{
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_CONNECTED")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(PINI, "NO")
|
||||
field(VAL, "1")
|
||||
}
|
||||
|
||||
# Call the reset function of the corresponding sinqAxis
|
||||
# This record is coupled to the parameter library via motorReset_ -> MOTOR_RESET.
|
||||
record(longout, "$(INSTR)$(M):Reset") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_RESET")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# This PV allows force-stopping the motor record from within the driver by setting
|
||||
# the motorForceStop_ value in the parameter library to 1. It should be reset to 0 by the driver afterwards.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorForceStop_ -> MOTOR_FORCE_STOP.
|
||||
record(longin, "$(INSTR)$(M):StopRBV")
|
||||
{
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_FORCE_STOP")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):Stop2Field")
|
||||
}
|
||||
record(longout, "$(INSTR)$(M):Stop2Field") {
|
||||
field(DOL, "$(INSTR)$(M):StopRBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).STOP")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
|
||||
# This record forwards the motor record resolution MRES to the parameter library
|
||||
# entry "MOTOR_REC_RESOLUTION" (solution from https://epics.anl.gov/tech-talk/2020/msg00378.php)
|
||||
# The value of MRES is needed inside the driver for various calculations (e.g.
|
||||
# for calculating the estimated time of arrival inside the watchdog).
|
||||
record(ao,"$(INSTR)$(M):RecResolution") {
|
||||
field(DESC, "$(M) resolution")
|
||||
field(DOL, "$(INSTR)$(M).MRES CP")
|
||||
field(OMSL, "closed_loop")
|
||||
field(DTYP, "asynFloat64")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_REC_RESOLUTION")
|
||||
}
|
||||
|
||||
# This record contains messages from the driver (usually error messages).
|
||||
# The macro MSGTEXTSIZE can be used to set the maximum length of the message.
|
||||
# if not provided, a default value of 200 is used.
|
||||
# This record is coupled to the parameter library via motorMessageText_ -> MOTOR_MESSAGE_TEXT.
|
||||
record(waveform, "$(INSTR)$(M)-MsgTxt") {
|
||||
field(DTYP, "asynOctetRead")
|
||||
field(INP, "@asyn($(PORT),$(N),1) MOTOR_MESSAGE_TEXT")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_MESSAGE_TEXT")
|
||||
field(FTVL, "CHAR")
|
||||
field(NELM, "$(MsgTxtSize=200)") # Should be the same as MAXBUF in the driver code
|
||||
field(NELM, "$(MSGTEXTSIZE=200)") # Should be the same as MAXBUF in the driver code
|
||||
field(SCAN, "I/O Intr")
|
||||
}
|
||||
|
||||
# Encoder type
|
||||
record(waveform, "$(P)$(M):Encoder_Type") {
|
||||
# User-writable switch which disables the motor for an input of zero and enables
|
||||
# it otherwise. Some motors can't be disabled in certain states (e.g. during
|
||||
# movement). This behaviour has to be implemented inside the driver.
|
||||
# This record is coupled to the parameter library via motorEnable_ -> MOTOR_ENABLE.
|
||||
record(longout, "$(INSTR)$(M):Enable") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_ENABLE")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# Readback value which returns 1 if the motor is disabled and 0 otherwise.
|
||||
# This record is coupled to the parameter library via motorEnableRBV_ -> MOTOR_ENABLE_RBV.
|
||||
record(longin, "$(INSTR)$(M):EnableRBV") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_ENABLE_RBV")
|
||||
field(PINI, "NO")
|
||||
field(SCAN, "I/O Intr")
|
||||
}
|
||||
|
||||
# Some (older) motors cannot be disabled. This property has to be specified in
|
||||
# the driver by setting the corresponding parameter library entry motorCanDisable_
|
||||
# to 0 (its default value is 1).
|
||||
# This record is coupled to the parameter library via motorCanDisable_ -> MOTOR_CAN_DISABLE.
|
||||
record(longin, "$(INSTR)$(M):CanDisable") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_CAN_DISABLE")
|
||||
field(PINI, "NO")
|
||||
field(SCAN, "I/O Intr")
|
||||
}
|
||||
|
||||
# For some motors, the user might be allowed to adjust the speed within the
|
||||
# limits specified in the motor record as VBAS and VMAX. This functionality can
|
||||
# be enabled by setting CANSETSPEED to 1. It is disabled by default.
|
||||
# This record is coupled to the parameter library via motorCanSetSpeed_ -> MOTOR_CAN_SET_SPEED.
|
||||
record(longout, "$(INSTR)$(M):CanSetSpeed") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_CAN_SET_SPEED")
|
||||
field(PINI, "YES")
|
||||
field(ASG, "READONLY") # Field is initialized during IOC startup
|
||||
field(VAL, "$(CANSETSPEED=0)")
|
||||
}
|
||||
|
||||
# If this PV has a value other than 0, adaptive polling for this axis is enabled.
|
||||
# The standard motor record behaviour is to poll all axis with the busy / move poll
|
||||
# period if at least one of the axes is moving. Adaptive polling changes this so
|
||||
# that only axes which were moving in the last poll are polled with the busy / move poll
|
||||
# period and all other axes are polled with the idle poll period.
|
||||
record(longout, "$(INSTR)$(M):AdaptivePolling") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) ADAPTIVE_POLLING")
|
||||
field(PINI, "YES")
|
||||
field(VAL, "$(ADAPTPOLL=1)")
|
||||
}
|
||||
|
||||
# The timeout mechanism for movements can be enabled / disabled by setting
|
||||
# this PV to 1 / 0.
|
||||
# This record is coupled to the parameter library via motorEnableMovWatchdog -> MOTOR_ENABLE_MOV_WATCHDOG.
|
||||
record(longout, "$(INSTR)$(M):EnableMovWatchdog") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_ENABLE_MOV_WATCHDOG")
|
||||
field(PINI, "YES")
|
||||
field(VAL, "$(ENABLEMOVWATCHDOG=0)")
|
||||
}
|
||||
|
||||
# For modern controllers, the high and low limits of the axis are read out
|
||||
# directly from the hardware. However, since the axis might slightly
|
||||
# "overshoot" when moving to a position next to the limits, the hardware might
|
||||
# go into a "limits hit" error state. To prevent this, this value allows adding
|
||||
# a small offset in EGU, which is subtracted from the high limit and added to the
|
||||
# low limit.
|
||||
# This record is coupled to the parameter library via motorLimitsOffset_ -> MOTOR_LIMITS_OFFSET.
|
||||
record(ao, "$(INSTR)$(M):LimitsOffset") {
|
||||
field(DTYP, "asynFloat64")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) MOTOR_LIMITS_OFFSET")
|
||||
field(PINI, "YES")
|
||||
field(ASG, "READONLY") # Field is initialized during IOC startup
|
||||
field(VAL, "$(LIMITSOFFSET=0)")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorHighLimitFromDriver_"
|
||||
# and pushes it to the motor record field "DHLM". This can be used to read limits
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorHighLimitFromDriver_ -> MOTOR_HIGH_LIMIT_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):DHLM_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(VAL, "$(DHLM=0)")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_HIGH_LIMIT_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushDHLM2Field")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushDHLM2Field") {
|
||||
field(DOL, "$(INSTR)$(M):DHLM_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).DHLM")
|
||||
field(OMSL, "closed_loop")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorLowLimitFromDriver_"
|
||||
# and pushes it to the motor record field "DLLM". This can be used to read limits
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorLowLimitFromDriver_ -> MOTOR_LOW_LIMIT_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):DLLM_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(VAL, "$(DLLM=0)")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_LOW_LIMIT_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushDLLM2Field")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushDLLM2Field") {
|
||||
field(DOL, "$(INSTR)$(M):DLLM_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).DLLM")
|
||||
field(OMSL, "closed_loop")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorVeloFromDriver_"
|
||||
# and pushes it to the motor record field "VELO". This can be used to read the speed value
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorVeloFromDriver_ -> MOTOR_VELO_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):VELO_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_VELO_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushVELO2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVELO2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VELO_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VELO")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorVbasFromDriver_"
|
||||
# and pushes it to the motor record field "VBAS". This can be used to read the lower speed limit
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorVbasFromDriver_ -> MOTOR_VBAS_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):VBAS_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_VBAS_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushVBAS2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVBAS2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VBAS_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VBAS")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorVmaxFromDriver_"
|
||||
# and pushes it to the motor record field "VMAX". This can be used to read the upper speed limit
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorVmaxFromDriver_ -> MOTOR_VMAX_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):VMAX_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_VMAX_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushVMAX2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVMAX2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VMAX_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VMAX")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
|
||||
# This record pair reads the parameter library value for "motorAcclFromDriver_"
|
||||
# and pushes it to the motor record field "ACCL". This can be used to read the acceleration
|
||||
# from the hardware and correspondingly update the motor record from the driver.
|
||||
# The implementation strategy is taken from https://epics.anl.gov/tech-talk/2022/msg00464.php.
|
||||
# This record is coupled to the parameter library via motorAcclFromDriver_ -> MOTOR_ACCL_FROM_DRIVER.
|
||||
record(ai, "$(INSTR)$(M):ACCL_RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_ACCL_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(INSTR)$(M):PushACCL2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushACCL2Field") {
|
||||
field(DOL, "$(INSTR)$(M):ACCL_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).ACCL")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
|
||||
# Read out the encoder type in human-readable form. The output numbers are ASCII
|
||||
# codes and can be converted to chars in order to get the encoder type.
|
||||
# EPICS prepends the ASCII code with 80
|
||||
# The following encoder types are defined:
|
||||
# - "Absolute encoder" (array 80 65 98 115 111 108 117 116 101 32 101 110 99 111 100 101 114)
|
||||
# - "Incremental encoder" (array 80 73 110 99 114 101 109 101 110 116 97 108 32 101 110 99 111 100 101 114)
|
||||
# This record is coupled to the parameter library via encoderType -> ENCODER_TYPE.
|
||||
record(waveform, "$(INSTR)$(M):EncoderType") {
|
||||
field(DTYP, "asynOctetRead")
|
||||
field(INP, "@asyn($(PORT),$(N),1) ENCODER_TYPE")
|
||||
field(INP, "@asyn($(CONTROLLER),$(AXIS),1) ENCODER_TYPE")
|
||||
field(FTVL, "CHAR")
|
||||
field(NELM, "80")
|
||||
field(SCAN, "I/O Intr")
|
||||
}
|
||||
|
||||
# enable axis
|
||||
record(longout, "$(P)$(M):Enable") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(PORT),$(N),1) ENABLE_AXIS")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# enable axis
|
||||
record(longin, "$(P)$(M):Enable_RBV") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(PORT),$(N),1) AXIS_ENABLED")
|
||||
field(PINI, "YES")
|
||||
}
|
||||
|
||||
# reread encoder
|
||||
record(longout, "$(P)$(M):Reread_Encoder") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(PORT),$(N),1) REREAD_ENCODER_POSITION")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# reread encoder
|
||||
record(longin, "$(P)$(M):Reread_Encoder_RBV") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(INP, "@asyn($(PORT),$(N),1) REREAD_ENCODER_POSITION_RBV")
|
||||
field(PINI, "YES")
|
||||
}
|
||||
|
||||
# reread encoder
|
||||
record(longout, "$(P)$(M):Read_Config") {
|
||||
field(DTYP, "asynInt32")
|
||||
field(OUT, "@asyn($(PORT),$(N),1) READ_CONFIG")
|
||||
field(PINI, "NO")
|
||||
}
|
||||
|
||||
# Provides the motor resolution MRES via an additional PV as explained here:
|
||||
# https://epics.anl.gov/tech-talk/2020/msg00378.php
|
||||
record(ao,"$(P)$(M):Resolution") {
|
||||
field(DESC, "$(M) resolution")
|
||||
field(DOL, "$(P)$(M).MRES CP MS")
|
||||
field(OMSL, "closed_loop")
|
||||
field(DTYP, "asynFloat64")
|
||||
field(OUT, "@asyn($(PORT),$(ADDR)) MOTOR_REC_RESOLUTION")
|
||||
field(PREC, "$(PREC)")
|
||||
}
|
||||
|
||||
# ===================================================================
|
||||
# The following records read the high / low limits from the parameter
|
||||
# library and copy those values into the corresponding fields of the main motor record.
|
||||
# This strategy is described here: https://epics.anl.gov/tech-talk/2022/msg00464.php
|
||||
|
||||
# Helper record for the high limit which is filled in by the driver
|
||||
record(ai, "$(P)$(M):MOTOR_HIGH_LIMIT-RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(PREC, "$(PREC)")
|
||||
field(INP, "@asyn($(PORT),$(ADDR)) MOTOR_HIGH_LIMIT_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(P)$(M):PUSH_DHLM_TO_FIELD")
|
||||
}
|
||||
|
||||
# Push the value into the field of the main motor record
|
||||
record(ao, "$(P)$(M):PUSH_DHLM_TO_FIELD") {
|
||||
field(PREC, "$(PREC)")
|
||||
field(DOL, "$(P)$(M):MOTOR_HIGH_LIMIT-RBV CP")
|
||||
field(OUT, "$(P)$(M).DHLM")
|
||||
field(OMSL, "closed_loop") # This configuration keeps the input value $(P)$(M):HLM_ADD_OFFSET and the output field $(P)$(M).DHLM in sync
|
||||
}
|
||||
|
||||
# Helper record for the low limit which is filled in by the driver
|
||||
record(ai, "$(P)$(M):MOTOR_LOW_LIMIT-RBV")
|
||||
{
|
||||
field(DTYP, "asynFloat64")
|
||||
field(PREC, "$(PREC)")
|
||||
field(INP, "@asyn($(PORT),$(ADDR)) MOTOR_LOW_LIMIT_FROM_DRIVER")
|
||||
field(SCAN, "I/O Intr")
|
||||
field(FLNK, "$(P)$(M):PUSH_DLLM_TO_FIELD")
|
||||
}
|
||||
|
||||
# Push the value into the field of the main motor record
|
||||
record(ao, "$(P)$(M):PUSH_DLLM_TO_FIELD") {
|
||||
field(PREC, "$(PREC)")
|
||||
field(DOL, "$(P)$(M):MOTOR_LOW_LIMIT-RBV CP")
|
||||
field(OUT, "$(P)$(M).DLLM")
|
||||
field(OMSL, "closed_loop") # This configuration keeps the input value $(P)$(M):LLM_ADD_OFFSET and the output field $(P)$(M).DLLM in sync
|
||||
}
|
||||
|
113
src/msgPrintControl.cpp
Normal file
113
src/msgPrintControl.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
#include "msgPrintControl.h"
|
||||
#include <unordered_map>
|
||||
|
||||
msgPrintControlKey::msgPrintControlKey(char *controller, int axisNo,
|
||||
const char *functionName, int line,
|
||||
size_t maxRepetitions) {
|
||||
controller_ = controller;
|
||||
axisNo_ = axisNo;
|
||||
line_ = line;
|
||||
functionName_ = functionName;
|
||||
maxRepetitions_ = maxRepetitions;
|
||||
}
|
||||
|
||||
void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
|
||||
snprintf(buffer, bufferSize, "controller %s, axis %d, function %s, line %d",
|
||||
controller_.c_str(), axisNo_, functionName_, line_);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
|
||||
asynUser *pasynUser) {
|
||||
|
||||
// Reset the suffix
|
||||
suffix_[0] = 0;
|
||||
|
||||
if (wantToPrint) {
|
||||
/*
|
||||
We want to print the message associated with key -> Check if the number
|
||||
of allowed repetitions is exceeded. If true, inform the user that
|
||||
further output is suppressed.
|
||||
*/
|
||||
if (map_.find(key) != map_.end()) {
|
||||
size_t repetitions = map_[key];
|
||||
if (repetitions < key.maxRepetitions_) {
|
||||
// Number of allowed repetitions not exceeded -> Printing the
|
||||
// message is ok.
|
||||
map_[key] = repetitions + 1;
|
||||
return true;
|
||||
} else if (repetitions == key.maxRepetitions_) {
|
||||
// Reached number of allowed repetitions -> Printing the message
|
||||
// is ok, but further trys are rejected.
|
||||
char formattedKey[100] = {0};
|
||||
key.format(formattedKey, sizeof(formattedKey));
|
||||
snprintf(suffix_, sizeof(suffix_),
|
||||
" Further repetition of this error message (key "
|
||||
"\"%s\") is suppressed.",
|
||||
formattedKey);
|
||||
map_[key] = repetitions + 1;
|
||||
return true;
|
||||
} else {
|
||||
// Exceeded number of allowed repetitions -> Do not print the
|
||||
// message
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Message is not yet in map -> create an entry so it is watched in
|
||||
// the future.
|
||||
map_[key] = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
We do not want to print the message associated with key -> If the key is
|
||||
part of the map, set the counter back to zero.
|
||||
*/
|
||||
if (map_.find(key) != map_.end()) {
|
||||
if (map_[key] != 0) {
|
||||
if (pasynUser != nullptr) {
|
||||
char formattedKey[100] = {0};
|
||||
key.format(formattedKey, sizeof(formattedKey));
|
||||
asynPrint(
|
||||
pasynUser, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d\nError "
|
||||
"associated with key \"%s\" has been resolved.\n",
|
||||
key.controller_.c_str(), key.axisNo_, key.functionName_,
|
||||
key.line_, formattedKey);
|
||||
}
|
||||
map_[key] = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool msgPrintControl::shouldBePrinted(char *portName, int axisNo,
|
||||
const char *functionName, int line,
|
||||
bool wantToPrint, asynUser *pasynUser,
|
||||
size_t maxRepetitions) {
|
||||
msgPrintControlKey key =
|
||||
msgPrintControlKey(portName, axisNo, functionName, __LINE__);
|
||||
return shouldBePrinted(key, wantToPrint, pasynUser);
|
||||
}
|
||||
|
||||
void msgPrintControl::resetCount(msgPrintControlKey &key, asynUser *pasynUser) {
|
||||
if (map_.find(key) != map_.end()) {
|
||||
if (map_[key] != 0) {
|
||||
if (pasynUser != nullptr) {
|
||||
char formattedKey[100] = {0};
|
||||
key.format(formattedKey, sizeof(formattedKey));
|
||||
asynPrint(pasynUser, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d\nError "
|
||||
"associated with key \"%s\" has been resolved.\n",
|
||||
key.controller_.c_str(), key.axisNo_,
|
||||
key.functionName_, key.line_, formattedKey);
|
||||
}
|
||||
map_[key] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *msgPrintControl::getSuffix() { return suffix_; }
|
147
src/msgPrintControl.h
Normal file
147
src/msgPrintControl.h
Normal file
@ -0,0 +1,147 @@
|
||||
#ifndef msgPrintControl_H
|
||||
#define msgPrintControl_H
|
||||
|
||||
#define DefaultMaxRepetitions 4
|
||||
|
||||
#include <asynDriver.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
/**
|
||||
* @brief Class to identify a message print location. See the docstring of
|
||||
* `msgPrintControl` on how to use this key.
|
||||
*
|
||||
*/
|
||||
class msgPrintControlKey {
|
||||
public:
|
||||
std::string controller_;
|
||||
|
||||
// -1 indicates a non-axis specific message
|
||||
int axisNo_;
|
||||
|
||||
const char *functionName_;
|
||||
int line_;
|
||||
|
||||
/**
|
||||
* @brief Maximum number of times a message is printed before it is
|
||||
* suppressed. This number is not used as part of the hash.
|
||||
*
|
||||
*/
|
||||
size_t maxRepetitions_;
|
||||
|
||||
msgPrintControlKey(char *controller_, int axisNo, const char *fileName,
|
||||
int line, size_t maxRepetitions = DefaultMaxRepetitions);
|
||||
|
||||
bool operator==(const msgPrintControlKey &other) const {
|
||||
return axisNo_ == other.axisNo_ && line_ == other.line_ &&
|
||||
strcmp(functionName_, other.functionName_) == 0 &&
|
||||
controller_ == other.controller_;
|
||||
}
|
||||
|
||||
void format(char *buffer, size_t bufferSize);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implementation of the hash functionality for `msgPrintControlKey`
|
||||
*
|
||||
*/
|
||||
namespace std {
|
||||
template <> struct hash<msgPrintControlKey> {
|
||||
size_t operator()(const msgPrintControlKey &obj) const {
|
||||
// Combine the hashes of the members (x and y)
|
||||
size_t h1 = std::hash<std::string>{}(obj.controller_);
|
||||
size_t h2 = hash<int>{}(obj.axisNo_);
|
||||
size_t h3 = std::hash<const char *>{}(obj.functionName_);
|
||||
size_t h4 = hash<int>{}(obj.line_);
|
||||
// Combine the hashes (simple XOR and shifting technique)
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
/**
|
||||
* @brief Class to control the number of repetitions of error messages
|
||||
*
|
||||
* This class is used to prevent excessive repetitions of identical error
|
||||
* messages. For example, if the communication between a controller and an
|
||||
* axis fails, a corresponding error message is created in each poll. This
|
||||
* could "flood" the IOC shell with noise. To prevent this, this class keeps
|
||||
* track of the number of subsequent error message repetition. Each message is
|
||||
* uniquely identified by `msgPrintControlKey`. The function `shouldBePrinted`
|
||||
* can be used in order to see if a message should be printed or not:
|
||||
*
|
||||
* ```
|
||||
* const char* controller = "MCU" // Name of the controller
|
||||
* int axisNo = 0; // Number of the axis
|
||||
* bool wantToPrint = evaluateConditions(...); *
|
||||
* if (msgPrintControl.shouldBePrinted(controller, axisNo, __PRETTY_FUNCTION__,
|
||||
* __LINE__, wantToPrint)) { asynPrint(...)
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class msgPrintControl {
|
||||
public:
|
||||
/**
|
||||
* @brief Checks if the error message associated with "key" has been printed
|
||||
* more than `this->maxRepetitions_` times in a row. If yes, returns false,
|
||||
* otherwise true. Counter is reset if `wantToPrint` is false.
|
||||
*
|
||||
* If the conditions for printing a message are met, `wantToPrint` must be
|
||||
* set to true. The function then checks if `maxRepetitions_` has been
|
||||
* exceeded. If yes, the function returns no, indicating that the message
|
||||
* should not be printed. If no, the number of repetitions stored in the map
|
||||
* is incremented and the function returns true, indicating that the message
|
||||
* should be printed.
|
||||
*
|
||||
* If the conditions for printing a message are not met, `wantToPrint` must
|
||||
* be set to false. This resets the map entry.
|
||||
*
|
||||
* @param key Key associated with the message, used to
|
||||
* identify individual messages
|
||||
* @param wantToPrint If the message associated with key should be
|
||||
* printed, this value should be true, otherwise false.
|
||||
* @param pasynUser If the problem has been resolved (wantToPrint =
|
||||
* false), a corresponding status message is printed using the given
|
||||
* asynUser. If this pointer is a nullptr, no message is printed.
|
||||
* @return bool If true, the message should be printed, if
|
||||
* false, it should not.
|
||||
*/
|
||||
bool shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
|
||||
asynUser *pasynUser);
|
||||
|
||||
/**
|
||||
* @brief Like `shouldBePrinted(msgPrintControlKey key, bool wantToPrint)`,
|
||||
* but constructs the key from the first four arguments.
|
||||
*
|
||||
* @param controller_
|
||||
* @param axisNo
|
||||
* @param fileName
|
||||
* @param line
|
||||
* @param wantToPrint
|
||||
* @param pasynUser
|
||||
*/
|
||||
bool shouldBePrinted(char *controller, int axisNo, const char *functionName,
|
||||
int line, bool wantToPrint, asynUser *pasynUser,
|
||||
size_t maxRepetitions = DefaultMaxRepetitions);
|
||||
|
||||
/**
|
||||
* @brief Reset the error message count incremented in `shouldBePrinted` for
|
||||
* the given key
|
||||
*
|
||||
* @param key Key associated with the message, used to
|
||||
* identify individual messages
|
||||
* @param pasynUser If the problem has been resolved (`wantToPrint =
|
||||
* false`), a corresponding status message is printed using the given
|
||||
* asynUser. If this pointer is a nullptr, no message is printed.
|
||||
*/
|
||||
void resetCount(msgPrintControlKey &key, asynUser *pasynUser);
|
||||
|
||||
char *getSuffix();
|
||||
|
||||
private:
|
||||
std::unordered_map<msgPrintControlKey, size_t> map_;
|
||||
char suffix_[300] = {0};
|
||||
};
|
||||
|
||||
#endif
|
927
src/sinqAxis.cpp
927
src/sinqAxis.cpp
File diff suppressed because it is too large
Load Diff
247
src/sinqAxis.h
247
src/sinqAxis.h
@ -4,9 +4,10 @@ This class extends asynMotorAxis by some features used in SINQ.
|
||||
Stefan Mathis, November 2024
|
||||
*/
|
||||
|
||||
#ifndef __SINQDRIVER
|
||||
#define __SINQDRIVER
|
||||
#ifndef sinqAxis_H
|
||||
#define sinqAxis_H
|
||||
#include "asynMotorAxis.h"
|
||||
#include <epicsTime.h>
|
||||
|
||||
class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
public:
|
||||
@ -19,36 +20,31 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
sinqAxis(class sinqController *pC_, int axisNo);
|
||||
|
||||
/**
|
||||
* @brief This function is executed once during the very first poll.
|
||||
*
|
||||
* This function is executed at the very first poll after the IOC startup.
|
||||
If it returns anything else than 'asynSuccess', the function is evaluated
|
||||
again after 100 ms until it succeeds. Every 10 trials a warning is emitted.
|
||||
The default implementation just returns asynSuccess and is meant to be
|
||||
overwritten by concrete driver implementations.
|
||||
*
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus atFirstPoll();
|
||||
|
||||
/**
|
||||
* @brief Perform some standardized operation before and after the concrete
|
||||
* @brief Perform some standardized operations before and after the concrete
|
||||
`doPoll` implementation.
|
||||
*
|
||||
* Wrapper around doPoll which performs the following operations:
|
||||
Before calling doPoll:
|
||||
- Try to execute atFirstPoll once (and retry, if that failed)
|
||||
* Wrapper around `doPoll` which performs the following operations:
|
||||
|
||||
- Call the `doPoll` method
|
||||
|
||||
After calling doPoll:
|
||||
- Reset motorStatusProblem_, motorStatusCommsError_ and motorMessageText_ if
|
||||
doPoll returned asynSuccess
|
||||
- Run `callParamCallbacks`
|
||||
|
||||
- If the movement timeout watchdog has been started, check it.
|
||||
|
||||
- The flags `motorStatusHome_`, `motorStatusHomed_` and
|
||||
`motorStatusAtHome_` are set to their idle values (0, 1 and 1 respectively)
|
||||
in the `poll()` method once the homing procedure is finished. See the
|
||||
documentation of the `home()` method for more details.
|
||||
|
||||
- Run `callParamCallbacks()`
|
||||
|
||||
- Return the status of `doPoll`
|
||||
*
|
||||
* @param moving Forwarded to `doPoll`.
|
||||
* @return asynStatus Forward the status of `doPoll`, unless one of
|
||||
the parameter library operation fails (in that case, returns the failed
|
||||
operation status).
|
||||
the parameter library operation fails (in that case, returns the status of
|
||||
the failed operation.
|
||||
*/
|
||||
asynStatus poll(bool *moving);
|
||||
|
||||
@ -63,11 +59,12 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
virtual asynStatus doPoll(bool *moving);
|
||||
|
||||
/**
|
||||
* @brief Perform some standardized operation before and after the concrete
|
||||
* @brief Perform some standardized operations before and after the concrete
|
||||
`doMove` implementation.
|
||||
|
||||
* Wrapper around `doMove` which calculates the (absolute) target position
|
||||
and stores it in the parameter library. After that, it calls and returns
|
||||
and stores it in the member variable `targetPosition_`. This member variable
|
||||
is e.g. used for the movement watchdog. Afterwards, it calls and returns
|
||||
`doMove`.
|
||||
*
|
||||
* @param position Forwarded to `doMove`.
|
||||
@ -98,23 +95,42 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
double maxVelocity, double acceleration);
|
||||
|
||||
/**
|
||||
* @brief Perform some standardized operation before and after the concrete
|
||||
`doHome` implementation.
|
||||
*
|
||||
* Wrapper around move which calculates the (absolute) target position and
|
||||
stores it in the parameter library. The target position in a homing maneuver
|
||||
is calculated as follows:
|
||||
* @brief Wrapper around doHome which handles the homing-related flags
|
||||
*
|
||||
* The homing procedure of the motor record is controlled by the following
|
||||
* parameter library flags:
|
||||
*
|
||||
* - `motorMoveToHome_`: Setting this flag to `1` indicates to EPICS that a
|
||||
homing procedure should start and can therefore be used to start homing from
|
||||
within the driver.
|
||||
|
||||
if abs(current position - high limit) > abs(current position - low limit)
|
||||
{
|
||||
high limit
|
||||
}
|
||||
else
|
||||
{
|
||||
low limit
|
||||
}
|
||||
* - `motorStatusHome_`: This flag should be set to `1` while the motor is
|
||||
actively moving toward its home position and to `0` when the home position
|
||||
is reached.
|
||||
*
|
||||
* - `motorStatusHomed_`: This flag should be set to `0` at the start of a
|
||||
homing command and to 1 once the home position is reached.
|
||||
*
|
||||
* - `motorStatusAtHome_`: This flag is similar to `motorStatusHomed_`, but
|
||||
in addition it should also be `1` when the motor is at its home position,
|
||||
but wasn't actively homed in order to get there.
|
||||
*
|
||||
* This function performs the following operations in the given order:
|
||||
*
|
||||
* - Call `doHome()` and forward the parameters
|
||||
*
|
||||
* - If `doHome()` returned asynSuccess: Set `motorStatusHome_` to `1`,
|
||||
`motorStatusHomed_` to `0` and `motorStatusAtHome_` to `0`.
|
||||
*
|
||||
* - If `doHome()` returned asynError: This means that the motor cannot be
|
||||
homed because the encoder is absolute. Set a corresponding error message,
|
||||
but return asynSuccess in order to avoid any automatic retries by asyn.
|
||||
|
||||
After that, it calls and returns doHome.
|
||||
* - If `doHome()` returned anything else: Forward the status.
|
||||
*
|
||||
* The flags `motorStatusHome_`, `motorStatusHomed_` and
|
||||
`motorStatusAtHome_` are set to their idle values (0, 1 and 1 respectively)
|
||||
in the `poll()` method once the homing procedure is finished.
|
||||
*
|
||||
* @param minVelocity Forwarded to `doHome`.
|
||||
* @param maxVelocity Forwarded to `doHome`.
|
||||
@ -129,7 +145,9 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
|
||||
/**
|
||||
* @brief Implementation of the "proper", device-specific home method. This
|
||||
method should be implemented by a child class of sinqAxis.
|
||||
method should be implemented by a child class of sinqAxis. If the motor
|
||||
cannot be homed because it has an absolute encoder, this function should
|
||||
return asynError.
|
||||
*
|
||||
* @param minVelocity Minimum velocity VMIN from the motor record
|
||||
* @param maxVelocity Maximum velocity VMAX from the motor record
|
||||
@ -141,6 +159,76 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
virtual asynStatus doHome(double minVelocity, double maxVelocity,
|
||||
double acceleration, int forwards);
|
||||
|
||||
/**
|
||||
* @brief This function is called when the PV "$(INSTR)$(M):Reset" is set to
|
||||
* any value. It calls `doReset` (which ought to be implemented by a child
|
||||
* class) and then performs da defined number of consecutive fast polls. If
|
||||
* one of the polls returns asynSuccess, it returns immediately.
|
||||
*
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus reset();
|
||||
|
||||
/**
|
||||
* @brief Implementation of the "proper", device-specific `reset` method.
|
||||
This method should be implemented by a child class of sinqAxis. If the
|
||||
motor cannot be reset, this function should return asynError.
|
||||
*
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus doReset();
|
||||
|
||||
/**
|
||||
* @brief This function enables / disables an axis. It should be implemented
|
||||
* by a child class of sinqAxis.
|
||||
*
|
||||
* The concrete implementation should (but doesn't need to) follow the
|
||||
* convention that a value of 0 disables the axis and any other value
|
||||
* enables it.
|
||||
*
|
||||
* @param on
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus enable(bool on);
|
||||
|
||||
/**
|
||||
* @brief Populate the motor record fields VELO, VBAS and VMAX
|
||||
*
|
||||
* Populates the speed fields of the motor record. If the param lib
|
||||
* entry motorCanSetSpeed_ (connected to the PV x:VariableSpeed) is set to
|
||||
* 1, VBAS and VMAX are set to min and max respectively. Otherwise, they are
|
||||
* set to val. Additionally, the speed itself is set to VELO.
|
||||
*
|
||||
* The units of the inputs are engineering units (EGU) per second (e.g. mm/s
|
||||
* if the EGU is mm).
|
||||
*
|
||||
* If the given configuration is invalid (min > max, velo < min, velo > max)
|
||||
* and the motor is configured as a variable speed motor (param lib entry
|
||||
* motorCanSetSpeed_ is 1), this function returns an asynError.
|
||||
*
|
||||
* @param velo Actual velocity (EGU / s)
|
||||
* @param vbas Minimum allowed velocity (EGU / s)
|
||||
* @param velo Maximum allowed velocity (EGU / s)
|
||||
*
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus setVeloFields(double velo, double vbas, double vmax);
|
||||
|
||||
/**
|
||||
* @brief Populate the ACCL field of the motor record
|
||||
*
|
||||
* Populates the acceleration field of the motor record with the given
|
||||
* value. If accl is not positive, this function does not set the value and
|
||||
* returns an asynError.
|
||||
*
|
||||
* The unit of the input is engineering units (EGU) per second squared (e.g.
|
||||
* mm/s^2 if the EGU is mm).
|
||||
*
|
||||
* @param accl Actual acceleration (EGU / s^2)
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus setAcclField(double accl);
|
||||
|
||||
/**
|
||||
* @brief Start the watchdog for the movement, if the watchdog is not
|
||||
disabled. See the documentation of checkMovTimeoutWatchdog for more details.
|
||||
@ -164,15 +252,15 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
|
||||
with
|
||||
|
||||
timeContSpeed = abs(motorTargetPosition - motorPosition) / motorVelBase
|
||||
timeContSpeed = abs(targetPosition - motorPosition) / motorVelBase
|
||||
timeAcc = motorVelBase / motorAccel
|
||||
|
||||
The values motorTargetPosition, motorVelBase, motorAccel and
|
||||
positionAtMovementStart are taken from the parameter library. Therefore it
|
||||
is necessary to populate them before using this function. If they are not
|
||||
given, both speed and velocity are assumed to be infinite. This means that
|
||||
timeContSpeed and/or timeAcc are set to zero. motorTargetPosition is
|
||||
populated automatically when using the doMove function.
|
||||
The values motorVelBase, motorAccel and positionAtMovementStart are taken
|
||||
from the parameter library. Therefore it is necessary to populate them
|
||||
before using this function. If they are not given, both speed and velocity
|
||||
are assumed to be infinite. This means that timeContSpeed and/or timeAcc are
|
||||
set to zero. targetPosition is populated automatically when using the doMove
|
||||
function.
|
||||
|
||||
The values offsetMovTimeout_ and scaleMovTimeout_ can be set directly from
|
||||
the IOC shell with the functions setScaleMovTimeout and setOffsetMovTimeout,
|
||||
@ -201,7 +289,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
* @brief Set the offsetMovTimeout. Also available in the IOC shell
|
||||
* (see "extern C" section in sinqController.cpp).
|
||||
*
|
||||
See documentation of `checkMovTimeoutWatchdog` for details.
|
||||
* See documentation of `checkMovTimeoutWatchdog` for details.
|
||||
*
|
||||
* @param offsetMovTimeout Offset (in seconds)
|
||||
* @return asynStatus
|
||||
@ -225,18 +313,67 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
friend class sinqController;
|
||||
/**
|
||||
* @brief Return the axis number of this axis
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int axisNo() { return axisNo_; }
|
||||
|
||||
/**
|
||||
* @brief Read the motor position from the paramLib, adjusted for the
|
||||
* motorRecResolution
|
||||
*
|
||||
* The motorPosition value in the paramLib is the encoder position
|
||||
* divided by the motorRecResolution (see README.md). This function
|
||||
* fetches the paramLib value and multiplies it with motorRecResolution
|
||||
* (also fetched from the paramLib).
|
||||
*
|
||||
* @param motorPositon
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus motorPosition(double *motorPositon);
|
||||
|
||||
/**
|
||||
* @brief Write the motor position in the paramLib, adjusted for the
|
||||
* motorRecResolution
|
||||
*
|
||||
* The motorPosition value in the paramLib is the encoder position
|
||||
* divided by the motorRecResolution (see README.md). This function takes
|
||||
* the input value and divides it with motorRecResolution (fetched from
|
||||
* the paramLib).
|
||||
*
|
||||
* @param motorPosition
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus setMotorPosition(double motorPosition);
|
||||
|
||||
/**
|
||||
* @brief Check if the axis is not connected and print a corresponding error
|
||||
* message
|
||||
*
|
||||
* This method is meant to be used at the end of "interactive" function
|
||||
* calls such as move, home, stop etc which can be manually triggered from
|
||||
* the IOC shell or from the channel access protocol.
|
||||
*/
|
||||
asynStatus assertConnected();
|
||||
|
||||
protected:
|
||||
bool initial_poll_;
|
||||
int init_poll_counter_;
|
||||
|
||||
// Helper variables for movementTimeoutWatchdog
|
||||
// Internal variables used in the movement timeout watchdog
|
||||
time_t expectedArrivalTime_;
|
||||
time_t offsetMovTimeout_;
|
||||
|
||||
double scaleMovTimeout_;
|
||||
bool watchdogEnabled_;
|
||||
bool watchdogMovActive_;
|
||||
// Store the motor target position for the movement time calculation
|
||||
double targetPosition_;
|
||||
|
||||
bool wasMoving_;
|
||||
|
||||
/*
|
||||
Store the time since the last poll
|
||||
*/
|
||||
epicsTimeStamp lastPollTime_;
|
||||
|
||||
private:
|
||||
sinqController *pC_;
|
||||
|
@ -5,6 +5,32 @@
|
||||
#include "iocsh.h"
|
||||
#include "sinqAxis.h"
|
||||
#include <errlog.h>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
Contains all instances of turboPmacAxis which have been created and is used in
|
||||
the initialization hook function.
|
||||
*/
|
||||
static std::vector<sinqController *> controller;
|
||||
|
||||
/**
|
||||
* @brief Hook function to perform certain actions during the IOC initialization
|
||||
*
|
||||
* @param iState
|
||||
*/
|
||||
void sinqController::epicsInithookFunction(initHookState iState) {
|
||||
if (iState == initHookAfterIocRunning) {
|
||||
// Iterate through all axes of each and call the initialization method
|
||||
// on each one of them.
|
||||
for (std::vector<sinqController *>::iterator itC = controller.begin();
|
||||
itC != controller.end(); ++itC) {
|
||||
|
||||
sinqController *controller = *itC;
|
||||
controller->startPoller(controller->movingPollPeriod_,
|
||||
controller->idlePollPeriod_, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sinqController::sinqController(const char *portName,
|
||||
const char *ipPortConfigName, int numAxes,
|
||||
@ -15,25 +41,39 @@ sinqController::sinqController(const char *portName,
|
||||
// As described in the function documentation, an offset of 1 is
|
||||
// added for better readability of the configuration.
|
||||
numAxes + 1,
|
||||
/*
|
||||
2 Parameters are added in sinqController:
|
||||
- MOTOR_MESSAGE_TEXT
|
||||
- MOTOR_TARGET_POSITION
|
||||
*/
|
||||
NUM_MOTOR_DRIVER_PARAMS + numExtraParams + 2,
|
||||
NUM_MOTOR_DRIVER_PARAMS + NUM_SINQMOTOR_DRIVER_PARAMS +
|
||||
numExtraParams,
|
||||
0, // No additional interfaces beyond those in base class
|
||||
0, // No additional callback interfaces beyond those in base class
|
||||
ASYN_CANBLOCK | ASYN_MULTIDEVICE,
|
||||
1, // autoconnect
|
||||
0,
|
||||
0) // Default priority and stack size
|
||||
{
|
||||
1, // autoconnect
|
||||
0, 0), // Default priority and stack size
|
||||
msgPrintControl_() {
|
||||
|
||||
// Initialization of local variables
|
||||
asynStatus status = asynSuccess;
|
||||
|
||||
// Initialization of all member variables
|
||||
lowLevelPortUser_ = nullptr;
|
||||
// Handle to the asynUser of the IP port asyn driver
|
||||
pasynOctetSyncIOipPort_ = nullptr;
|
||||
|
||||
// Initial values for the average timeout mechanism, can be overwritten
|
||||
// later by a FFI function
|
||||
comTimeoutWindow_ = 3600; // seconds
|
||||
|
||||
// Number of timeouts which may occur before an error is forwarded to the
|
||||
// user
|
||||
maxNumberTimeouts_ = 60;
|
||||
|
||||
// Queue holding the timeout event timestamps
|
||||
timeoutEvents_ = {};
|
||||
|
||||
// Inform the user after 10 timeouts in a row (default value)
|
||||
maxSubsequentTimeouts_ = 10;
|
||||
maxSubsequentTimeoutsExceeded_ = false;
|
||||
|
||||
// Store the poll period information. The poller itself will be started
|
||||
// later (after the IOC is running in epicsInithookFunction)
|
||||
movingPollPeriod_ = movingPollPeriod;
|
||||
idlePollPeriod_ = idlePollPeriod;
|
||||
|
||||
// =========================================================================;
|
||||
|
||||
@ -41,12 +81,13 @@ sinqController::sinqController(const char *portName,
|
||||
We try to connect to the port via the port name provided by the constructor.
|
||||
If this fails, the function is terminated via exit.
|
||||
*/
|
||||
pasynOctetSyncIO->connect(ipPortConfigName, 0, &lowLevelPortUser_, NULL);
|
||||
if (status != asynSuccess || lowLevelPortUser_ == nullptr) {
|
||||
errlogPrintf(
|
||||
"%s => line %d:\nFATAL ERROR (cannot connect to MCU controller).\n"
|
||||
"Terminating IOC",
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
pasynOctetSyncIO->connect(ipPortConfigName, 0, &pasynOctetSyncIOipPort_,
|
||||
NULL);
|
||||
if (status != asynSuccess || pasynOctetSyncIOipPort_ == nullptr) {
|
||||
errlogPrintf("Controller \"%s\" => %s, line %d:\nFATAL ERROR (cannot "
|
||||
"connect to MCU controller).\n"
|
||||
"Terminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@ -59,78 +100,451 @@ sinqController::sinqController(const char *portName,
|
||||
createParam("MOTOR_MESSAGE_TEXT", asynParamOctet, &motorMessageText_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\nFATAL ERROR (creating a parameter failed "
|
||||
"with %s).\nTerminating IOC",
|
||||
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Internal parameter library entry which stores the movement target
|
||||
status = createParam("MOTOR_TARGET_POSITION", asynParamFloat64,
|
||||
&motorTargetPosition_);
|
||||
status = createParam("MOTOR_ENABLE", asynParamInt32, &motorEnable_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\nFATAL ERROR (creating a parameter failed "
|
||||
"with %s).\nTerminating IOC",
|
||||
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Poller configuration
|
||||
status = startPoller(movingPollPeriod, idlePollPeriod, 1);
|
||||
status = createParam("MOTOR_RESET", asynParamInt32, &motorReset_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\nFATAL ERROR (starting the poller failed "
|
||||
"with %s).\nTerminating IOC",
|
||||
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
|
||||
pasynOctetSyncIO->disconnect(lowLevelPortUser_);
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_ENABLE_RBV", asynParamInt32, &motorEnableRBV_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status =
|
||||
createParam("MOTOR_CAN_DISABLE", asynParamInt32, &motorCanDisable_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status =
|
||||
createParam("MOTOR_CAN_SET_SPEED", asynParamInt32, &motorCanSetSpeed_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_LIMITS_OFFSET", asynParamFloat64,
|
||||
&motorLimitsOffset_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_CONNECTED", asynParamInt32, &motorConnected_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
We need to introduce 2 new parameters in order to write the limits from the
|
||||
driver to the EPICS record. See the comment in sinqController.h next to
|
||||
the declaration of motorHighLimitFromDriver_.
|
||||
*/
|
||||
status = createParam("MOTOR_HIGH_LIMIT_FROM_DRIVER", asynParamFloat64,
|
||||
&motorHighLimitFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_LOW_LIMIT_FROM_DRIVER", asynParamFloat64,
|
||||
&motorLowLimitFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_ENABLE_MOV_WATCHDOG", asynParamInt32,
|
||||
&motorEnableMovWatchdog_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_VELO_FROM_DRIVER", asynParamFloat64,
|
||||
&motorVeloFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_VBAS_FROM_DRIVER", asynParamFloat64,
|
||||
&motorVbasFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_VMAX_FROM_DRIVER", asynParamFloat64,
|
||||
&motorVmaxFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_ACCL_FROM_DRIVER", asynParamFloat64,
|
||||
&motorAcclFromDriver_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("ADAPTIVE_POLLING", asynParamInt32, &adaptivePolling_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("ENCODER_TYPE", asynParamOctet, &encoderType_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
status = createParam("MOTOR_FORCE_STOP", asynParamInt32, &motorForceStop_);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
|
||||
"parameter failed with %s).\nTerminating IOC",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__,
|
||||
stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Register the hook function during construction of the first axis object
|
||||
if (controller.empty()) {
|
||||
initHookRegister(&epicsInithookFunction);
|
||||
}
|
||||
|
||||
// Collect all axes into this list which will be used in the hook function
|
||||
controller.push_back(this);
|
||||
}
|
||||
|
||||
sinqController::~sinqController(void) {
|
||||
/*
|
||||
Cleanup of the memory allocated in the asynMotorController constructor
|
||||
*/
|
||||
|
||||
// Free all axes
|
||||
for (int axisNo = 0; axisNo < numAxes_; axisNo++) {
|
||||
if (pAxes_[axisNo] != nullptr) {
|
||||
delete pAxes_[axisNo];
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup of the array allocated in the asynMotorController constructor
|
||||
free(this->pAxes_);
|
||||
}
|
||||
|
||||
asynStatus sinqController::errMsgCouldNotParseResponse(const char *command,
|
||||
const char *response,
|
||||
int axisNo_,
|
||||
const char *functionName,
|
||||
int lineNumber) {
|
||||
asynPrint(lowLevelPortUser_, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\n Could not interpret response %s for "
|
||||
"command %s.\n",
|
||||
functionName, lineNumber, response, command);
|
||||
msgPrintControl &sinqController::getMsgPrintControl() {
|
||||
return msgPrintControl_;
|
||||
}
|
||||
|
||||
setStringParam(
|
||||
asynStatus sinqController::writeInt32(asynUser *pasynUser, epicsInt32 value) {
|
||||
int function = pasynUser->reason;
|
||||
|
||||
// =====================================================================
|
||||
|
||||
asynMotorAxis *asynAxis = getAxis(pasynUser);
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
|
||||
if (axis == nullptr) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nAxis is not an "
|
||||
"instance of sinqAxis",
|
||||
portName, axis->axisNo(), __PRETTY_FUNCTION__, __LINE__);
|
||||
return asynError;
|
||||
}
|
||||
|
||||
// Handle custom PVs
|
||||
if (function == motorEnable_) {
|
||||
return axis->enable(value != 0);
|
||||
} else if (function == motorReset_) {
|
||||
return axis->reset();
|
||||
} else if (function == motorForceStop_) {
|
||||
return axis->stop(0.0);
|
||||
} else {
|
||||
return asynMotorController::writeInt32(pasynUser, value);
|
||||
}
|
||||
}
|
||||
|
||||
asynStatus sinqController::readInt32(asynUser *pasynUser, epicsInt32 *value) {
|
||||
|
||||
// Casting into a sinqAxis is necessary to get access to the field axisNo()
|
||||
asynMotorAxis *asynAxis = getAxis(pasynUser);
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
|
||||
if (axis == nullptr) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nAxis is not an "
|
||||
"instance of sinqAxis.\n",
|
||||
portName, axis->axisNo(), __PRETTY_FUNCTION__, __LINE__);
|
||||
return asynError;
|
||||
}
|
||||
|
||||
if (pasynUser->reason == motorEnableRBV_) {
|
||||
return getIntegerParam(axis->axisNo(), motorEnableRBV_, value);
|
||||
} else if (pasynUser->reason == motorCanDisable_) {
|
||||
return getIntegerParam(axis->axisNo(), motorCanDisable_, value);
|
||||
} else {
|
||||
return asynMotorController::readInt32(pasynUser, value);
|
||||
}
|
||||
}
|
||||
|
||||
asynStatus sinqController::couldNotParseResponse(const char *command,
|
||||
const char *response,
|
||||
int axisNo,
|
||||
const char *functionName,
|
||||
int line) {
|
||||
asynStatus pl_status = asynSuccess;
|
||||
|
||||
asynPrint(pasynOctetSyncIOipPort_, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nCould not interpret "
|
||||
"response \"%s\" for command \"%s\".\n",
|
||||
portName, axisNo, functionName, line, response, command);
|
||||
|
||||
pl_status = setStringParam(
|
||||
motorMessageText_,
|
||||
"Could not interpret MCU response. Please call the software support");
|
||||
setIntegerParam(motorStatusCommsError_, 1);
|
||||
"Could not interpret controller response. Please call the support");
|
||||
if (pl_status != asynSuccess) {
|
||||
return paramLibAccessFailed(pl_status, "motorMessageText_", axisNo,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
pl_status = setIntegerParam(motorStatusCommsError_, 1);
|
||||
if (pl_status != asynSuccess) {
|
||||
return paramLibAccessFailed(pl_status, "motorStatusCommsError_", axisNo,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
return asynError;
|
||||
}
|
||||
|
||||
asynStatus sinqController::paramLibAccessFailed(asynStatus status,
|
||||
const char *parameter,
|
||||
int axisNo,
|
||||
const char *functionName,
|
||||
int lineNumber) {
|
||||
int line) {
|
||||
|
||||
if (status != asynSuccess) {
|
||||
// Log the error message and try to propagate it
|
||||
asynPrint(lowLevelPortUser_, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\n Accessing the parameter library failed for "
|
||||
"parameter %s.\n",
|
||||
functionName, lineNumber, parameter);
|
||||
setStringParam(
|
||||
motorMessageText_,
|
||||
"Accessing paramLib failed. Please call the software support.");
|
||||
asynPrint(pasynOctetSyncIOipPort_, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\n Accessing the "
|
||||
"parameter library failed for parameter %s with error %s.\n",
|
||||
portName, axisNo, functionName, line, parameter,
|
||||
stringifyAsynStatus(status));
|
||||
|
||||
// Log the error message and try to propagate it. If propagating fails,
|
||||
// there is nothing we can do here anyway.
|
||||
setStringParam(motorMessageText_,
|
||||
"Accessing paramLib failed. Please call the support.");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
asynStatus sinqController::checkComTimeoutWatchdog(int axisNo,
|
||||
char *motorMessage,
|
||||
size_t motorMessageSize) {
|
||||
|
||||
asynStatus paramLibStatus = asynSuccess;
|
||||
|
||||
// Add a new timeout event to the queue
|
||||
timeoutEvents_.push_back(time(NULL));
|
||||
|
||||
// Remove every event which is older than the time window from the deque
|
||||
while (1) {
|
||||
if (timeoutEvents_.empty()) {
|
||||
break;
|
||||
}
|
||||
if (timeoutEvents_[0] + comTimeoutWindow_ <= time(NULL)) {
|
||||
timeoutEvents_.pop_front();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the maximum allowed number of events has been exceeded
|
||||
bool wantToPrint = timeoutEvents_.size() > maxNumberTimeouts_;
|
||||
|
||||
if (msgPrintControl_.shouldBePrinted(portName, axisNo, __PRETTY_FUNCTION__,
|
||||
__LINE__, wantToPrint,
|
||||
pasynUserSelf)) {
|
||||
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nMore than %ld "
|
||||
"communication timeouts in %ld "
|
||||
"seconds.%s\n",
|
||||
portName, axisNo, __PRETTY_FUNCTION__, __LINE__,
|
||||
maxNumberTimeouts_, comTimeoutWindow_,
|
||||
msgPrintControl_.getSuffix());
|
||||
}
|
||||
|
||||
if (wantToPrint) {
|
||||
snprintf(motorMessage, motorMessageSize,
|
||||
"More than %ld communication timeouts in %ld seconds. Please "
|
||||
"call the support.",
|
||||
maxNumberTimeouts_, comTimeoutWindow_);
|
||||
|
||||
paramLibStatus = setIntegerParam(motorStatusCommsError_, 1);
|
||||
if (paramLibStatus != asynSuccess) {
|
||||
return paramLibAccessFailed(paramLibStatus,
|
||||
"motorStatusCommsError_", axisNo,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
return asynError;
|
||||
} else {
|
||||
return asynSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
asynStatus sinqController::checkComTimeoutWatchdog(sinqAxis *axis) {
|
||||
|
||||
char motorMessage[200] = {0};
|
||||
|
||||
asynStatus status =
|
||||
checkComTimeoutWatchdog(axis->axisNo(), motorMessage, 200);
|
||||
if (status == asynError) {
|
||||
status = axis->setStringParam(motorMessageText_, motorMessage);
|
||||
if (status != asynSuccess) {
|
||||
return paramLibAccessFailed(status, "motorMessageText_",
|
||||
axis->axisNo(), __PRETTY_FUNCTION__,
|
||||
__LINE__);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
|
||||
char *motorMessage,
|
||||
size_t motorMessageSize) {
|
||||
asynStatus paramLibStatus = asynSuccess;
|
||||
|
||||
if (timeoutNo >= maxSubsequentTimeouts_) {
|
||||
if (!maxSubsequentTimeoutsExceeded_) {
|
||||
snprintf(motorMessage, motorMessageSize,
|
||||
"Communication timeout between IOC and motor controller. "
|
||||
"Trying to reconnect ...");
|
||||
asynPrint(
|
||||
this->pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nMore than %d "
|
||||
"subsequent communication timeouts. Check whether the "
|
||||
"controller is still running and connected to the network.\n",
|
||||
this->portName, axisNo, __PRETTY_FUNCTION__, __LINE__,
|
||||
maxSubsequentTimeouts_);
|
||||
|
||||
paramLibStatus = setIntegerParam(motorStatusCommsError_, 1);
|
||||
if (paramLibStatus != asynSuccess) {
|
||||
return paramLibAccessFailed(paramLibStatus,
|
||||
"motorStatusCommsError_", axisNo,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
maxSubsequentTimeoutsExceeded_ = true;
|
||||
}
|
||||
|
||||
return asynError;
|
||||
} else {
|
||||
maxSubsequentTimeoutsExceeded_ = false;
|
||||
motorMessage[0] = '\0';
|
||||
return asynSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo,
|
||||
sinqAxis *axis) {
|
||||
|
||||
char motorMessage[200] = {0};
|
||||
|
||||
asynStatus status = checkMaxSubsequentTimeouts(timeoutNo, axis->axisNo(),
|
||||
motorMessage, 200);
|
||||
if (status == asynError) {
|
||||
status = axis->setStringParam(motorMessageText_, motorMessage);
|
||||
if (status != asynSuccess) {
|
||||
return paramLibAccessFailed(status, "motorMessageText_",
|
||||
axis->axisNo(), __PRETTY_FUNCTION__,
|
||||
__LINE__);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// Static pointers (valid for the entire lifetime of the IOC). The number behind
|
||||
// the strings gives the integer number of each variant (see also method
|
||||
// stringifyAsynStatus)
|
||||
@ -186,161 +600,131 @@ const char *sinqController::stringifyAsynStatus(asynStatus status) {
|
||||
return asynParamInvalidListStringified;
|
||||
}
|
||||
|
||||
asynPrint(
|
||||
pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"%s => line %d:\nInput did not match any variant of asynStatus.\n",
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
|
||||
"%s, line %d:\nInput did not match any "
|
||||
"variant of asynStatus.\n",
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
|
||||
return inputDidNotMatchAsynStatus;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Provide the setters to IOC shell
|
||||
// IOC shell functions
|
||||
extern "C" {
|
||||
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* @brief Enable / disable the watchdog (FFI implementation)
|
||||
* @brief Set the threshold for the communication timeout frequency (FFI
|
||||
* implementation)
|
||||
*
|
||||
* @param portName Name of the controller
|
||||
* @param axisNo Axis number
|
||||
* @param enable If 0, disable the watchdog, otherwise enable
|
||||
* it
|
||||
* @param comTimeoutWindow Size of the time window used to calculate
|
||||
* the moving average of timeout events in seconds. Set this value to 0 to
|
||||
* deactivate the watchdog.
|
||||
* @param maxNumberTimeouts Maximum number of timeouts which may occur
|
||||
* within the time window before the watchdog is triggered.
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus setWatchdogEnabled(const char *portName, int axisNo, int enable) {
|
||||
asynStatus setThresholdComTimeout(const char *portName, int comTimeoutWindow,
|
||||
int maxNumberTimeouts) {
|
||||
|
||||
sinqController *pC;
|
||||
pC = (sinqController *)findAsynPortDriver(portName);
|
||||
if (pC == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nPort %s not found.", __PRETTY_FUNCTION__,
|
||||
__LINE__, portName);
|
||||
errlogPrintf("Controller \"%s\" => %s, line %d:\nPort %s not found.",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__, portName);
|
||||
return asynError;
|
||||
}
|
||||
|
||||
asynMotorAxis *asynAxis = pC->getAxis(axisNo);
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
if (axis == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nAxis %d does not exist or is not an "
|
||||
"instance of sinqAxis.",
|
||||
__PRETTY_FUNCTION__, __LINE__, axisNo);
|
||||
}
|
||||
|
||||
return axis->setWatchdogEnabled(enable != 0);
|
||||
return pC->setThresholdComTimeout(comTimeoutWindow, maxNumberTimeouts);
|
||||
}
|
||||
|
||||
static const iocshArg setWatchdogEnabledArg0 = {"Controller port name",
|
||||
iocshArgString};
|
||||
static const iocshArg setWatchdogEnabledArg1 = {"Axis number", iocshArgInt};
|
||||
static const iocshArg setWatchdogEnabledArg2 = {
|
||||
"Enabling / disabling the watchdog", iocshArgInt};
|
||||
static const iocshArg *const setWatchdogEnabledArgs[] = {
|
||||
&setWatchdogEnabledArg0, &setWatchdogEnabledArg1, &setWatchdogEnabledArg2};
|
||||
static const iocshFuncDef setWatchdogEnabledDef = {"setWatchdogEnabled", 3,
|
||||
setWatchdogEnabledArgs};
|
||||
static const iocshArg setThresholdComTimeoutArg0 = {"Controller port name",
|
||||
iocshArgString};
|
||||
static const iocshArg setThresholdComTimeoutArg1 = {
|
||||
"Time window communication timeout frequency", iocshArgInt};
|
||||
static const iocshArg setThresholdComTimeoutArg2 = {
|
||||
"Maximum allowed number of communication timeouts within the window",
|
||||
iocshArgInt};
|
||||
static const iocshArg *const setThresholdComTimeoutArgs[] = {
|
||||
&setThresholdComTimeoutArg0, &setThresholdComTimeoutArg1,
|
||||
&setThresholdComTimeoutArg2};
|
||||
static const iocshFuncDef setThresholdComTimeoutDef = {
|
||||
"setThresholdComTimeout", 3, setThresholdComTimeoutArgs};
|
||||
|
||||
static void setWatchdogEnabledCallFunc(const iocshArgBuf *args) {
|
||||
setWatchdogEnabled(args[0].sval, args[1].ival, args[2].ival);
|
||||
static void setThresholdComTimeoutCallFunc(const iocshArgBuf *args) {
|
||||
setThresholdComTimeout(args[0].sval, args[1].ival, args[2].ival);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* @brief Set the offsetMovTimeout (FFI implementation)
|
||||
* @brief Set the maximum number of subsequent timeouts (FFI implementation)
|
||||
*
|
||||
* @param portName Name of the controller
|
||||
* @param axisNo Axis number
|
||||
* @param offsetMovTimeout Offset (in seconds)
|
||||
* @param comTimeoutWindow Size of the time window used to calculate
|
||||
* the moving average of timeout events. Set this value to 0 to deactivate
|
||||
* the watchdog.
|
||||
* @param maxNumberTimeouts Maximum number of timeouts which may occur
|
||||
* within the time window before the watchdog is triggered.
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus setOffsetMovTimeout(const char *portName, int axisNo,
|
||||
double offsetMovTimeout) {
|
||||
asynStatus setMaxSubsequentTimeouts(const char *portName,
|
||||
int maxSubsequentTimeouts) {
|
||||
void *ptr = findAsynPortDriver(portName);
|
||||
if (ptr == nullptr) {
|
||||
/*
|
||||
We can't use asynPrint here since this macro would require us
|
||||
to get a pasynOctetSyncIOipPort_ from a pointer to an asynPortDriver.
|
||||
However, the given pointer is a nullptr and therefore doesn't
|
||||
have a pasynOctetSyncIOipPort_! printf is an EPICS alternative which
|
||||
works w/o that, but doesn't offer the comfort provided
|
||||
by the asynTrace-facility
|
||||
*/
|
||||
errlogPrintf("Controller \"%s\" => %s, line %d:\nPort %s not found.",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__, portName);
|
||||
return asynError;
|
||||
}
|
||||
// Unsafe cast of the pointer to an asynPortDriver
|
||||
asynPortDriver *apd = (asynPortDriver *)(ptr);
|
||||
|
||||
sinqController *pC;
|
||||
pC = (sinqController *)findAsynPortDriver(portName);
|
||||
// Safe downcast
|
||||
sinqController *pC = dynamic_cast<sinqController *>(apd);
|
||||
if (pC == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nPort %s not found.", __PRETTY_FUNCTION__,
|
||||
__LINE__, portName);
|
||||
errlogPrintf(
|
||||
"Controller \"%s\" => %s, line %d:\ncontroller on port %s is not a "
|
||||
"turboPmacController.",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__, portName);
|
||||
return asynError;
|
||||
}
|
||||
|
||||
asynMotorAxis *asynAxis = pC->getAxis(axisNo);
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
if (axis == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nAxis %d does not exist or is not an "
|
||||
"instance of sinqAxis.",
|
||||
__PRETTY_FUNCTION__, __LINE__, axisNo);
|
||||
}
|
||||
// Set the new value
|
||||
pC->setMaxSubsequentTimeouts(maxSubsequentTimeouts);
|
||||
|
||||
return axis->setOffsetMovTimeout(offsetMovTimeout);
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
static const iocshArg setOffsetMovTimeoutArg0 = {"Controller port name",
|
||||
iocshArgString};
|
||||
static const iocshArg setOffsetMovTimeoutArg1 = {"Axis number", iocshArgInt};
|
||||
static const iocshArg setOffsetMovTimeoutArg2 = {"Offset timeout for movement",
|
||||
iocshArgDouble};
|
||||
static const iocshArg *const setOffsetMovTimeoutArgs[] = {
|
||||
&setOffsetMovTimeoutArg0, &setOffsetMovTimeoutArg1,
|
||||
&setOffsetMovTimeoutArg2};
|
||||
static const iocshFuncDef setOffsetMovTimeoutDef = {"setOffsetMovTimeout", 3,
|
||||
setOffsetMovTimeoutArgs};
|
||||
|
||||
static void setOffsetMovTimeoutCallFunc(const iocshArgBuf *args) {
|
||||
setOffsetMovTimeout(args[0].sval, args[1].ival, args[2].dval);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* @brief Set the setScaleMovTimeout (FFI implementation)
|
||||
*
|
||||
* @param portName Name of the controller
|
||||
* @param axisNo Axis number
|
||||
* @param scaleMovTimeout Scaling factor (in seconds)
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus setScaleMovTimeout(const char *portName, int axisNo,
|
||||
double scaleMovTimeout) {
|
||||
|
||||
sinqController *pC;
|
||||
pC = (sinqController *)findAsynPortDriver(portName);
|
||||
if (pC == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nPort %s not found.", __PRETTY_FUNCTION__,
|
||||
__LINE__, portName);
|
||||
return asynError;
|
||||
}
|
||||
|
||||
asynMotorAxis *asynAxis = pC->getAxis(axisNo);
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
if (axis == nullptr) {
|
||||
errlogPrintf("%s => line %d:\nAxis %d does not exist or is not an "
|
||||
"instance of sinqAxis.",
|
||||
__PRETTY_FUNCTION__, __LINE__, axisNo);
|
||||
}
|
||||
|
||||
return axis->setScaleMovTimeout(scaleMovTimeout);
|
||||
}
|
||||
|
||||
static const iocshArg setScaleMovTimeoutArg0 = {"Controller port name",
|
||||
iocshArgString};
|
||||
static const iocshArg setScaleMovTimeoutArg1 = {"Axis number", iocshArgInt};
|
||||
static const iocshArg setScaleMovTimeoutArg2 = {
|
||||
"Multiplier for calculated move time", iocshArgDouble};
|
||||
static const iocshArg *const setScaleMovTimeoutArgs[] = {
|
||||
&setScaleMovTimeoutArg0, &setScaleMovTimeoutArg1, &setScaleMovTimeoutArg2};
|
||||
static const iocshFuncDef setScaleMovTimeoutDef = {"setScaleMovTimeout", 3,
|
||||
setScaleMovTimeoutArgs};
|
||||
|
||||
static void setScaleMovTimeoutCallFunc(const iocshArgBuf *args) {
|
||||
setScaleMovTimeout(args[0].sval, args[1].ival, args[2].dval);
|
||||
static const iocshArg SetMaxSubsequentTimeoutsArg0 = {
|
||||
"Controller name (e.g. mcu1)", iocshArgString};
|
||||
static const iocshArg SetMaxSubsequentTimeoutsArg1 = {
|
||||
"Maximum number of subsequent timeouts before the user receives an error "
|
||||
"message",
|
||||
iocshArgInt};
|
||||
static const iocshArg *const SetMaxSubsequentTimeoutsArgs[] = {
|
||||
&SetMaxSubsequentTimeoutsArg0, &SetMaxSubsequentTimeoutsArg1};
|
||||
static const iocshFuncDef setMaxSubsequentTimeoutsDef = {
|
||||
"setMaxSubsequentTimeouts", 2, SetMaxSubsequentTimeoutsArgs};
|
||||
static void setMaxSubsequentTimeoutsCallFunc(const iocshArgBuf *args) {
|
||||
setMaxSubsequentTimeouts(args[0].sval, args[1].ival);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
// This function is made known to EPICS in sinqMotor.dbd and is called by EPICS
|
||||
// in order to register all functions in the IOC shell
|
||||
static void sinqControllerRegister(void) {
|
||||
iocshRegister(&setOffsetMovTimeoutDef, setOffsetMovTimeoutCallFunc);
|
||||
iocshRegister(&setScaleMovTimeoutDef, setScaleMovTimeoutCallFunc);
|
||||
iocshRegister(&setWatchdogEnabledDef, setWatchdogEnabledCallFunc);
|
||||
iocshRegister(&setThresholdComTimeoutDef, setThresholdComTimeoutCallFunc);
|
||||
iocshRegister(&setMaxSubsequentTimeoutsDef,
|
||||
setMaxSubsequentTimeoutsCallFunc);
|
||||
}
|
||||
epicsExportRegistrar(sinqControllerRegister);
|
||||
|
||||
|
@ -1,15 +1,23 @@
|
||||
/*
|
||||
This class extends asynMotorController by some features used in SINQ.
|
||||
This class extends asynMotorController by some features used in SINQ. See the
|
||||
README.md for details.
|
||||
|
||||
Stefan Mathis, November 2024
|
||||
*/
|
||||
|
||||
#ifndef __sinqController
|
||||
#define __sinqController
|
||||
#ifndef sinqController_H
|
||||
#define sinqController_H
|
||||
#include "asynMotorController.h"
|
||||
#include "msgPrintControl.h"
|
||||
#include <deque>
|
||||
#include <initHooks.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#define motorMessageIsFromDriverString "MOTOR_MESSAGE_DRIVER"
|
||||
#define motorMessageTextString "MOTOR_MESSAGE_TEXT"
|
||||
#define IncrementalEncoder "incremental"
|
||||
#define AbsoluteEncoder "absolute"
|
||||
#define NoEncoder "none"
|
||||
|
||||
class epicsShareClass sinqController : public asynMotorController {
|
||||
public:
|
||||
@ -24,17 +32,17 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
pAxes_ which has the length specified here. When getting an axis, the
|
||||
`getAxis` function indexes into this array. A length of 8 would therefore
|
||||
mean that the axis slots 0 to 7 are available. However, in order to keep the
|
||||
axis enumeration in sync with the electronics counting logic, we start
|
||||
counting the axes with 1 and end at 8. Therefore, an offset of 1 is added
|
||||
when forwarding this number to asynMotorController.
|
||||
axis enumeration identical to that of the hardware, we start counting the
|
||||
axes with 1 and end at 8. Therefore, an offset of 1 is added when forwarding
|
||||
this number to asynMotorController.
|
||||
* @param movingPollPeriod Time between polls when moving (in seconds)
|
||||
* @param idlePollPeriod Time between polls when not moving (in
|
||||
seconds)
|
||||
* @param extraParams Number of extra parameter library entries
|
||||
* created in a concrete driver implementation
|
||||
*/
|
||||
sinqController(const char *portName, const char *SINQPortName, int numAxes,
|
||||
double movingPollPeriod, double idlePollPeriod,
|
||||
sinqController(const char *portName, const char *ipPortConfigName,
|
||||
int numAxes, double movingPollPeriod, double idlePollPeriod,
|
||||
int numExtraParams);
|
||||
|
||||
/**
|
||||
@ -46,14 +54,35 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
*/
|
||||
virtual ~sinqController(void);
|
||||
|
||||
friend class sinqAxis;
|
||||
/**
|
||||
* @brief Overloaded function of asynMotorController
|
||||
*
|
||||
* The function is overloaded to allow enabling / disabling the motor.
|
||||
*
|
||||
* @param pasynUser Specify the axis via the asynUser
|
||||
* @param value New value
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
|
||||
|
||||
/**
|
||||
* @brief Overloaded function of asynMotorController
|
||||
*
|
||||
* The function is overloaded to get readback values for the enabling /
|
||||
* disabling status.
|
||||
*
|
||||
* @param pasynUser Specify the axis via the asynUser
|
||||
* @param value Read-out value
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
|
||||
|
||||
/**
|
||||
* @brief Error handling in case accessing the parameter library failed.
|
||||
*
|
||||
* If accessing the parameter library failed (return status !=
|
||||
asynSuccess), calling this function writes a standardized message to both
|
||||
the IOC shell and the motor message text PV. It then returns the input
|
||||
the IOC shell and the motorMessageText PV. It then returns the input
|
||||
status.
|
||||
*
|
||||
* @param status Status of the failed parameter library access
|
||||
@ -61,12 +90,13 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
error messages.
|
||||
* @param functionName Name of the caller function. It is recommended
|
||||
to use a macro, e.g. __func__ or __PRETTY_FUNCTION__.
|
||||
* @param lineNumber Source code line where this function is
|
||||
* @param line Source code line where this function is
|
||||
called. It is recommended to use a macro, e.g. __LINE__.
|
||||
* @return asynStatus Returns input status.
|
||||
*/
|
||||
asynStatus paramLibAccessFailed(asynStatus status, const char *parameter,
|
||||
const char *functionName, int lineNumber);
|
||||
int axisNo, const char *functionName,
|
||||
int line);
|
||||
|
||||
/**
|
||||
* @brief Error handling in case parsing a command response failed.
|
||||
@ -81,14 +111,13 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
* @param axisNo_ Axis where the problem occurred
|
||||
* @param functionName Name of the caller function. It is recommended
|
||||
to use a macro, e.g. __func__ or __PRETTY_FUNCTION__.
|
||||
* @param lineNumber Source code line where this function is
|
||||
* @param line Source code line where this function is
|
||||
called. It is recommended to use a macro, e.g. __LINE__.
|
||||
* @return asynStatus Returns asynError.
|
||||
*/
|
||||
asynStatus errMsgCouldNotParseResponse(const char *command,
|
||||
const char *response, int axisNo_,
|
||||
const char *functionName,
|
||||
int lineNumber);
|
||||
asynStatus couldNotParseResponse(const char *command, const char *response,
|
||||
int axisNo, const char *functionName,
|
||||
int line);
|
||||
|
||||
/**
|
||||
* @brief Convert an asynStatus into a descriptive string.
|
||||
@ -98,10 +127,250 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
*/
|
||||
const char *stringifyAsynStatus(asynStatus status);
|
||||
|
||||
/**
|
||||
* @brief This function should be called when a communication timeout
|
||||
occured. It calculates the frequency of communication timeout events and
|
||||
creates an error message, if an threshold has been exceeded.
|
||||
|
||||
Occasionally, communication timeouts between the IOC and the motor
|
||||
controller may happen, usually because the controller takes too long to
|
||||
respond. If this happens infrequently, this is not a problem. However, if it
|
||||
happens very often, this may indicate a network problem and must therefore
|
||||
be forwarded to the user. This is checked by calculating the moving average
|
||||
of events and comparing it to a threshhold. Both the threshold and the time
|
||||
window for the moving average can be configured in the IOC via the function
|
||||
setThresholdCom.
|
||||
|
||||
This function exists in two variants: Either the error message can be
|
||||
written into a buffer provided by the caller or it written directly into the
|
||||
parameter library of the provided axis.
|
||||
|
||||
* @param axis Axis to which the error message is sent
|
||||
*
|
||||
* @return asynStatus asynError, if the threshold has been
|
||||
exceeded, asynSuccess otherwise
|
||||
*/
|
||||
virtual asynStatus checkComTimeoutWatchdog(class sinqAxis *axis);
|
||||
|
||||
/**
|
||||
* @brief See documentation of checkComTimeoutWatchdog(sinqAxis * axis)
|
||||
*
|
||||
* @param userMessage Buffer for the user message
|
||||
* @param userMessageSize Buffer size in chars
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus checkComTimeoutWatchdog(int axisNo, char *motorMessage,
|
||||
size_t motorMessageSize);
|
||||
|
||||
/**
|
||||
* @brief Set the threshold for the communication timeout mechanism
|
||||
*
|
||||
* @param comTimeoutWindow Size of the time window used to calculate
|
||||
* the moving average of timeout events. Set this value to 0 to deactivate
|
||||
* the watchdog.
|
||||
* @param maxNumberTimeouts Maximum number of timeouts which may occur
|
||||
* within the time window before the watchdog is triggered.
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus setThresholdComTimeout(time_t comTimeoutWindow,
|
||||
size_t maxNumberTimeouts) {
|
||||
comTimeoutWindow_ = comTimeoutWindow;
|
||||
maxNumberTimeouts_ = maxNumberTimeouts;
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inform the user, if the number of timeouts exceeds the threshold
|
||||
* specified with `setMaxSubsequentTimeouts`.
|
||||
*
|
||||
* @param timeoutNo Number of subsequent timeouts which already
|
||||
* happened.
|
||||
* @param axis
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus checkMaxSubsequentTimeouts(int timeoutNo,
|
||||
class sinqAxis *axis);
|
||||
|
||||
/**
|
||||
* @brief See documentation of `checkMaxSubsequentTimeouts(sinqAxis * axis)`
|
||||
*
|
||||
* @param userMessage Buffer for the user message
|
||||
* @param userMessageSize Buffer size in chars
|
||||
* @return asynStatus
|
||||
*/
|
||||
virtual asynStatus checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
|
||||
char *motorMessage,
|
||||
size_t motorMessageSize);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum number of subsequent timeouts before the user is
|
||||
* informed.
|
||||
*
|
||||
* @param maxSubsequentTimeouts
|
||||
* @return asynStatus
|
||||
*/
|
||||
asynStatus setMaxSubsequentTimeouts(int maxSubsequentTimeouts) {
|
||||
maxSubsequentTimeouts_ = maxSubsequentTimeouts;
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a reference to the map used to control the maximum number of
|
||||
* message repetitions. See the documentation of `printRepetitionWatchdog`
|
||||
* in msgPrintControl.h for details.
|
||||
*/
|
||||
msgPrintControl &getMsgPrintControl();
|
||||
|
||||
// =========================================================================
|
||||
// Public getters for protected members
|
||||
|
||||
// Accessors for double parameters
|
||||
int motorMoveRel() { return motorMoveRel_; }
|
||||
int motorMoveAbs() { return motorMoveAbs_; }
|
||||
int motorMoveVel() { return motorMoveVel_; }
|
||||
int motorHome() { return motorHome_; }
|
||||
int motorStop() { return motorStop_; }
|
||||
int motorVelocity() { return motorVelocity_; }
|
||||
int motorVelBase() { return motorVelBase_; }
|
||||
int motorAccel() { return motorAccel_; }
|
||||
int motorPosition() { return motorPosition_; }
|
||||
int motorEncoderPosition() { return motorEncoderPosition_; }
|
||||
int motorDeferMoves() { return motorDeferMoves_; }
|
||||
int motorMoveToHome() { return motorMoveToHome_; }
|
||||
int motorResolution() { return motorResolution_; }
|
||||
int motorEncoderRatio() { return motorEncoderRatio_; }
|
||||
int motorPGain() { return motorPGain_; }
|
||||
int motorIGain() { return motorIGain_; }
|
||||
int motorDGain() { return motorDGain_; }
|
||||
int motorHighLimit() { return motorHighLimit_; }
|
||||
int motorLowLimit() { return motorLowLimit_; }
|
||||
int motorClosedLoop() { return motorClosedLoop_; }
|
||||
int motorPowerAutoOnOff() { return motorPowerAutoOnOff_; }
|
||||
int motorPowerOnDelay() { return motorPowerOnDelay_; }
|
||||
int motorPowerOffDelay() { return motorPowerOffDelay_; }
|
||||
int motorPowerOffFraction() { return motorPowerOffFraction_; }
|
||||
int motorPostMoveDelay() { return motorPostMoveDelay_; }
|
||||
int motorStatus() { return motorStatus_; }
|
||||
int motorUpdateStatus() { return motorUpdateStatus_; }
|
||||
|
||||
// Accessors for status bits (integers)
|
||||
int motorStatusDirection() { return motorStatusDirection_; }
|
||||
int motorStatusDone() { return motorStatusDone_; }
|
||||
int motorStatusHighLimit() { return motorStatusHighLimit_; }
|
||||
int motorStatusAtHome() { return motorStatusAtHome_; }
|
||||
int motorStatusSlip() { return motorStatusSlip_; }
|
||||
int motorStatusPowerOn() { return motorStatusPowerOn_; }
|
||||
int motorStatusFollowingError() { return motorStatusFollowingError_; }
|
||||
int motorStatusHome() { return motorStatusHome_; }
|
||||
int motorStatusHasEncoder() { return motorStatusHasEncoder_; }
|
||||
int motorStatusProblem() { return motorStatusProblem_; }
|
||||
int motorStatusMoving() { return motorStatusMoving_; }
|
||||
int motorStatusGainSupport() { return motorStatusGainSupport_; }
|
||||
int motorStatusCommsError() { return motorStatusCommsError_; }
|
||||
int motorStatusLowLimit() { return motorStatusLowLimit_; }
|
||||
int motorStatusHomed() { return motorStatusHomed_; }
|
||||
|
||||
// Parameters for passing additional motor record information to the driver
|
||||
int motorRecResolution() { return motorRecResolution_; }
|
||||
int motorRecDirection() { return motorRecDirection_; }
|
||||
int motorRecOffset() { return motorRecOffset_; }
|
||||
|
||||
// Accessors for additional PVs defined in sinqController
|
||||
int motorMessageText() { return motorMessageText_; }
|
||||
int motorReset() { return motorReset_; }
|
||||
int motorEnable() { return motorEnable_; }
|
||||
int motorEnableRBV() { return motorEnableRBV_; }
|
||||
int motorCanDisable() { return motorCanDisable_; }
|
||||
int motorEnableMovWatchdog() { return motorEnableMovWatchdog_; }
|
||||
int motorCanSetSpeed() { return motorCanSetSpeed_; }
|
||||
int motorLimitsOffset() { return motorLimitsOffset_; }
|
||||
int motorForceStop() { return motorForceStop_; }
|
||||
int motorConnected() { return motorConnected_; }
|
||||
int motorVeloFromDriver() { return motorVeloFromDriver_; }
|
||||
int motorVbasFromDriver() { return motorVbasFromDriver_; }
|
||||
int motorVmaxFromDriver() { return motorVmaxFromDriver_; }
|
||||
int motorAcclFromDriver() { return motorAcclFromDriver_; }
|
||||
int motorHighLimitFromDriver() { return motorHighLimitFromDriver_; }
|
||||
int motorLowLimitFromDriver() { return motorLowLimitFromDriver_; }
|
||||
int adaptivePolling() { return adaptivePolling_; }
|
||||
int encoderType() { return encoderType_; }
|
||||
|
||||
// Additional members
|
||||
int numAxes() { return numAxes_; }
|
||||
double idlePollPeriod() { return idlePollPeriod_; }
|
||||
double movingPollPeriod() { return movingPollPeriod_; }
|
||||
|
||||
/**
|
||||
* @brief Return a pointer to the asynUser of the controller
|
||||
*
|
||||
* @return asynUser*
|
||||
*/
|
||||
asynUser *pasynUser() { return pasynUserSelf; }
|
||||
|
||||
/**
|
||||
* @brief Return a pointer to the low-level octet (string) IP Port
|
||||
*
|
||||
* @return asynUser*
|
||||
*/
|
||||
asynUser *pasynOctetSyncIOipPort() { return pasynOctetSyncIOipPort_; }
|
||||
|
||||
// =========================================================================
|
||||
|
||||
protected:
|
||||
asynUser *lowLevelPortUser_;
|
||||
// Pointer to the port user which is specified by the char array
|
||||
// `ipPortConfigName` in the constructor
|
||||
asynUser *pasynOctetSyncIOipPort_;
|
||||
double movingPollPeriod_;
|
||||
double idlePollPeriod_;
|
||||
msgPrintControl msgPrintControl_;
|
||||
|
||||
// Internal variables used in the communication timeout frequency watchdog
|
||||
time_t comTimeoutWindow_; // Size of the time window
|
||||
size_t maxNumberTimeouts_; // Maximum acceptable number of events within the
|
||||
// time window
|
||||
std::deque<time_t>
|
||||
timeoutEvents_; // Deque holding the timestamps of the individual events
|
||||
|
||||
// Communicate a timeout to the user after it has happened this many times
|
||||
// in a row
|
||||
int maxSubsequentTimeouts_;
|
||||
bool maxSubsequentTimeoutsExceeded_;
|
||||
|
||||
/*
|
||||
See the documentation in db/sinqMotor.db for the following integers
|
||||
*/
|
||||
#define FIRST_SINQMOTOR_PARAM motorMessageText_
|
||||
int motorMessageText_;
|
||||
int motorTargetPosition_;
|
||||
int motorReset_;
|
||||
int motorEnable_;
|
||||
int motorEnableRBV_;
|
||||
int motorCanDisable_;
|
||||
int motorEnableMovWatchdog_;
|
||||
int motorCanSetSpeed_;
|
||||
int motorLimitsOffset_;
|
||||
int motorForceStop_;
|
||||
int motorConnected_;
|
||||
/*
|
||||
These parameters are here to write values from the hardware to the EPICS
|
||||
motor record. Using motorHighLimit_ / motorLowLimit_ does not work:
|
||||
https://epics.anl.gov/tech-talk/2023/msg00576.php. Therefore, some
|
||||
additional records are introduced which read from these parameters and write
|
||||
into the motor record.
|
||||
*/
|
||||
int motorVeloFromDriver_;
|
||||
int motorVbasFromDriver_;
|
||||
int motorVmaxFromDriver_;
|
||||
int motorAcclFromDriver_;
|
||||
int motorHighLimitFromDriver_;
|
||||
int motorLowLimitFromDriver_;
|
||||
int adaptivePolling_;
|
||||
int encoderType_;
|
||||
#define LAST_SINQMOTOR_PARAM encoderType_
|
||||
|
||||
private:
|
||||
static void epicsInithookFunction(initHookState iState);
|
||||
};
|
||||
#define NUM_SINQMOTOR_DRIVER_PARAMS \
|
||||
(&LAST_SINQMOTOR_PARAM - &FIRST_SINQMOTOR_PARAM + 1)
|
||||
|
||||
#endif
|
||||
|
@ -2,3 +2,4 @@
|
||||
# SINQ specific DB definitions
|
||||
#---------------------------------------------
|
||||
registrar(sinqControllerRegister)
|
||||
registrar(sinqAxisRegister)
|
||||
|
Reference in New Issue
Block a user