From d48c8ce8a5d0d15a51f396aa4807fa4822d7155d Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 14 Aug 2015 21:21:25 +0200 Subject: [PATCH] config: convert 'pi_proportional_exponent' to the new scheme. Signed-off-by: Richard Cochran --- config.c | 7 +------ config.h | 1 - pi.c | 8 +++++--- pi.h | 7 ------- ptp4l.c | 1 - 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/config.c b/config.c index 07cb016..43f96fe 100644 --- a/config.c +++ b/config.c @@ -98,6 +98,7 @@ struct config_item config_tab[] = { 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_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_scale", 0.0, 0.0, DBL_MAX), GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX), GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX), @@ -544,12 +545,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_proportional_exponent")) { - r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX); - if (r != PARSED_OK) - return r; - *cfg->pi_proportional_exponent = df; - } else if (!strcmp(option, "pi_proportional_norm_max")) { r = get_ranged_double(value, &df, DBL_MIN, 1.0); if (r != PARSED_OK) diff --git a/config.h b/config.h index 4b8a4a2..afd7142 100644 --- a/config.h +++ b/config.h @@ -69,7 +69,6 @@ struct config { struct port_defaults pod; enum servo_type clock_servo; - double *pi_proportional_exponent; double *pi_proportional_norm_max; double *pi_integral_scale; double *pi_integral_exponent; diff --git a/pi.c b/pi.c index 8fe847a..b340963 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_kp_exponent = -0.3; double configured_pi_kp_norm_max = 0.7; double configured_pi_ki_scale = 0.0; double configured_pi_ki_exponent = 0.4; @@ -55,6 +54,7 @@ struct pi_servo { double configured_pi_kp; double configured_pi_ki; double configured_pi_kp_scale; + double configured_pi_kp_exponent; }; static void pi_destroy(struct servo *servo) @@ -160,7 +160,7 @@ static void pi_sync_interval(struct servo *servo, double interval) { struct pi_servo *s = container_of(servo, struct pi_servo, servo); - s->kp = s->configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent); + s->kp = s->configured_pi_kp_scale * pow(interval, s->configured_pi_kp_exponent); if (s->kp > configured_pi_kp_norm_max / interval) s->kp = configured_pi_kp_norm_max / interval; @@ -198,6 +198,8 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts) s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const"); s->configured_pi_ki = config_get_double(cfg, NULL, "pi_integral_const"); s->configured_pi_kp_scale = config_get_double(cfg, NULL, "pi_proportional_scale"); + s->configured_pi_kp_exponent = + config_get_double(cfg, NULL, "pi_proportional_exponent"); if (s->configured_pi_kp && s->configured_pi_ki) { /* Use the constants as configured by the user without @@ -205,7 +207,7 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts) unstable. */ s->configured_pi_kp_scale = s->configured_pi_kp; configured_pi_ki_scale = s->configured_pi_ki; - configured_pi_kp_exponent = 0.0; + s->configured_pi_kp_exponent = 0.0; configured_pi_ki_exponent = 0.0; configured_pi_kp_norm_max = MAX_KP_NORM_MAX; configured_pi_ki_norm_max = MAX_KI_NORM_MAX; diff --git a/pi.h b/pi.h index d3e541e..27a64b1 100644 --- a/pi.h +++ b/pi.h @@ -21,13 +21,6 @@ #include "servo.h" -/** - * This variable determines the exponent in the formula used to set the - * proportional constant of the PI controller from the sync interval. - * kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync) - */ -extern double configured_pi_kp_exponent; - /** * This variable determines the normalized maximum in the formula used to set * the proportional constant of the PI controller from the sync interval. diff --git a/ptp4l.c b/ptp4l.c index b96bee3..43dd977 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_proportional_exponent = &configured_pi_kp_exponent, .pi_proportional_norm_max = &configured_pi_kp_norm_max, .pi_integral_scale = &configured_pi_ki_scale, .pi_integral_exponent = &configured_pi_ki_exponent,