Skip to content

Commit

Permalink
config: convert 'pi_proportional_scale' to the new scheme.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 23, 2015
1 parent 07b2299 commit 94048a2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
7 changes: 1 addition & 6 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_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),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
Expand Down Expand Up @@ -543,12 +544,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_scale")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
return r;
*cfg->pi_proportional_scale = df;

} else if (!strcmp(option, "pi_proportional_exponent")) {
r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
if (r != PARSED_OK)
Expand Down
1 change: 0 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

double *pi_proportional_scale;
double *pi_proportional_exponent;
double *pi_proportional_norm_max;
double *pi_integral_scale;
Expand Down
13 changes: 7 additions & 6 deletions pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_scale = 0.0;
double configured_pi_kp_exponent = -0.3;
double configured_pi_kp_norm_max = 0.7;
double configured_pi_ki_scale = 0.0;
Expand All @@ -55,6 +54,7 @@ struct pi_servo {
/* configuration: */
double configured_pi_kp;
double configured_pi_ki;
double configured_pi_kp_scale;
};

static void pi_destroy(struct servo *servo)
Expand Down Expand Up @@ -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 = configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent);
s->kp = s->configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent);
if (s->kp > configured_pi_kp_norm_max / interval)
s->kp = configured_pi_kp_norm_max / interval;

Expand Down Expand Up @@ -197,23 +197,24 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
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");
s->configured_pi_kp_scale = config_get_double(cfg, NULL, "pi_proportional_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. */
configured_pi_kp_scale = s->configured_pi_kp;
s->configured_pi_kp_scale = s->configured_pi_kp;
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;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
} else if (!configured_pi_kp_scale || !configured_pi_ki_scale) {
} else if (!s->configured_pi_kp_scale || !configured_pi_ki_scale) {
if (sw_ts) {
configured_pi_kp_scale = SWTS_KP_SCALE;
s->configured_pi_kp_scale = SWTS_KP_SCALE;
configured_pi_ki_scale = SWTS_KI_SCALE;
} else {
configured_pi_kp_scale = HWTS_KP_SCALE;
s->configured_pi_kp_scale = HWTS_KP_SCALE;
configured_pi_ki_scale = HWTS_KI_SCALE;
}
}
Expand Down
8 changes: 0 additions & 8 deletions pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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_scale;

/**
* This variable determines the exponent in the formula used to set the
* proportional constant of the PI controller from the sync interval.
Expand Down
1 change: 0 additions & 1 deletion ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

.pi_proportional_scale = &configured_pi_kp_scale,
.pi_proportional_exponent = &configured_pi_kp_exponent,
.pi_proportional_norm_max = &configured_pi_kp_norm_max,
.pi_integral_scale = &configured_pi_ki_scale,
Expand Down

0 comments on commit 94048a2

Please sign in to comment.