From 75333362346e3c24c01b2db0c0e5eaf85bc4ff78 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 14 Aug 2015 21:31:16 +0200 Subject: [PATCH] config: convert 'pi_integral_scale' to the new scheme. Signed-off-by: Richard Cochran --- config.c | 7 +------ config.h | 1 - pi.c | 14 ++++++++------ pi.h | 8 -------- ptp4l.c | 1 - 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/config.c b/config.c index 5775272..fc7dd23 100644 --- a/config.c +++ b/config.c @@ -97,6 +97,7 @@ struct config_item config_tab[] = { GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX), GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX), GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX), + GLOB_ITEM_DBL("pi_integral_scale", 0.0, 0.0, DBL_MAX), GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX), GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX), GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0), @@ -546,12 +547,6 @@ static enum parser_result parse_global_setting(const char *option, cfg->dds.freq_est_interval = val; pod->freq_est_interval = val; - } else if (!strcmp(option, "pi_integral_scale")) { - r = get_ranged_double(value, &df, 0.0, DBL_MAX); - if (r != PARSED_OK) - return r; - *cfg->pi_integral_scale = df; - } else if (!strcmp(option, "pi_integral_exponent")) { r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX); if (r != PARSED_OK) diff --git a/config.h b/config.h index 37e540d..d6f2b8f 100644 --- a/config.h +++ b/config.h @@ -69,7 +69,6 @@ struct config { struct port_defaults pod; enum servo_type clock_servo; - double *pi_integral_scale; double *pi_integral_exponent; double *pi_integral_norm_max; int *ntpshm_segment; diff --git a/pi.c b/pi.c index ef3c619..dba141c 100644 --- a/pi.c +++ b/pi.c @@ -36,7 +36,6 @@ #define FREQ_EST_MARGIN 0.001 /* These take their values from the configuration file. (see ptp4l.c) */ -double configured_pi_ki_scale = 0.0; double configured_pi_ki_exponent = 0.4; double configured_pi_ki_norm_max = 0.3; @@ -55,6 +54,7 @@ struct pi_servo { double configured_pi_kp_scale; double configured_pi_kp_exponent; double configured_pi_kp_norm_max; + double configured_pi_ki_scale; }; static void pi_destroy(struct servo *servo) @@ -164,7 +164,7 @@ static void pi_sync_interval(struct servo *servo, double interval) if (s->kp > s->configured_pi_kp_norm_max / interval) s->kp = s->configured_pi_kp_norm_max / interval; - s->ki = configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent); + s->ki = s->configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent); if (s->ki > configured_pi_ki_norm_max / interval) s->ki = configured_pi_ki_norm_max / interval; @@ -202,24 +202,26 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts) config_get_double(cfg, NULL, "pi_proportional_exponent"); s->configured_pi_kp_norm_max = config_get_double(cfg, NULL, "pi_proportional_norm_max"); + s->configured_pi_ki_scale = + config_get_double(cfg, NULL, "pi_integral_scale"); if (s->configured_pi_kp && s->configured_pi_ki) { /* Use the constants as configured by the user without adjusting for sync interval unless they make the servo unstable. */ s->configured_pi_kp_scale = s->configured_pi_kp; - configured_pi_ki_scale = s->configured_pi_ki; + s->configured_pi_ki_scale = s->configured_pi_ki; s->configured_pi_kp_exponent = 0.0; configured_pi_ki_exponent = 0.0; s->configured_pi_kp_norm_max = MAX_KP_NORM_MAX; configured_pi_ki_norm_max = MAX_KI_NORM_MAX; - } else if (!s->configured_pi_kp_scale || !configured_pi_ki_scale) { + } else if (!s->configured_pi_kp_scale || !s->configured_pi_ki_scale) { if (sw_ts) { s->configured_pi_kp_scale = SWTS_KP_SCALE; - configured_pi_ki_scale = SWTS_KI_SCALE; + s->configured_pi_ki_scale = SWTS_KI_SCALE; } else { s->configured_pi_kp_scale = HWTS_KP_SCALE; - configured_pi_ki_scale = HWTS_KI_SCALE; + s->configured_pi_ki_scale = HWTS_KI_SCALE; } } diff --git a/pi.h b/pi.h index 514186c..915034c 100644 --- a/pi.h +++ b/pi.h @@ -21,14 +21,6 @@ #include "servo.h" -/** - * When set to a non-zero value, this variable determines the scale in the - * formula used to set the integral constant of the PI controller from the - * sync interval. - * ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync) - */ -extern double configured_pi_ki_scale; - /** * This variable determines the exponent in the formula used to set the * integral constant of the PI controller from the sync interval. diff --git a/ptp4l.c b/ptp4l.c index b60e531..d67a34d 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -103,7 +103,6 @@ static struct config cfg_settings = { .transport = TRANS_UDP_IPV4, .clock_servo = CLOCK_SERVO_PI, - .pi_integral_scale = &configured_pi_ki_scale, .pi_integral_exponent = &configured_pi_ki_exponent, .pi_integral_norm_max = &configured_pi_ki_norm_max, .ntpshm_segment = &ntpshm_segment,