Module: xenomai-3 Branch: master Commit: e3c818fee687fcf07c448c462cbba5ce29100e0b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e3c818fee687fcf07c448c462cbba5ce29100e0b
Author: Jorge Ramirez-Ortiz <j...@xenomai.org> Date: Tue Oct 14 21:53:25 2014 -0400 utils/analogy: calibration - generating the calibration file is not a user API --- include/rtdm/analogy.h | 4 -- lib/analogy/calibration.c | 103 +++++++++++++++++++++---------------- lib/analogy/calibration.h | 3 ++ lib/analogy/math.c | 51 +++++++++++++++++- utils/analogy/analogy_calibrate.c | 6 +++ utils/analogy/calibration_ni_m.c | 15 +++--- 6 files changed, 125 insertions(+), 57 deletions(-) diff --git a/include/rtdm/analogy.h b/include/rtdm/analogy.h index c03d2b1..a87ce54 100644 --- a/include/rtdm/analogy.h +++ b/include/rtdm/analogy.h @@ -230,10 +230,6 @@ int a4l_ftoraw(a4l_chinfo_t *chan, int a4l_dtoraw(a4l_chinfo_t *chan, a4l_rnginfo_t *rng, void *dst, double *src, int cnt); -void a4l_write_calibration_file(FILE *dst, struct list *l, - struct a4l_calibration_subdev *subd, - a4l_desc_t *desc); - int a4l_read_calibration_file(char *name, struct a4l_calibration_data *data); int a4l_math_polyfit(unsigned order, double *r,double orig, diff --git a/lib/analogy/calibration.c b/lib/analogy/calibration.c index 85860d1..dcec16d 100644 --- a/lib/analogy/calibration.c +++ b/lib/analogy/calibration.c @@ -103,6 +103,64 @@ static inline void write_calibration(FILE *file, char *fmt, ...) va_end(ap); } +void +write_calibration_file(FILE *dst, struct list *l, + struct a4l_calibration_subdev *subd, a4l_desc_t *desc) +{ + struct subdevice_calibration_node *e, *t; + int i, j = 0; + + if (list_empty(l)) + return; + + /* TODO: modify the meaning of board/driver in the proc */ + if (desc) { + write_calibration(dst, "[%s] \n",PLATFORM_STR); + write_calibration(dst, DRIVER_STR" = %s;\n", desc->board_name); + write_calibration(dst, BOARD_STR" = %s;\n", desc->driver_name); + } + + write_calibration(dst, "\n[%s] \n", subd->name); + write_calibration(dst, INDEX_STR" = %d;\n", subd->idx); + list_for_each_entry_safe(e, t, l, node) { + j++; + } + write_calibration(dst, ELEMENTS_STR" = %d;\n", j); + + j = 0; + list_for_each_entry_safe(e, t, l, node) { + write_calibration(dst, "[%s_%d] \n", subd->name, j); + write_calibration(dst, CHANNEL_STR" = %d;\n", e->channel); + write_calibration(dst, RANGE_STR" = %d;\n", e->range); + write_calibration(dst, EXPANSION_STR" = %g;\n", + e->polynomial->expansion_origin); + write_calibration(dst, NBCOEFF_STR"= %d;\n", + e->polynomial->nb_coefficients); + + for (i = 0; i < e->polynomial->nb_coefficients; i++) + write_calibration(dst, COEFF_STR"_%d = %g;\n", + i, + e->polynomial->coefficients[i]); + j++; + } + + return; +} + +/*! + * @ingroup analogy_lib_level2 + * @defgroup analogy_lib_calibration Software calibration API + * @{ + */ + +/** + * @brief Read the analogy generated calibration file + * + * @param[in] name Name of the calibration file + * @param[out] data Pointer to the calibration file contents + * + */ + int a4l_read_calibration_file(char *name, struct a4l_calibration_data *data) { const char *subdevice[2] = { AI_SUBD_STR, AO_SUBD_STR }; @@ -186,48 +244,5 @@ int a4l_read_calibration_file(char *name, struct a4l_calibration_data *data) return 0; } -void a4l_write_calibration_file(FILE *dst, struct list *l, - struct a4l_calibration_subdev *subd, - a4l_desc_t *desc) -{ - struct subdevice_calibration_node *e, *t; - int i, j = 0; - - if (list_empty(l)) - return; - - /* TODO: modify the meaning of board/driver in the proc */ - if (desc) { - write_calibration(dst, "[%s] \n",PLATFORM_STR); - write_calibration(dst, DRIVER_STR" = %s;\n", desc->board_name); - write_calibration(dst, BOARD_STR" = %s;\n", desc->driver_name); - } - - write_calibration(dst, "\n[%s] \n", subd->name); - write_calibration(dst, INDEX_STR" = %d;\n", subd->idx); - list_for_each_entry_safe(e, t, l, node) { - j++; - } - write_calibration(dst, ELEMENTS_STR" = %d;\n", j); - - j = 0; - list_for_each_entry_safe(e, t, l, node) { - write_calibration(dst, "[%s_%d] \n", subd->name, j); - write_calibration(dst, CHANNEL_STR" = %d;\n", e->channel); - write_calibration(dst, RANGE_STR" = %d;\n", e->range); - write_calibration(dst, EXPANSION_STR" = %g;\n", - e->polynomial->expansion_origin); - write_calibration(dst, NBCOEFF_STR"= %d;\n", - e->polynomial->nb_coefficients); - - for (i = 0; i < e->polynomial->nb_coefficients; i++) - write_calibration(dst, COEFF_STR"_%d = %g;\n", - i, - e->polynomial->coefficients[i]); - j++; - } - - return; -} - +/** @} Calibration API */ diff --git a/lib/analogy/calibration.h b/lib/analogy/calibration.h index 4080c60..50e898c 100644 --- a/lib/analogy/calibration.h +++ b/lib/analogy/calibration.h @@ -61,5 +61,8 @@ struct subdevice_calibration_node { unsigned range; }; +void write_calibration_file(FILE *dst, struct list *l, + struct a4l_calibration_subdev *subd, + a4l_desc_t *desc); #endif diff --git a/lib/analogy/math.c b/lib/analogy/math.c index e85464d..a6d3c31 100644 --- a/lib/analogy/math.c +++ b/lib/analogy/math.c @@ -325,7 +325,27 @@ static int mat_qr(struct mat *r, struct vec *y) return rc; } -/* + +/*! + * @ingroup analogy_lib_level2 + * @defgroup analogy_lib_math Math API + * @{ + */ + + +/** + * @brief Calculate the polynomial fit + * + * @param[in] order Order of the resulting polynomial + * @param[out] r Polynomial + * @param[in] orig + * @param[in] dim Number of elements in the polynomials + * @param[in] x Polynomial + * @param[in] y Polynomial + * + * + * Operation: + * * We are looking for Res such that A.Res = Y, with A the Vandermonde * matrix made from the X vector. * @@ -340,6 +360,7 @@ static int mat_qr(struct mat *r, struct vec *y) * * We can then obtain Res by back substitution using * mat_upper_triangular_backsub() with R upper triangular. + * */ int a4l_math_polyfit(unsigned order, double *r, double orig, const unsigned dim, double *x, double *y) @@ -375,6 +396,14 @@ int a4l_math_polyfit(unsigned order, double *r, double orig, const unsigned dim, return rc; } +/** + * @brief Calculate the aritmetic mean of an array of values + * + * @param[out] pmean Pointer to the resulting value + * @param[in] val Array of input values + * @param[in] nr Number of array elements + * + */ void a4l_math_mean(double *pmean, double *val, unsigned nr) { double sum; @@ -386,6 +415,15 @@ void a4l_math_mean(double *pmean, double *val, unsigned nr) *pmean = sum / nr; } +/** + * @brief Calculate the standard deviation of an array of values + * + * @param[out] pstddevm Pointer to the resulting value + * @param[in] mean Mean value + * @param[in] val Array of input values + * @param[in] nr Number of array elements + * + */ void a4l_math_stddev(double *pstddev, double mean, double *val, unsigned nr) { double sum, sum_sq; @@ -400,6 +438,15 @@ void a4l_math_stddev(double *pstddev, double mean, double *val, unsigned nr) *pstddev = sqrt((sum_sq - (sum * sum) / nr) / (nr - 1)); } +/** + * @brief Calculate the standard deviation of the mean + * + * @param[out] pstddevm Pointer to the resulting value + * @param[in] mean Mean value + * @param[in] val Array of input values + * @param[in] nr Number of array elements + * + */ void a4l_math_stddev_of_mean(double *pstddevm, double mean, double *val, unsigned nr) { double sum, sum_sq; @@ -415,4 +462,4 @@ void a4l_math_stddev_of_mean(double *pstddevm, double mean, double *val, unsigne } - +/** @} Math API */ diff --git a/utils/analogy/analogy_calibrate.c b/utils/analogy/analogy_calibrate.c index f9add4d..1b87e39 100644 --- a/utils/analogy/analogy_calibrate.c +++ b/utils/analogy/analogy_calibrate.c @@ -74,6 +74,12 @@ static void __attribute__ ((constructor)) __analogy_calibrate_init(void) clock_gettime(CLOCK_MONOTONIC, &calibration_start_time); } +/* + * + * the calibration file generated by the Analogy software calibrate utility is + * not compatible with Comedi's despite holding the exact same information. + * + */ int main(int argc, char *argv[]) { char *device = NULL, *file = NULL; diff --git a/utils/analogy/calibration_ni_m.c b/utils/analogy/calibration_ni_m.c index dc2f667..55f5a3b 100644 --- a/utils/analogy/calibration_ni_m.c +++ b/utils/analogy/calibration_ni_m.c @@ -121,7 +121,8 @@ static int eeprom_read_reference_voltage(float *val) /* * subdevice operations */ -static int data_read_hint(struct a4l_calibration_subdev *s, int channel, int range, int aref) +static int data_read_hint(struct a4l_calibration_subdev *s, int channel, + int range, int aref) { sampl_t dummy_data; a4l_insn_t insn; @@ -141,8 +142,8 @@ static int data_read_hint(struct a4l_calibration_subdev *s, int channel, int ran return 0; } -static int data_read(unsigned *data, struct a4l_calibration_subdev *s, int channel, - int range, int aref) +static int data_read(unsigned *data, struct a4l_calibration_subdev *s, + int channel, int range, int aref) { a4l_insn_t insn; int err; @@ -161,8 +162,8 @@ static int data_read(unsigned *data, struct a4l_calibration_subdev *s, int chann return 0; } -static int data_write(long int *data, struct a4l_calibration_subdev *s, int channel, - int range, int aref) +static int data_write(long int *data, struct a4l_calibration_subdev *s, + int channel, int range, int aref) { a4l_insn_t insn; int err; @@ -1256,7 +1257,7 @@ int ni_m_software_calibrate(FILE *p) if (err) error(EXIT, 0, "ai calibration error (%d)", err); - a4l_write_calibration_file(p, &ai_calibration_list, &ai_subd, &descriptor); + write_calibration_file(p, &ai_calibration_list, &ai_subd, &descriptor); /* only calibrate the analog output subdevice if present */ if (ao_subd.idx < 0) { @@ -1268,7 +1269,7 @@ int ni_m_software_calibrate(FILE *p) if (err) error(EXIT, 0, "ao calibration error (%d)", err); - a4l_write_calibration_file(p, &ao_calibration_list, &ao_subd, NULL); + write_calibration_file(p, &ao_calibration_list, &ao_subd, NULL); return 0; } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git