Commit 69c0c160 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Add definitions for wavefront sensors

parent 834a6e42
......@@ -76,7 +76,8 @@ include_HEADERS = \
tao-test-preprocessing.h \
tao-threadpools.h \
tao-threads.h \
tao-utils.h
tao-utils.h \
tao-wavefront-sensors.h
libtao_la_SOURCES = \
arrays.c \
......@@ -101,7 +102,9 @@ libtao_la_SOURCES = \
shared-objects.c \
threadpools.c \
threads.c \
utils.c
utils.c \
wavefront-sensors.c
libtao_la_LIBADD = $(OTHER_LIBS)
libtao_la_LDFLAGS = -version-info @version_info@
......
......@@ -434,28 +434,35 @@ const char* FUNC(
CASE(TAO_BAD_SIZE, "Invalid size");
CASE(TAO_BAD_SERIAL, "Invalid serial number");
CASE(TAO_BAD_ROI, "Invalid region of interest");
CASE(TAO_BAD_RESTORING_FORCE, "Invalid restoring force");
CASE(TAO_BAD_REFERENCE, "Invalid reference");
CASE(TAO_BAD_RANK, "Invalid number of dimensions");
CASE(TAO_BAD_PREPROCESSING, "Bad pre-processing settings");
CASE(TAO_BAD_PIXELTYPE, "Bad pixel type");
CASE(TAO_BAD_NAME, "Bad parameter name");
CASE(TAO_BAD_PREPROCESSING, "Invalid pre-processing settings");
CASE(TAO_BAD_PIXELTYPE, "Invalid pixel type");
CASE(TAO_BAD_NUMBER, "Invalid number of values");
CASE(TAO_BAD_NAME, "Invalid parameter name");
CASE(TAO_BAD_MAX_EXCURSION, "Invalid maximum excursion");
CASE(TAO_BAD_MAGIC, "Invalid magic number");
CASE(TAO_BAD_GAIN, "Invalid detector gain");
CASE(TAO_BAD_FRAMERATE, "Invalid acquisition frame rate");
CASE(TAO_BAD_FORGETTING_FACTOR, "Invalid forgetting factor");
CASE(TAO_BAD_FILENAME, "Invalid file name");
CASE(TAO_BAD_FANSPEED, "Invalid fan speed");
CASE(TAO_BAD_EXPOSURETIME, "Invalid exposure time");
CASE(TAO_BAD_ESCAPE, "Unknown escape sequence");
CASE(TAO_BAD_ENCODING, "Bad encoding");
CASE(TAO_BAD_ENCODING, "Invalid encoding");
CASE(TAO_BAD_DEVICE, "Invalid device");
CASE(TAO_BAD_DEPTH, "Invalid bits per pixel");
CASE(TAO_BAD_CONNECTION, "Invalid connection");
CASE(TAO_BAD_COMMAND, "Invalid command");
CASE(TAO_BAD_CHARACTER, "Illegal character");
CASE(TAO_BAD_CHANNELS, "Invalid number of channels");
CASE(TAO_BAD_BUFFERS, "Bad number of buffers");
CASE(TAO_BAD_BUFFERS, "Invalid number of buffers");
CASE(TAO_BAD_BOUNDING_BOX, "Invalid bounding box");
CASE(TAO_BAD_BIAS, "Invalid detector bias");
CASE(TAO_BAD_ATTACHMENTS, "Invalid number of attachments");
CASE(TAO_BAD_ARGUMENT, "Invalid argument");
CASE(TAO_BAD_ALGORITHM, "Invalid algorithm");
CASE(TAO_BAD_ADDRESS, "Invalid address");
CASE(TAO_ASSERTION_FAILED, "Assertion failed");
CASE(TAO_ALREADY_IN_USE, "Resource already in use");
......
......@@ -73,64 +73,71 @@ TAO_BEGIN_DECLS
* returned by many functions of the TAO Library.
*/
typedef enum tao_error_code_ {
TAO_SUCCESS = 0, ///< Operation was successful
TAO_ACQUISITION_RUNNING = -1, ///< Acquisition running
TAO_ALREADY_EXIST = -2, ///< Destination already exists
TAO_ALREADY_IN_USE = -3, ///< Resource already in use
TAO_ASSERTION_FAILED = -4, ///< Assertion failed
TAO_BAD_ADDRESS = -5, ///< Invalid address
TAO_BAD_ARGUMENT = -6, ///< Invalid argument
TAO_BAD_ATTACHMENTS = -7, ///< Invalid number of attachments
TAO_BAD_BIAS = -8, ///< Invalid detector bias
TAO_BAD_BUFFERS = -9, ///< Bad number of buffers
TAO_BAD_CHANNELS = -10, ///< Invalid number of channels
TAO_BAD_CHARACTER = -11, ///< Illegal character
TAO_BAD_COMMAND = -12, ///< Invalid command
TAO_BAD_CONNECTION = -13, ///< Invalid connection
TAO_BAD_DEPTH = -14, ///< Invalid bits per pixel
TAO_BAD_DEVICE = -15, ///< Invalid device
TAO_BAD_ENCODING = -16, ///< Bad encoding
TAO_BAD_ESCAPE = -17, ///< Unknown escape sequence
TAO_BAD_EXPOSURETIME = -18, ///< Invalid exposure time
TAO_BAD_FANSPEED = -19, ///< Invalid fan speed
TAO_BAD_FILENAME = -20, ///< Invalid file name
TAO_BAD_FRAMERATE = -21, ///< Invalid acquisition frame rate
TAO_BAD_GAIN = -22, ///< Invalid detector gain
TAO_BAD_MAGIC = -23, ///< Invalid magic number
TAO_BAD_NAME = -24, ///< Bad parameter name
TAO_BAD_PIXELTYPE = -25, ///>Bad pixel type
TAO_BAD_PREPROCESSING = -26, ///< Bad pre-processing settings
TAO_BAD_RANK = -27, ///< Invalid number of dimensions
TAO_BAD_ROI = -28, ///< Invalid region of interest
TAO_BAD_SERIAL = -29, ///< Invalid serial number
TAO_BAD_SIZE = -30, ///< Invalid size
TAO_BAD_SPEED = -31, ///< Invalid connection speed
TAO_BAD_STAGE = -32, ///< Invalid or unexpected stage
TAO_BAD_TYPE = -33, ///< Invalid type
TAO_BAD_VALUE = -34, ///< Invalid parameter value
TAO_BROKEN_CYCLE = -35, ///< Broken cycle or unordered operations
TAO_CANT_TRACK_ERROR = -36, ///< Insufficient memory to track errors
TAO_CORRUPTED = -37, ///< Corrupted structure
TAO_DESTROYED = -38, ///< Resource has been destroyed
TAO_EXHAUSTED = -39, ///< Resource exhausted
TAO_MISSING_SEPARATOR = -40, ///< Separator missing
TAO_MUST_RESET = -41, ///< Device must be reset
TAO_NOT_ACQUIRING = -42, ///< Acquisition not started
TAO_NOT_FOUND = -43, ///< Item not found
TAO_NOT_LOCKED = -44, ///< Resource not locked by caller
TAO_NOT_READY = -45, ///< Device not ready
TAO_NOT_RUNNING = -46, ///< Server or thread is not running
TAO_NOT_YET_IMPLEMENTED = -47, ///< Not yet implemented
TAO_NO_DATA = -48, ///< No data available
TAO_NO_FITS_SUPPORT = -49, ///< Compiled with no FITS support
TAO_OUT_OF_RANGE = -50, ///< Out of range argument
TAO_OVERWRITTEN = -51, ///< Contents has been overwritten
TAO_SYSTEM_ERROR = -52, ///< Unknown system error
TAO_UNCLOSED_STRING = -53, ///< Unclosed string
TAO_UNREADABLE = -54, ///< Not readable
TAO_UNRECOVERABLE = -55, ///< Unrecoverable error
TAO_UNSUPPORTED = -56, ///< Unsupported feature
TAO_UNWRITABLE = -57, ///< Not writable
TAO_SUCCESS = 0,///< Operation was successful
TAO_ACQUISITION_RUNNING = -1,///< Acquisition running
TAO_ALREADY_EXIST = -2,///< Destination already exists
TAO_ALREADY_IN_USE = -3,///< Resource already in use
TAO_ASSERTION_FAILED = -4,///< Assertion failed
TAO_BAD_ADDRESS = -5,///< Invalid address
TAO_BAD_ALGORITHM = -6,///< Invalid algorithm
TAO_BAD_ARGUMENT = -7,///< Invalid argument
TAO_BAD_ATTACHMENTS = -8,///< Invalid number of attachments
TAO_BAD_BIAS = -9,///< Invalid detector bias
TAO_BAD_BOUNDING_BOX = -10,///< Invalid bounding box
TAO_BAD_BUFFERS = -11,///< Bad number of buffers
TAO_BAD_CHANNELS = -12,///< Invalid number of channels
TAO_BAD_CHARACTER = -13,///< Illegal character
TAO_BAD_COMMAND = -14,///< Invalid command
TAO_BAD_CONNECTION = -15,///< Invalid connection
TAO_BAD_DEPTH = -16,///< Invalid bits per pixel
TAO_BAD_DEVICE = -17,///< Invalid device
TAO_BAD_ENCODING = -18,///< Bad encoding
TAO_BAD_ESCAPE = -19,///< Unknown escape sequence
TAO_BAD_EXPOSURETIME = -20,///< Invalid exposure time
TAO_BAD_FANSPEED = -21,///< Invalid fan speed
TAO_BAD_FILENAME = -22,///< Invalid file name
TAO_BAD_FORGETTING_FACTOR = -23,///< Invalid forgetting factor
TAO_BAD_FRAMERATE = -24,///< Invalid acquisition frame rate
TAO_BAD_GAIN = -25,///< Invalid detector gain
TAO_BAD_MAGIC = -26,///< Invalid magic number
TAO_BAD_MAX_EXCURSION = -27,///< Invalid maximum excursion
TAO_BAD_NAME = -28,///< Bad parameter name
TAO_BAD_NUMBER = -29,///< Invalid number of values
TAO_BAD_PIXELTYPE = -30,///< Bad pixel type
TAO_BAD_PREPROCESSING = -31,///< Bad pre-processing settings
TAO_BAD_RANK = -32,///< Invalid number of dimensions
TAO_BAD_REFERENCE = -33,///< Invalid reference
TAO_BAD_RESTORING_FORCE = -34,///< Invalid restoring force
TAO_BAD_ROI = -35,///< Invalid region of interest
TAO_BAD_SERIAL = -36,///< Invalid serial number
TAO_BAD_SIZE = -37,///< Invalid size
TAO_BAD_SPEED = -38,///< Invalid connection speed
TAO_BAD_STAGE = -39,///< Invalid or unexpected stage
TAO_BAD_TYPE = -40,///< Invalid type
TAO_BAD_VALUE = -41,///< Invalid parameter value
TAO_BROKEN_CYCLE = -42,///< Broken cycle or unordered operations
TAO_CANT_TRACK_ERROR = -43,///< Insufficient memory to track errors
TAO_CORRUPTED = -44,///< Corrupted structure
TAO_DESTROYED = -45,///< Resource has been destroyed
TAO_EXHAUSTED = -46,///< Resource exhausted
TAO_MISSING_SEPARATOR = -47,///< Separator missing
TAO_MUST_RESET = -48,///< Device must be reset
TAO_NOT_ACQUIRING = -49,///< Acquisition not started
TAO_NOT_FOUND = -50,///< Item not found
TAO_NOT_LOCKED = -51,///< Resource not locked by caller
TAO_NOT_READY = -52,///< Device not ready
TAO_NOT_RUNNING = -53,///< Server or thread is not running
TAO_NOT_YET_IMPLEMENTED = -54,///< Not yet implemented
TAO_NO_DATA = -55,///< No data available
TAO_NO_FITS_SUPPORT = -56,///< Compiled with no FITS support
TAO_OUT_OF_RANGE = -57,///< Out of range argument
TAO_OVERWRITTEN = -58,///< Contents has been overwritten
TAO_SYSTEM_ERROR = -59,///< Unknown system error
TAO_UNCLOSED_STRING = -60,///< Unclosed string
TAO_UNREADABLE = -61,///< Not readable
TAO_UNRECOVERABLE = -62,///< Unrecoverable error
TAO_UNSUPPORTED = -63,///< Unsupported feature
TAO_UNWRITABLE = -64,///< Not writable
} tao_error_code;
/**
......
// tao-wavefront-sensors.h -
//
// Definitions for wavefront sensors in TAO.
//
//-----------------------------------------------------------------------------
//
// This file if part of TAO real-time software licensed under the MIT license
// (https://git-cral.univ-lyon1.fr/tao/tao-rt).
//
// Copyright (C) 2022, Éric Thiébaut.
#ifndef TAO_WAVEFRONT_SENSORS_H_
#define TAO_WAVEFRONT_SENSORS_H_ 1
#include <tao-basics.h>
TAO_BEGIN_DECLS
/**
* @defgroup WavefrontSensors Wavefront sensors
*
* @brief Definitions for wavefront sensors.
*
* @{
*/
/**
* Wavefront sensing algorithms.
*/
typedef enum tao_algorithm_ {
TAO_CENTER_OF_GRAVITY = 0,
TAO_LINEARIZED_MATCHED_FILTER = 1,
} tao_algorithm;
/**
* Bounding box.
*/
typedef struct tao_bounding_box_ {
int16_t xmin;///< Minimum abscissa (inclusive).
int16_t xmax;///< Maximum abscissa (inclusive).
int16_t ymin;///< Minimum ordinate (inclusive).
int16_t ymax;///< Maximum ordinate (inclusive).
} tao_bounding_box;
/**
* 2-dimensional position.
*/
typedef struct tao_position_ {
double x;///< Abscissa.
double y;///< Ordinate.
} tao_position;
/**
* Measured 2-dimensional position.
*/
typedef struct tao_measured_position_ {
// The two first member must be the same as for a `tao_position` to allow
// for a cast.
double x;///< Measured abscissa.
double y;///< Measured ordinate.
double wxx;///< Precision of `x`.
double wxy;///< Joint precision of `x` and `y`;
double wyy;///< Precision of `y`.
} tao_measured_position;
/**
* Definition of a wavefront sensor sub-pupil.
*/
typedef struct tao_wavefront_sensor_subpupil_ {
tao_bounding_box box;///< Bounding box of the sub-pupil.
tao_position ref;///< Reference position in the sub-pupil.
} tao_wavefront_sensor_subpupil;
/**
* Wavefront sensor elementary data.
*
* This structure represents an elementary data in the output data-frames
* delivered by a wavefront sensor.
*/
typedef struct tao_wavefront_sensor_data_ {
// The first members must be identical to those of the structure
// `tao_wavefront_sensor_subpupil`.
tao_bounding_box box;///< Bounding box of the sub-pupil.
tao_position ref;///< Reference position in the sub-pupil.
// Memebers not in `tao_wavefront_sensor_subpupil` structure.
tao_measured_position dat;///< Measured position in the sub-pupil (relative
/// to the reference).
double alpha;///< Intensity factor.
double epsilon;///< Quality factor.
} tao_wavefront_sensor_data;
/**
* Wavefront sensor configuration.
*
* This structure represents the fixed size part of a wavefront sensor
* configuration. The variable size parts (the layout of the sub-pupils grid
* and the list of sub-pupils definitions) are provided separately.
*/
typedef struct tao_wavefront_sensor_config_ {
double forgetting_factor;
double restoring_force;
double max_excursion;
tao_algorithm algo;
long nsubs;///< Number of sub-pupils.
long dims[2];///< Dimensions of sub-pupil grid.
} tao_wavefront_sensor_config;
/**
* Check wavefront sensor configuration.
*
* @param cfg The fixed size part of the wavefront sensor configuration.
*
* @param inds The layout of the sub-pupils.
*
* @param subs The parameters of the sub-pupils.
*
* @param width The width of the image.
*
* @param height The height of the image.
*
* @return @ref TAO_OK on success; @ref TAO_ERROR in case of failure.
*/
extern tao_status tao_wavefront_sensor_check_config(
const tao_wavefront_sensor_config* cfg,
const long* inds,
const tao_wavefront_sensor_subpupil* subs,
long width,
long height);
/**
* @}
*/
TAO_END_DECLS
#endif // TAO_WAVEFRONT_SENSORS_H_
// wavefront-sensors.c -
//
// Management of wavefront sensors.
//
//-----------------------------------------------------------------------------
//
// This file if part of TAO real-time software licensed under the MIT license
// (https://git-cral.univ-lyon1.fr/tao/tao-rt).
//
// Copyright (C) 2022, Éric Thiébaut.
#include <math.h>
#include "tao-errors.h"
#include "tao-layouts.h"
#include "tao-wavefront-sensors.h"
tao_status tao_wavefront_sensor_check_config(
const tao_wavefront_sensor_config* cfg,
const long* inds,
const tao_wavefront_sensor_subpupil* subs,
long width,
long height)
{
if (cfg == NULL || inds == NULL || subs == NULL) {
tao_store_error(__func__, TAO_BAD_ADDRESS);
return TAO_ERROR;
}
long dim1 = cfg->dims[0];
long dim2 = cfg->dims[1];
long nsubs = cfg->nsubs;
if (width < 1 || height < 1 || dim1 < 1 || dim2 < 1 || nsubs < 1) {
tao_store_error(__func__, TAO_BAD_SIZE);
return TAO_ERROR;
}
long count = tao_indexed_layout_check(inds, dim1, dim2);
if (count < 0) {
return TAO_ERROR;
}
if (nsubs != count) {
tao_store_error(__func__, TAO_BAD_NUMBER);
return TAO_ERROR;
}
for (long i = 0; i < nsubs; ++i) {
const tao_bounding_box* box = &subs[i].box;
if (box->xmin < 0 || box->xmin > box->xmax || box->xmax >= width ||
box->ymin < 0 || box->ymin > box->ymax || box->ymax >= height) {
tao_store_error(__func__, TAO_BAD_BOUNDING_BOX);
return TAO_ERROR;
}
const tao_position* ref = &subs[i].ref;
if (!isfinite(ref->x) || !isfinite(ref->y)) {
tao_store_error(__func__, TAO_BAD_REFERENCE);
return TAO_ERROR;
}
}
if (!isfinite(cfg->forgetting_factor) || cfg->forgetting_factor < 0) {
tao_store_error(__func__, TAO_BAD_FORGETTING_FACTOR);
return TAO_ERROR;
}
if (!isfinite(cfg->restoring_force) || cfg->restoring_force < 0) {
tao_store_error(__func__, TAO_BAD_RESTORING_FORCE);
return TAO_ERROR;
}
if (!isnan(cfg->max_excursion) || cfg->max_excursion < 0) {
tao_store_error(__func__, TAO_BAD_MAX_EXCURSION);
return TAO_ERROR;
}
if (cfg->algo != TAO_CENTER_OF_GRAVITY &&
cfg->algo != TAO_LINEARIZED_MATCHED_FILTER) {
tao_store_error(__func__, TAO_BAD_ALGORITHM);
return TAO_ERROR;
}
return TAO_OK;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment