From 266142ba41af990ddabd45bed9bfd77ad0a14e3e Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 8 Aug 2019 10:31:45 -0500 Subject: [PATCH 1/5] Changes from Steffen Rau to allow PIGCSPiezoController to work with relative encoders, as well as with firmware versions that don't support the "TRS?" and "FRF?" commands. --- pigcs2App/src/PIGCSController.cpp | 2 +- pigcs2App/src/PIGCSController.h | 2 +- pigcs2App/src/PIGCSPiezoController.cpp | 68 ++++++++++++++++++++++++++ pigcs2App/src/PIGCSPiezoController.h | 5 ++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/pigcs2App/src/PIGCSController.cpp b/pigcs2App/src/PIGCSController.cpp index 1184c0a..539a240 100644 --- a/pigcs2App/src/PIGCSController.cpp +++ b/pigcs2App/src/PIGCSController.cpp @@ -655,7 +655,7 @@ asynStatus PIGCSController::getReferencedState(PIasynAxis* pAxis) { return status; } - if (getValue(buf, pAxis->m_homed)) + if (!getValue(buf, pAxis->m_homed)) { return asynError; } diff --git a/pigcs2App/src/PIGCSController.h b/pigcs2App/src/PIGCSController.h index 29db5fb..cb203e3 100644 --- a/pigcs2App/src/PIGCSController.h +++ b/pigcs2App/src/PIGCSController.h @@ -51,7 +51,7 @@ class PIGCSController virtual asynStatus move( PIasynAxis* pAxis, double target); virtual asynStatus moveCts( PIasynAxis* pAxis, int target); virtual asynStatus moveCts( PIasynAxis** pAxesArray, int* pTargetCtsArray, int numAxes); - virtual asynStatus referenceVelCts( PIasynAxis* pAxis, double velocity, int forwards) { return asynSuccess; } + virtual asynStatus referenceVelCts( PIasynAxis* pAxis, double velocity, int forwards) = 0; virtual asynStatus haltAxis(PIasynAxis* pAxis); diff --git a/pigcs2App/src/PIGCSPiezoController.cpp b/pigcs2App/src/PIGCSPiezoController.cpp index 6578462..32a8675 100644 --- a/pigcs2App/src/PIGCSPiezoController.cpp +++ b/pigcs2App/src/PIGCSPiezoController.cpp @@ -39,12 +39,39 @@ asynStatus PIGCSPiezoController::getStatus(PIasynAxis* pAxis, int& homing, int& asynStatus PIGCSPiezoController::getReferencedState(PIasynAxis* pAxis) { + if (m_hasqFRF) + { + asynStatus status = PIGCSController::getReferencedState (pAxis); + if (asynSuccess == status) + { + return status; + } + if (getGCSError () != PI_CNTR_UNKNOWN_COMMAND__2) + { + return asynError; + } + m_hasqFRF = false; + } pAxis->m_homed = 1; return asynSuccess; } asynStatus PIGCSPiezoController::initAxis(PIasynAxis* pAxis) { + pAxis->m_bHasReference = false; + if (m_hasqTRS) + { + asynStatus status = hasReferenceSensor (pAxis); + if (asynSuccess != status) + { + if (getGCSError () != PI_CNTR_UNKNOWN_COMMAND__2) + { + return asynError; + } + m_hasqTRS = false; + } + } + pAxis->m_movingStateMask = pow(2.0, pAxis->getAxisNo()); return setServo(pAxis, 1); @@ -72,4 +99,45 @@ asynStatus PIGCSPiezoController::haltAxis(PIasynAxis* pAxis) return status; } +asynStatus PIGCSPiezoController::referenceVelCts (PIasynAxis* pAxis, double velocity, int forwards) +{ + if (!m_hasqFRF) + { + // device does not know how to reference, many piezo stages have absolute sensors + return asynSuccess; + } + + asynStatus status = setServo(pAxis, 0); // piezo controllers need the servo to be disabled + if (asynSuccess != status) + return status; + + char cmd[100]; + if (pAxis->m_bHasReference) + { + // call FRF - find reference + sprintf(cmd,"FRF %s", pAxis->m_szAxisName); + } + else + { + asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_ERROR, + "PIGCSPiezoController::referenceVelCts() failed - axis has no reference switch\n"); + epicsSnprintf(pAxis->m_pasynUser->errorMessage,pAxis->m_pasynUser->errorMessageSize, + "PIGCSPiezoController::referenceVelCts() failed - axis has no reference switch\n"); + return asynError; + } + status = m_pInterface->sendOnly(cmd); + if (asynSuccess != status) + return status; + int errorCode = getGCSError(); + if (errorCode == 0) + { + return asynSuccess; + } + asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_ERROR, + "PIGCSPiezoController::referenceVelCts() failed\n"); + epicsSnprintf(pAxis->m_pasynUser->errorMessage,pAxis->m_pasynUser->errorMessageSize, + "PIGCSPiezoController::referenceVelCts() failed - GCS Error %d\n",errorCode); + return asynError; + +} diff --git a/pigcs2App/src/PIGCSPiezoController.h b/pigcs2App/src/PIGCSPiezoController.h index 19ce655..b65dd0b 100644 --- a/pigcs2App/src/PIGCSPiezoController.h +++ b/pigcs2App/src/PIGCSPiezoController.h @@ -28,6 +28,8 @@ class PIGCSPiezoController : public PIGCSController public: PIGCSPiezoController(PIInterface* pInterface, const char* szIDN) : PIGCSController(pInterface, szIDN) + , m_hasqFRF (true) + , m_hasqTRS (true) { } ~PIGCSPiezoController() {} @@ -38,9 +40,12 @@ class PIGCSPiezoController : public PIGCSController virtual asynStatus getStatus(PIasynAxis* pAxis, int& homing, int& moving, int& negLimit, int& posLimit, int& servoControl); virtual asynStatus getReferencedState(PIasynAxis* pAxis); + virtual asynStatus referenceVelCts( PIasynAxis* pAxis, double velocity, int forwards); private: + bool m_hasqFRF; ///< is "FRF?" command available + bool m_hasqTRS; ///< is "TRS?" command available }; From 4ea9dd105a2ec8a7da071b4b8822f0d110704816 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 14 Aug 2019 10:42:31 -0500 Subject: [PATCH 2/5] More changes from Steffen Rau: Added PIGCSController::getStatusFromBitMask Improved PIGCSPiezoController::getStatus and PIGCSPiezoController::initAxis --- pigcs2App/src/PIGCSController.cpp | 9 ++++++++ pigcs2App/src/PIGCSController.h | 11 +++++---- pigcs2App/src/PIGCSMotorController.cpp | 15 ++++-------- pigcs2App/src/PIGCSPiezoController.cpp | 32 ++++++++++++++++++++------ pigcs2App/src/PIGCSPiezoController.h | 4 ++-- 5 files changed, 48 insertions(+), 23 deletions(-) diff --git a/pigcs2App/src/PIGCSController.cpp b/pigcs2App/src/PIGCSController.cpp index 539a240..c533199 100644 --- a/pigcs2App/src/PIGCSController.cpp +++ b/pigcs2App/src/PIGCSController.cpp @@ -733,3 +733,12 @@ bool PIGCSController::getValue(const char* szMsg, bool& value) value = (ivalue =! 0); return true; } + +void PIGCSController::getStatusFromBitMask (long mask, int& homing, int& moving, int& negLimit, int& posLimit, int& servoControl) +{ + moving = (mask & 0x2000) ? 1 : 0; + homing = (mask & 0x4000) ? 1 : 0; + negLimit = (mask & 0x0001) ? 1 : 0; + posLimit = (mask & 0x0004) ? 1 : 0; + servoControl = (mask & 0x1000) ? 1 : 0; +} diff --git a/pigcs2App/src/PIGCSController.h b/pigcs2App/src/PIGCSController.h index cb203e3..94e8931 100644 --- a/pigcs2App/src/PIGCSController.h +++ b/pigcs2App/src/PIGCSController.h @@ -1,6 +1,6 @@ /* -FILENAME... PIGCScontroller.h - +FILENAME... PIGCScontroller.h + ************************************************************************* * Copyright (c) 2011-2013 Physik Instrumente (PI) GmbH & Co. KG * This file is distributed subject to the EPICS Open License Agreement @@ -8,7 +8,7 @@ FILENAME... PIGCScontroller.h ************************************************************************* -Original Author: Steffen Rau +Original Author: Steffen Rau Created: 15.12.2010 */ @@ -51,7 +51,7 @@ class PIGCSController virtual asynStatus move( PIasynAxis* pAxis, double target); virtual asynStatus moveCts( PIasynAxis* pAxis, int target); virtual asynStatus moveCts( PIasynAxis** pAxesArray, int* pTargetCtsArray, int numAxes); - virtual asynStatus referenceVelCts( PIasynAxis* pAxis, double velocity, int forwards) = 0; + virtual asynStatus referenceVelCts (PIasynAxis* pAxis, double velocity, int forwards) = 0; virtual asynStatus haltAxis(PIasynAxis* pAxis); @@ -95,6 +95,9 @@ class PIGCSController PIInterface* m_pInterface; static const size_t MAX_NR_AXES = 64; bool m_bAnyAxisMoving; + + static void getStatusFromBitMask(long mask, int& homing, int& moving, int& negLimit, int& posLimit, int& servoControl); + protected: asynStatus setGCSParameter(PIasynAxis* pAxis, unsigned int paramID, double value); asynStatus getGCSParameter(PIasynAxis* pAxis, unsigned int paramID, double& value); diff --git a/pigcs2App/src/PIGCSMotorController.cpp b/pigcs2App/src/PIGCSMotorController.cpp index 78e320f..52cde6e 100644 --- a/pigcs2App/src/PIGCSMotorController.cpp +++ b/pigcs2App/src/PIGCSMotorController.cpp @@ -1,5 +1,5 @@ /* -FILENAME... PIGCSMotorController.cpp +FILENAME... PIGCSMotorController.cpp ************************************************************************* * Copyright (c) 2011-2013 Physik Instrumente (PI) GmbH & Co. KG @@ -8,7 +8,7 @@ FILENAME... PIGCSMotorController.cpp ************************************************************************* -Original Author: Steffen Rau +Original Author: Steffen Rau Created: 15.12.2010 */ @@ -141,19 +141,14 @@ asynStatus PIGCSMotorController::getStatus(PIasynAxis* pAxis, int& homing, int& { return status; } - // TODO this is for a single axis C-863/867 controller!!!! - // TODO a) change it to multi-axis code. - // TODO b) support other controllers which do not understand #4 or have different bit masks + // TODO this is for C-863/867 controllers!!!! + // TODO support other controllers which do not understand #4 or have different bit masks int idx = 2 + pAxis->getAxisNo()*4; buf[idx+4] = '\0'; char* szMask = buf+idx; long mask = strtol(szMask, NULL, 16); - moving = (mask & 0x2000) ? 1 : 0; - homing = (mask & 0x4000) ? 1 : 0; - negLimit = (mask & 0x0001) ? 1 : 0; - posLimit = (mask & 0x0004) ? 1 : 0; - servoControl = (mask & 0x1000) ? 1 : 0; + getStatusFromBitMask (mask, homing, moving, negLimit, posLimit, servoControl); asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_FLOW, "PIGCSMotorController::getStatus() buf:%s moving %d, svo: %d\n", buf, moving, servoControl); diff --git a/pigcs2App/src/PIGCSPiezoController.cpp b/pigcs2App/src/PIGCSPiezoController.cpp index 32a8675..ae66bc3 100644 --- a/pigcs2App/src/PIGCSPiezoController.cpp +++ b/pigcs2App/src/PIGCSPiezoController.cpp @@ -8,7 +8,7 @@ FILENAME... PIGCSPiezoController.cpp ************************************************************************* -Original Author: Steffen Rau +Original Author: Steffen Rau Created: 15.12.2010 */ @@ -24,15 +24,26 @@ Created: 15.12.2010 asynStatus PIGCSPiezoController::getStatus(PIasynAxis* pAxis, int& homing, int& moving, int& negLimit, int& posLimit, int& servoControl) { - asynStatus status = getMoving(pAxis, moving); + char cmd[100]; + char buf[255]; + sprintf(cmd, "SRG? %s 1", pAxis->m_szAxisName); + asynStatus status = m_pInterface->sendAndReceive(cmd, buf, 99); if (status != asynSuccess) { - return status; + return status; + } + + const char* p = strstr(buf, "="); + if (p==NULL || *p == '\0') + { + return asynError; } - homing = 0; - negLimit = 0; - posLimit = 0; + long mask = strtol(p+1, NULL, 0); + getStatusFromBitMask (mask, homing, moving, negLimit, posLimit, servoControl); + asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_FLOW, + "PIGCSPiezoController::getStatus() buf:%s moving %d, svo: %d\n", + buf, moving, servoControl); return status; } @@ -59,6 +70,7 @@ asynStatus PIGCSPiezoController::getReferencedState(PIasynAxis* pAxis) asynStatus PIGCSPiezoController::initAxis(PIasynAxis* pAxis) { pAxis->m_bHasReference = false; + if (m_hasqTRS) { asynStatus status = hasReferenceSensor (pAxis); @@ -74,7 +86,13 @@ asynStatus PIGCSPiezoController::initAxis(PIasynAxis* pAxis) pAxis->m_movingStateMask = pow(2.0, pAxis->getAxisNo()); - return setServo(pAxis, 1); + // enable servo only if axis is homed + int servoState = 1; + if (asynSuccess == getReferencedState (pAxis)) + { + servoState = pAxis->m_homed; + } + return setServo(pAxis, servoState); } /** diff --git a/pigcs2App/src/PIGCSPiezoController.h b/pigcs2App/src/PIGCSPiezoController.h index b65dd0b..7a748c1 100644 --- a/pigcs2App/src/PIGCSPiezoController.h +++ b/pigcs2App/src/PIGCSPiezoController.h @@ -8,7 +8,7 @@ FILENAME... PIGCScontroller.h ************************************************************************* -Original Author: Steffen Rau +Original Author: Steffen Rau Created: 15.12.2010 */ @@ -27,7 +27,7 @@ class PIGCSPiezoController : public PIGCSController { public: PIGCSPiezoController(PIInterface* pInterface, const char* szIDN) - : PIGCSController(pInterface, szIDN) + : PIGCSController (pInterface, szIDN) , m_hasqFRF (true) , m_hasqTRS (true) { From efdc37cca9e7513d6c7f866a062e61556ddd9f12 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 19 Aug 2019 10:56:01 -0500 Subject: [PATCH 3/5] Temporarily disable limits for piezo stages. --- pigcs2App/src/PIGCSPiezoController.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pigcs2App/src/PIGCSPiezoController.cpp b/pigcs2App/src/PIGCSPiezoController.cpp index ae66bc3..3bf5697 100644 --- a/pigcs2App/src/PIGCSPiezoController.cpp +++ b/pigcs2App/src/PIGCSPiezoController.cpp @@ -41,6 +41,9 @@ asynStatus PIGCSPiezoController::getStatus(PIasynAxis* pAxis, int& homing, int& long mask = strtol(p+1, NULL, 0); getStatusFromBitMask (mask, homing, moving, negLimit, posLimit, servoControl); + // TODO: use parameter or "LIM?" to find out if stage has limit switches + negLimit = 0; + posLimit = 0; asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_FLOW, "PIGCSPiezoController::getStatus() buf:%s moving %d, svo: %d\n", buf, moving, servoControl); From 43039e7b385f84648d89f28c7822009a31736a89 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 19 Aug 2019 10:58:48 -0500 Subject: [PATCH 4/5] Corrected positionCts format in call to asynPrint in PIGCSController::setAxisPositionCts --- pigcs2App/src/PIGCSController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigcs2App/src/PIGCSController.cpp b/pigcs2App/src/PIGCSController.cpp index c533199..77bb9dc 100644 --- a/pigcs2App/src/PIGCSController.cpp +++ b/pigcs2App/src/PIGCSController.cpp @@ -163,7 +163,7 @@ asynStatus PIGCSController::setAxisPositionCts(PIasynAxis* pAxis, double positio double position = double(positionCts) * pAxis->m_CPUdenominator / pAxis->m_CPUnumerator; asynPrint(m_pInterface->m_pCurrentLogSink, ASYN_TRACE_FLOW|ASYN_TRACE_ERROR, - "PIGCSController::setAxisPositionCts(, %d) \n", positionCts); + "PIGCSController::setAxisPositionCts(, %f) \n", positionCts); return setAxisPosition(pAxis, position); } From 16557f0022695c78078462d36cd06f545759e548 Mon Sep 17 00:00:00 2001 From: Kevin Peterson Date: Fri, 15 Nov 2019 09:34:11 -0600 Subject: [PATCH 5/5] Fixed typo in PIGCSController::getValue --- pigcs2App/src/PIGCSController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigcs2App/src/PIGCSController.cpp b/pigcs2App/src/PIGCSController.cpp index 77bb9dc..bc78400 100644 --- a/pigcs2App/src/PIGCSController.cpp +++ b/pigcs2App/src/PIGCSController.cpp @@ -730,7 +730,7 @@ bool PIGCSController::getValue(const char* szMsg, bool& value) return false; } int ivalue = atoi(p+1); - value = (ivalue =! 0); + value = (ivalue != 0); return true; }