/**
 * \brief Main function of the CalibrationProcess class
 *
 * This method assumes that the observed star position depends linearly
 * on time and the applied correction. It then performs several position
 * measurements and solves for the equation. The resulting matrix should have
 * two nearly perpendicular columns.
 *
 * The mesurements are placed in a grid pattern with coordinate (ra, dec)
 * corresponding to a point that can be reached from the initial position
 * by speeing up (down for negative values) the right ascension/declination
 * motors for ra resp. dec seconds. After each measurement, we return to the
 * central position.
 *
 */
void	CalibrationProcess::main(astro::thread::Thread<CalibrationProcess>& _thread) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "start calibrating: terminate = %s",
		_thread.terminate() ? "YES" : "NO");
	// set the start time
	starttime = Timer::gettime();

	// grid range we want to scan
	range = 1;

	// the grid constant normally depends on the focallength and the
	// pixels size. Smaller pixels are larger focallength allow to
	// use a smaller grid constant. The default value of 10 is a good
	// choice for a 100mm guide scope and 7u pixels as for the SBIG
	// ST-i guider kit
	grid = gridconstant(_focallength, _pixelsize);

	// prepare a GuiderCalibrator class that does the actual computation
	GuiderCalibrator	calibrator;

	// measure the initial point
	CalibrationPoint	initialpoint(0, Point(0, 0), starAt(0, 0));
	calibrator.add(initialpoint);
	callback(initialpoint);

	// perform a grid search
	try {
		for (int ra = -range; ra <= range; ra++) {
			for (int dec = -range; dec <= range; dec++) {
				measure(calibrator, ra, dec);
				if (_thread.terminate()) {
					debug(LOG_DEBUG, DEBUG_LOG, 0,
						"terminate signal received");
					throw calibration_interrupted();
				}
				_progress = currentprogress(ra, dec);
			}
		}
	} catch (calibration_interrupted&) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "calibration interrupted");
		return;
	}
	
	// now compute the calibration data, and fix the time constant
	GuiderCalibration	cal = calibrator.calibrate();
	//cal.rescale(1. / grid);
	guider().calibration(cal);

	// inform the callback that calibration is complete
	callback(cal);

	// the guider is now calibrated
	debug(LOG_DEBUG, DEBUG_LOG, 0, "calibration: %s",
		guider().calibration().toString().c_str());
	calibrated = true;

	// signal other threads that we are done
	debug(LOG_DEBUG, DEBUG_LOG, 0, "calibration complete");
	_progress = 1.0;
}
/**
 * \brief Send the completed calibration data to the callback
 */
void	CalibrationProcess::callback(const GuiderCalibration& calibration) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "send guider calibration data");
	if (guider().calibrationcallback) {
		astro::callback::CallbackDataPtr	data(
			new GuiderCalibrationCallbackData(calibration));
		(*guider().calibrationcallback)(data);
	}
}
/**
 * \brief Send a calibration point to the callback
 */
void	CalibrationProcess::callback(const CalibrationPoint& calpoint) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "send calibration point to callback");
	if (guider().calibrationcallback) {
		astro::callback::CallbackDataPtr	data(
			new CalibrationPointCallbackData(calpoint));
		(*guider().calibrationcallback)(data);
	}
}
Example #4
0
int main(){
	/*
		infile - pointer to infile
		outfile - pointer to outfile
		indata - input data
		nodes - input path
	*/
	FILE *infile, *outfile;
	indata Bdata;
	path_node *nodes;

	infile = NULL;
	outfile = NULL;
	nodes=NULL;
	
	infile = fopen ("input.txt","r");
	outfile = fopen ("output.txt","w");
	
	loader(&Bdata, infile);
	int size = guider(&nodes, &Bdata);
	path_to_file(nodes, size, outfile);
	
	free(Bdata.P);
	free(Bdata.Q);
	free(nodes);
	fclose(infile);
	fclose(outfile);
}
/**
 * \brief driving thread main function
 *
 * The main function works in a loop until the thread is terminated and
 * keeps feeding the guiderport with control commands based on the settings
 * of the tx and ty values. The tx and ty values are signed duty cycle numbers
 * for the guider port, 1 means that the corresponding plus signal of the
 * guiderport should be activated all the time. The loop is timed by the
 * _interval variable, so the method just computes the time to activate
 * the guiderport and then goes to sleep for the rest of the interval.
 */
void	DrivingWork::main(astro::thread::Thread<DrivingWork>& thread) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "GUIDE: thread main function starts");
	do {
		double	raplus = 0, raminus = 0;
		double	decplus = 0, decminus = 0;
		// read the currently valid corrections from tx and ty,
		// this must be done while the mutex is held, or the
		// data we read my be inconsistent.
		{
			std::unique_lock<std::mutex>	lock(mutex);
			if (totalx > 0) {
				double	dx = std::min(_interval, totalx);
				if (stepx > 0) {
					raplus = dx;
				} else {
					raminus = dx;
				}
				totalx -= dx;
			} else {
				if (defaultx > 0) {
					raplus = defaultx * _interval;
				} else {
					raminus = -defaultx * _interval;
				}
			}
			if (totaly > 0) {
				double	dy = std::min(_interval, totaly);
				if (stepy > 0) {
					decplus = dy;
				} else {
					decminus = dy;
				}
				totaly -= dy;
			} else {
				if (defaulty > 0) {
					decplus = defaulty * _interval;
				} else {
					decminus = -defaulty * _interval;
				}
			}
			if (totalx < 0) { totalx = 0.; }
			if (totaly < 0) { totaly = 0.; }
		}

		// now activate the guider port outputs for the times we found
		debug(LOG_DEBUG, DEBUG_LOG, 0,
			"GUIDE: activate(%.3f, %.3f, %.3f, %.3f)",
			raplus, raminus, decplus, decminus);
		guider().guiderport()->activate(raplus, raminus,
			decplus, decminus);

		// wait for one second.
		Timer::sleep(_interval);

		// checking for termination signal
	} while (!thread.terminate());
	debug(LOG_DEBUG, DEBUG_LOG, 0, "GUIDE: Termination signal received");
}
/**
 * \brief Analyze a single grid point
 *
 * Moves (relatively) to a grid point, takes an image and returns the
 * the offset as measured by the tracker.
 */
Point	CalibrationProcess::starAt(double ra, double dec) {
	// move the telescope to the point
	moveto(grid * ra, grid * dec);

	// take an image at that position
	imager().startExposure(exposure());
	usleep(1000000 * exposure().exposuretime());
	ImagePtr	image = guider().getImage();

	// analze the image
	Point	star = (*tracker())(image);
	debug(LOG_DEBUG, DEBUG_LOG, 0, "tracker found star at %s",
		star.toString().c_str());
	return star;
}