StereoWatchdogController.cpp 3.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * 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;
Jacob Lamblin's avatar
Jacob Lamblin committed
27
using namespace icpcon7215;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

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);

56
57
	m_serverThread = NULL;

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

}

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() {
82
83
84
85
	if (m_serverThread != NULL) {
		m_serverThread->join();
		delete m_serverThread;
	}
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
}


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()){
105
			d0.set(m_Driver->readDigitalOutput(0));
106
107
108
109
			if(d0()==0) value=1;
			else value=0;
			m_Driver->writeDigitalOutput(0,value);
			d0.set(m_Driver->readDigitalOutput(0));
110
			sleep(5);
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
		}
		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);
}

}