The VisAO Camera
GimbalMotorCtrl.h
Go to the documentation of this file.
1 /************************************************************
2  * GimbalMotorCtrl.h
3  *
4  * Author: Jared R. Males (jrmales@email.arizona.edu)
5  *
6  * Declarations for the VisAO gimbal motor controller.
7  *
8  * Developed as part of the Magellan Adaptive Optics system.
9  ************************************************************/
10 
11 /** \file GimbalMotorCtrl.h
12  * \author Jared R. Males
13  * \brief Declarations for the gimbal motor controller.
14  *
15  */
16 
17 #ifndef __GimbalMotorCtrl_h__
18 #define __GimbalMotorCtrl_h__
19 
20 #include "VisAOApp_standalone.h"
21 #include "libvisao.h"
22 #include "ESPMotorCtrl.h"
23 #include "AOStates.h"
24 extern "C"
25 {
26 #include "hwlib/netseriallib.h"
27 }
28 
29 namespace VisAO
30 {
31 
32 /// The gimbal motor controller class.
33 /** Manages the X and Y axis controllers of the Gimbal mirror.
34  * This is a standalone VisAOApp, so it doesn't depend on MsgD. In addition to the optional standard config options inherited from \ref VisAOApp_standalone this class REQUIRES:
35  * - <b>x_addr</b> <tt>int</tt> - the address of the x axis controller
36  * - <b>y_addr</b> <tt>int</tt> - the address of teh y axis controller
37  * - <b>power_outlet</b> <tt>int</tt> - the number of the power strip outlet the controllers are plugged in to.
38  * - <b>scale</b> <tt>double</tt> (arcsec/mm) - the conversion from encoder mm to arcsec on the CCD47
39  * - <b>x_center</b> <tt>double</tt> (arcsec) - the scaled encoder position of the x center of travel
40  * - <b>y_center</b> <tt>double</tt> (arcsec) - the scaled encoder position of the y senter of travel
41  *
42  *
43  * See \ref VisAOApp_standalone for command line arguments. There are no additional command line arguments for GimbalCtrl.
44  *
45  * This app exposes the remote, local, and script command fifos. The following commands are recognized on all channels:
46  * - "state?" returns a state string "A,B,C,D,E,F,E\n" where the letters have the following meaning
47  * - A = a one character representation of control mode, N, R, L, or S.
48  * - B = the connection status with the controllers (STATE_READY, etc.)
49  * - C = the power state of the controllers, derived from the power outlet status.
50  * - 0 = off
51  * - 1 = on
52  * - -1 = unknown
53  * - D = x moving state.
54  * - 0 = not moving
55  * - 1 = moving
56  * - E = x position (arcsec)
57  * - F = y moving state.
58  * - 0 = not moving
59  * - 1 = moving
60  * - G = y position (arcsec)
61  * - E = scale (arcsec/mm)
62  * - "xpos?" returns the x position in mm
63  * - "xmoving?" returns the x moving state
64  * - 0 = not moving
65  * - 1 = moving
66  * - "ypos?" returns the y position in mm
67  * - "ymoving?" returns the y moving state
68  * - 0 = not moving
69  * - 1 = moving
70  * - "stop" stops motion on all axes
71  * - "stopx" stops motion on the x axis
72  * - "stopy" stops motion on the axis
73  * - "center" - center both axes
74  * - "savepreset" - save current position as preset
75  * - "xrel x" moves x by a relative amount x, in mm.
76  * - "xabs x" moves x to the absolute position x, in mm
77  * - "yrel x" moves y by a relative amount x, in mm.
78  * - "yabs x" moves y to the absolute position x, in mm
79  */
81 {
82 
83 public:
84  /// Standard constructor with a config file.
85  GimbalMotorCtrl(std::string name, const std::string& conffile) throw (AOException);
86 
87  /// Standard constructor with a command line.
88  GimbalMotorCtrl( int argc, char**argv) throw (AOException);
89 
90  virtual ~GimbalMotorCtrl();
91 
92 
93  /// Initialization common to both constructors.
94  /** Reads the app specific config detals, and sets up the fifo_list.
95  */
96  void Create();
97 
98 protected:
99  std::string ip_addr; ///<ip address of the serial converter
100  int ip_port; ///<ip port on which the motor controllers are connected
101 
102  int curState; ///<The current controller state (READY, etc.)
103  int postHoming; ///<When 1, the gimbal will center after homing
104 
105 
106  int x_addr; ///<The controller address of the x axis
107  int y_addr; ///<The controller address of the y axis
108  int xAxisNo; ///<The axis number of x, e.g. 0
109  int yAxisNo; ///<The axis number of y, e.g. 1
110 
111  int power_outlet; ///<Configuration variable, setting which power outlet to monitor
112  int *powerOutletState; ///<The power strip outlet controlling shutter power.
113 
114  power_status_board * psb;///<This is for monitoring power outlet state
115 
116  double scale; ///<The conversion scale from encoder mm to arcsec on the CCD47, i.e. arcsec/mm
117  double x_center; ///<The configurable location of the default x-center
118  double x_dark;///<The configurable location of the x dark location
119 
120  int xMoving; ///<Status of moving in the x direction
121 
122  double y_center; ///<The configurable location of the default x-center
123  double y_dark;///<The configurable location of the y dark location
124 
125  bool isMoving; ///<True if moving - set when move starts and updating data logger.
126 
127 
128  pthread_mutex_t comMutex; ///< Mutex for communicating with the controllers.
129 
130 
131  VisAO::filterwheel_status_board *fw2sb; ///<pointer to status board of F/W 2 (for presets)
132  VisAO::filterwheel_status_board *fw3sb; ///<pointer to status board of F/W 3 (for presets)
133  VisAO::wollaston_status_board *wsb; ///<pointer to status board of wollaston (for presets)
134  VisAO::aosystem_status_board *aosb; ///<pointer to status board of VisAOI (for presets)
135 
136 public:
137  ///Establish the serial-over-ip connection.
138  /** Closes any existing connection, and then attempts to establish the link.
139  */
140  int setupNetwork();
141 
142  ///Check connection status by querying the status of each controller. Changes curState.
143  /** \retval 0 on success
144  * \retval -1 on error (other than not being connected).
145  */
146  int checkConnStat();
147 
148  ///Get the current process state
149  int getCurState(){return curState;}
150 
151  /// Get the x position
152  double get_x_pos();
153 
154  /// Get the moving status of the x axis.
155  int getXMoving();
156 
157  /// Get the y position
158  double get_y_pos();
159 
160  /// Get the moving status of the y axis.
161  int getYMoving();
162 
163  ///Get the status of the power outlet
164  /** \retval 1 if on
165  * \retval 0 if off
166  * \retval -1 if no status available
167  */
168  int getPowerStatus();
169 
170  ///Read the preset center position for current board conditions, and gimbal to it.
171  int center();
172 
173  ///Gimbal to the dark position.
174  int dark();
175 
176  ///Save the current position as the preset for this board setup.
177  int savepreset();
178 
179  ///Implementation of ESPMotorCtrl sendCommand
180  virtual int sendCommand(std::string &com, std::string &resp, int timeout);
181 
182  ///Implementation of ESPMotorCtrl sendCommand
183  virtual int sendCommand(std::string &com);
184 
185 
186  /// The main loop.
187  /** Sets the signal handling for SIGIO then
188  * starts pausing()-ing.
189  */
190  virtual int Run();
191 
192  /// Overridden from VisAOApp_base::remote_command, here just calls common_command.
193  virtual std::string remote_command(std::string com);
194  /// Overridden from VisAOApp_base::local_command, here just calls common_command.
195  virtual std::string local_command(std::string com);
196  /// Overridden from VisAOApp_base::script_command, here just calls common_command.
197  virtual std::string script_command(std::string com);
198 
199  /// The common command processor for commands received by fifo.
200  std::string common_command(std::string com, int cmode);
201 
202  /// Get the state string.
203  /** The state string encodes the current state of the controller as:
204  */
205  std::string get_state_str();
206 
207  ///Called when a move starts, for data logging. Overriden from ESPMotorCtrl
208  virtual void moveStart();
209 
210  ///Called when a move stops, for data logging.
211  void moveStop();
212 
213 public:
214  ///Update the gimbal status board
215  virtual int update_statusboard();
216 
217  ///Write gimbal positions to the data log
218  virtual void dataLogger(timeval tv);
219 };
220 
221 } //namespace VisAO
222 
223 #endif //__GimbalMotorCtrl_h__
int center()
Read the preset center position for current board conditions, and gimbal to it.
Declarations for a Newport ESP motor controller.
int x_addr
The controller address of the x axis.
int y_addr
The controller address of the y axis.
virtual std::string script_command(std::string com)
Overridden from VisAOApp_base::script_command, here just calls common_command.
int * powerOutletState
The power strip outlet controlling shutter power.
int getXMoving()
Get the moving status of the x axis.
double x_dark
The configurable location of the x dark location.
int xAxisNo
The axis number of x, e.g. 0.
int postHoming
When 1, the gimbal will center after homing.
pthread_mutex_t comMutex
Mutex for communicating with the controllers.
The standalone VisAO application, does not interface with the AO Supervisor.
int xMoving
Status of moving in the x direction.
std::string common_command(std::string com, int cmode)
The common command processor for commands received by fifo.
Declarations for the standalone VisAO application.
double get_x_pos()
Get the x position.
VisAO::filterwheel_status_board * fw2sb
pointer to status board of F/W 2 (for presets)
virtual int sendCommand(std::string &com, std::string &resp, int timeout)
Implementation of ESPMotorCtrl sendCommand.
bool isMoving
True if moving - set when move starts and updating data logger.
int savepreset()
Save the current position as the preset for this board setup.
The ESP motor controller class.
Definition: ESPMotorCtrl.h:37
int getCurState()
Get the current process state.
VisAO software utilitites, declarations.
double scale
The conversion scale from encoder mm to arcsec on the CCD47, i.e. arcsec/mm.
int ip_port
ip port on which the motor controllers are connected
virtual int update_statusboard()
Update the gimbal status board.
int getYMoving()
Get the moving status of the y axis.
int setupNetwork()
Establish the serial-over-ip connection.
virtual void dataLogger(timeval tv)
Write gimbal positions to the data log.
int getPowerStatus()
Get the status of the power outlet.
double get_y_pos()
Get the y position.
The gimbal motor controller class.
void moveStop()
Called when a move stops, for data logging.
double y_center
The configurable location of the default x-center.
int power_outlet
Configuration variable, setting which power outlet to monitor.
VisAO::wollaston_status_board * wsb
pointer to status board of wollaston (for presets)
VisAO::aosystem_status_board * aosb
pointer to status board of VisAOI (for presets)
virtual void moveStart()
Called when a move starts, for data logging. Overriden from ESPMotorCtrl.
virtual std::string remote_command(std::string com)
Overridden from VisAOApp_base::remote_command, here just calls common_command.
power_status_board * psb
This is for monitoring power outlet state.
int checkConnStat()
Check connection status by querying the status of each controller. Changes curState.
int curState
The current controller state (READY, etc.)
virtual int Run()
The main loop.
double x_center
The configurable location of the default x-center.
double y_dark
The configurable location of the y dark location.
int yAxisNo
The axis number of y, e.g. 1.
virtual std::string local_command(std::string com)
Overridden from VisAOApp_base::local_command, here just calls common_command.
VisAO::filterwheel_status_board * fw3sb
pointer to status board of F/W 3 (for presets)
void Create()
Initialization common to both constructors.
std::string ip_addr
ip address of the serial converter
The namespace of VisAO software.
int dark()
Gimbal to the dark position.
GimbalMotorCtrl(std::string name, const std::string &conffile)
Standard constructor with a config file.
std::string get_state_str()
Get the state string.