/* * File: BunchCharge.h * Author: lpiccoli * * Created on June 7, 2010, 3:59 PM */ #ifndef _BUNCHCHARGE_H #define _BUNCHCHARGE_H #include "Defs.h" #include "LoopConfiguration.h" #include "Algorithm.h" #include "MeasurementAverage.h" #include "CaChannel.h" FF_NAMESPACE_START /** * The BunchCharge algorithm behaves a little different than the other feedbacks. * It is constantly reading the single measurement (BPMS:IN20:221:TMIT) and * once it accumulates 10 good measurements, a new actuator value is calculated * and written out (if possible). * * @author L.Piccoli */ class BunchCharge : public Algorithm { public: BunchCharge() : Algorithm("BunchCharge"), _m1Average(10, "M1 Measurement Average"), _m1(NULL), _s1(NULL), _a1(NULL), _goodMeasurementsCount(0), _actuatorSkipCount(0), _mismatchPulseIdMeasurements(0), _laserWaveplateMovingChannel(NULL), _laserWaveplateDoneMovingChannel(NULL), _cameraWaveplateMovingChannel(NULL), _cameraWaveplateDoneMovingChannel(NULL) { }; virtual ~BunchCharge() { if (_laserWaveplateMovingChannel != NULL) delete _laserWaveplateMovingChannel; if (_laserWaveplateDoneMovingChannel != NULL) delete _laserWaveplateDoneMovingChannel; if (_cameraWaveplateMovingChannel != NULL) delete _cameraWaveplateMovingChannel; if (_cameraWaveplateDoneMovingChannel != NULL) delete _cameraWaveplateDoneMovingChannel; }; virtual int configure(LoopConfiguration *configuration, MeasurementSet *measurements, ActuatorSet *actuators, StateSet *states) throw (Exception); virtual int calculate(LoopConfiguration &configuration, MeasurementSet &measurements, ActuatorSet &actuators, StateSet &states) throw (Exception); protected: virtual int getMeasurements(); private: /** Running average of M1 measurements */ MeasurementAverage _m1Average; /** Pointer to the M1 measurement */ MeasurementDevice *_m1; /** Pointer to the S1 state */ StateDevice *_s1; /** Pointer to the A1 actuator */ ActuatorDevice *_a1; /** Count the number of good TMITs collected */ unsigned _goodMeasurementsCount; /** * Count the number of times actuator setting was skipped because * waveplates were not done moving */ unsigned _actuatorSkipCount; /** Count how many measurements had mismatching PULSEID in sequence */ unsigned _mismatchPulseIdMeasurements; /** * ChannelAccess connection to laser waveplate (1 if it still moving), * PV -> WPLT:LR20:116:WP2_ANGLE.MOVN */ CaChannel *_laserWaveplateMovingChannel; /** * ChannelAccess connection to laser waveplate (1 if done moving), * PV -> WPLT:LR20:116:WP2_ANGLE.DMOV */ CaChannel *_laserWaveplateDoneMovingChannel; /** * ChannelAccess connection to camera waveplate (1 if it still moving), * PV -> WPLT:IN20:181:VCC_ANGLE.MOVN */ CaChannel *_cameraWaveplateMovingChannel; /** * ChannelAccess connection to camera waveplate (1 if done moving), * PV -> WPLT:IN20:181:VCC_ANGLE.DMOV */ CaChannel *_cameraWaveplateDoneMovingChannel; static const unsigned MAX_GOOD_MEASUREMENTS = 10; static const double ACTUATOR_DEADBAND = 0.005; static const unsigned MAX_ACTUATOR_SKIP = 10; static const unsigned MAX_MISMATCHED_PULSEID_MEASUREMENTS = 20; double calculateActuator(); void updateActuator(double newValue); void updateState(double newValue); bool checkWaveplate() throw (Exception); bool isWaveplateMoving(); bool doneMoving(); }; FF_NAMESPACE_END #endif /* _BUNCHCHARGE_H */