Commit 3b0a5823 authored by Jacob Lamblin's avatar Jacob Lamblin
Browse files

Controller for the Stereo watchdog

parent 72939570
<module name="stereo_watchdog">
<controller class="stereo_watchdog::StereoWatchdogController"/>
<include path="$(NOMAD_HOME)/../NomadSpecialModules/src"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
</module>
\ No newline at end of file
/*
* 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 "StereoWatchdogController.h"
#include "controllers/common/family/Families.h"
#include <boost/thread.hpp>
#include <boost/bind.hpp>
using namespace std;
using namespace icpcon7217;
namespace stereo_watchdog {
const string StereoWatchdogController::TYPE = "stereo_watchdog_controller";
/*
* Constructor
*/
StereoWatchdogController::StereoWatchdogController(const string& name) :ExperimentController(name) {
setFamily(family::SAMPLE_ENVIRONMENT);
// Init property
d0.init(this, NOSAVE, "D0");
safe.init(this,NOSAVE, "safe");
temperaturemax.init(this,SAVE,"temperaturemax");
temperature.init(this,NOSAVE,"temperature");
level1.init(this,NOSAVE,"level1");
level2.init(this,NOSAVE,"level2");
m_Driver.init(this, "driver");
m_TemperatureDriver.init(this, "tempdriver");
m_Level1Driver.init(this, "level1driver");
m_Level2Driver.init(this, "level2driver");
registerFunction(TYPE);
}
StereoWatchdogController::StereoWatchdogController(const StereoWatchdogController& controller) :
ExperimentController(controller){
d0.copy(this, controller.d0);
safe.copy(this, controller.safe);
temperaturemax.copy(this, controller.temperaturemax);
temperature.copy(this, controller.temperature);
level1.copy(this, controller.level1);
level2.copy(this, controller.level2);
m_Driver.copy(controller.m_Driver);
m_TemperatureDriver.copy(controller.m_TemperatureDriver);
m_Level1Driver.copy(controller.m_Level1Driver);
m_Level2Driver.copy(controller.m_Level2Driver);
}
/*
* Destructor
*/
StereoWatchdogController::~StereoWatchdogController() {
m_serverThread->join();
delete m_serverThread;
}
void StereoWatchdogController::postConfiguration() {
m_serverThread = new boost::thread(boost::bind(&StereoWatchdogController::Loop, this));
registerUpdater(m_TemperatureDriver->actualTemperature, &StereoWatchdogController::updateTemperature, this);
registerUpdater(m_Level1Driver->nitrogenLevel, &StereoWatchdogController::updateLevel1, this);
registerUpdater(m_Level2Driver->nitrogenLevel, &StereoWatchdogController::updateLevel2, this);
}
void StereoWatchdogController::Loop() {
int value;
while(true){
if(temperature()>temperaturemax()||level1()||level2()) safe.set(false); // the experiment is not safe
else safe.set(true);
if(safe()){
//d0.set(m_Driver->readDigitalOutput(0));
if(d0()==0) value=1;
else value=0;
m_Driver->writeDigitalOutput(0,value);
sleep(15);
d0.set(m_Driver->readDigitalOutput(0));
sleep(15);
}
else sleep(5);
}
}
void StereoWatchdogController::updateTemperature(){
temperature.set(m_TemperatureDriver->actualTemperature());
}
void StereoWatchdogController::updateLevel1(){
if(m_Level1Driver->nitrogenLevel()>99) level1.set(true);
else level1.set(false);
}
void StereoWatchdogController::updateLevel2(){
if(m_Level2Driver->nitrogenLevel()>99) level2.set(true);
else level2.set(false);
}
}
/*
* 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 STEREOWATCHDOGCONTROLLER_H
#define STEREOWATCHDOGCONTROLLER_H
#include <Controller.h>
#include "../../NomadModules/src/drivers/icp/icpcon7217/ICPcon7217Driver.h"
#include "../../NomadModules/src/drivers/icp/icpcon7217/ICPcon7217ChannelDriver.h"
#include <boost/thread.hpp>
namespace stereo_watchdog {
/*!
* \class StereoWatchdogController
*/
class StereoWatchdogController: public ExperimentController{
public:
//! Type of controller
static const std::string TYPE;
/*!
* \brief Constructor
*
* It is the default constructor called by the creator class ExperimentControllerCreator.
*
* \param[in] name the name of the controller
*/
StereoWatchdogController(const std::string& name);
/*!
* \brief Copy constructor
*
* \param[in] controller the controller to copy
*/
StereoWatchdogController(const StereoWatchdogController& controller);
/*!
* \brief Destructor
*/
virtual ~StereoWatchdogController();
/*!
* \brief Method called before changing the property value
*
* This method is called after setting configuration during the creation of controller.
*/
virtual void postConfiguration();
/*!
* Properties
*/
protected:
Property<int32> d0;
Property<bool> safe;
Property<float64> temperaturemax;
Property<float64> temperature;
Property<bool> level1;
Property<bool> level2;
DriverPtr<icpcon7217::ICPcon7217Driver> m_Driver; //! The ICPconDriver itself
DriverPtr<icpcon7217::ICPcon7217ChannelDriver> m_TemperatureDriver; //! The driver linked to the controller
DriverPtr<icpcon7217::ICPcon7217ChannelDriver> m_Level1Driver; //! The driver linked to the controller
DriverPtr<icpcon7217::ICPcon7217ChannelDriver> m_Level2Driver; //! The driver linked to the controller
/*!
* \brief start
*
*/
virtual void start(){};
private:
boost::thread * m_serverThread;
void Loop();
virtual void updateTemperature();
virtual void updateLevel1();
virtual void updateLevel2();
/*!
* \brief update the progression property from driver one
*/
void updateProgression();
};
}
#endif // STEREOWATCHDOGCONTROLLER_H
StereoWatchdog.temperaturePrefix=Temperature
StereoWatchdog.level1Prefix=Level 1
StereoWatchdog.level2Prefix=Level 2
StereoWatchdog.safePrefix=Safe state
StereoWatchdog.d0Prefix=D0
\ No newline at end of file
<controller_plugin_config type="stereo_watchdog_controller">
<image key="HARDWARE_VME_MODULE"/>
<settings view="stereo_watchdog_controllerView.xml">
</settings>
</controller_plugin_config>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller type="stereo_watchdog_controller">
<property name="D0" type="int32">
</property>
<property name="safe" type="boolean">
</property>
<property name="temperaturemax" type="float64">
</property>
<property name="temperature" type="float64">
</property>
<property name="level1" type="boolean">
</property>
<property name="level2" type="boolean">
</property>
</controller>
<plugin ok="true">
<controller type="stereo_watchdog_controller" role="StereoWatchdogController1"/>
<label role="StereoWatchdogController1" property="temperature" prefix="StereoWatchdog.temperaturePrefix"/>
<text role="StereoWatchdogController1" property="temperaturemax"/>
<newLine/>
<label role="StereoWatchdogController1" property="level1" prefix="StereoWatchdog.level1Prefix"/>
<newLine/>
<label role="StereoWatchdogController1" property="level2" prefix="StereoWatchdog.level2Prefix"/>
<newLine/>
<label role="StereoWatchdogController1" property="safe" prefix="StereoWatchdog.safePrefix"/>
<newLine/>
<label role="StereoWatchdogController1" property="D0" prefix="StereoWatchdog.d0Prefix"/>
</plugin>
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