8 #ifndef filterWheelCtrl_hpp
9 #define filterWheelCtrl_hpp
12 #include "../../libMagAOX/libMagAOX.hpp"
13 #include "../../magaox_git_version.h"
227 int moveTo(
const double & filters );
261 config.add(
"timeouts.write",
"",
"timeouts.write", argType::Required,
"timeouts",
"write",
false,
"int",
"The timeout for writing to the device [msec]. Default = 1000");
262 config.add(
"timeouts.read",
"",
"timeouts.read", argType::Required,
"timeouts",
"read",
false,
"int",
"The timeout for reading the device [msec]. Default = 1000");
264 config.add(
"motor.acceleration",
"",
"motor.acceleration", argType::Required,
"motor",
"acceleration",
false,
"real",
"The motor acceleration parameter. Default=100.");
265 config.add(
"motor.deceleration",
"",
"motor.deceleration", argType::Required,
"motor",
"deceleration",
false,
"real",
"The motor deceleration parameter. Default=50.");
266 config.add(
"motor.speed",
"",
"motor.speed", argType::Required,
"motor",
"speed",
false,
"real",
"The motor speed parameter. Default=3000.");
267 config.add(
"motor.circleSteps",
"",
"motor.circleSteps", argType::Required,
"motor",
"circleSteps",
false,
"long",
"The number of steps in 1 revolution.");
268 config.add(
"stage.homeOffset",
"",
"stage.homeOffset", argType::Required,
"stage",
"homeOffset",
false,
"long",
"The homing offset in motor counts.");
312 createStandardIndiNumber<long>(
m_indiP_counts,
"counts", std::numeric_limits<long>::lowest(), std::numeric_limits<long>::max(), 0.0,
"%ld");
341 std::stringstream logs;
343 log<text_log>(logs.str());
366 std::stringstream logs;
368 log<text_log>(logs.str());
377 std::stringstream logs;
379 log<text_log>(logs.str());
408 std::stringstream logs;
410 log<text_log>(logs.str());
436 std::stringstream logs;
437 logs <<
"Connected to filter wheel on " <<
m_deviceName;
438 log<text_log>(logs.str());
449 log<software_error>({__FILE__,__LINE__});
455 std::string landfill;
465 log<software_error>({__FILE__,__LINE__});
525 return log<software_error,0>({__FILE__,__LINE__});
539 return log<software_error,0>({__FILE__,__LINE__});
562 return log<software_error,0>({__FILE__,__LINE__});
576 return log<software_error,0>({__FILE__,__LINE__});
589 return log<software_error,0>({__FILE__,__LINE__});
632 log<software_error>({__FILE__, __LINE__});
644 return log<
software_error,-1>({__FILE__,__LINE__,
"In state ERROR but no recovery implemented. Terminating."});
647 return log<
software_error,-1>({__FILE__,__LINE__,
"appLogic fell through. Terminating."});
665 log<software_error>({__FILE__,__LINE__});
679 log<software_error>({__FILE__,__LINE__});
685 log<software_error>({__FILE__, __LINE__});
696 double target_abs = -1;
697 if(
ipRecv.find(
"current"))
699 counts =
ipRecv[
"current"].get<
double>();
703 target_abs =
ipRecv[
"target"].get<
double>();
705 if(target_abs == -1) target_abs = counts;
708 m_preset_target = ((double) target_abs - m_homeOffset)/m_circleSteps*m_presetNames.size() + 1.0;
709 std::lock_guard<std::mutex> guard(m_indiMutex);
710 return moveToRaw(target_abs);
729 com =
"MOTTYP" + std::to_string(
m_motorType) +
"\r";
781 try{ speed = std::stol(resp.c_str());}
808 try{
m_rawPos = std::stol(resp.c_str());}
843 log<software_error>({__FILE__,__LINE__,
"error calculating " +
m_presetNotation +
" index, n < 0"});
872 std::string com =
"HOSP" + std::to_string(
m_motorSpeed) +
"\r";
914 com =
"LA" + std::to_string(counts) +
"\r";
939 com =
"LR" + std::to_string(counts_relative) +
"\r";
984 static long last_pos = 999999999999;
990 telem<telem_position>(fpos);
Internal class to manage setuid privilege escalation with RAII.
The base-class for MagAO-X 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
int onPowerOff()
Actions on power off.
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 updateINDI()
Update the INDI properties for this device controller.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int whilePowerOff()
Actions while powered off.
int m_homePreset
If >=0, this preset position is moved to after homing.
int8_t m_moving
Whether or not the stage is moving. -2 means powered off, -1 means not homed, 0 means not moving,...
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
The positions, in arbitrary units, of each preset. If 0, then the integer position number (starting f...
int recordStage(bool force=false)
int8_t m_movingState
Used to track the type of command. If > 1 this is a command to move to a preset. If 0 then it is a mo...
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(prop)
Get the name of the static callback wrapper for a new property.
@ 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.
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.
INDI_VALIDATE_CALLBACK_PROPS(function, ipRecv)
const pcf::IndiProperty & ipRecv
INDI_NEWCALLBACK_DEFN(acesxeCtrl, m_indiP_windspeed)(const pcf
constexpr static 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 appLogic()
Perform telemeter application logic.
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.
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