config: convert 'pi_integral_const' to the new scheme.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-13 22:54:22 +02:00
parent 25c903b0d2
commit 07b229907d
6 changed files with 9 additions and 20 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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':

7
pi.c
View File

@ -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;

6
pi.h
View File

@ -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

View File

@ -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,