Commit 6c9b8f9c authored by Franck Cecillon's avatar Franck Cecillon

new module Opening

parent 41c3f7db
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "Utilities/Calculations.h"
#include "controllers/common/family/Families.h"
#include "controllers/common/baselegacy/ControllerErrorDef.h"
#include <cmath>
#include <boost/thread/thread.hpp>
#include <controllers/lss/d17/OpeningV2.h>
#include <drivers/astrium/chopper_ncs/ChopperNCSDef.h>
using namespace std;
using namespace chopper;
namespace d17 {
const string OpeningV2::TYPE = "openingV2";
/*
* constructor
*/
OpeningV2::OpeningV2(const string& name) :
ExperimentController(name), controller::Stoppable(this), controller::Read(this) {
setFamily(family::BEAM_PARAMETERS, family::CHOPPER);
// Init property
opening.init(this, SAVE| SCAN | SPY, "actual_opening", "wanted_opening", "OpeningV2");
ratio.init(this, SAVE, "ratio_speed");
speed.init(this, SAVE | SPY, "actual_speed", "wanted_speed", "Speed");
speedChopper1.init(this, NOSAVE, "actual_speed1", "wanted_speed1", "Speed1");
speedChopper2.init(this, NOSAVE, "actual_speed2", "wanted_speed2", "Speed2");
phaseChopper1.init(this, NOSAVE, "actual_phase1", "wanted_phase1", "Phase1");
phaseChopper2.init(this, NOSAVE, "actual_phase2", "wanted_phase2", "Phase2");
refForOpeningV2.init(this, SAVE, "refforopening");
refForPickup.init(this, SAVE, "refforpickup");
chopper1Name.init(this, NOSAVE, "chopper1_name");
chopper2Name.init(this, NOSAVE, "chopper2_name");
offsetOppening.init(this, SAVE, "offset_oppening");
indiceChopperMaster.init(this,SAVE, "indiceChopperMaster");
indChopperActive.init(this, SAVE, "indChopperActive");
// Init drivers
m_NCSDriver.init(this, "ncs_driver");
registerFunction(TYPE);
}
/*
* destructor
*/
OpeningV2::~OpeningV2() {
}
/*
* postConfiguration
*/
void OpeningV2::postConfiguration() {
Publisher::attach(this);
// Method to set properties
registerRefresher(opening.setpoint, &OpeningV2::refreshWantedOpeningV2, this);
// Link with controller update
registerUpdater(m_NCSDriver->currentSpeed , &OpeningV2::updateSpeed, this);
registerUpdater(m_NCSDriver->currentPhase , &OpeningV2::updatePhase, this);
registerUpdater(m_NCSDriver->chopperStatus ,&OpeningV2::updateActualStatus, this);
// Progression
registerProgression(m_NCSDriver, &OpeningV2::updateProgression, this);
chopper1Name = "CH1";
chopper2Name = "CH2";
}
void OpeningV2::refreshWantedOpeningV2(float64 value) throw (CannotSetValue) {
if (value > 10.0) {
stringstream message;
message << "Allowed max opening is 10)";
sendErrorEvent(WARNING_ERROR, message.str());
throw CannotSetValue(LIMIT_STR);
}
calculate_before(value);
}
// Chopper 1
void OpeningV2::updateSpeed(int32 ki){
if (ki == 1 ) {
speedChopper1 = m_NCSDriver->currentSpeed.get(ki);
speed = m_NCSDriver->currentSpeed.get(ki);
}else {
speedChopper2 = m_NCSDriver->currentSpeed.get(ki);
}
}
void OpeningV2::updatePhase(int32 ki) {
if (ki == 1 ) {
phaseChopper1 = m_NCSDriver->currentPhase.get(ki);
}else {
phaseChopper2 = m_NCSDriver->currentPhase.get(ki);
}
ComputeActualOpeningV2();
}
void OpeningV2::ComputeActualOpeningV2() {
float64 newopen = refForPickup() + phaseChopper1() - phaseChopper2() - (offsetOppening());
opening.update(newopen);
}
/*
* updateProgression
*/
void OpeningV2::updateProgression() {
int32 lProgression = 0;
lProgression = (m_NCSDriver->commandProgression() + m_NCSDriver->commandProgression()) / 2;
if (lProgression >= 100) {
lProgression = 99;
}
commandProgression = lProgression;
}
void OpeningV2::calculate_before( float64 value) {
if (ratio() == 0) {
ratio = 1;
}
speedChopper1.setpoint = speed.setpoint();
speedChopper2.setpoint = speed.setpoint() / ratio();
phaseChopper1.setpoint = refForOpeningV2();
phaseChopper2.setpoint = (-1 * value ) + refForPickup() + phaseChopper1.setpoint() - (offsetOppening() );
}
void OpeningV2::calculate() {
if (ratio() == 0) {
ratio = 1;
}
speedChopper1.setpoint = speed.setpoint();
speedChopper2.setpoint = speed.setpoint() / ratio();
phaseChopper1.setpoint = refForOpeningV2();
phaseChopper2.setpoint = (-1 * opening.setpoint()) + refForPickup() + phaseChopper1.setpoint() - (offsetOppening() );
}
void OpeningV2::setNewOffsetOppening(float64 value){
offsetOppening = value;
ComputeActualOpeningV2();
}
/*
* start
*/
void OpeningV2::start() {
commandProgression = 0; // Set progression to 0
commandStatus.setRunning();
calculate();
try {
indiceChopperMaster = chopper_ncs::IND_CH1 ;
m_NCSDriver->isSync = 1;
m_NCSDriver->isMaster = 1;
m_NCSDriver->indChopperActive = chopper_ncs::IND_CH1 ;
m_NCSDriver->speed.setpoint = speedChopper1.setpoint();
m_NCSDriver->phase.setpoint = phaseChopper1.setpoint();
m_NCSDriver.execute(driver::START_COMMAND, true);
m_NCSDriver->indChopperActive = chopper_ncs::IND_CH2 ;
m_NCSDriver->speed.setpoint = speedChopper2.setpoint();
m_NCSDriver->phase.setpoint = phaseChopper2.setpoint();
/* Parallel::begin();
chopper1->startParallel(false);
chopper2->startParallel(false);
Parallel::end();*/
} catch (CannotSetValue &e) {
cerr << " Chopper OpeningV2 Over limits" << endl;
}
log(Level::s_Info) << opening << endlog;
commandStatus.setIdle();
commandProgression = 100;
}
/*
* read
*/
void OpeningV2::read() {
}
/*
* stop
*/
void OpeningV2::stop() {
m_NCSDriver.execute(driver::STOP_COMMAND, true);
log(Level::s_Info) << "Stopped" << endlog;
}
void OpeningV2::updateActualStatus(int32 ki){
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef OPENINGV2_H
#define OPENINGV2_H
#include <Controller.h>
#include "controllers/common/chopper/ChopperController.h"
#include <drivers/astrium/chopper_ncs/ChopperNCSDriver.h>
namespace d17 {
/*!
* \class OpeningV2
* \brief lss instrument
* \brief Manage the two mirror needed for OpeningV2
*
* \par
* This class is implemented simple Chopper functionalities
*/
class OpeningV2: public ExperimentController, public controller::Stoppable, public controller::Read {
public:
//! Type of controller
static const std::string TYPE;
/*!
* \brief Constructor
* \param[in] name the name of the experiment controller
*/
OpeningV2(const std::string& name);
/*!
* \brief Destructor
*/
virtual ~OpeningV2();
/*!
* Properties
*/
Property<float64, SETPOINT> opening; //! config a integer to store the resolution config
Property<int32> ratio;
Property<int32, SETPOINT> speed;
Property<int32, SETPOINT> speedChopper1;
Property<int32, SETPOINT> speedChopper2;
Property<float64, SETPOINT> phaseChopper1;
Property<float64, SETPOINT> phaseChopper2;
Property<float64> refForOpeningV2;
Property<float64> refForPickup;
Property<std::string> chopper1Name;
Property<std::string> chopper2Name;
Property<float64 > offsetOppening;
Property<int32> indiceChopperMaster;
Property<int32> indChopperActive; //! speed property
// ControllerPtr<chopper::ChopperController> chopper1; //! chopper CH1 link
// ControllerPtr<chopper::ChopperController> chopper2; //! chopper CH2 link
DriverPtr<chopper_ncs::chopperNCSDriver> m_NCSDriver;
/*!
* \brief Method called before changing the property value
*
* This method is called after setting configuration during the creation of controller.
*/
virtual void postConfiguration();
void setNewOffsetOppening(float64 value);
protected:
/*!
* \brief start
* - send parameters to the two axis
* - send command to axis
*/
virtual void start();
/*!
* \brief Stop command
*/
virtual void stop();
/*!
* \brief Read command
*/
virtual void read();
/*!
* \brief Method called before changing the Wanted Config (resolution) property value
* \param[in] value the property value
* \throws CannotSetValue the value isn't corrected, or property couldn't be changed
*/
virtual void refreshWantedOpeningV2(float64 value) throw (CannotSetValue);
virtual void updateSpeed(int32 ki);
virtual void updatePhase(int32 ki);
virtual void updateActualStatus(int32 ki);
/*!
* \brief update the progression property from driver one
*/
void updateProgression();
/*!
* \brief calculate : choice or calculate the good choppers parameters related to the resolution
*/
virtual void calculate();
virtual void calculate_before( float64 value);
virtual void ComputeActualOpeningV2();
};
}
#endif //OPENING_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment