config: convert 'pi_proportional_const' to the new scheme.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-13 22:48:25 +02:00
parent a7db9bad37
commit 25c903b0d2
7 changed files with 14 additions and 23 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_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("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX), GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_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_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX), GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255), PORT_ITEM_INT("udp_ttl", 1, 1, 255),
@ -541,12 +542,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val; cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val; pod->freq_est_interval = val;
} else if (!strcmp(option, "pi_proportional_const")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
return r;
*cfg->pi_proportional_const = df;
} else if (!strcmp(option, "pi_integral_const")) { } else if (!strcmp(option, "pi_integral_const")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX); r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK) if (r != PARSED_OK)

View File

@ -69,7 +69,6 @@ struct config {
struct port_defaults pod; struct port_defaults pod;
enum servo_type clock_servo; enum servo_type clock_servo;
double *pi_proportional_const;
double *pi_integral_const; double *pi_integral_const;
double *pi_proportional_scale; double *pi_proportional_scale;
double *pi_proportional_exponent; double *pi_proportional_exponent;

View File

@ -1243,7 +1243,7 @@ int main(int argc, char *argv[])
} }
cfg = &phc2sys_config; cfg = &phc2sys_config;
configured_pi_kp = KP; config_set_double(cfg, "pi_proportional_const", KP);
configured_pi_ki = KI; configured_pi_ki = KI;
/* Process the command line arguments. */ /* Process the command line arguments. */
@ -1289,8 +1289,9 @@ int main(int argc, char *argv[])
} }
break; break;
case 'P': case 'P':
if (get_arg_val_d(c, optarg, &configured_pi_kp, if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
0.0, DBL_MAX)) return -1;
if (config_set_double(cfg, "pi_proportional_const", tmp))
return -1; return -1;
break; break;
case 'I': case 'I':

11
pi.c
View File

@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "config.h"
#include "pi.h" #include "pi.h"
#include "print.h" #include "print.h"
#include "servo_private.h" #include "servo_private.h"
@ -35,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001 #define FREQ_EST_MARGIN 0.001
/* These take their values from the configuration file. (see ptp4l.c) */ /* These take their values from the configuration file. (see ptp4l.c) */
double configured_pi_kp = 0.0;
double configured_pi_ki = 0.0; double configured_pi_ki = 0.0;
double configured_pi_kp_scale = 0.0; double configured_pi_kp_scale = 0.0;
double configured_pi_kp_exponent = -0.3; double configured_pi_kp_exponent = -0.3;
@ -53,6 +53,8 @@ struct pi_servo {
double ki; double ki;
double last_freq; double last_freq;
int count; int count;
/* configuration: */
double configured_pi_kp;
}; };
static void pi_destroy(struct servo *servo) static void pi_destroy(struct servo *servo)
@ -177,7 +179,7 @@ static void pi_reset(struct servo *servo)
s->count = 0; s->count = 0;
} }
struct servo *pi_servo_create(int fadj, int sw_ts) struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
{ {
struct pi_servo *s; struct pi_servo *s;
@ -193,12 +195,13 @@ struct servo *pi_servo_create(int fadj, int sw_ts)
s->last_freq = fadj; s->last_freq = fadj;
s->kp = 0.0; s->kp = 0.0;
s->ki = 0.0; s->ki = 0.0;
s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const");
if (configured_pi_kp && configured_pi_ki) { if (s->configured_pi_kp && configured_pi_ki) {
/* Use the constants as configured by the user without /* Use the constants as configured by the user without
adjusting for sync interval unless they make the servo adjusting for sync interval unless they make the servo
unstable. */ unstable. */
configured_pi_kp_scale = configured_pi_kp; configured_pi_kp_scale = s->configured_pi_kp;
configured_pi_ki_scale = configured_pi_ki; configured_pi_ki_scale = configured_pi_ki;
configured_pi_kp_exponent = 0.0; configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0; configured_pi_ki_exponent = 0.0;

8
pi.h
View File

@ -21,12 +21,6 @@
#include "servo.h" #include "servo.h"
/**
* When set to a non-zero value, this variable determines the
* proportional constant for the PI controller.
*/
extern double configured_pi_kp;
/** /**
* When set to a non-zero value, this variable determines the * When set to a non-zero value, this variable determines the
* integral constant for the PI controller. * integral constant for the PI controller.
@ -77,6 +71,6 @@ extern double configured_pi_ki_exponent;
*/ */
extern double configured_pi_ki_norm_max; extern double configured_pi_ki_norm_max;
struct servo *pi_servo_create(int fadj, int sw_ts); struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts);
#endif #endif

View File

@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4, .transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI, .clock_servo = CLOCK_SERVO_PI,
.pi_proportional_const = &configured_pi_kp,
.pi_integral_const = &configured_pi_ki, .pi_integral_const = &configured_pi_ki,
.pi_proportional_scale = &configured_pi_kp_scale, .pi_proportional_scale = &configured_pi_kp_scale,
.pi_proportional_exponent = &configured_pi_kp_exponent, .pi_proportional_exponent = &configured_pi_kp_exponent,

View File

@ -37,7 +37,7 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,
switch (type) { switch (type) {
case CLOCK_SERVO_PI: case CLOCK_SERVO_PI:
servo = pi_servo_create(fadj, sw_ts); servo = pi_servo_create(cfg, fadj, sw_ts);
break; break;
case CLOCK_SERVO_LINREG: case CLOCK_SERVO_LINREG:
servo = linreg_servo_create(fadj); servo = linreg_servo_create(fadj);