7#ifndef filterWheelCtrl_hpp
8#define filterWheelCtrl_hpp
10#include "../../libMagAOX/libMagAOX.hpp"
11#include "../../magaox_git_version.h"
254 config.add(
"timeouts.write",
262 "The timeout for writing to the device [msec]. Default = 1000" );
263 config.add(
"timeouts.read",
271 "The timeout for reading the device [msec]. Default = 1000" );
273 config.add(
"motor.acceleration",
275 "motor.acceleration",
281 "The motor acceleration parameter. Default=100." );
282 config.add(
"motor.deceleration",
284 "motor.deceleration",
290 "The motor deceleration parameter. Default=50." );
291 config.add(
"motor.speed",
299 "The motor speed parameter. Default=3000." );
300 config.add(
"motor.circleSteps",
308 "The number of steps in 1 revolution." );
309 config.add(
"stage.homeOffset",
317 "The homing offset in motor counts." );
359 m_indiP_counts,
"counts", std::numeric_limits<long>::lowest(), std::numeric_limits<long>::max(), 0.0,
"%ld" );
387 std::stringstream
logs;
413 std::stringstream
logs;
424 std::stringstream
logs;
457 std::stringstream
logs;
459 <<
" no longer found in udev";
486 std::stringstream
logs;
700 {
__FILE__,
__LINE__,
"In state ERROR but no recovery implemented. Terminating." } );
746 double target_abs = -1;
747 if(
ipRecv.find(
"current" ) )
749 counts =
ipRecv[
"current"].get<
double>();
751 if(
ipRecv.find(
"target" ) )
753 target_abs =
ipRecv[
"target"].get<
double>();
755 if( target_abs == -1 )
758 clearPresetNameTracking();
760 m_preset_target = ( (double)target_abs - m_homeOffset ) / m_circleSteps * m_presetNames.size() + 1.0;
761 std::lock_guard<std::mutex> guard( m_indiMutex );
762 return moveToRaw( target_abs );
836 speed = std::stol(
resp.c_str() );
987 com =
"LA" + std::to_string( counts ) +
"\r";
1061 static long last_pos = 999999999999;
Internal class to manage setuid privilege escalation with RAII.
The base-class for XWCTk applications.
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
int m_powerState
Current power state, 1=On, 0=Off, -1=Unk.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
int stateLogged()
Updates and returns the value of m_stateLogged. Will be 0 on first call after a state change,...
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::mutex m_indiMutex
Mutex for locking INDI communications.
MagAO-X standard motion stage interface.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
std::vector< std::string > m_presetNames
The names of each position on the stage.
bool m_powerOnHome
If true, then the motor is homed at startup (by this software or actual power on)
std::string m_presetNotation
Notation used to refer to a preset, should be singular, as in "preset" or "filter".
float m_preset_target
The target numerical preset position [1.0 is index 0 in the preset name vector].
pcf::IndiProperty m_indiP_home
Command the stage to home. .
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int m_homePreset
If >=0, this preset position is moved to after homing.
pcf::IndiProperty m_indiP_stop
Command the stage to halt.
pcf::IndiProperty m_indiP_preset
The position of the stage in presets.
float m_preset
The current numerical preset position [1.0 is index 0 in the preset name vector].
int appStartup()
Startup function.
std::vector< float > m_presetPositions
int recordStage(bool force=false)
Record the stage telemetry state.
virtual int appLogic()
Implementation of the FSM for the TTM Modulator.
long m_circleSteps
The number of position counts in 1 360-degree revolution.
int home()
Start a low-level homing sequence.
int recordPosition(bool force=false)
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
virtual int whilePowerOff()
This method is called while the power is off, once per FSM loop.
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
int getSwitch()
Get the home switch status, sets m_switch to true or false.
pcf::IndiProperty m_indiP_counts
The position of the wheel in counts.
int startHoming()
Start a high-level homing sequence.
int moveToRaw(const long &counts)
Move to an absolute position in raw counts.
long m_homeOffset
The number of position counts to offset from the home position.
INDI_NEWCALLBACK_DECL(filterWheelCtrl, m_indiP_counts)
int onPowerOnConnect()
Set up the MCBL controller, called after each power-on/connection.
int recordStage(bool force=false)
int getPos()
Get the current position of the wheel, sets m_rawPos to the current motor counts.
long m_rawPos
The position of the wheel in motor counts.
int moveTo(const double &filters)
Move to an absolute position in filter units.
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
filterWheelCtrl()
Default c'tor.
virtual int onPowerOff()
This method is called when the change to poweroff is detected.
int m_writeTimeOut
The timeout for writing to the device [msec].
bool m_switch
The home switch status.
int moveToRawRelative(const long &counts)
Move to a new position relative to current, in raw counts.
~filterWheelCtrl() noexcept
D'tor, declared and defined for noexcept.
int m_homingState
The homing state, tracks the stages of homing.
int recordTelem(const telem_stage *)
int getMoving()
Get the moving-state of the wheel, sets m_moving to true or false.
int m_readTimeOut
The timeout for reading from the device [msec].
virtual int appStartup()
Startup functions.
int stop()
Stop the wheel motion immediately.
#define INDI_NEWCALLBACK_DEFN(class, prop)
Define the callback for a new property request.
#define INDI_NEWCALLBACK(prop)
Get the name of the static callback wrapper for a new property.
int ttyWriteRead(std::string &strRead, const std::string &strWrite, const std::string &eot, bool swallowEcho, int fd, int timeoutWrite, int timeoutRead)
Write to a tty on an open file descriptor, then get the result.
std::string ttyErrorString(int ec)
Get a text explanation of a TTY_E_ error code.
int ttyWrite(const std::string &buffWrite, int fd, int timeoutWrite)
Write to the tty console indicated by a file descriptor.
int ttyRead(std::string &strRead, int bytes, int fd, int timeoutRead)
Read from a tty console indicated by a file-descriptor, until a given number of bytes are read.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
static constexpr logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
A device base class which saves telemetry.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
@ OPERATING
The device is operating, other than homing.
@ NODEVICE
No device exists for the application to control.
@ NOTHOMED
The device has not been homed.
@ HOMING
The device is homing.
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
@ READY
The device is ready for operation, but is not operating.
@ CONNECTED
The application has connected to the device or service.
@ UNINITIALIZED
The application is unitialized, the default.
@ INITIALIZED
The application has been initialized, set just before calling appStartup().
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
Log entry recording position stage specific status.
Log entry recording stdMotionStage status.
A USB device as a TTY device.
std::string m_deviceName
The device path name, e.g. /dev/ttyUSB0.
int m_fileDescrip
The file descriptor.
int connect()
Connect to the device.
int getDeviceName()
Get the device name from udev using the vendor, product, and serial number.
std::string m_idProduct
The product id 4-digit code.
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for the USB section.
std::string m_serial
The serial number.
int loadConfig(mx::app::appConfigurator &config)
Load the USB section from an application configurator.
speed_t m_baudRate
The baud rate specification.
std::string m_idVendor
The vendor id 4-digit code.
#define TTY_E_DEVNOTFOUND