Remove APPLY_SCALE command (always enabled). Add cfg SCALE for scaling of source data

This commit is contained in:
Anders Sandstrom
2020-10-02 16:15:47 +02:00
parent 2cce34dbd1
commit 88bbddd58a
5 changed files with 35 additions and 24 deletions

View File

@@ -46,7 +46,7 @@ The different available configuration settings:
* SOURCE= source variable : Sets source variable for FFT (example: ec0.s1.AI_1). This config is mandatory.
* DBG_PRINT=1/0 : Enables/disables printouts from plugin, default = disabled.
* NFFT= nfft : Data points to collect, default = 4096.
* APPLY_SCALE=1/0 : Apply scale, default = enabled.
* SCALE=scale : Apply scale to input data, default = 1.0.
* RM_DC=1/0 : Remove DC offset of input data (SOURCE), default = disabled.
* RM_LIN=1/0 : Remove linear component input data (SOURCE), default = disabled.
* ENABLE=1/0 : Enable data acq. and calcs (can be controlled over asyn), default = disabled.
@@ -88,19 +88,19 @@ Exmaple: 1024
```
"NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
#### APPLY_SCALE (default disabled)
Apply scaling in order to get correct amplitude of fft. Disabled as default (lower cpu usage).
#### SCALE (default 1.0)
Apply custom scale to input data.
Exmaple: Enable
Exmaple: 5.0
```
"APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
"SCALE=5.0;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
### RM_DC
Remove DC of input signal. Default is disabled.
Exmaple: Remove DC offset
```
"RM_DC=1;APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
"RM_DC=1;SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
### RM_LIN
@@ -110,14 +110,14 @@ Could be usefull for values that increase, like actual position.
Exmaple: Remove linear component
```
"RM_LIN=1;APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
"RM_LIN=1;SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
#### ENABLE (default: disabled)
Enable data acq. and FFT calcs. The default settings is disabled so needs to be enabled from plc or over asyn in order to start calculations.
Exmaple: Enable at startup by config
```
"ENABLE=1;RM_DC=1;APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
"ENABLE=1;RM_DC=1;SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
Exmaple: Enable FFT index 0 from EPICS:
```
@@ -154,7 +154,7 @@ Triggered mode:
Exmaple: Mode triggered
```
"MODE=TRIGG;ENABLE=1;RM_DC=1;APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
"MODE=TRIGG;ENABLE=1;RM_DC=1;SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
Exmaple: Mode from EPICS record
```
@@ -171,7 +171,7 @@ Note: only a lower and "integer" division of sample rate can be defined.
Exmaple: Rate = 100Hz
```
RATE=100;MODE=TRIGG;ENABLE=1;RM_DC=1;APPLY_SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
RATE=100;MODE=TRIGG;ENABLE=1;RM_DC=1;SCALE=1;NFFT=1024;DBG_PRINT=0;SOURCE=ax1.poserr;"
```
## EPICS records
Each FFT plugin object will create a new asynportdriver-port named "PLUGIN.FFT<index>" (index is explaine above).
@@ -279,7 +279,7 @@ Plugin info:
DBG_PRINT=<1/0> : Enables/disables printouts from plugin, default = disabled.
SOURCE=<source> : Sets source variable for FFT (example: ec0.s1.AI_1).
NFFT=<nfft> : Data points to collect, default = 4096.
APPLY_SCALE=<1/0> : Apply scale, default = disabled.
SCALE=<1/0> : Apply scale, default = disabled.
RM_DC=<1/0> : Remove DC offset of input data (SOURCE), default = disabled.
ENABLE=<1/0> : Enable data acq. and calcs (can be controlled over asyn), default = disabled.
MODE=<CONT/TRIGG> : Continious or triggered mode, defaults to TRIGG

View File

@@ -129,9 +129,10 @@ ecmcFFT::ecmcFFT(int fftIndex, // index of this object (if several is cr
cfgNfft_ = ECMC_PLUGIN_DEFAULT_NFFT; // samples in fft (must be n^2)
cfgDcRemove_ = 0;
cfgLinRemove_ = 0;
cfgApplyScale_ = 1; // Scale as default to get correct amplitude in fft
//cfgApplyScale_ = 1; // Scale as default to get correct amplitude in fft
cfgEnable_ = 0; // start disabled (enable over asyn)
cfgMode_ = TRIGG;
cfgScale_ = 1.0;
parseConfigStr(configStr); // Assigns all configs
// Check valid nfft
@@ -237,11 +238,11 @@ void ecmcFFT::parseConfigStr(char *configStr) {
cfgNfft_ = atoi(pThisOption);
}
// ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD (1/0)
else if (!strncmp(pThisOption, ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD, strlen(ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD))) {
pThisOption += strlen(ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD);
cfgApplyScale_ = atoi(pThisOption);
}
// // ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD (1/0)
// else if (!strncmp(pThisOption, ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD, strlen(ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD))) {
// pThisOption += strlen(ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD);
// cfgApplyScale_ = atoi(pThisOption);
// }
// ECMC_PLUGIN_RM_DC_OPTION_CMD (1/0)
else if (!strncmp(pThisOption, ECMC_PLUGIN_RM_DC_OPTION_CMD, strlen(ECMC_PLUGIN_RM_DC_OPTION_CMD))) {
@@ -278,6 +279,12 @@ void ecmcFFT::parseConfigStr(char *configStr) {
cfgFFTSampleRateHz_ = atof(pThisOption);
}
// ECMC_PLUGIN_SCALE_OPTION_CMD rate in HZ
else if (!strncmp(pThisOption, ECMC_PLUGIN_SCALE_OPTION_CMD, strlen(ECMC_PLUGIN_SCALE_OPTION_CMD))) {
pThisOption += strlen(ECMC_PLUGIN_SCALE_OPTION_CMD);
cfgScale_ = atof(pThisOption);
}
pThisOption = pNextOption;
}
free(pOptions);
@@ -414,8 +421,8 @@ void ecmcFFT::dataUpdatedCallback(uint8_t* data,
void ecmcFFT::addDataToBuffer(double data) {
if(rawDataBuffer_ && (elementsInBuffer_ < cfgNfft_) ) {
rawDataBuffer_[elementsInBuffer_] = data;
prepProcDataBuffer_[elementsInBuffer_] = data;
rawDataBuffer_[elementsInBuffer_] = data* cfgScale_;
prepProcDataBuffer_[elementsInBuffer_] = data *cfgScale_;
}
elementsInBuffer_ ++;
}
@@ -446,9 +453,10 @@ void ecmcFFT::calcFFT() {
}
void ecmcFFT::scaleFFT() {
if(!cfgApplyScale_) {
return;
}
// Always scale
//if(!cfgApplyScale_) {
// return;
//}
for(unsigned int i = 0 ; i < cfgNfft_ ; ++i ) {
fftBufferResult_[i] = fftBufferResult_[i] * scale_;

View File

@@ -104,6 +104,7 @@ class ecmcFFT : public asynPortDriver {
int cfgEnable_; // Config: Enable data acq./calc.
FFT_MODE cfgMode_; // Config: Mode continous or triggered.
double cfgFFTSampleRateHz_; // Config: Sample rate (defaukts to ecmc rate)
double cfgScale_;
bool isEcEntry_;

View File

@@ -18,11 +18,13 @@
#define ECMC_PLUGIN_DBG_PRINT_OPTION_CMD "DBG_PRINT="
#define ECMC_PLUGIN_SOURCE_OPTION_CMD "SOURCE="
#define ECMC_PLUGIN_NFFT_OPTION_CMD "NFFT="
#define ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD "APPLY_SCALE="
//#define ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD "APPLY_SCALE="
#define ECMC_PLUGIN_RM_DC_OPTION_CMD "RM_DC="
#define ECMC_PLUGIN_ENABLE_OPTION_CMD "ENABLE="
#define ECMC_PLUGIN_RATE_OPTION_CMD "RATE="
#define ECMC_PLUGIN_RM_LIN_OPTION_CMD "RM_LIN="
#define ECMC_PLUGIN_SCALE_OPTION_CMD "SCALE="
// CONT, TRIGG
#define ECMC_PLUGIN_MODE_OPTION_CMD "MODE="

View File

@@ -118,7 +118,7 @@ struct ecmcPluginData pluginDataDef = {
.optionDesc = "\n "ECMC_PLUGIN_DBG_PRINT_OPTION_CMD"<1/0> : Enables/disables printouts from plugin, default = disabled.\n"
" "ECMC_PLUGIN_SOURCE_OPTION_CMD"<source> : Sets source variable for FFT (example: ec0.s1.AI_1).\n"
" "ECMC_PLUGIN_NFFT_OPTION_CMD"<nfft> : Data points to collect, default = 4096.\n"
" "ECMC_PLUGIN_APPLY_SCALE_OPTION_CMD"<1/0> : Apply scale, default = disabled.\n"
" "ECMC_PLUGIN_SCALE_OPTION_CMD"scalefactor : Apply scale to source data, default = 1.0.\n"
" "ECMC_PLUGIN_RM_DC_OPTION_CMD"<1/0> : Remove DC offset of input data (SOURCE), default = disabled.\n"
" "ECMC_PLUGIN_RM_LIN_OPTION_CMD"<1/0> : Remove linear component in data (SOURCE) by least square, default = disabled.\n"
" "ECMC_PLUGIN_ENABLE_OPTION_CMD"<1/0> : Enable data acq. and calcs (can be controlled over asyn), default = disabled.\n"