Commit 63f70ec9 authored by Franck Cecillon's avatar Franck Cecillon

new controller

parent b45e99ba
/*
* 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/ChopperSetup.h>
#include <drivers/astrium/chopper_ncs/ChopperNCSDef.h>
#include "DeviceContainer/Def/CommandDef.h"
using namespace std;
using namespace chopper;
namespace d17 {
const string ChopperSetup::TYPE = "chopperSetup";
/*
* constructor
*/
ChopperSetup::ChopperSetup(const string& name) :
ExperimentController(name), controller::Stoppable(this) {
setFamily(family::BEAM_PARAMETERS, family::CHOPPER);
// Init property
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");
gear1.init(this, SAVE, "actual_gear1", "wanted_gear1", "gear1");
dire1.init(this, SAVE, "actual_dire1", "wanted_dire1", "Dire1");
gear2.init(this, SAVE, "actual_gear2", "wanted_gear2", "gear2");
dire2.init(this, SAVE, "actual_dire2", "wanted_dire2", "Dire2");
chopper1Name.init(this, NOSAVE, "chopper1_name");
chopper2Name.init(this, NOSAVE, "chopper2_name");
indiceChopperMaster.init(this, SAVE, "indiceChopperMaster");
indChopperActive.init(this, SAVE, "indChopperActive");
indiceActionChopper.init(this, SAVE, "indiceActionChopper");
// Init drivers
m_NCSDriver.init(this, "ncs_driver");
registerFunction(TYPE);
indChopperActive = 0;
indiceActionChopper = CMD1_ON_IDLE;
}
/*
* destructor
*/
ChopperSetup::~ChopperSetup() {
}
/*
* postConfiguration
*/
void ChopperSetup::postConfiguration() {
Publisher::attach(this);
// Link with controller update
registerUpdater(m_NCSDriver->currentSpeed, &ChopperSetup::updateSpeed, this);
registerUpdater(m_NCSDriver->currentPhase, &ChopperSetup::updatePhase, this);
registerUpdater(m_NCSDriver->chopperStatus, &ChopperSetup::updateActualStatus, this);
// Progression
registerProgression(m_NCSDriver, &ChopperSetup::updateProgression, this);
chopper1Name = "CH1";
chopper2Name = "CH2";
}
// Chopper 1
void ChopperSetup::updateSpeed(int32 ki) {
if (ki == 0) {
speedChopper1 = m_NCSDriver->currentSpeed.get(ki);
} else {
speedChopper2 = m_NCSDriver->currentSpeed.get(ki);
}
}
void ChopperSetup::updatePhase(int32 ki) {
if (ki == 0) {
phaseChopper1 = m_NCSDriver->currentPhase.get(ki);
} else {
phaseChopper2 = m_NCSDriver->currentPhase.get(ki);
}
}
/*
* updateProgression
*/
void ChopperSetup::updateProgression() {
int32 lProgression = 0;
lProgression = (m_NCSDriver->commandProgression() + m_NCSDriver->commandProgression()) / 2;
if (lProgression >= 100) {
lProgression = 99;
}
commandProgression = lProgression;
}
/*
* start
*/
void ChopperSetup::start() {
commandProgression = 0; // Set progression to 0
commandStatus.setRunning();
indiceChopperMaster = indChopperActive();
m_NCSDriver->isSync = 0;
m_NCSDriver->isMaster = 1;
m_NCSDriver->indChopperActive = indChopperActive();
m_NCSDriver->speed.setpoint = speedChopper1.setpoint();
m_NCSDriver->phase.setpoint = phaseChopper1.setpoint();
switch (indiceActionChopper()) {
case CMD1_ON_RESET:
cout << " CMD1_ON_RESET ?? not implemented" << endl;
//m_NCSDriver.execute(driver::START_COMMAND, true);
break;
case CMD1_ON_CALIBRATION:
m_NCSDriver.execute(COMMAND_CALIBRATE_DEVICE_CONTAINER, true);
break;
case CMD1_ON_BRAKE:
if (indChopperActive() == chopper_ncs::IND_CH1) {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH1;
} else {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH2;
}
break;
case CMD1_SETDIR:
if (indChopperActive() == chopper_ncs::IND_CH1) {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH1;
m_NCSDriver->dire = dire1.setpoint();
} else {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH2;
m_NCSDriver->dire = dire2.setpoint();
}
m_NCSDriver.execute(COMMAND_SETDIR_DEVICE_CONTAINER, true);
break;
case CMD1_SETGEAR:
if (indChopperActive() == chopper_ncs::IND_CH1) {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH1;
m_NCSDriver->gear = gear1.setpoint();
} else {
m_NCSDriver->indChopperActive.setpoint = chopper_ncs::IND_CH2;
m_NCSDriver->gear = gear2.setpoint();
}
m_NCSDriver.execute(COMMAND_SETGEAR_DEVICE_CONTAINER, true);
break;
default:
cout << " CMD unknown " << endl;
return;
}
switch(indiceActionChopper() )
m_NCSDriver.execute(driver::START_COMMAND, true);
m_NCSDriver->isSync = 1;
}
/*
* stop
*/
void ChopperSetup::stop() {
m_NCSDriver.execute(driver::STOP_COMMAND, true);
log(Level::s_Info) << "Stopped" << endlog;
}
void ChopperSetup::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 CHOPPERSETUP_H
#define CHOPPERSETUP_H
#include <Controller.h>
#include "controllers/common/chopper/ChopperController.h"
#include <drivers/astrium/chopper_ncs/ChopperNCSDriver.h>
namespace d17 {
/*!
* \class ChopperSetup
* \brief lss instrument
* \brief Manage the two mirror needed for ChopperSetup
*
* \par
* This class is implemented simple Chopper functionalities
*/
class ChopperSetup: public ExperimentController, public controller::Stoppable{
public:
//! Type of controller
static const std::string TYPE;
/*!
* \brief Constructor
* \param[in] name the name of the experiment controller
*/
ChopperSetup(const std::string& name);
/*!
* \brief Destructor
*/
virtual ~ChopperSetup();
/*!
* Properties
*/
Property<int32, SETPOINT> speedChopper1;
Property<int32, SETPOINT> speedChopper2;
Property<float64, SETPOINT> phaseChopper1;
Property<float64, SETPOINT> phaseChopper2;
Property<int32, SETPOINT > gear1; //! phase property
Property<std::string, SETPOINT> dire1; //! dir property
Property<int32, SETPOINT > gear2; //! phase property
Property<std::string, SETPOINT> dire2; //! dir property
Property<std::string> chopper1Name;
Property<std::string> chopper2Name;
Property<int32> indiceChopperMaster;
Property<int32> indChopperActive;
Property<int32> indiceActionChopper;
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();
protected:
/*!
* \brief start
* - send parameters to the two axis
* - send command to axis
*/
virtual void start();
/*!
* \brief Stop command
*/
virtual void stop();
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();
static const uint16 CMD1_ON_RESET = 0;
static const uint16 CMD1_ON_CALIBRATION = 1;
static const uint16 CMD1_ON_BRAKE = 2;
static const uint16 CMD1_SETDIR = 3;
static const uint16 CMD1_SETGEAR = 4;
static const uint16 CMD1_ON_IDLE = 20;
};
}
#endif //CHOPPERSETUP_H
......@@ -11,5 +11,7 @@
<controller class="d17::CalSAN"/>
<controller class="d17::D17ChopperController"/>
<controller class="d17::OpeningV2"/>
<controller class="d17::ChopperSetup"/>
</module>
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