The VisAO Camera
ShutterControl.cpp
Go to the documentation of this file.
1 /************************************************************
2 * ShutterControl.cpp
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Generic shutter controller. Used for simulations or as base class for real shutter.
7 *
8 * Developed as part of the Magellan Adaptive Optics system.
9 ************************************************************/
10 
11 /** \file ShutterControl.cpp
12  * \author Jared R. Males (jrmales@email.arizona.edu)
13  * \brief Definitions for a generic shutter controller.
14  *
15  * Declarations in \ref ShutterControl.h
16  *
17 */
18 
19 #include "ShutterControl.h"
20 
21 
23 {
25 }
26 
28 {
30 
31  dead_time = dt;
32 
33  sw_state = st;
34 
35  #ifdef SIMSHUTTER
36  hw_state = st;
37  #else
38  hw_state = 0;
39  #endif
40 
41 }
42 
44 {
45  dead_time = 0;
46 
47  sw_state = 0;
48  hw_state = 0;
49  ignore_hw_state = false;
50 
51  curr_t = 0;
52  last_t = 0;
53 
54  #ifdef SIMSHUTTER
55  delta_t = 0.001;
56  #endif
57 
58  return 0;
59 }
60 
61 int ShutterControl::set_last_t(double lt)
62 {
63  last_t = lt;
64  return 0;
65 }
66 
67 int ShutterControl::open_shutter(void *adata)
68 {
69  int state;
70  double ct;
71  ct = get_curr_t();
72 
73  state = get_state();
74 
75  if(state == 1) return sw_state; //already open
76 
77  //if(state == 0 && hw_state == 1) return 0; //probably already open.
78  if(ct - last_t >= dead_time) //not open, check dead time
79  {
80  if(do_shutter_open(adata) == 0)
81  {
82  sw_state = 1; //update state
83 
84  hw_state = get_hw_state();
85  last_t = ct; //update time
86 
87  return 1;
88  }
89  else
90  {
91  last_t = ct; //update time
92  std::cerr << "Error in do_shutter_open()\n";
93  return 0;
94  }
95  }
96 
97  return -1; //still shut
98 }
99 
100 int ShutterControl::close_shutter(void *adata)
101 {
102  int state;
103  double ct;
104  ct = get_curr_t();
105 
106  state = get_state();
107 
108  if(state == -1) return sw_state; //already shut
109 
110  //if(state == 0 && hw_state == -1) return 0; //probably already shut
111 
112  if(ct - last_t >= dead_time) // not shut, check dead time
113  {
114  if(do_shutter_close(adata) == 0)
115  {
116  sw_state = -1; //update state
117  hw_state = get_hw_state();
118  last_t = ct; //update time
119  return -1;
120  }
121  else
122  {
123  last_t = ct; //update time
124  std::cerr << "Error in do_shutter_close()\n";
125  return 0;
126  }
127  }
128 
129  return 1; //still open
130 }
131 
132 int ShutterControl::set_state(int st)
133 {
134 
135  if(st > 0) return open_shutter();
136  else return close_shutter();
137 
138 }
139 
140 int ShutterControl::get_state()
141 {
142 
143  sw_state = get_sw_state();
144 
145  hw_state = get_hw_state();
146 
147  if(sw_state == hw_state)
148  {
149  return sw_state;
150  }
151  return 0;
152 }
153 
154 int ShutterControl::get_sw_state()
155 {
156  return sw_state;
157 }
158 
159 int ShutterControl::get_hw_state()
160 {
161  return sw_state;
162 }
163 
164 double ShutterControl::get_curr_t()
165 {
166  #ifdef SIMSHUTTER
167  curr_t+=delta_t; //for simulations
168  #else
169  gettimeofday(&tp, 0);
170  curr_t = tp.tv_sec + tp.tv_usec/1e6;
171  #endif
172 
173  return curr_t;
174 }
175 
176 int ShutterControl::do_shutter_open(void *adata)
177 {
178  return 0;
179 }
180 
181 int ShutterControl::do_shutter_close(void *adata)
182 {
183  return 0;
184 }
185 
186 int ShutterControl::start_ShutterControl()
187 {
188  return 0;
189 }
190 
191 int ShutterControl::shutdown_ShutterControl()
192 {
193  return 0;
194 }
195 
196 
Declarations for a generic shutter controller.
double dead_time
Time to wait between commanded changes in state.
ShutterControl()
Default constructor.
int initialize_ShutterControl()
Sets the basic parameters to default values.
double last_t
the time of the last commanded change in state
int hw_state
1 is open, -1 is shut, 0 is unknown
int sw_state
1 is open, -1 is shut, 0 is unknown
double curr_t
the current time
timeval tp
for use in getting system time
bool ignore_hw_state
For when hw_state is unavailable.