The VisAO Camera
VisAOJoeCtrl.h
Go to the documentation of this file.
1 /************************************************************
2 * VisAOJoeCtrl.h
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Declarations for CCD47 control from the AO Supervisor.
7 *
8 * Developed as part of the Magellan Adaptive Optics system.
9 ************************************************************/
10 
11 /** \file VisAOJoeCtrl.h
12  * \author Jared R. Males
13  * \brief Declarations for CCD47 control from the AO Supervisor.
14  *
15  * Based on the Arcetri JoeCtrl class.
16  *
17 */
18 
19 #ifndef __VisAOJoeCtrl_h__
20 #define __VisAOJoeCtrl_h__
21 
22 #include <vector>
23 #include <string>
24 
25 #include "stdconfig.h"
26 #include "base/thrdlib.h"
27 #include "AOApp.h"
28 #include "AOStates.h"
29 
30 #include "CCD47Ctrl.h"
31 
32 #define _debug
33 
34 namespace VisAO
35 {
36 
37 ///The interface between the \ref CCD47Ctrl class and the AO Supervisor.
38 /** Based on the Arcetri JoeCtrl class, this class works in nearly identical fashion
39  * except it passes commands to the CCD47Ctrl process instead of to the little joe.
40  */
41 class JoeCtrl: public AOApp, public VisAOApp_base
42 {
43 
44  public:
45  ///Config file constructor
46  JoeCtrl( std::string name, const std::string &conffile) throw (AOException);
47 
48  ///Command line constructor
49  JoeCtrl( int argc, char **argv) throw (AOException);
50 
51  protected:
52  /// CCD number (set from cfg file)
53  int _ccdNum;
54 
55  /// CCD name
56  std::string _ccdName;
57 
58  // CCD parameters
59  int _ccdDx; ///< Size in x
60  int _ccdDy; ///< Size in y
61  unsigned int _ccdNumSpeeds; ///<Number of speeds
62  int _maxNumSpeeds; ///<Maximum number of speeds
63  int _maxNumBins; ///<Maximum number of binnings
64  int _maxNumWins;
65  std::vector<int> _ccdXbins; ///<Vector of x binnings
66  std::vector<int> _ccdYbins; ///<Vector of y binnings
67  std::vector<int> _ccdSpeeds; ///<Vector of speeds
68  std::vector<int> _ccdBlacks; ///<Vector of black levels
69  int _ccdBlacksNum; ///<Nuber of blacks.
70  int _minRep; ///<Minimum repititions (controls integration time)
71  int _maxRep; ///<Maximum repititions (controls integration time)
72 
73  int cur_ProgramSet; ///<The Current program set loaded on the little joe
74  int cur_Program; ///<The current program running on the little joe
75  int cur_Gain; ///<The current gain running on the little joe
76  int cur_Reps; ///<The current repititions running on the little joe
77 
78  // Default parameters
79  int _startProgramSet; ///<The program set currently set to load from flash on little joe power up
80  int _ccdDefaultXbin; ///<Default x binning
81  int _ccdDefaultYbin; ///<Default y binning
82  int _ccdDefaultSpeed; ///<Default speed
83  int _ccdDefaultBlack; ///<Default black levels
84 
85  /// Struct representing LittleJoe's internal memory
87 
88  /// Struct array representing files that can be uploaded to LittleJoe (each one is a memory dump)
89  std::vector<littlejoe_programset> ondisk;
90 
91  // RTDB variables
92 
93  RTDBvar var_name, var_status, var_errmsg, var_enable_cur, var_enable_req;
94  RTDBvar var_dx, var_dx_cur, var_dy, var_dx_req, var_dy_cur,var_dy_req, var_windowxs, var_windowys,var_xbins, var_ybins, var_speeds;
95  RTDBvar var_xbin_cur, var_ybin_cur, var_speed_cur, var_black_cur;
96  RTDBvar var_xbin_req, var_ybin_req, var_speed_req, var_black_req;
97  RTDBvar var_temps, var_framerate_cur, var_framerate_req;
98  RTDBvar var_rep_cur, var_rep_req;
99  RTDBvar var_gain_cur, var_gain_req;
100 
101  RTDBvar var_fanReq;
102 
103  RTDBvar var_cmode_cur; ///<The current control mode in the RTDB.
104  RTDBvar var_cmode_req; ///<The requested control mode in the RTDB.
105 
106  RTDBvar var_preset_req; ///<Preset to program set 0, program 0, for presetVisAO.
107 
108  // Temperature thresholds for fan on/off
109  int _fanCtrlActive;
110  int _fanOnTemp;
111  int _fanOffTemp;
112 
113  protected:
114  ///Read the JoeCtrl specific config vars and connect to the CCD47Ctrl
115  void Create(void) throw (AOException);
116 
117  ///VIRTUAL - Perform post-initialization settings
118  void PostInit();
119 
120  ///VIRTUAL - Setups variables in RTDB
121  void SetupVars(void);
122 
123  ///VIRTUAL - StateChange
124  /** Used to invalidate CUR variables when losing connection
125  * Automatically called by AOApp when a state change occurs.
126  * Used here to invalidate "CUR" variables when losing connections
127  */
128  void StateChange( int oldstate, int state);
129 
130  ///VIRTUAL - Run
131  /**Switches the stage from one state to the other
132  */
133  void Run();
134 
135  ///Perform controller functions and manage states
136  /**Switches the controller from one state to another. States can be changed asynchronously
137  * from this thread or the listening thread, and this function will properly react to a new state.
138  * Many states include a msleep() function to slow down the thread when immediate action is not necessary
139  */
140  int DoFSM(void);
141 
142  ///Send a start command to the CCD47Ctrl
143  int Start();
144 
145  ///Send a stop command to the CCD47Ctrl
146  int Stop();
147 
148  ///Calculate and send a reprogram request to the CCD47Ctrl
149  int ReprogramJoe( int force=0);
150 
151  ///Test the link with the CCD47Ctrl, and get its state.
152  int TestCCD47CtrlLink();
153 
154  ///Send a command to the CCD47 and get its response.
155  std::string send_ccd47_command(std::string com);
156 
157  int GetProgramPos( int speed, int xbin, int ybin, int *need_upload);
158 
159  int UpdateJoeMemory( unsigned int uploaded_file);
160 
161  int LoadJoeDiskFiles(void);
162 
163  int EraseLocalMemory(void);
164 
165  int SetLocalMemory( unsigned int programset_num);
166 
167  int ComputeFramerate();
168 
169  int ChangeFramerate( double framerate, int bestspeed=1);
170 
171  littlejoe_program *GetProgram( int speed, int xbin, int ybin);
172 
173  int ExposeSpeeds();
174 
175  int ExposeWindows();
176 
177  int insert_value( std::vector<int> &array, int value);
178 
179  littlejoe_program ReadProgram( Config_File &cfg);
180 
181  littlejoe_programset ReadProgramSet( Config_File &cfg);
182 
183  /// RTDB handler for an enable change request form the AO Supervisor
184  static int EnableReqChanged( void *pt, Variable *var);
185 
186  /// RTDB handler for an x-bin change request form the AO Supervisor
187  static int XbinReqChanged( void *pt, Variable *var);
188 
189  /// RTDB handler for a y-bin change request form the AO Supervisor
190  static int YbinReqChanged( void *pt, Variable *var);
191 
192  /// RTDB handler for a speed change request form the AO Supervisor
193  static int SpeedReqChanged( void *pt, Variable *var);
194 
195  /// RTDB handler for a black level change request form the AO Supervisor
196  static int BlackReqChanged( void *pt, Variable *var);
197 
198  /// RTDB handler for a frame rate change request form the AO Supervisor
199  static int FrameRateReqChanged( void *pt, Variable *var);
200 
201  /// RTDB handler for a repetitions change request form the AO Supervisor
202  static int RepReqChanged( void *pt, Variable *var);
203 
204  /// RTDB handler for a gain change request form the AO Supervisor
205  static int GainReqChanged( void *pt, Variable *var);
206 
207  /// RTDB handler for a control mode change request from the AO Supervisor.
208  static int CModeReqChanged(void *pt, Variable *msgb);
209 
210  /// RTDB handler for preset request from the AO Supervisor.
211  static int PresetReqChanged(void *pt, Variable *msgb);
212 
213  ///Gets the complete path of a program/pattern file
214  std::string getCompletePath( std::string filename);
215 
216 };
217 
218 } //namespace VisAO
219 
220 #endif //__VisAOJoeCtrl_h__
221 
int _minRep
Minimum repititions (controls integration time)
Definition: VisAOJoeCtrl.h:70
RTDBvar var_preset_req
Preset to program set 0, program 0, for presetVisAO.
Definition: VisAOJoeCtrl.h:106
int cur_Reps
The current repititions running on the little joe.
Definition: VisAOJoeCtrl.h:76
int _maxRep
Maximum repititions (controls integration time)
Definition: VisAOJoeCtrl.h:71
void Run()
VIRTUAL - Run.
int cur_Program
The current program running on the little joe.
Definition: VisAOJoeCtrl.h:74
Holds the details of a little joe program set (i.e. a pattern/con file pair)
Definition: CCD47Ctrl.h:83
int cur_ProgramSet
The Current program set loaded on the little joe.
Definition: VisAOJoeCtrl.h:73
static int EnableReqChanged(void *pt, Variable *var)
RTDB handler for an enable change request form the AO Supervisor.
static int PresetReqChanged(void *pt, Variable *msgb)
RTDB handler for preset request from the AO Supervisor.
littlejoe_programset memory
Struct representing LittleJoe's internal memory.
Definition: VisAOJoeCtrl.h:86
unsigned int _ccdNumSpeeds
Number of speeds.
Definition: VisAOJoeCtrl.h:61
std::string send_ccd47_command(std::string com)
Send a command to the CCD47 and get its response.
STL namespace.
static int SpeedReqChanged(void *pt, Variable *var)
RTDB handler for a speed change request form the AO Supervisor.
int Stop()
Send a stop command to the CCD47Ctrl.
void SetupVars(void)
VIRTUAL - Setups variables in RTDB.
std::string _ccdName
CCD name.
Definition: VisAOJoeCtrl.h:56
static int RepReqChanged(void *pt, Variable *var)
RTDB handler for a repetitions change request form the AO Supervisor.
int Start()
Send a start command to the CCD47Ctrl.
static int BlackReqChanged(void *pt, Variable *var)
RTDB handler for a black level change request form the AO Supervisor.
int cur_Gain
The current gain running on the little joe.
Definition: VisAOJoeCtrl.h:75
RTDBvar var_cmode_cur
The current control mode in the RTDB.
Definition: VisAOJoeCtrl.h:103
static int CModeReqChanged(void *pt, Variable *msgb)
RTDB handler for a control mode change request from the AO Supervisor.
std::vector< int > _ccdXbins
Vector of x binnings.
Definition: VisAOJoeCtrl.h:65
std::vector< littlejoe_programset > ondisk
Struct array representing files that can be uploaded to LittleJoe (each one is a memory dump) ...
Definition: VisAOJoeCtrl.h:89
static int XbinReqChanged(void *pt, Variable *var)
RTDB handler for an x-bin change request form the AO Supervisor.
int TestCCD47CtrlLink()
Test the link with the CCD47Ctrl, and get its state.
int _ccdDy
Size in y.
Definition: VisAOJoeCtrl.h:60
std::vector< int > _ccdSpeeds
Vector of speeds.
Definition: VisAOJoeCtrl.h:67
int _maxNumBins
Maximum number of binnings.
Definition: VisAOJoeCtrl.h:63
static int FrameRateReqChanged(void *pt, Variable *var)
RTDB handler for a frame rate change request form the AO Supervisor.
int ReprogramJoe(int force=0)
Calculate and send a reprogram request to the CCD47Ctrl.
int _ccdDx
Size in x.
Definition: VisAOJoeCtrl.h:59
int _ccdDefaultXbin
Default x binning.
Definition: VisAOJoeCtrl.h:80
int DoFSM(void)
Perform controller functions and manage states.
static int YbinReqChanged(void *pt, Variable *var)
RTDB handler for a y-bin change request form the AO Supervisor.
int _ccdBlacksNum
Nuber of blacks.
Definition: VisAOJoeCtrl.h:69
int _startProgramSet
The program set currently set to load from flash on little joe power up.
Definition: VisAOJoeCtrl.h:79
The base class for VisAO applications.
Definition: VisAOApp_base.h:48
std::vector< int > _ccdBlacks
Vector of black levels.
Definition: VisAOJoeCtrl.h:68
void StateChange(int oldstate, int state)
VIRTUAL - StateChange.
int _ccdDefaultSpeed
Default speed.
Definition: VisAOJoeCtrl.h:82
std::vector< int > _ccdYbins
Vector of y binnings.
Definition: VisAOJoeCtrl.h:66
Holds the details of one little joe program.
Definition: CCD47Ctrl.h:61
int _maxNumSpeeds
Maximum number of speeds.
Definition: VisAOJoeCtrl.h:62
int _ccdDefaultYbin
Default y binning.
Definition: VisAOJoeCtrl.h:81
The interface between the CCD47Ctrl class and the AO Supervisor.
Definition: VisAOJoeCtrl.h:41
Declarations for the VisAO CCD47 controller.
The namespace of VisAO software.
static int GainReqChanged(void *pt, Variable *var)
RTDB handler for a gain change request form the AO Supervisor.
std::string getCompletePath(std::string filename)
Gets the complete path of a program/pattern file.
int _ccdNum
CCD number (set from cfg file)
Definition: VisAOJoeCtrl.h:53
void Create(void)
Read the JoeCtrl specific config vars and connect to the CCD47Ctrl.
JoeCtrl(std::string name, const std::string &conffile)
Config file constructor.
RTDBvar var_cmode_req
The requested control mode in the RTDB.
Definition: VisAOJoeCtrl.h:104
int _ccdDefaultBlack
Default black levels.
Definition: VisAOJoeCtrl.h:83
void PostInit()
VIRTUAL - Perform post-initialization settings.