diff --git a/config.c b/config.c index 3bd98da..2437ec0 100644 --- a/config.c +++ b/config.c @@ -96,6 +96,7 @@ struct config_item config_tab[] = { GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX), 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_proportional_const", 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), @@ -542,12 +543,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_const")) { - r = get_ranged_double(value, &df, 0.0, DBL_MAX); - if (r != PARSED_OK) - return r; - *cfg->pi_integral_const = df; - } else if (!strcmp(option, "pi_proportional_scale")) { r = get_ranged_double(value, &df, 0.0, DBL_MAX); if (r != PARSED_OK) diff --git a/config.h b/config.h index 4f24f51..4b7bd74 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_const; double *pi_proportional_scale; double *pi_proportional_exponent; double *pi_proportional_norm_max; diff --git a/phc2sys.c b/phc2sys.c index 76f161a..c2c611b 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -1244,7 +1244,7 @@ int main(int argc, char *argv[]) cfg = &phc2sys_config; config_set_double(cfg, "pi_proportional_const", KP); - configured_pi_ki = KI; + config_set_double(cfg, "pi_integral_const", KI); /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); @@ -1295,8 +1295,9 @@ int main(int argc, char *argv[]) return -1; break; case 'I': - if (get_arg_val_d(c, optarg, &configured_pi_ki, - 0.0, DBL_MAX)) + if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX)) + return -1; + if (config_set_double(cfg, "pi_integral_const", tmp)) return -1; break; case 'S': diff --git a/pi.c b/pi.c index 7549dd6..dc3ccfd 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 = 0.0; double configured_pi_kp_scale = 0.0; double configured_pi_kp_exponent = -0.3; double configured_pi_kp_norm_max = 0.7; @@ -55,6 +54,7 @@ struct pi_servo { int count; /* configuration: */ double configured_pi_kp; + double configured_pi_ki; }; static void pi_destroy(struct servo *servo) @@ -196,13 +196,14 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts) s->kp = 0.0; s->ki = 0.0; s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const"); + s->configured_pi_ki = config_get_double(cfg, NULL, "pi_integral_const"); - if (s->configured_pi_kp && configured_pi_ki) { + 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. */ configured_pi_kp_scale = s->configured_pi_kp; - configured_pi_ki_scale = configured_pi_ki; + configured_pi_ki_scale = s->configured_pi_ki; configured_pi_kp_exponent = 0.0; configured_pi_ki_exponent = 0.0; configured_pi_kp_norm_max = MAX_KP_NORM_MAX; diff --git a/pi.h b/pi.h index cd3c74f..9993ab2 100644 --- a/pi.h +++ b/pi.h @@ -21,12 +21,6 @@ #include "servo.h" -/** - * When set to a non-zero value, this variable determines the - * integral constant for the PI controller. - */ -extern double configured_pi_ki; - /** * When set to a non-zero value, this variable determines the scale in the * formula used to set the proportional constant of the PI controller from the diff --git a/ptp4l.c b/ptp4l.c index 5c23ddf..88f1180 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_const = &configured_pi_ki, .pi_proportional_scale = &configured_pi_kp_scale, .pi_proportional_exponent = &configured_pi_kp_exponent, .pi_proportional_norm_max = &configured_pi_kp_norm_max,