27 #include "../../libMagAOX/libMagAOX.hpp"
28 #include "../../magaox_git_version.h"
222 config.add(
"dm.serialNumber",
"",
"dm.serialNumber", argType::Required,
"dm",
"serialNumber",
false,
"string",
"The BMC serial number used to find correct DM Profile.");
223 config.add(
"dm.calibRelDir",
"",
"dm.calibRelDir", argType::Required,
"dm",
"calibRelDir",
false,
"string",
"Used to find the default config directory.");
224 config.add(
"dm.satThresh",
"",
"dm.satThresh", argType::Required,
"dm",
"satThresh",
false,
"string",
"Threshold above which to log saturation.");
253 log<software_critical>({__FILE__,__LINE__});
259 log<software_critical>({__FILE__,__LINE__,
"calibration not loaded properly"});
321 ret = BMCOpen(&
m_dm, ser.c_str());
328 err = BMCErrorString(ret);
337 log<text_log>(
"DM initialization failed. Couldn't open DM handle.",
logPrio::LOG_ERROR);
349 map_lut = (uint32_t *)malloc(
sizeof(uint32_t)*MAX_DM_SIZE);
350 ret = BMCLoadMap(&
m_dm, NULL, map_lut);
355 err = BMCErrorString(ret);
356 log<text_log>(std::string(
"DM initialization failed. Couldn't load map.") + err,
logPrio::LOG_ERROR);
377 for (uint32_t idx = 0; idx <
m_nbAct; ++idx)
384 log<text_log>(
"DM initialization failed. Failed to get actuator mapping.",
logPrio::LOG_ERROR);
413 double * dminputs = (
double*) calloc(
m_nbAct,
sizeof(
double ) );
416 BMCRC ret = BMCSetArray(&
m_dm, dminputs, NULL);
424 err = BMCErrorString(ret);
429 log<text_log>(
"DM zeroed");
449 for (uint32_t idx = 0; idx <
m_nbAct; ++idx)
469 for (uint32_t idx = 0 ; idx <
m_nbAct ; ++idx)
492 err = BMCErrorString(ret);
498 for (uint32_t idx = 0; idx <
m_nbAct; ++idx)
501 if(address == -1)
continue;
529 pthread_kill(
m_smThread.native_handle(), SIGUSR1);
542 ret = BMCClearArray(&
m_dm);
547 err = BMCErrorString(ret);
553 ret = BMCClose(&
m_dm);
560 err = BMCErrorString(ret);
584 std::string calibpath =
m_calibPath +
"/" +
"bmc_2k_userconfig.txt";
587 fp = fopen(calibpath.c_str(),
"r");
590 log<text_log>(
"Could not read configuration file at " + calibpath,
logPrio::LOG_ERROR);
594 calibvals = (
double*) malloc(2*
sizeof(
double));
596 while ((read = getline(&line, &len, fp)) != -1)
599 calibvals[idx] = strtod(line, NULL);
611 log<text_log>(
"BMC " +
m_serialNumber +
": Using stroke and volume calibration from " + calibpath);
626 std::string calibpath =
m_calibPath +
"/" +
"bmc_2k_actuator_mapping.fits";
628 if ( !fits_open_image(&fptr, calibpath.c_str(), READONLY, &status) )
633 if (fits_get_hdu_type(fptr, &hdutype, &status) || hdutype != IMAGE_HDU) {
634 printf(
"Error: this program only works on images, not tables\n");
638 fits_get_img_dim(fptr, &naxis, &status);
639 fits_get_img_size(fptr, 2, naxes, &status);
641 if (status || naxis != 2) {
642 printf(
"Error: NAXIS = %d. Only 2-D images are supported.\n", naxis);
646 int * pix = (
int *) malloc(naxes[0] *
sizeof(
int));
649 printf(
"Memory allocation error\n");
659 for (fpixel[1] = 1; fpixel[1] <= naxes[1]; fpixel[1]++)
662 if (fits_read_pix(fptr, TINT, fpixel, naxes[0],0, pix,0, &status))
666 for (
int ii = 0; ii < naxes[0]; ii++) {
673 fits_close_file(fptr, &status);
679 fits_report_error(stderr, status);
683 log<text_log>(
"BMC " +
m_serialNumber +
": Using actuator mapping from " + calibpath);
The base-class for MagAO-X applications.
stateCodes::stateCodeT state()
Get the current state code.
int shutdown()
Get the value of the shutdown flag.
bool m_powerMgtEnabled
Flag controls whether power mgt is used. Set this in the constructor of a derived app....
The MagAO-X BMC DM Controller.
uint32_t m_nbAct
The number of actuators.
double m_act_gain
Actuator gain (microns/volt)
bool m_dmopen
Track whether the DM connection has been opened.
virtual int whilePowerOff()
Maintenace while powered off.
DM m_dm
BMC SDK handle for the DM.
int commandDM(void *curr_src)
Send a command to the DM.
int initDM()
Initialize the DM and prepare for operation.
virtual void setupConfig()
Setup the configuration system.
double * m_dminputs
Pre-allocated command vector, used only in commandDM.
std::string m_serialNumber
The BMC serial number used to open the correct DM profile.
double m_volume_factor
the volume factor to convert from displacement to commands
virtual int appLogic()
Implementation of the FSM for bmcCtrl.
long m_satThresh
Threshold above which to log saturation.
virtual int appShutdown()
Shutdown the app.
virtual void loadConfig()
Load the configuration.
friend class bmcCtrl_test
int releaseDM()
Release the DM, making it safe to turn off power.
int zeroDM()
Zero all commands on the DM.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
virtual int onPowerOff()
Cleanup after a power off.
float realT
This defines the datatype used to signal the DM using the ImageStreamIO library.
int * m_actuator_mapping
Array containing the mapping from 2D grid position to linear index in the command vector.
int get_actuator_mapping()
Read the actuator mapping from a FITS file.
virtual int appStartup()
Startup function.
int parse_calibration_file()
Parse the BMC calibration file.
~bmcCtrl() noexcept
D'tor.
std::string m_calibPath
The path to this DM's calibration files.
void setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
std::string m_calibRelDir
The directory relative to the calibPath. Set this before calling dm<derivedT,realT>::loadConfig().
void loadConfig(mx::app::appConfigurator &config)
load the configuration system results
int appShutdown()
DM shutdown.
mx::improc::eigenImage< uint8_t > m_instSatMap
The instantaneous saturation map, 0/1, set by the commandDM() function of the derived class.
int whilePowerOff()
DM Poweroff Updates.
int appStartup()
Startup function.
int onPowerOff()
DM Poweroff.
int appLogic()
DM application logic.
int appStartup()
Startup function.
int appLogic()
Checks the shmimMonitor thread.
std::thread m_smThread
A separate thread for the actual monitoring.
int appShutdown()
Shuts down the shmimMonitor thread.
@ OPERATING
The device is operating, other than homing.
@ POWEROFF
The device power is off.
@ READY
The device is ready for operation, but is not operating.
@ POWERON
The device power is on.
constexpr static logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
constexpr static logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
constexpr static logPrioT LOG_NOTICE
A normal but significant condition.