The VisAO Camera
FilterWheelLocal.h
Go to the documentation of this file.
1 /************************************************************
2 * FilterWheelLocal.h
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Declarations for the FilterWheelLocal class, which interfaces
7 * with the VisAOSimpleMotorCtrl class via the MsgD.
8 *
9 * Developed as part of the Magellan Adaptive Optics system.
10 ************************************************************/
11 
12 /** \file FilterWheelLocal.h
13  * \author Jared R. Males
14  * \brief Declarations for the FilterWheelLocal class, which interfaces with the VisAOSimpleMotorCtrl class via the MsgD.
15  *
16 */
17 
18 #ifndef __FilterWheelLocal_h__
19 #define __FilterWheelLocal_h__
20 
21 #include "AOApp.h"
22 #include "AOStates.h"
23 
24 #include "VisAOApp_base.h"
25 
26 #include <cmath>
27 
28 
29 namespace VisAO
30 {
31 
32 /// A class to provide Filter Wheel functionality for the VisAO Camera.
33 /** Exposes Local and Script fifos, and passes commands on the the
34  * F/W controllers on the supervisor via the MsgD.
35  */
36 class FilterWheelLocal : public AOApp, public VisAOApp_base
37 {
38 
39 public:
40  ///Standard adopt style config file constructor.
41  FilterWheelLocal( std::string name, const std::string &conffile) throw (AOException);
42 
43  ///Standard adopt style command line constructor.
44  FilterWheelLocal( int argc, char **argv) throw (AOException);
45 
46 protected:
47  ///Basic setup of the class, called by both constructors.
48  /** Reads the com_path parameter from config, and sets up the
49  * \ref fifo_list to have local and script command fifos.
50  * Also established the COMMODE RTDB varialbe and its notifier.
51  */
52  void setupVisAOApp();
53 
54  ///Read the corresponding filter wheel controller configuration file.
55  void readFilterConfig();
56 
57  RTDBvar var_status;///<The current status of the controller, STATE_CONNECTED, STATE_OPERATING,STATE_HOMING, etc.
58 
59  RTDBvar var_cmode_cur; ///<The current control mode in the RTDB.
60  RTDBvar var_cmode_req; ///<The requested control mode in the RTDB.
61 
62  RTDBvar var_pos_cur; ///<The current position
63  RTDBvar var_pos_req; ///<The requested position
64 
65  RTDBvar var_pos_local_req;///<Position requester for local control
66  RTDBvar var_pos_script_req; ///<Position requester for script control
67 
68  double _abortPos;
69  double _homingPos;
70  float _startingPos;
71 
72  map<string, float> _customPos;
73  int cur_state;
74  double cur_pos;
75  double req_pos;
76 
77  std::string aoapp_name;
78 
79  /// Virtual function to setup variables in RTDB
80  void SetupVars();
81 
82  ///An iterator for accessing the custom pos list.
83  map<std::string, float>::iterator cpos_it;
84 
85  /// Custom filter types list
86  multimap<int, float> _customTypes;
87  ///An iterator for accessing the custom pos list.
88  multimap<int, float>::iterator ctype_it;
89 
90  ///Get the position name from wheel position
91  std::string GetPosName(double pos);
92 
93  ///Get the position type from the wheel position
94  int GetType(double pos);
95 
96  ///The main loop.
97  void Run();
98 
99  /// Local FSM
100  int DoFSM();
101 
102  /// Update position variables in RTDB
103  virtual void updatePos( double pos);
104  /// Update req position variables in RTDB
105  virtual void updateReq( double pos);
106 
107  void set_control_mode(int cmode);
108  void set_status(int stat);
109 
110  pthread_t signal_thread; ///< The thread where fifo async signals are caught.
111 
112  public:
113  ///Signal loop, normally won't need to be overridden.
114  /** This does need to be started by the Run() function if it is desired.
115  * Before starting, must have setup and connected the fifo list.
116  * Can be started with start_signal_catcher(). The main loop
117  * should then block SIGIO and RTSIGIO.
118  */
119  void signal_catcher();
120 
121  protected:
122  ///Starts the signal catching loop
123  /** \param inherit_sched if true (default) then the signal_catcher is started with the same RT priority as the main loop.
124  */
125  virtual int start_signal_catcher(bool inherit_sched = true);
126 
127 
128  public:
129 
130  virtual int request_control(int cmode); ///< Calls \ref request_control(int,bool) "request_control(cmode, 0)"
131 
132  ///Attempts to change the control type.
133  /** \param cmode The requested control mode \see control_modes.
134  * \param override If not true, forces the change no matter what current mode is.
135  * \retval control_mode if successful.
136  * \retval -1 if unsuccessful.
137  */
138  virtual int request_control(int cmode, bool override);
139 
140 
141  /// RTDB handler for a control mode change request from the AO Supervisor.
142  static int CModeCurChanged(void *pt, Variable *msgb);
143 
144  /// RTDB handler for a position change by the AO Supervisor
145  /** After checking if control_mode == CMODE_REMOTE, just calls
146  * SimpleMotorCtrl::PosReqChanged.
147  */
148  static int PosCurChanged( void *pt, Variable *msgb);
149 
150  static int PosReqChanged( void *pt, Variable *msgb);
151 
152  static int StatusChanged( void *pt, Variable *msgb);
153 
154  /// An interface to SimpleMotorCtrl::PosReqChanged for the fifo command processors.
155  /** We don't actually reimplement any motor control logic.
156  */
157  int ChangePos(double pos);
158 
159  /// Exposes the abort Position (_abortPos) for use in PosReqChanged (which is static)
160  double getAbortPos(){ return _abortPos;}
161 
162 public:
163  ///VisAO remote command fifo handler.
164  /** Though no fifo is created, this is used to process the
165  * RTDB control mode changes.
166  */
167  virtual std::string remote_command(std::string com);
168 
169  ///VisAO local command fifo handler
170  virtual std::string local_command(std::string com);
171 
172  ///VisAO script command fifo handler
173  virtual std::string script_command(std::string com);
174 
175  ///Where the command logic actually happens, since it is common.
176  std::string common_command(std::string com, int);
177 
178  ///Produce the state string for response to state?
179  std::string get_state_str();
180 
181  /// Update the status board.
182  /** Calls this as VisAOApp_base::update_statusboard so the basics are taken care of.
183  * \retval 0 on success
184  * \retval -1 on failure
185  */
186  virtual int update_statusboard();
187 };
188 
189 } //namespace VisAO
190 
191 #endif //__FilterWheelLocal_h__
192 
193 
RTDBvar var_status
The current status of the controller, STATE_CONNECTED, STATE_OPERATING,STATE_HOMING, etc.
A class to provide Filter Wheel functionality for the VisAO Camera.
virtual void updatePos(double pos)
Update position variables in RTDB.
virtual std::string local_command(std::string com)
VisAO local command fifo handler.
RTDBvar var_pos_cur
The current position.
RTDBvar var_cmode_cur
The current control mode in the RTDB.
void readFilterConfig()
Read the corresponding filter wheel controller configuration file.
void SetupVars()
Virtual function to setup variables in RTDB.
std::string common_command(std::string com, int)
Where the command logic actually happens, since it is common.
int GetType(double pos)
Get the position type from the wheel position.
std::string GetPosName(double pos)
Get the position name from wheel position.
double getAbortPos()
Exposes the abort Position (_abortPos) for use in PosReqChanged (which is static) ...
virtual int start_signal_catcher(bool inherit_sched=true)
Starts the signal catching loop.
multimap< int, float >::iterator ctype_it
An iterator for accessing the custom pos list.
multimap< int, float > _customTypes
Custom filter types list.
pthread_t signal_thread
The thread where fifo async signals are caught.
FilterWheelLocal(std::string name, const std::string &conffile)
Standard adopt style config file constructor.
static int PosCurChanged(void *pt, Variable *msgb)
RTDB handler for a position change by the AO Supervisor.
void Run()
The main loop.
RTDBvar var_pos_local_req
Position requester for local control.
std::string get_state_str()
Produce the state string for response to state?
virtual std::string remote_command(std::string com)
VisAO remote command fifo handler.
The base class for VisAO applications.
Definition: VisAOApp_base.h:48
void setupVisAOApp()
Basic setup of the class, called by both constructors.
virtual int request_control(int cmode)
Calls request_control(cmode, 0).
RTDBvar var_pos_script_req
Position requester for script control.
Declarations for VisAOApp_base.
RTDBvar var_cmode_req
The requested control mode in the RTDB.
void signal_catcher()
Signal loop, normally won't need to be overridden.
virtual std::string script_command(std::string com)
VisAO script command fifo handler.
The namespace of VisAO software.
RTDBvar var_pos_req
The requested position.
int ChangePos(double pos)
An interface to SimpleMotorCtrl::PosReqChanged for the fifo command processors.
virtual void updateReq(double pos)
Update req position variables in RTDB.
virtual int update_statusboard()
Update the status board.
static int CModeCurChanged(void *pt, Variable *msgb)
RTDB handler for a control mode change request from the AO Supervisor.
map< std::string, float >::iterator cpos_it
An iterator for accessing the custom pos list.