Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
3071e402b2 | |||
dd0610fd99 | |||
c7936191d9 | |||
3ec83b115e | |||
bfda809257 | |||
76a91d4a2f | |||
228bcf7fd7 | |||
db03ffea0e | |||
4c3254687d | |||
eb94379efe | |||
1dd132c709 |
92
README.md
92
README.md
@ -17,9 +17,48 @@ The full inheritance chain for two different motor drivers "a" and "b" looks lik
|
||||
`asynController -> sinqController -> bController`
|
||||
`asynAxis -> sinqAxis -> bAxis`
|
||||
|
||||
Those inheritance chains are created at runtime by loading shared libraries. Therefore, it is important to load compatible versions. At SINQ, the versioning numbers follow the SemVer standard (https://semver.org/lang/de/). For example, if driver "a" depends on version 2.1.0 of "sinqMotor", then it is safe to use "sinqMotor" 2.5.3 since 2.5.3 is backwards compatible to 2.1.0. However, it is not allowed to use e.g. version 1.9.0 or 2.0.0 or 3.0.1 instead. For more details on SemVer, please refer to the official documentation.
|
||||
Those inheritance chains are created at runtime by loading shared libraries. These libraries must be compatible to each other (see next section).
|
||||
|
||||
To find out which version of sinqMotor is needed by driver "a", refer to its Makefile (line `sinqMotor_VERSION=x.x.x`, where x.x.x is the minimum required version).
|
||||
### 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
|
||||
|
||||
@ -29,15 +68,15 @@ An EPICS IOC for motor control at SINQ is started by executing a script with the
|
||||
|
||||
# Load libraries needed for the IOC
|
||||
require sinqMotor, 1.0.0
|
||||
require turboPmac, 1.2.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
|
||||
< turboPmac1.cmd
|
||||
< turboPmac2.cmd
|
||||
< actualDriver.cmd
|
||||
< actualDriver.cmd
|
||||
|
||||
iocInit()
|
||||
```
|
||||
@ -46,11 +85,11 @@ The script for controller 1 ("turboPmac1.cmd") for a Turbo PMAC (see https://git
|
||||
|
||||
```
|
||||
# Define the name of the controller and the corresponding port
|
||||
epicsEnvSet("NAME","turboPmac1")
|
||||
epicsEnvSet("ASYN_PORT","p$(NAME)")
|
||||
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("$(ASYN_PORT)","172.28.101.24:1025")
|
||||
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:
|
||||
@ -58,25 +97,25 @@ drvAsynIPPortConfigure("$(ASYN_PORT)","172.28.101.24:1025")
|
||||
# 0.05: Busy poll period in seconds
|
||||
# 1: Idle poll period in seconds
|
||||
# 1: Socket communication timeout in seconds
|
||||
turboPmacController("$(NAME)", "$(ASYN_PORT)", 8, 0.05, 1, 1);
|
||||
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!
|
||||
turboPmacAxis("$(NAME)",1);
|
||||
turboPmacAxis("$(NAME)",2);
|
||||
turboPmacAxis("$(NAME)",5);
|
||||
actualDriverAxis("$(DRIVER_PORT)",1);
|
||||
actualDriverAxis("$(DRIVER_PORT)",2);
|
||||
actualDriverAxis("$(DRIVER_PORT)",5);
|
||||
|
||||
# Set the number of subsequent timeouts
|
||||
setMaxSubsequentTimeouts("$(NAME)", 20);
|
||||
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("$(NAME)", 300, 10);
|
||||
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)/$(NAME).substitutions", "INSTR=$(INSTR)$(NAME):,CONTROLLER=$(NAME)")
|
||||
epicsEnvSet("SINQDBPATH","$(turboPmac_DB)/turboPmac.db")
|
||||
dbLoadTemplate("$(TOP)/$(NAME).substitutions", "INSTR=$(INSTR)$(NAME):,CONTROLLER=$(NAME)")
|
||||
dbLoadRecords("$(sinqMotor_DB)/asynRecord.db","P=$(INSTR)$(NAME),PORT=$(ASYN_PORT)")
|
||||
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
|
||||
@ -87,11 +126,11 @@ To work with sinqMotor, "mcu1.substitutions" needs to look like this (the order
|
||||
file "$(SINQDBPATH)"
|
||||
{
|
||||
pattern
|
||||
{ AXIS, M, DESC, EGU, DIR, MRES, MSGTEXTSIZE, ENABLEMOVWATCHDOG, LIMITSOFFSET, CANSETSPEED }
|
||||
{ 1, "lin1", "Linear motor doing whatever", mm, Pos, 0.001, 200, 1, 1.0, 1 }
|
||||
{ 2, "rot1", "First rotary motor", degree, Neg, 0.001, 200, 0, 1.0, 0 }
|
||||
{ 3, "rot2", "Second rotary motor", degree, Pos, 0.001, 200, 0, 0.0, 1 }
|
||||
{ 5, "rot3", "Surprise: Third rotary motor", degree, Pos, 0.001, 200, 1, 2.0, 0 }
|
||||
{ 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`.
|
||||
@ -99,7 +138,7 @@ The variable `SINQDBPATH` has been set in "mcu1.cmd" before calling `dbLoadTempl
|
||||
#### 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, NAME and M. For example, the PV of the first axis would be "SQ:SINQTEST:mcu1:lin1".
|
||||
- `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).
|
||||
@ -114,6 +153,7 @@ be further reduced by this offset in order to avoid errors due to slight oversho
|
||||
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
|
||||
|
||||
@ -155,6 +195,10 @@ 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
|
||||
|
@ -23,7 +23,10 @@
|
||||
# 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.
|
||||
# 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=$(M))")
|
||||
@ -34,21 +37,33 @@ record(motor,"$(INSTR)$(M)")
|
||||
field(EGU,"$(EGU)")
|
||||
field(INIT,"")
|
||||
field(PINI,"NO")
|
||||
field(DHLM, "$(DHLM=0)")
|
||||
field(DLLM, "$(DLLM=0)")
|
||||
field(TWV,"1")
|
||||
field(RTRY,"0")
|
||||
field(RDBD,"0")
|
||||
field(BDST,"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.
|
||||
}
|
||||
|
||||
# This PV reads out the 10th bit of the MSTA field of the motor record, which
|
||||
# is the "motorStatusProblem_" bit. The 10th bit is adressed by 0x0200. If the
|
||||
# bit is 0, the .VAL field is 0 as well. If the bit is 1, we need to divide by
|
||||
# 512 (=2^9) in order to set the .VAL field to 1 (and not to 512).
|
||||
# is the "motorStatusProblem_" bit.
|
||||
record(calc, "$(INSTR)$(M):StatusProblem")
|
||||
{
|
||||
field(INPA, "$(INSTR)$(M).MSTA CP")
|
||||
field(CALC, "(A&0x200)/512")
|
||||
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
|
||||
@ -71,7 +86,7 @@ record(longin, "$(INSTR)$(M):StopRBV")
|
||||
field(FLNK, "$(INSTR)$(M):Stop2Field")
|
||||
}
|
||||
record(longout, "$(INSTR)$(M):Stop2Field") {
|
||||
field(DOL, "$(INSTR)$(M):StopRBV CP")
|
||||
field(DOL, "$(INSTR)$(M):StopRBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).STOP")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
@ -82,7 +97,7 @@ record(longout, "$(INSTR)$(M):Stop2Field") {
|
||||
# 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 MS")
|
||||
field(DOL, "$(INSTR)$(M).MRES CP")
|
||||
field(OMSL, "closed_loop")
|
||||
field(DTYP, "asynFloat64")
|
||||
field(OUT, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_REC_RESOLUTION")
|
||||
@ -142,6 +157,18 @@ record(longout, "$(INSTR)$(M):CanSetSpeed") {
|
||||
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.
|
||||
@ -175,14 +202,17 @@ record(ao, "$(INSTR)$(M):LimitsOffset") {
|
||||
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 CP")
|
||||
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_"
|
||||
@ -193,14 +223,17 @@ record(ao, "$(INSTR)$(M):PushDHLM2Field") {
|
||||
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 CP")
|
||||
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_"
|
||||
@ -216,7 +249,7 @@ record(ai, "$(INSTR)$(M):VELO_RBV")
|
||||
field(FLNK, "$(INSTR)$(M):PushVELO2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVELO2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VELO_RBV CP")
|
||||
field(DOL, "$(INSTR)$(M):VELO_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VELO")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
@ -234,7 +267,7 @@ record(ai, "$(INSTR)$(M):VBAS_RBV")
|
||||
field(FLNK, "$(INSTR)$(M):PushVBAS2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVBAS2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VBAS_RBV CP")
|
||||
field(DOL, "$(INSTR)$(M):VBAS_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VBAS")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
@ -252,7 +285,7 @@ record(ai, "$(INSTR)$(M):VMAX_RBV")
|
||||
field(FLNK, "$(INSTR)$(M):PushVMAX2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushVMAX2Field") {
|
||||
field(DOL, "$(INSTR)$(M):VMAX_RBV CP")
|
||||
field(DOL, "$(INSTR)$(M):VMAX_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).VMAX")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
@ -270,7 +303,7 @@ record(ai, "$(INSTR)$(M):ACCL_RBV")
|
||||
field(FLNK, "$(INSTR)$(M):PushACCL2Field")
|
||||
}
|
||||
record(ao, "$(INSTR)$(M):PushACCL2Field") {
|
||||
field(DOL, "$(INSTR)$(M):ACCL_RBV CP")
|
||||
field(DOL, "$(INSTR)$(M):ACCL_RBV NPP")
|
||||
field(OUT, "$(INSTR)$(M).ACCL")
|
||||
field(OMSL, "closed_loop")
|
||||
}
|
||||
@ -288,4 +321,4 @@ record(waveform, "$(INSTR)$(M):EncoderType") {
|
||||
field(FTVL, "CHAR")
|
||||
field(NELM, "80")
|
||||
field(SCAN, "I/O Intr")
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,13 @@
|
||||
#include <unordered_map>
|
||||
|
||||
msgPrintControlKey::msgPrintControlKey(char *controller, int axisNo,
|
||||
const char *functionName, int line) {
|
||||
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) {
|
||||
@ -16,10 +18,6 @@ void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
|
||||
|
||||
// =============================================================================
|
||||
|
||||
msgPrintControl::msgPrintControl(size_t maxRepetitions) {
|
||||
maxRepetitions_ = maxRepetitions;
|
||||
}
|
||||
|
||||
bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
|
||||
asynUser *pasynUser) {
|
||||
|
||||
@ -34,12 +32,12 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
|
||||
*/
|
||||
if (map_.find(key) != map_.end()) {
|
||||
size_t repetitions = map_[key];
|
||||
if (repetitions < maxRepetitions_) {
|
||||
if (repetitions < key.maxRepetitions_) {
|
||||
// Number of allowed repetitions not exceeded -> Printing the
|
||||
// message is ok.
|
||||
map_[key] = repetitions + 1;
|
||||
return true;
|
||||
} else if (repetitions == maxRepetitions_) {
|
||||
} else if (repetitions == key.maxRepetitions_) {
|
||||
// Reached number of allowed repetitions -> Printing the message
|
||||
// is ok, but further trys are rejected.
|
||||
char formattedKey[100] = {0};
|
||||
@ -88,7 +86,8 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
|
||||
|
||||
bool msgPrintControl::shouldBePrinted(char *portName, int axisNo,
|
||||
const char *functionName, int line,
|
||||
bool wantToPrint, asynUser *pasynUser) {
|
||||
bool wantToPrint, asynUser *pasynUser,
|
||||
size_t maxRepetitions) {
|
||||
msgPrintControlKey key =
|
||||
msgPrintControlKey(portName, axisNo, functionName, __LINE__);
|
||||
return shouldBePrinted(key, wantToPrint, pasynUser);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef msgPrintControl_H
|
||||
#define msgPrintControl_H
|
||||
|
||||
#define DefaultMaxRepetitions 4
|
||||
|
||||
#include <asynDriver.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
@ -21,8 +23,15 @@ class msgPrintControlKey {
|
||||
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);
|
||||
int line, size_t maxRepetitions = DefaultMaxRepetitions);
|
||||
|
||||
bool operator==(const msgPrintControlKey &other) const {
|
||||
return axisNo_ == other.axisNo_ && line_ == other.line_ &&
|
||||
@ -73,8 +82,6 @@ template <> struct hash<msgPrintControlKey> {
|
||||
*/
|
||||
class msgPrintControl {
|
||||
public:
|
||||
msgPrintControl(size_t maxRepetitions);
|
||||
|
||||
/**
|
||||
* @brief Checks if the error message associated with "key" has been printed
|
||||
* more than `this->maxRepetitions_` times in a row. If yes, returns false,
|
||||
@ -115,7 +122,8 @@ class msgPrintControl {
|
||||
* @param pasynUser
|
||||
*/
|
||||
bool shouldBePrinted(char *controller, int axisNo, const char *functionName,
|
||||
int line, bool wantToPrint, asynUser *pasynUser);
|
||||
int line, bool wantToPrint, asynUser *pasynUser,
|
||||
size_t maxRepetitions = DefaultMaxRepetitions);
|
||||
|
||||
/**
|
||||
* @brief Reset the error message count incremented in `shouldBePrinted` for
|
||||
@ -129,13 +137,6 @@ class msgPrintControl {
|
||||
*/
|
||||
void resetCount(msgPrintControlKey &key, asynUser *pasynUser);
|
||||
|
||||
/**
|
||||
* @brief Maximum number of times a message is printed before it is
|
||||
* suppressed.
|
||||
*
|
||||
*/
|
||||
size_t maxRepetitions_;
|
||||
|
||||
char *getSuffix();
|
||||
|
||||
private:
|
||||
|
210
src/sinqAxis.cpp
210
src/sinqAxis.cpp
@ -14,13 +14,16 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
scaleMovTimeout_ = 2.0;
|
||||
offsetMovTimeout_ = 30;
|
||||
targetPosition_ = 0.0;
|
||||
wasMoving_ = false;
|
||||
|
||||
epicsTimeGetCurrent(&lastPollTime_);
|
||||
|
||||
// This check is also done in asynMotorAxis, but there the IOC continues
|
||||
// running even though the configuration is incorrect. When failing this
|
||||
// check, the IOC is stopped, since this is definitely a configuration
|
||||
// problem.
|
||||
if ((axisNo < 0) || (axisNo >= pC->numAxes())) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(axis index %d is not in range 0 to %d)\n. Terminating IOC",
|
||||
pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, axisNo,
|
||||
@ -31,7 +34,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
// Motor is assumed to be enabled
|
||||
status = setIntegerParam(pC_->motorEnableRBV(), 1);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -43,7 +46,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
// By default, motors cannot be disabled
|
||||
status = setIntegerParam(pC_->motorCanDisable(), 0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -55,7 +58,19 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
// Provide a default value for the motor position.
|
||||
status = setDoubleParam(pC_->motorPosition(), 0.0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
|
||||
pC_->stringifyAsynStatus(status));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Assume that the motor is connected initially
|
||||
status = setIntegerParam(pC_->motorConnected(), 1);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -67,7 +82,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
// We assume that the motor has no status problems initially
|
||||
status = setIntegerParam(pC_->motorStatusProblem(), 0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -79,7 +94,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
// Set the homing-related flags
|
||||
status = setIntegerParam(pC_->motorStatusHome(), 0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -89,7 +104,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
}
|
||||
status = setIntegerParam(pC_->motorStatusHomed(), 0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -99,7 +114,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
}
|
||||
status = setIntegerParam(pC_->motorStatusAtHome(), 0);
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
|
||||
"(setting a parameter value failed "
|
||||
"with %s)\n. Terminating IOC",
|
||||
@ -110,11 +125,53 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
}
|
||||
|
||||
asynStatus sinqAxis::poll(bool *moving) {
|
||||
|
||||
// Local variable declaration
|
||||
asynStatus pl_status = asynSuccess;
|
||||
asynStatus poll_status = asynSuccess;
|
||||
int homing = 0;
|
||||
int homed = 0;
|
||||
int adaptivePolling = 0;
|
||||
|
||||
/*
|
||||
If adaptive polling is enabled:
|
||||
- Check if the motor was moving during the last poll
|
||||
- If yes, perform the poll
|
||||
- If no, check if the last poll was at least an idlePollPeriod ago
|
||||
- If yes, perform the poll
|
||||
- If no, skip it
|
||||
*/
|
||||
|
||||
pl_status =
|
||||
pC_->getIntegerParam(axisNo_, pC_->adaptivePolling(), &adaptivePolling);
|
||||
if (pl_status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(pl_status, "adaptivePolling", axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
};
|
||||
|
||||
// Using the EPICS timestamp here, see
|
||||
// https://docs.epics-controls.org/projects/base/en/latest/epicsTime_h.html#_CPPv414epicsTimeStamp
|
||||
|
||||
// Get the current time
|
||||
epicsTimeStamp ts;
|
||||
epicsTimeGetCurrent(&ts);
|
||||
|
||||
if (adaptivePolling != 0) {
|
||||
// Motor wasn't moving during the last poll
|
||||
if (!wasMoving_) {
|
||||
|
||||
// Add the idle poll period
|
||||
epicsTimeStamp earliestTimeNextPoll = lastPollTime_;
|
||||
epicsTimeAddSeconds(&earliestTimeNextPoll, pC_->idlePollPeriod());
|
||||
|
||||
if (epicsTimeLessThanEqual(&earliestTimeNextPoll, &ts) == 0) {
|
||||
*moving = false;
|
||||
return asynSuccess;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Update the start time of the last poll
|
||||
lastPollTime_ = ts;
|
||||
|
||||
/*
|
||||
At the beginning of the poll, it is assumed that the axis has no status
|
||||
@ -146,6 +203,9 @@ asynStatus sinqAxis::poll(bool *moving) {
|
||||
// return.
|
||||
poll_status = doPoll(moving);
|
||||
|
||||
// Motor was moving during this poll
|
||||
wasMoving_ = *moving;
|
||||
|
||||
// The poll did not succeed: Something went wrong and the motor has a status
|
||||
// problem.
|
||||
if (poll_status != asynSuccess) {
|
||||
@ -202,8 +262,8 @@ asynStatus sinqAxis::poll(bool *moving) {
|
||||
bool wantToPrint = pl_status != asynSuccess;
|
||||
if (pC_->getMsgPrintControl().shouldBePrinted(
|
||||
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, wantToPrint,
|
||||
pC_->asynUserSelf())) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
pC_->pasynUser())) {
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line "
|
||||
"%d:\ncallParamCallbacks failed with %s.%s\n",
|
||||
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
|
||||
@ -223,36 +283,47 @@ asynStatus sinqAxis::move(double position, int relative, double minVelocity,
|
||||
double maxVelocity, double acceleration) {
|
||||
|
||||
// Status of parameter library operations
|
||||
asynStatus pl_status = asynSuccess;
|
||||
asynStatus status = asynSuccess;
|
||||
double motorRecResolution = 0.0;
|
||||
|
||||
// =========================================================================
|
||||
|
||||
// When a new move is done, the motor is not homed anymore
|
||||
pl_status = setIntegerParam(pC_->motorStatusHomed(), 0);
|
||||
if (pl_status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(pl_status, "motorStatusHomed_",
|
||||
axisNo_, __PRETTY_FUNCTION__,
|
||||
__LINE__);
|
||||
}
|
||||
pl_status = setIntegerParam(pC_->motorStatusAtHome(), 0);
|
||||
if (pl_status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(pl_status, "motorStatusAtHome_",
|
||||
axisNo_, __PRETTY_FUNCTION__,
|
||||
__LINE__);
|
||||
}
|
||||
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
|
||||
&motorRecResolution);
|
||||
if (pl_status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
|
||||
axisNo_, __PRETTY_FUNCTION__,
|
||||
__LINE__);
|
||||
}
|
||||
|
||||
// Store the target position internally
|
||||
targetPosition_ = position * motorRecResolution;
|
||||
|
||||
return doMove(position, relative, minVelocity, maxVelocity, acceleration);
|
||||
status = doMove(position, relative, minVelocity, maxVelocity, acceleration);
|
||||
if (status != asynSuccess) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = assertConnected();
|
||||
if (status != asynSuccess) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Since the move command was successfull, we assume that the motor has
|
||||
// started its movement.
|
||||
status = setIntegerParam(pC_->motorStatusHomed(), 0);
|
||||
if (status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(status, "motorStatusHomed_", axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
status = setIntegerParam(pC_->motorStatusAtHome(), 0);
|
||||
if (status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(status, "motorStatusAtHome_", axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
|
||||
&motorRecResolution);
|
||||
if (status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(status, "motorRecResolution_", axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
// Needed for adaptive polling
|
||||
wasMoving_ = true;
|
||||
|
||||
return pC_->callParamCallbacks();
|
||||
}
|
||||
|
||||
asynStatus sinqAxis::doMove(double position, int relative, double minVelocity,
|
||||
@ -297,6 +368,11 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
|
||||
__LINE__);
|
||||
}
|
||||
|
||||
status = assertConnected();
|
||||
if (status != asynSuccess) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Update the motor record
|
||||
return callParamCallbacks();
|
||||
|
||||
@ -310,11 +386,16 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
|
||||
__LINE__);
|
||||
}
|
||||
|
||||
status = assertConnected();
|
||||
if (status != asynSuccess) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Update the motor record
|
||||
return callParamCallbacks();
|
||||
} else {
|
||||
// Bubble up all other problems
|
||||
return status;
|
||||
return assertConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,6 +406,7 @@ asynStatus sinqAxis::doHome(double minVelocity, double maxVelocity,
|
||||
|
||||
asynStatus sinqAxis::reset() {
|
||||
asynStatus status = doReset();
|
||||
|
||||
if (status == asynSuccess) {
|
||||
// Perform some fast polls
|
||||
pC_->lock();
|
||||
@ -337,6 +419,12 @@ asynStatus sinqAxis::reset() {
|
||||
}
|
||||
pC_->unlock();
|
||||
}
|
||||
|
||||
asynStatus pl_status = assertConnected();
|
||||
if (pl_status != asynSuccess) {
|
||||
return pl_status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -390,6 +478,25 @@ asynStatus sinqAxis::setMotorPosition(double motorPosition) {
|
||||
return status;
|
||||
}
|
||||
|
||||
asynStatus sinqAxis::assertConnected() {
|
||||
asynStatus status = asynSuccess;
|
||||
int connected = 0;
|
||||
|
||||
status = pC_->getIntegerParam(axisNo(), pC_->motorConnected(), &connected);
|
||||
if (status != asynSuccess) {
|
||||
return pC_->paramLibAccessFailed(status, "motorConnected", axisNo(),
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
if (connected == 0) {
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line "
|
||||
"%d:\nAxis is not connected, all commands are ignored.\n",
|
||||
pC_->portName, axisNo(), __PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
|
||||
asynStatus status = asynSuccess;
|
||||
int variableSpeed = 0;
|
||||
@ -405,7 +512,7 @@ asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
|
||||
|
||||
// Check the inputs and create corresponding error messages
|
||||
if (vbas > vmax) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nLower speed "
|
||||
"limit vbas=%lf must not be smaller than upper limit "
|
||||
"vmax=%lf.\n",
|
||||
@ -423,7 +530,7 @@ asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
|
||||
return asynError;
|
||||
}
|
||||
if (velo < vbas || velo > vmax) {
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nActual "
|
||||
"speed velo=%lf must be between lower limit vbas=%lf and "
|
||||
"upper limit vmax=%lf.\n",
|
||||
@ -617,14 +724,22 @@ asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
// Create the unique callsite identifier manually so it can be used later in
|
||||
// the shouldBePrinted calls.
|
||||
msgPrintControlKey key = msgPrintControlKey(pC_->portName, axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
|
||||
// Check if the expected time of arrival has been exceeded.
|
||||
if (expectedArrivalTime_ < time(NULL)) {
|
||||
// Check the watchdog
|
||||
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nExceeded "
|
||||
"expected arrival time %ld (current time is %ld).\n",
|
||||
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
|
||||
expectedArrivalTime_, time(NULL));
|
||||
if (pC_->getMsgPrintControl().shouldBePrinted(key, true,
|
||||
pC_->pasynUser())) {
|
||||
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
|
||||
"Controller \"%s\", axis %d => %s, line %d:\nExceeded "
|
||||
"expected arrival time %ld (current time is %ld).\n",
|
||||
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
|
||||
expectedArrivalTime_, time(NULL));
|
||||
}
|
||||
|
||||
pl_status = setStringParam(
|
||||
pC_->motorMessageText(),
|
||||
@ -640,10 +755,11 @@ asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
|
||||
pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_", axisNo_,
|
||||
__PRETTY_FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
// Even if the movement timed out, the rest of the poll should continue.
|
||||
return asynSuccess;
|
||||
} else {
|
||||
pC_->getMsgPrintControl().resetCount(key, pC_->pasynUser());
|
||||
}
|
||||
|
||||
// Even if the movement timed out, the rest of the poll should continue.
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
@ -662,8 +778,7 @@ extern "C" {
|
||||
*/
|
||||
asynStatus setWatchdogEnabled(const char *portName, int axisNo, int enable) {
|
||||
|
||||
sinqController *pC;
|
||||
pC = (sinqController *)findAsynPortDriver(portName);
|
||||
sinqController *pC = (sinqController *)findAsynPortDriver(portName);
|
||||
if (pC == nullptr) {
|
||||
errlogPrintf("Controller \"%s\" => %s, line %d:\nPort %s not found.",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__, portName);
|
||||
@ -721,8 +836,7 @@ asynStatus setOffsetMovTimeout(const char *portName, int axisNo,
|
||||
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
|
||||
if (axis == nullptr) {
|
||||
errlogPrintf("Controller \"%s\" => %s, line %d:\nAxis %d does not "
|
||||
"exist or is not an "
|
||||
"instance of sinqAxis.",
|
||||
"exist or is not an instance of sinqAxis.",
|
||||
portName, __PRETTY_FUNCTION__, __LINE__, axisNo);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ Stefan Mathis, November 2024
|
||||
#ifndef sinqAxis_H
|
||||
#define sinqAxis_H
|
||||
#include "asynMotorAxis.h"
|
||||
#include <epicsTime.h>
|
||||
|
||||
class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
public:
|
||||
@ -347,15 +348,33 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
*/
|
||||
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:
|
||||
// Internal variables used in the movement timeout watchdog
|
||||
time_t expectedArrivalTime_;
|
||||
time_t offsetMovTimeout_;
|
||||
|
||||
double scaleMovTimeout_;
|
||||
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_;
|
||||
};
|
||||
|
@ -48,10 +48,12 @@ sinqController::sinqController(const char *portName,
|
||||
ASYN_CANBLOCK | ASYN_MULTIDEVICE,
|
||||
1, // autoconnect
|
||||
0, 0), // Default priority and stack size
|
||||
msgPrintControl_(4) {
|
||||
msgPrintControl_() {
|
||||
|
||||
asynStatus status = asynSuccess;
|
||||
ipPortUser_ = 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
|
||||
@ -79,8 +81,9 @@ 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, &ipPortUser_, NULL);
|
||||
if (status != asynSuccess || ipPortUser_ == nullptr) {
|
||||
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",
|
||||
@ -167,6 +170,16 @@ sinqController::sinqController(const char *portName,
|
||||
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
|
||||
@ -249,6 +262,16 @@ sinqController::sinqController(const char *portName,
|
||||
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,
|
||||
@ -353,7 +376,7 @@ asynStatus sinqController::couldNotParseResponse(const char *command,
|
||||
int line) {
|
||||
asynStatus pl_status = asynSuccess;
|
||||
|
||||
asynPrint(ipPortUser_, ASYN_TRACE_ERROR,
|
||||
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);
|
||||
@ -382,7 +405,7 @@ asynStatus sinqController::paramLibAccessFailed(asynStatus status,
|
||||
int line) {
|
||||
|
||||
if (status != asynSuccess) {
|
||||
asynPrint(ipPortUser_, ASYN_TRACE_ERROR,
|
||||
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,
|
||||
@ -651,9 +674,9 @@ asynStatus setMaxSubsequentTimeouts(const char *portName,
|
||||
if (ptr == nullptr) {
|
||||
/*
|
||||
We can't use asynPrint here since this macro would require us
|
||||
to get a ipPortUser_ from a pointer to an asynPortDriver.
|
||||
to get a pasynOctetSyncIOipPort_ from a pointer to an asynPortDriver.
|
||||
However, the given pointer is a nullptr and therefore doesn't
|
||||
have a ipPortUser_! printf is an EPICS alternative which
|
||||
have a pasynOctetSyncIOipPort_! printf is an EPICS alternative which
|
||||
works w/o that, but doesn't offer the comfort provided
|
||||
by the asynTrace-facility
|
||||
*/
|
||||
|
@ -41,8 +41,8 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
* @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);
|
||||
|
||||
/**
|
||||
@ -115,9 +115,9 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
called. It is recommended to use a macro, e.g. __LINE__.
|
||||
* @return asynStatus Returns asynError.
|
||||
*/
|
||||
asynStatus couldNotParseResponse(const char *command,
|
||||
const char *response, int axisNo,
|
||||
const char *functionName, int line);
|
||||
asynStatus couldNotParseResponse(const char *command, const char *response,
|
||||
int axisNo, const char *functionName,
|
||||
int line);
|
||||
|
||||
/**
|
||||
* @brief Convert an asynStatus into a descriptive string.
|
||||
@ -285,27 +285,41 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
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_; }
|
||||
asynUser *asynUserSelf() { return pasynUserSelf; }
|
||||
asynUser *ipPortUser() { return ipPortUser_; }
|
||||
|
||||
/**
|
||||
* @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:
|
||||
// Pointer to the port user which is specified by the char array
|
||||
// `ipPortConfigName` in the constructor
|
||||
asynUser *ipPortUser_;
|
||||
asynUser *pasynOctetSyncIOipPort_;
|
||||
double movingPollPeriod_;
|
||||
double idlePollPeriod_;
|
||||
msgPrintControl msgPrintControl_;
|
||||
@ -322,6 +336,9 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
int maxSubsequentTimeouts_;
|
||||
bool maxSubsequentTimeoutsExceeded_;
|
||||
|
||||
/*
|
||||
See the documentation in db/sinqMotor.db for the following integers
|
||||
*/
|
||||
#define FIRST_SINQMOTOR_PARAM motorMessageText_
|
||||
int motorMessageText_;
|
||||
int motorReset_;
|
||||
@ -332,6 +349,7 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
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:
|
||||
@ -345,6 +363,7 @@ class epicsShareClass sinqController : public asynMotorController {
|
||||
int motorAcclFromDriver_;
|
||||
int motorHighLimitFromDriver_;
|
||||
int motorLowLimitFromDriver_;
|
||||
int adaptivePolling_;
|
||||
int encoderType_;
|
||||
#define LAST_SINQMOTOR_PARAM encoderType_
|
||||
|
||||
|
Reference in New Issue
Block a user