add focuser management

This commit is contained in:
eddyem 2017-09-12 13:27:19 +03:00
parent 6b85b772fd
commit 15a91168db
4 changed files with 161 additions and 23 deletions

View File

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <math.h> #include <math.h>
#include <limits.h>
#include <libfli.h> #include <libfli.h>
#include "cmdlnopts.h" #include "cmdlnopts.h"
#include "usefull_macros.h" #include "usefull_macros.h"
@ -52,7 +53,8 @@ glob_pars const Gdefault = {
.X1 = -1, .Y1 = -1, .X1 = -1, .Y1 = -1,
.temperature = 1e6, .temperature = 1e6,
.shtr_cmd = -1, .shtr_cmd = -1,
.confio = -1, .setio = -1 .confio = -1, .setio = -1,
.gotopos = INT_MAX, .addsteps = INT_MAX,
}; };
/* /*
@ -68,7 +70,8 @@ myoption cmdlnopts[] = {
{"close-shutter",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_CLOSE,arg_none,NULL, N_("close shutter")}, {"close-shutter",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_CLOSE,arg_none,NULL, N_("close shutter")},
{"shutter-on-low",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_LOW,arg_none,NULL, N_("run exposition on LOW @ pin5 I/O port")}, {"shutter-on-low",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_LOW,arg_none,NULL, N_("run exposition on LOW @ pin5 I/O port")},
{"shutter-on-high",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_HIGH,arg_none,NULL, N_("run exposition on HIGH @ pin5 I/O port")}, {"shutter-on-high",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_HIGH,arg_none,NULL, N_("run exposition on HIGH @ pin5 I/O port")},
{"get-ioport",NO_ARGS, NULL, 'g', arg_int, APTR(&G.getio), N_("get value of I/O port pins")}, {"get-ioport",NO_ARGS, NULL, 'i', arg_int, APTR(&G.getio), N_("get value of I/O port pins")},
{"async", NO_ARGS, &G.async,1, arg_none, NULL, N_("move stepper motor asynchronous")},
//{"fast", NO_ARGS, NULL, '8', arg_int, APTR(&G.fast), N_("run in 8-bit mode")}, //{"fast", NO_ARGS, NULL, '8', arg_int, APTR(&G.fast), N_("run in 8-bit mode")},
//{"", NO_ARGS, NULL, '', arg_int, APTR(&G.), N_("")}, //{"", NO_ARGS, NULL, '', arg_int, APTR(&G.), N_("")},
@ -92,7 +95,8 @@ myoption cmdlnopts[] = {
{"Y1", NEED_ARG, NULL, 0, arg_int, APTR(&G.Y1), N_("frame Y1 coordinate (-1 - all with overscan)")}, {"Y1", NEED_ARG, NULL, 0, arg_int, APTR(&G.Y1), N_("frame Y1 coordinate (-1 - all with overscan)")},
{"set-ioport",NEED_ARG, NULL, 's', arg_int, APTR(&G.setio), N_("set I/O port pins to given value (decimal number, pin1 is LSB)")}, {"set-ioport",NEED_ARG, NULL, 's', arg_int, APTR(&G.setio), N_("set I/O port pins to given value (decimal number, pin1 is LSB)")},
{"conf-ioport",NEED_ARG,NULL, 'c', arg_int, APTR(&G.confio), N_("configure I/O port pins to given value (decimal number, pin1 is LSB, 1 == output, 0 == input)")}, {"conf-ioport",NEED_ARG,NULL, 'c', arg_int, APTR(&G.confio), N_("configure I/O port pins to given value (decimal number, pin1 is LSB, 1 == output, 0 == input)")},
{"goto", NEED_ARG, NULL, 'g', arg_int, APTR(&G.gotopos), N_("move wheel/turret motor to absolute position")},
{"addsteps",NEED_ARG, NULL, 'a', arg_int, APTR(&G.addsteps), N_("move wheel/turret motor to relative position")},
//{"", NEED_ARG, NULL, '', arg_int, APTR(&G.), N_("")}, //{"", NEED_ARG, NULL, '', arg_int, APTR(&G.), N_("")},
{"set-temp",NEED_ARG, NULL, 't', arg_double, APTR(&G.temperature),N_("set CCD temperature to given value (degr C)")}, {"set-temp",NEED_ARG, NULL, 't', arg_double, APTR(&G.temperature),N_("set CCD temperature to given value (degr C)")},

View File

@ -50,6 +50,9 @@ typedef struct{
int setio; // set value of ioport int setio; // set value of ioport
int confio; // configure ioport int confio; // configure ioport
double temperature; // temperature of CCD double temperature; // temperature of CCD
int gotopos; // move stepper motor of focuser/wheel to absolute position
int addsteps; // move stepper motor of focuser/wheel to relative position
int async; // asynchronous moving
} glob_pars; } glob_pars;

View File

@ -20,13 +20,19 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
*/ */
//#include <locale.h>
// for strcasestr
#define _GNU_SOURCE
#include <string.h>
#include <limits.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <fitsio.h> #include <fitsio.h>
#include <math.h> #include <math.h>
#include "main.h" #include "main.h"
#ifdef USEPNG #ifdef USEPNG
@ -84,27 +90,34 @@ void info(const char *fmt, ...){
} }
int main(int argc, char **argv){ int main(int argc, char **argv){
int i, numcams = 0; int i, num;
long ltmp;
char libver[LIBVERSIZ]; // FLI library version char libver[LIBVERSIZ]; // FLI library version
cam_t *cam = NULL; // list of CCDs available cam_t *cam = NULL; // list of CCDs available
flidev_t dev;
char buff[BUFF_SIZ];
initial_setup(); initial_setup();
G = parse_args(argc, argv); G = parse_args(argc, argv);
//TRYFUNC(FLISetDebugLevel, NULL /* "NO HOST" */, FLIDEBUG_ALL); // #ifdef EBUG
TRYFUNC(FLISetDebugLevel, NULL /* "NO HOST" */, FLIDEBUG_NONE);
/* #else
TRYFUNC(FLISetDebugLevel, NULL, FLIDEBUG_NONE); TRYFUNC(FLISetDebugLevel, NULL, FLIDEBUG_NONE);
#endif */
TRYFUNC(FLIGetLibVersion, libver, LIBVERSIZ); TRYFUNC(FLIGetLibVersion, libver, LIBVERSIZ);
// 髋矣裳 律绿上耘松 '%s' // 髋矣裳 律绿上耘松 '%s'
info(_("Library version '%s'"), libver); info(_("Library version '%s'"), libver);
numcams = findcams(FLIDOMAIN_USB, &cam); /*
i = 0; * Find CCDs and work with each of them
for (i = 0; i < numcams; i++){ */
long x0,x1, y0,y1, row, img_rows, row_width, ltmp; num = findcams(FLIDOMAIN_USB | FLIDEVICE_CAMERA, &cam);
flidev_t dev; if(!num) WARNX(_("No CCD found"));
char buff[BUFF_SIZ]; for (i = 0; i < num; i++){
long x0,x1, y0,y1, row, img_rows, row_width;
u_int16_t *img; u_int16_t *img;
int j; int j;
// 肓团伊 '%s' 哨 南团瘟 %s // 肓团伊 '%s' 哨 南团瘟 %s
info(_("Camera '%s', domain %s"), cam[i].name, cam[i].dname); info(_("Camera '%s', domain %s"), cam[i].name, cam[i].dname);
TRYFUNC(FLIOpen, &dev, cam[i].name, FLIDEVICE_CAMERA | cam[i].domain); TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain);
if(r) continue; if(r) continue;
TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ); TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ);
// 硐呐特:\t\t%s // 硐呐特:\t\t%s
@ -288,9 +301,128 @@ int main(int argc, char **argv){
FREE(img); FREE(img);
TRYFUNC(FLIClose, dev); TRYFUNC(FLIClose, dev);
} }
for (i = 0; i < numcams; i++) for (i = 0; i < num; i++)
FREE(cam[i].name); FREE(cam[i].name);
FREE(cam); FREE(cam);
/*
* Find focusers and work with each of them
*/
num = findcams(FLIDOMAIN_USB | FLIDEVICE_FOCUSER, &cam);
if(!num) WARNX(_("No focusers found"));
for (i = 0; i < num; i++){
TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain);
if(r) continue;
TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ);
if(!r){
if(!strcasestr(buff, "focuser")){ // not focuser
TRYFUNC(FLIClose, dev);
continue;
}
// íÏÄÅÌØ:\t\t%s
info(_("Model:\t\t%s"), buff);
}
info(_("Focuser '%s', domain %s"), cam[i].name, cam[i].dname);
TRYFUNC(FLIGetHWRevision, dev, &ltmp);
// áÐÐ. ×ÅÒÓÉÑ: %ld
if(!r) info(_("HW revision: %ld"), ltmp);
TRYFUNC(FLIGetFWRevision, dev, &ltmp);
// ðÒÏÇÒ. ×ÅÒÓÉÑ: %ld
if(!r) info(_("SW revision: %ld"), ltmp);
TRYFUNC(FLIReadTemperature, dev, FLI_TEMPERATURE_INTERNAL, &t_ext);
// ôÅÍÐÅÒÁÔÕÒÁ (×ÎÅÛÎ.): %f
if(!r) green(_("Focuser temperature: %f\n"), t_ext);
long curpos = -1, maxpos = -1;
TRYFUNC(FLIGetStepperPosition, dev, &ltmp);
if(!r){
// ðÏÚÉÃÉÑ ÆÏËÕÓÅÒÁ: %ld
info(_("Focuser position %ld"), ltmp);
curpos = ltmp;
}
TRYFUNC(FLIGetFocuserExtent, dev, &ltmp);
if(!r){
// íÁËÓÉÍÁÌØÎÁÑ ÐÏÚÉÃÉÑ ÆÏËÕÓÅÒÁ: %ld
info(_("Focuser extent: %ld"), ltmp);
maxpos = ltmp;
}
do{
if(G->gotopos != INT_MAX && G->addsteps != INT_MAX){
// îÅÌØÚÑ ÏÄÎÏ×ÒÅÍÅÎÎÏ ÕËÁÚÙ×ÁÔØ ÏÔÎÏÓÉÔÅÌØÎÕÀ É ÁÂÓÏÌÀÔÎÕÀ ÐÏÚÉÃÉÀ
WARNX(_("You can't use both relative and absolute position"));
break;
}
if(curpos < 0 || maxpos < 0){
// ïÛÉÂËÁ ÏÐÒÅÄÅÌÅÎÉÑ ÐÏÚÉÃÉÉ
WARNX(_("Error in position detection"));
break;
}
long pos = -1, steps = 0;
if(G->gotopos != INT_MAX){ // absolute pointing
pos = G->gotopos;
steps = pos - curpos;
}else if(G->addsteps != INT_MAX){ // relative pointing
steps = G->addsteps;
pos = curpos + steps;
}else break;
if(!steps){
info(_("Already at position"));
break;
}
if(pos > maxpos || pos < 0){
// ðÏÚÉÃÉÑ ÎÅ ÄÏÌÖÎÁ ×ÙÈÏÄÉÔØ ÚÁ ÐÒÅÄÅÌÙ 0...%ld
WARNX(_("Position should be in 0...%ld"), maxpos);
break;
}
if(pos == 0){
// ðÅÒÅÍÅÝÅÎÉÅ × ÎÕÌÅ×ÕÀ ÐÏÚÉÃÉÀ
info(_("Moving to home position"));
if(G->async) TRYFUNC(FLIHomeDevice, dev);
else TRYFUNC(FLIHomeFocuser, dev);
}else{
// ðÅÒÅÍÅÝÅÎÉÅ ÎÁ %ld ÛÁÇÏ×
info(_("Moving for %ld steps"), steps);
if(G->async) TRYFUNC(FLIStepMotorAsync, dev, steps);
else TRYFUNC(FLIStepMotor, dev, steps);
}
TRYFUNC(FLIGetStepperPosition, dev, &ltmp);
// äÏÓÔÉÇÎÕÔÁ ÐÏÚÉÃÉÑ %ls
if(!r) info(_("Reached position %ld"), ltmp);
}while(0);
;
TRYFUNC(FLIClose, dev);
}
for (i = 0; i < num; i++)
FREE(cam[i].name);
FREE(cam);
/*
* Find wheels and work with each of them
*
num = findcams(FLIDOMAIN_USB | FLIDEVICE_FILTERWHEEL, &cam);
if(!num) WARNX(_("No wheels found"));
for (i = 0; i < num; i++){
info(_("Wheel '%s', domain %s"), cam[i].name, cam[i].dname);
TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain);
if(r) continue;
TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ);
// íÏÄÅÌØ:\t\t%s
info(_("Model:\t\t%s"), buff);
TRYFUNC(FLIGetHWRevision, dev, &ltmp);
// áÐÐ. ×ÅÒÓÉÑ: %ld
info(_("HW revision: %ld"), ltmp);
TRYFUNC(FLIGetFWRevision, dev, &ltmp);
// ðÒÏÇÒ. ×ÅÒÓÉÑ: %ld
info(_("SW revision: %ld"), ltmp);
TRYFUNC(FLIReadTemperature, dev, FLI_TEMPERATURE_INTERNAL, &t_ext);
// ôÅÍÐÅÒÁÔÕÒÁ (×ÎÅÛÎ.): %f
green(_("Wheel temperature: %f\n"), t_ext);
// ðÏÚÉÃÉÑ ÔÕÒÅÌÉ: %ld
TRYFUNC(FLIGetFilterPos, dev, &ltmp);
info(_("Filter position"), ltmp);
;
TRYFUNC(FLIClose, dev);
}
for (i = 0; i < num; i++)
FREE(cam[i].name);
FREE(cam);*/
exit(0); exit(0);
} }
@ -298,13 +430,13 @@ int findcams(flidomain_t domain, cam_t **cam){
long r; long r;
char **tmplist; char **tmplist;
int numcams = 0; int numcams = 0;
TRYFUNC(FLIList, domain | FLIDEVICE_CAMERA, &tmplist); TRYFUNC(FLIList, domain, &tmplist);
if (tmplist != NULL && tmplist[0] != NULL){ if (tmplist && tmplist[0]){
int i, cams = 0; int i, cams = 0;
for (i = 0; tmplist[i] != NULL; i++) cams++; for (i = 0; tmplist[i]; i++) cams++;
if ((*cam = realloc(*cam, (numcams + cams) * sizeof(cam_t))) == NULL) if ((*cam = realloc(*cam, (numcams + cams) * sizeof(cam_t))) == NULL)
ERR("realloc() failed"); ERR("realloc() failed");
for (i = 0; tmplist[i] != NULL; i++) { for (i = 0; tmplist[i]; i++){
int j; int j;
cam_t *tmpcam = *cam + i; cam_t *tmpcam = *cam + i;
for (j = 0; tmplist[i][j] != '\0'; j++) for (j = 0; tmplist[i][j] != '\0'; j++)
@ -313,7 +445,7 @@ int findcams(flidomain_t domain, cam_t **cam){
break; break;
} }
tmpcam->domain = domain; tmpcam->domain = domain;
switch (domain){ switch (domain & 0xff){
case FLIDOMAIN_PARALLEL_PORT: case FLIDOMAIN_PARALLEL_PORT:
tmpcam->dname = "parallel port"; tmpcam->dname = "parallel port";
break; break;
@ -331,11 +463,11 @@ int findcams(flidomain_t domain, cam_t **cam){
break; break;
} }
tmpcam->name = strdup(tmplist[i]); tmpcam->name = strdup(tmplist[i]);
DBG("found: %s @ %s", tmpcam->name, tmpcam->dname);
} }
numcams += cams; numcams += cams;
} }
// ëÁÍÅÒÙ ÎÅ ÎÁÊÄÅÎÙ!\n else DBG("No devices");
else WARNX(_("No cameras found!\n"));
TRYFUNC(FLIFreeList, tmplist); TRYFUNC(FLIFreeList, tmplist);
return numcams; return numcams;
} }

View File

@ -24,8 +24,6 @@
#ifndef __MAIN_H__ #ifndef __MAIN_H__
#define __MAIN_H__ #define __MAIN_H__
#define _XOPEN_SOURCE 501
#include "usefull_macros.h" #include "usefull_macros.h"
#include "cmdlnopts.h" #include "cmdlnopts.h"
@ -50,6 +48,7 @@ typedef struct{
}cam_t; }cam_t;
int findcams(flidomain_t domain, cam_t **cam); int findcams(flidomain_t domain, cam_t **cam);
#ifdef USERAW #ifdef USERAW
int writeraw(char *filename, int width, int height, void *data); int writeraw(char *filename, int width, int height, void *data);
#endif // USERAW #endif // USERAW