diff --git a/README.md b/README.md index 073ca20..05737b2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ecmc_plugin_safety IMPORTANT: This plugin or ecmc does NOT offer any safety functionality. This plugin only offers a standard interface to an external safety system / safety PLC / safety relay!!!! - This plugin is designed for interfacing safety systems to ecmc motion axes. # Loading of plugin @@ -69,7 +68,7 @@ epicsEnvSet(RAMP_DOWN_CMD,"ec${ECMC_EC_MASTER_ID}.s${DRV_SLAVE}.ZERO.0") epicsEnvSet(STANDSTILL_STAT,"ec${ECMC_EC_MASTER_ID}.s${DRV_SLAVE}.ZERO.1") ${SCRIPTEXEC} ${ecmc_plugin_safety_DIR}addSS1Group.cmd "NAME=first,EC_RAMP_DOWN_CMD=${RAMP_DOWN_CMD},EC_STANDSTILL_STAT=${STANDSTILL_STAT},DELAY_MS=500" -#- Add axes +# Add axes to group "first" ${SCRIPTEXEC} ${ecmc_plugin_safety_DIR}addAxisToGroup.cmd "NAME=first,AX_ID=1,VELO_LIM=1" ${SCRIPTEXEC} ${ecmc_plugin_safety_DIR}addAxisToGroup.cmd "NAME=first,AX_ID=2,VELO_LIM=1" ${SCRIPTEXEC} ${ecmc_plugin_safety_DIR}addAxisToGroup.cmd "NAME=first,AX_ID=3,VELO_LIM=1" diff --git a/docs/.MODULE_LOG b/docs/.MODULE_LOG deleted file mode 100644 index b60b012..0000000 --- a/docs/.MODULE_LOG +++ /dev/null @@ -1,28 +0,0 @@ ->> -Script is used : e3TemplateGenerator.bash -Script Path : /home/anderssandstrom/plugin_ecmc/e3-tools/e3TemplateGenerator -Script Version : 1.0.8 -Script Run Time : 2020Mar22-1607-33CET -User : anderssandstrom -e3-tools Hash : bf03d40 ->> ->> git diff - ->> ->> git diff --cached - ->> ->> git diff HEAD - - ->> ->> Your sources are located in e3-ecmcPlugin_Simple. ->> -EPICS_MODULE_NAME : ecmcPlugin_Simple -E3_MODULE_SRC_PATH : ecmcPlugin_Simple -E3_TARGET_URL : https://github.com/anderssandstrom ->> -e3 module name : e3-ecmcPlugin_Simple -e3 target url full : https://github.com/anderssandstrom/e3-ecmcPlugin_Simple.git ->> -e3 module is located in siteMods diff --git a/docs/ecmcPLC5HzFFT.png b/docs/ecmcPLC5HzFFT.png deleted file mode 100644 index 70cdaa9..0000000 Binary files a/docs/ecmcPLC5HzFFT.png and /dev/null differ diff --git a/docs/ecmcPLC5HzRAW.png b/docs/ecmcPLC5HzRAW.png deleted file mode 100644 index 866cea7..0000000 Binary files a/docs/ecmcPLC5HzRAW.png and /dev/null differ diff --git a/docs/gui/ecmcArrayGui.png b/docs/gui/ecmcArrayGui.png deleted file mode 100644 index feba6bf..0000000 Binary files a/docs/gui/ecmcArrayGui.png and /dev/null differ diff --git a/docs/gui/ecmcFFTGui.png b/docs/gui/ecmcFFTGui.png deleted file mode 100644 index f53c601..0000000 Binary files a/docs/gui/ecmcFFTGui.png and /dev/null differ diff --git a/docs/gui/ecmcFFTMainGui.png b/docs/gui/ecmcFFTMainGui.png deleted file mode 100644 index fcbffe2..0000000 Binary files a/docs/gui/ecmcFFTMainGui.png and /dev/null differ diff --git a/src/ecmcSS1SafetyGroup.cpp b/src/ecmcSS1SafetyGroup.cpp index a07640c..08d5ecf 100644 --- a/src/ecmcSS1SafetyGroup.cpp +++ b/src/ecmcSS1SafetyGroup.cpp @@ -182,8 +182,7 @@ void ecmcSS1SafetyGroup::validateCfgs() { } } -void ecmcSS1SafetyGroup::validateAxes() { - +void ecmcSS1SafetyGroup::validateAxes() { // Ensure that axis is not linked twice to group for(std::vector::iterator iaxis = axes_.begin(); iaxis != axes_.end(); ++iaxis) { int axisLinkedCounter = 0; @@ -213,11 +212,19 @@ void ecmcSS1SafetyGroup::validateAxes() { } } + int axisCounter = 0; // Check axis object exists and valid for(std::vector::iterator saxis = axes_.begin(); saxis != axes_.end(); ++saxis) { if(!getAxisValid((*saxis)->axisId_)) { throw std::runtime_error( "Safety: Ecmc Axis object not valid."); } + axisCounter++; + } + + // do not allow empty group + if(axisCounter == 0) { + printf("Safety %s: Error, group empty (axis count zero)\n",sName_); + throw std::runtime_error( "Safety: Error, empty group not allowed."); } } diff --git a/src/ecmcSafetyPlgWrap.cpp b/src/ecmcSafetyPlgWrap.cpp index 0ab1810..ff9d4e3 100644 --- a/src/ecmcSafetyPlgWrap.cpp +++ b/src/ecmcSafetyPlgWrap.cpp @@ -37,13 +37,32 @@ int setCfgString(const char* cfgString) { return 0; } +ecmcSS1SafetyGroup* getGroupFromName(const char *name) { + // Find group by name + for(std::vector::iterator psafetyGroup = safetyGroups.begin(); psafetyGroup != safetyGroups.end(); ++psafetyGroup) { + bool found = strcmp(name, (*psafetyGroup)->getName().c_str()) == 0; + if(found) { + return (*psafetyGroup); + } + } + return NULL; +} + + int createSafetyGroup(const char *name, const char *ec_rampdown_cmd, const char *ec_standstill_status, int time_delay_ms) { + // ensure group does not already exist + ecmcSS1SafetyGroup* safetyGroup = getGroupFromName(name); + if( safetyGroup ) { + printf("Safety: Error, group %s already defined. Plugin will unload.\n"); + throw std::runtime_error( "Safety: Error, group already defined."); + } + // create new ecmcSS1SafetyGroup object - ecmcSS1SafetyGroup* safetyGroup = NULL; + safetyGroup = NULL; // create asynport name for new object () memset(portNameBuffer, 0, ECMC_PLUGIN_MAX_PORTNAME_CHARS); @@ -61,7 +80,6 @@ int createSafetyGroup(const char *name, if(safetyGroup) { delete safetyGroup; } - return ECMC_PLUGIN_SAFETY_ERROR_CODE; } safetyGroups.push_back(safetyGroup); @@ -74,16 +92,17 @@ int addAxisToSafetyGroup(const char *groupName, int axisId, double veloLimit, int standStillTimeMs) { - // Find group by name - for(std::vector::iterator psafetyGroup = safetyGroups.begin(); psafetyGroup != safetyGroups.end(); ++psafetyGroup) { - bool found = strcmp(groupName, (*psafetyGroup)->getName().c_str()) == 0; - if(found) { - (*psafetyGroup)->addAxis(axisId,veloLimit,standStillTimeMs); - return asynSuccess; - } + + ecmcSS1SafetyGroup* grp = getGroupFromName(groupName); + + if( !grp ) { + printf("Safety: Error, group %s not found. Plugin will unload.\n",groupName); + throw std::runtime_error( "Safety: Error, group not found."); } - return asynError; + grp->addAxis(axisId,veloLimit,standStillTimeMs); + + return asynSuccess; } void deleteAllSafetyGroups() { @@ -98,17 +117,26 @@ void deleteAllSafetyGroups() { } int validate() { + int groupCount = 0; for(std::vector::iterator psafetyGroup = safetyGroups.begin(); psafetyGroup != safetyGroups.end(); ++psafetyGroup) { if(*psafetyGroup) { try { (*psafetyGroup)->validate(); + groupCount++; } catch(std::exception& e) { - printf("Exception: %s. Plugin will unload.\n",e.what()); + printf("Safety: %s. Plugin will unload.\n",e.what()); return ECMC_PLUGIN_SAFETY_ERROR_CODE; } } } + + // Do not allow loaded plugin with no group configured + if(groupCount == 0) { + printf("Saftey: Error, group count 0. Plugin will unload.\n"); + return ECMC_PLUGIN_SAFETY_ERROR_CODE; + } + return 0; } @@ -120,7 +148,7 @@ int executeSafetyGroups() { (*psafetyGroup)->execute(); } catch(std::exception& e) { - printf("Exception: %s. Plugin will unload.\n",e.what()); + printf("Safety: %s. Plugin will unload.\n",e.what()); return ECMC_PLUGIN_SAFETY_ERROR_CODE; } } @@ -165,7 +193,7 @@ int ecmcAddSS1SafetyGroup(const char* name, const char* ec_rampdown_cmd,const ch } if(time_delay_ms <= 0) { printf("Error: time_delay invalid.\n"); - exit (1); + exit (EXIT_FAILURE); } try { @@ -173,7 +201,7 @@ int ecmcAddSS1SafetyGroup(const char* name, const char* ec_rampdown_cmd,const ch } catch(std::exception& e) { printf("Exception: %s. Add safety group failed.\n",e.what()); - exit (1); + exit (EXIT_FAILURE); } return asynSuccess; @@ -224,24 +252,24 @@ int ecmcAddAxisToSafetyGroup(const char* name, int axis_id, double velo_lim, int if(axis_id <= 0) { printf("Error: Invalid axis id.\n"); - exit (1); + exit(EXIT_FAILURE); } if(velo_lim < 0) { printf("Error: Invalid velocity limit.\n"); - exit (1); + exit(EXIT_FAILURE); } if(stand_still_time < 0) { printf("Error: Invalid stand still filter time.\n"); - exit (1); + exit(EXIT_FAILURE); } try { return addAxisToSafetyGroup(name,axis_id, velo_lim, stand_still_time); } catch(std::exception& e) { printf("Exception: %s. Add axis to safety group failed.\n",e.what()); - exit (1); + exit(EXIT_FAILURE); } return asynSuccess;