The VisAO Camera
VisAO::FocusMotorCtrl Class Reference

The focus stage stepper motor controller class. More...

#include <FocusMotorCtrl.h>

+ Inheritance diagram for VisAO::FocusMotorCtrl:

Public Member Functions

 FocusMotorCtrl (std::string name, const std::string &conffile) throw (AOException)
 Standard constructor with a config file.
 
 FocusMotorCtrl (int argc, char **argv) throw (AOException)
 Standard constructor with a command line.
 
void initapp ()
 Initialization common to both constructors. More...
 
double get_cur_pos ()
 Get the current position in microns.
 
int set_cur_pos (double)
 Set the current position. This does not move the motor. More...
 
int set_home ()
 Set the current position as the home position. More...
 
int get_power_state ()
 Get the power state of the controller.
 
int set_enable (bool en)
 Set the enable state of the controller. More...
 
int enable ()
 Call set_enable(true);.
 
int disable ()
 Call set_enable(false);.
 
int set_direction (bool dir)
 Set the direction of the controller. More...
 
int set_forward ()
 Call set_direction(true);.
 
int set_backward ()
 Call set_direction(false);.
 
int step (int nsteps)
 The routine to control motion of the stepper motor. More...
 
int step ()
 Move by 1 step in current direction. More...
 
int step_forward (int nsteps)
 Move the motor forward by nsteps. More...
 
int step_forward ()
 Move by 1 step in forward direction. More...
 
int step_backward (int nsteps)
 Move the motor backward by nsteps. More...
 
int step_backward ()
 Move by 1 step in backward direction. More...
 
int offset_pos (double dpos)
 Offset current position (in microns). More...
 
int goto_pos (double pos)
 Move to an absolute position (in microns). More...
 
int start_pending_move ()
 Calls either offset_pos(next_pos) or goto_pos(next_pos) when the main loop detects a pending move. More...
 
int get_preset (double &fcal, std::vector< double > &preset, std::string &presetf)
 Reads the preset file for the current setup as determined from the shared memory status boards. More...
 
int check_preset ()
 Check if the focus stage is currently at the preset (focused) position (within 2 microns)
 
int goto_preset ()
 Move the focus stage to the preset position for the current VisAO setup. More...
 
virtual int Run ()
 The main loop. More...
 
virtual std::string remote_command (std::string com)
 Overridden from VisAOApp_base::remote_command, here just calls common_command.
 
virtual std::string local_command (std::string com)
 Overridden from VisAOApp_base::local_command, here just calls common_command.
 
virtual std::string script_command (std::string com)
 Overridden from VisAOApp_base::script_command, here just calls common_command.
 
std::string common_command (std::string com, int cmode)
 The common command processor for commands received by fifo. More...
 
std::string get_state_str ()
 Get the state string. More...
 
virtual int update_statusboard ()
 Update the status board. More...
 
virtual void dataLogger (timeval tv)
 Write focus positions to the data log.
 
- Public Member Functions inherited from VisAO::VisAOApp_standalone
 VisAOApp_standalone () throw (AOException)
 Default constructor.
 
 VisAOApp_standalone (string name, int id, int logLevel=Logger::LOG_LEV_INFO) throw (AOException)
 Complicated constructor.
 
void set_conffile (std::string name) throw (AOException)
 
 VisAOApp_standalone (std::string name, const std::string &conffile) throw (AOException)
 Config file constructor.
 
void set_conffile (std::string name, const std::string &conffile) throw (AOException)
 For use if default constructed.
 
 VisAOApp_standalone (int argc, char **argv) throw (AOException)
 Command line constructor.
 
void usage ()
 
virtual std::string get_app_name ()
 Get the application name.
 
void log_msg (int LogLevel, std::string lmsg)
 Report an error. Also calls log_msg. Overloaded from VisAOApp_base. More...
 
virtual int Exec ()
 Installs the term and XXXX signal handlers, and calls Run(). More...
 
void signal_catcher ()
 Signal loop, normally won't need to be overridden. More...
 
virtual int start_signal_catcher (bool inherit_sched=true)
 Starts the signal catching loop. More...
 
virtual int install_sig_mainthread_catcher ()
 Install the SIG_MAINTHREAD signal catcher.
 
virtual int block_signal (int signum)
 Sets the signal mask to block signal signum.
 
virtual int block_sigio ()
 Sets the signal mask to block SIGIO and RTSIGIO.
 
virtual int kill_me ()
 Handle a timetodie condition upon exiting the signal catcher thread (e.g. tell main thread it is about to die) More...
 
- Public Member Functions inherited from VisAO::VisAOApp_base
 VisAOApp_base ()
 Default constructor.
 
virtual ~VisAOApp_base ()
 Virtual destructor.
 
int set_euid_called ()
 Changes the user id of the process to euid_called.
 
int set_euid_real ()
 Changes the user id fo the process to the real user id.
 
int set_RT_priority (int prio)
 Set the real-time priority of the current process. More...
 
int get_RT_priority ()
 Get the real-time priority of the current process.
 
int set_app_name (std::string an)
 Set the application name.
 
virtual int setup_baseApp (bool usethreads=false)
 Install fifo channels. More...
 
virtual int setup_baseApp (bool remfifo, bool locfifo, bool scrfifo, bool autfifo, bool usethreads=false)
 Create fifo names, then installs the fifo channels. More...
 
int setup_fifo_list (int nfifos)
 Allocate the fifo_list. More...
 
int connect_fifo_list ()
 Connect the fifo_list with exclusive locking. More...
 
int connect_fifo_list_nolock ()
 Connect the fifo_list without exclusive locking. More...
 
int setup_sigio ()
 Setup the SIGIO signal handling. More...
 
int setup_RTsigio ()
 Setup SIGIO signal handling using realtime signals. More...
 
int check_fifo_list_RTpending ()
 Check for pending reads for the fifo list while using the RT signals.
 
int write_fifo_channel (int ch, const char *com, int comlen, std::string *resp)
 Write data to a fifo_channel, and get a response if desired. More...
 
int write_fifo_channel (int ch, const char *com, int comlen, std::string *resp, char *sm)
 Write data to a fifo_channel, with a sequence message attached, and get a response if desired. More...
 
int get_fifo_channel_response (std::string *resp, int ch)
 Check, and wait if neccessary, for data on a fifo channel. More...
 
int set_wait_to (double to)
 Set the wait timeout for fifo channel responses. More...
 
double get_wait_to ()
 Get the wait timeout for fifo channel responses. More...
 
virtual int request_control (int cmode)
 Calls request_control(cmode, 0).
 
virtual int request_control (int cmode, bool override)
 Attempts to change the control type. More...
 
virtual std::string __remote_command (std::string com, char *seqmsg)
 Processing for remote commands. More...
 
virtual std::string remote_command (std::string com, char *seqmsg)
 
virtual std::string __local_command (std::string com, char *seqmsg)
 Processing for local commands. More...
 
virtual std::string local_command (std::string com, char *seqmsg)
 
virtual std::string __script_command (std::string com, char *seqmsg)
 Processing for script commands - not normally overriden. More...
 
virtual std::string script_command (std::string com, char *seqmsg)
 
virtual std::string auto_command (std::string com, char *seqmsg)
 Processing for auto commands - to be overriden. More...
 
virtual std::string post_auto_command (std::string com, char *seqmsg=0)
 Processing for auto commands - not normally overriden. More...
 
std::string control_mode_string ()
 Convenience function to return the control type string, e.g. "REMOTE".
 
std::string control_mode_response ()
 Convenience function to return the control type response string, e.g. "A\n".
 
virtual void error_report (int LogLevel, std::string emsg)
 Report an error. Also calls log_msg. More...
 
VisAO::profilerget_profile ()
 
int get_use_profiler ()
 
int start_profiler ()
 
void * get_statusboard_shmemptr ()
 Get the status board shared memory pointer. More...
 
int set_statusboard_shmemkey (key_t mkey)
 Set the status board shared memory key. Does nothing else. More...
 
key_t get_statusboard_shmemkey ()
 Get the status board shared memory key. More...
 

Protected Member Functions

int check_limits ()
 Gets the limit switch status from dioserver, and performs homing logic checks.
 
int save_init ()
 Save the initialization data to disk.
 
int delete_init ()
 Delete the initialization file.
 
- Protected Member Functions inherited from VisAO::VisAOApp_base
int create_statusboard (size_t sz)
 Creates and attaches to the statusboard shared memory. More...
 
std::string getDataFileName ()
 
int checkDataFileOpen ()
 

Protected Attributes

std::string diofifo_path
 The path of the dioserver fifos.
 
int dioch_enable
 The dioserver software channel connected to the enable pin.
 
int dioch_dir
 The dioserver software channel connected to the direction pin.
 
int dioch_step
 The dioserver software channel connected to the step pin.
 
int dioch_pwr
 The dioserver software channel connected to +5V terminal.
 
int dioch_limpos
 The dioserver software channel connected to the positive limit switch output.
 
int dioch_limhome
 The dioserver software channel connected to the middle limit switch output.
 
int dioch_limneg
 The dioserver software channel connected to the negative limit switch output.
 
pthread_mutex_t dio_mutex
 
int power_state
 
int cur_enabled
 Power state of the controller. More...
 
int DO_ENABLE
 Flag for main loop. +1 calls enable, -1 calls disable.
 
int cur_dir
 Tracks the current setting of the direction pin TTL level.
 
double min_step_time
 Minimum time between steps, in seconds. Can't be < 1e-6.
 
double step_ratio
 Microns per step. For E35H4N-12-900 with BSD-02H in 1/8 step resolution this is 0.375.
 
int hw_dir
 Sets the polarity of the direction pin relative to the software direction, that is so forward is forward as wired.
 
double cur_pos
 The position, relative to home, in microns.
 
int pending_move
 If non zero, a move is pending. Can be MOVE_OFFSET or MOVE_ABS.
 
double next_pos
 Position of next move. Interpreted as either an offset or absolute position depending on pending_move.
 
bool is_moving
 True if currently processing a position change.
 
bool stop_moving
 If true, the currently processing position change is terminated.
 
timeval last_step_time
 Time of the last step.
 
bool neg_limit
 True if negative limit switch is active.
 
bool pos_limit
 True if positive limit switch is active.
 
bool home_switch
 True if home limit switch is active.
 
bool pos_limit_disabled
 True if back limit is disabled for dismounting.
 
int sw_limits_only
 
double sw_neg_limit
 
double sw_pos_limit
 
double home_pos
 The position to set at the after homing to the home switch.
 
int homing
 
VisAO::filterwheel_status_boardfw2sb
 
VisAO::filterwheel_status_boardfw3sb
 
VisAO::wollaston_status_boardwsb
 
VisAO::aosystem_status_boardaosb
 
- Protected Attributes inherited from VisAO::VisAOApp_standalone
std::string init_file
 
Config_File * init_vars
 
pthread_t main_thread
 Identifier for the main thread.
 
pthread_t signal_thread
 Identifier for the separate signal handling thread.
 
pthread_mutex_t signal_mutex
 Mutex for the condition signaling.
 
pthread_cond_t signal_cond
 Condition for telling main thread that something changed.
 
double signalth_sleeptime
 
- Protected Attributes inherited from VisAO::VisAOApp_base
std::string app_name
 The name of the application.
 
double pause_time
 Time to pause during application main loop.
 
fifo_list fl
 The list of named-pipe fifos used for inter-process comms.
 
std::string com_path
 The control fifo path base name.
 
std::string com_path_remote
 The path for the remote control fifos.
 
std::string com_path_local
 The path for the local control fifos.
 
std::string com_path_script
 The path for the script control fifos.
 
std::string com_path_auto
 The path for the auto control fifos.
 
double wait_to
 The timeout for waiting on responses from FIFOs in seconds.
 
std::ostringstream logss
 Conveninence string stream for building log messages.
 
VisAO::profilerprofile
 
std::string profile_path
 
int use_profiler
 
void * statusboard_shmemptr
 The pointer to the shared memory block for the statusboard.
 
key_t statusboard_shmemkey
 The key used to lookup the shared memory.
 
int statusboard_shmemid
 The ID of the shared memory block.
 
std::ofstream dataof
 
bool dataFileOpen
 
double dataFileOpenTime
 
double data_log_time_length
 
std::string data_save_path
 
std::string data_file_prefix
 

Additional Inherited Members

- Public Types inherited from VisAO::VisAOApp_base
enum  control_modes {
  CMODE_NONE, CMODE_REMOTE, CMODE_LOCAL, CMODE_SCRIPT,
  CMODE_AUTO, CMODE_max
}
 The control modes.
 
- Static Public Member Functions inherited from VisAO::VisAOApp_standalone
static const std::string & ConfigFile ()
 
static const std::string & MyName ()
 
static const std::string & MyFullName ()
 
static int ID ()
 
static Config_File & ConfigDictionary ()
 
static int Verbosity ()
 
static string getConffile (string identity)
 Return configuration file path based on identity.
 
- Public Attributes inherited from VisAO::VisAOApp_base
pthread_mutex_t my_mutex
 Mutex used by the threaded versions of the standard command handlers.
 
- Static Protected Member Functions inherited from VisAO::VisAOApp_standalone
static void SetMyName (const std::string &name)
 
static void SetConfigFile (const std::string &conffile) throw (Config_File_Exception)
 
static void SetID (int id)
 
- Static Protected Attributes inherited from VisAO::VisAOApp_standalone
static Logger * _logger = NULL
 
- Static Protected Attributes inherited from VisAO::VisAOApp_base
static int control_mode = VisAOApp_base::CMODE_NONE
 The current control mode. More...
 
static int default_control_mode = -1
 The default control mode. More...
 

Detailed Description

Manges the digital inputs to the BSD-02 stepper motor controller. Tracks position relative to the home position in microns, as an integer number of steps of size step_ratio. Is a standalone VisAOApp, and has remote, local and script fifos. No auto control is provided. The config file parameters are:

  • MyName string (required)
  • ID int (required)
  • LogLevel string (required)
  • com_path string (optional)
  • diofifo_path string (optional)
  • dioch_enable int (required)
  • dioch_dir int (required)
  • dioch_step int (required)
  • step_ratio double (required)
  • min_step_time double (required)
  • hw_dir int (optional)

Definition at line 77 of file FocusMotorCtrl.h.

Member Function Documentation

int VisAO::FocusMotorCtrl::set_cur_pos ( double  cp)
Parameters
cpthe new value of the current position.
Return values
0on succes (always)

Definition at line 476 of file FocusMotorCtrl.cpp.

References cur_pos.

Referenced by step().

int VisAO::FocusMotorCtrl::set_home ( )

Equivalent to set_cur_pos(0).

Definition at line 507 of file FocusMotorCtrl.cpp.

References cur_pos.

int VisAO::FocusMotorCtrl::set_enable ( bool  en)

The software state is true=enabled, false=disabled. The hardware state is low=enabled, high=disabled. To enable call with en=true.

Parameters
enthe desired enable state.
Return values
0on success
-1on failure

Definition at line 514 of file FocusMotorCtrl.cpp.

References cur_enabled, FIFOCH_ENABLE, VisAO::VisAOApp_standalone::log_msg(), VisAO::VisAOApp_base::logss, and VisAO::VisAOApp_base::write_fifo_channel().

Referenced by disable(), and enable().

int VisAO::FocusMotorCtrl::set_direction ( bool  dir)

The software direction determines whether cur_pos increases or decreases. This also changes the hardware direction by setting the direction pin, but the actual direction of motion is set by the wiring and hw_dir.

Parameters
dir1 for forward, 0 for backward
Return values
0on success
-1on failure

Definition at line 554 of file FocusMotorCtrl.cpp.

References cur_dir, FIFOCH_DIR, hw_dir, VisAO::VisAOApp_standalone::log_msg(), VisAO::VisAOApp_base::logss, and VisAO::VisAOApp_base::write_fifo_channel().

Referenced by check_limits(), Run(), set_backward(), and set_forward().

int VisAO::FocusMotorCtrl::step ( int  nsteps)

The BSD-02 steps on a low-high transition. There is a minimum dwell time for each of 1 microsecond. This loop also waits at least min_step_time between steps, as part of the low dwell time. Enables the controller prior to first step, and updates cur_pos at each step. Stops moving and exits normally if stop_moving becomes true. On exit, is_moving, pending_move, and stop_moving are all false and the controller is disabled.

Parameters
nstepsis the number of steps to take.
Return values
0on success
-1on failure.

Definition at line 619 of file FocusMotorCtrl.cpp.

References check_limits(), cur_dir, cur_pos, dataLogger(), delete_init(), disable(), enable(), FIFOCH_STEP, get_power_state(), is_moving, last_step_time, VisAO::VisAOApp_standalone::log_msg(), VisAO::VisAOApp_base::logss, min_step_time, pending_move, save_init(), set_cur_pos(), step_ratio, stop_moving, TimeToDie, update_statusboard(), and VisAO::VisAOApp_base::write_fifo_channel().

int VisAO::FocusMotorCtrl::step ( )

Calls step(1)

Return values
0on success
-1on failure.

Definition at line 786 of file FocusMotorCtrl.cpp.

Referenced by start_pending_move(), step_backward(), and step_forward().

int VisAO::FocusMotorCtrl::step_forward ( int  nsteps)

First sets the direction, then calls step(nsteps).

Parameters
nstepsis the number of steps to take.
Return values
0on success
-1on failure.

Definition at line 791 of file FocusMotorCtrl.cpp.

References set_forward(), step(), and stop_moving.

int VisAO::FocusMotorCtrl::step_forward ( )

Calls step(1)

Return values
0on success
-1on failure.

Definition at line 798 of file FocusMotorCtrl.cpp.

Referenced by offset_pos().

int VisAO::FocusMotorCtrl::step_backward ( int  nsteps)

First sets the direction, then calls step(nsteps).

Parameters
nstepsis the number of steps to take.
Return values
0on success
-1on failure.

Definition at line 803 of file FocusMotorCtrl.cpp.

References set_backward(), step(), and stop_moving.

int VisAO::FocusMotorCtrl::step_backward ( )

Calls step(1)

Return values
0on success
-1on failure.

Definition at line 810 of file FocusMotorCtrl.cpp.

Referenced by offset_pos().

int VisAO::FocusMotorCtrl::offset_pos ( double  dpos)

Calculates the number of steps to move, and direction, then calls either step_forward(nsteps) or step_backward(nsteps) as appropriate.

Parameters
dposthe size of the offset desired, in microns
Return values
0on success.
-1on failure.

Definition at line 815 of file FocusMotorCtrl.cpp.

References cur_pos, is_moving, MOVE_NONE, next_pos, pending_move, step_backward(), step_forward(), and step_ratio.

Referenced by goto_pos(), and start_pending_move().

int VisAO::FocusMotorCtrl::goto_pos ( double  pos)

Calculates the number of steps to move, and direction, then calls either step_forward(nsteps) or step_backward(nsteps) as appropriate.

Parameters
posthe position to move to, in microns
Return values
0on success.
-1on failure.

Definition at line 832 of file FocusMotorCtrl.cpp.

References cur_pos, and offset_pos().

Referenced by start_pending_move().

int VisAO::FocusMotorCtrl::start_pending_move ( )

The main loop pause() is interrupted by a SIGIO signal, and once control returns it checks pending_move, and if ture calls this routine. The move will continue until complete or stopped.

Return values
0on success
-1on failure.

Definition at line 838 of file FocusMotorCtrl.cpp.

References cur_pos, goto_pos(), home_pos, MOVE_ABS, MOVE_OFFSET, next_pos, offset_pos(), pending_move, set_backward(), set_forward(), step(), and stop_moving.

Referenced by Run().

int VisAO::FocusMotorCtrl::get_preset ( double &  fcal,
std::vector< double > &  preset,
std::string &  presetf 
)

If a preset file exists for current conditions it is read and the arguments are populated.

Definition at line 868 of file FocusMotorCtrl.cpp.

References attach_shm(), VisAO::VisAOApp_standalone::log_msg(), and VisAO::VisAOApp_base::logss.

Referenced by check_preset(), and goto_preset().

int VisAO::FocusMotorCtrl::goto_preset ( )

Gets the current preset from get_preset. If a preset exists, the stage is moved.

Definition at line 926 of file FocusMotorCtrl.cpp.

References get_preset(), VisAO::VisAOApp_base::logss, MOVE_ABS, next_pos, and pending_move.

Referenced by common_command().

std::string VisAO::FocusMotorCtrl::common_command ( std::string  com,
int  cmode 
)

The return value depends on the command received. Recognized commands are:

  • POS? the return value is the current position in microns as "x.XXXX\n"
  • ISMOVING? the return value is "1\n" if moving, "0\n" if not moving.
  • STATE? returns the result of get_state_str()
  • ABORT if control_mode allows it, sets stop_moving = true and returns "0\n". Otherwise returns the control_mode in 1 letter.
  • POS x.x if control_mode allows it and not already moving, sets pending_move = MOVE_ABS and next_pos = x.x, and returns "1\n". if control_mode would allow it but already moving does nothing and returns "0\n". Othewrise, returns the control mode in 1 letter.
  • DPOS x.x if control_mode allows it and not already moving, sets pending_move = MOVE_OFFSET and next_pos = x.x, and returns "1\n". if control_mode would allow it but already moving does nothing and returns "0\n". Othewrise, returns the control mode in 1 letter.
  • For any other inputs returns "UNKNOWN COMMAND: (str)\n"

Definition at line 1060 of file FocusMotorCtrl.cpp.

References VisAO::VisAOApp_base::control_mode, VisAO::VisAOApp_base::control_mode_response(), cur_enabled, DO_ENABLE, get_cur_pos(), get_state_str(), goto_preset(), is_moving, VisAO::VisAOApp_standalone::main_thread, MOVE_ABS, MOVE_OFFSET, next_pos, pending_move, pos_limit_disabled, and stop_moving.

Referenced by local_command(), remote_command(), and script_command().

std::string VisAO::FocusMotorCtrl::get_state_str ( )

The state string encodes the current state of the controller as: C PPPPPPP.PPPP M RRRRRRR.RRRR Where C is the current control_mode, PPPPPPP.PPPP is the current position M is 1 if moving, 0 if not, and RRRRRRR.RRRR is the remaining distance to travel.

Returns
the state string

Definition at line 1223 of file FocusMotorCtrl.cpp.

References VisAO::VisAOApp_base::control_mode_response(), cur_enabled, cur_pos, home_switch, is_moving, neg_limit, next_pos, pos_limit, and pos_limit_disabled.

Referenced by common_command().

int VisAO::FocusMotorCtrl::update_statusboard ( )
virtual

Overridden versions should call this as VisAOApp_bas::update_statusboard so the basics are taken care of.

Return values
0on success
-1on failure

Reimplemented from VisAO::VisAOApp_base.

Definition at line 1234 of file FocusMotorCtrl.cpp.

References check_preset(), cur_dir, cur_enabled, cur_pos, is_moving, VisAO::VisAOApp_base::statusboard_shmemptr, and VisAO::VisAOApp_base::update_statusboard().

Referenced by step().

Member Data Documentation

int VisAO::FocusMotorCtrl::cur_enabled
protected

Tracks the current setting of the enable pin TTL level

Definition at line 110 of file FocusMotorCtrl.h.

Referenced by common_command(), get_state_str(), set_enable(), and update_statusboard().


The documentation for this class was generated from the following files: