config: convert 'pi_proportional_const' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
a7db9bad37
commit
25c903b0d2
7
config.c
7
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_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),
|
||||
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;
|
||||
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")) {
|
||||
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
||||
if (r != PARSED_OK)
|
||||
|
|
1
config.h
1
config.h
|
@ -69,7 +69,6 @@ struct config {
|
|||
struct port_defaults pod;
|
||||
enum servo_type clock_servo;
|
||||
|
||||
double *pi_proportional_const;
|
||||
double *pi_integral_const;
|
||||
double *pi_proportional_scale;
|
||||
double *pi_proportional_exponent;
|
||||
|
|
|
@ -1243,7 +1243,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
cfg = &phc2sys_config;
|
||||
|
||||
configured_pi_kp = KP;
|
||||
config_set_double(cfg, "pi_proportional_const", KP);
|
||||
configured_pi_ki = KI;
|
||||
|
||||
/* Process the command line arguments. */
|
||||
|
@ -1289,8 +1289,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
case 'P':
|
||||
if (get_arg_val_d(c, optarg, &configured_pi_kp,
|
||||
0.0, DBL_MAX))
|
||||
if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
|
||||
return -1;
|
||||
if (config_set_double(cfg, "pi_proportional_const", tmp))
|
||||
return -1;
|
||||
break;
|
||||
case 'I':
|
||||
|
|
11
pi.c
11
pi.c
|
@ -20,6 +20,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "pi.h"
|
||||
#include "print.h"
|
||||
#include "servo_private.h"
|
||||
|
@ -35,7 +36,6 @@
|
|||
#define FREQ_EST_MARGIN 0.001
|
||||
|
||||
/* 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_kp_scale = 0.0;
|
||||
double configured_pi_kp_exponent = -0.3;
|
||||
|
@ -53,6 +53,8 @@ struct pi_servo {
|
|||
double ki;
|
||||
double last_freq;
|
||||
int count;
|
||||
/* configuration: */
|
||||
double configured_pi_kp;
|
||||
};
|
||||
|
||||
static void pi_destroy(struct servo *servo)
|
||||
|
@ -177,7 +179,7 @@ static void pi_reset(struct servo *servo)
|
|||
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;
|
||||
|
||||
|
@ -193,12 +195,13 @@ struct servo *pi_servo_create(int fadj, int sw_ts)
|
|||
s->last_freq = fadj;
|
||||
s->kp = 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
|
||||
adjusting for sync interval unless they make the servo
|
||||
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_kp_exponent = 0.0;
|
||||
configured_pi_ki_exponent = 0.0;
|
||||
|
|
8
pi.h
8
pi.h
|
@ -21,12 +21,6 @@
|
|||
|
||||
#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
|
||||
* integral constant for the PI controller.
|
||||
|
@ -77,6 +71,6 @@ extern double configured_pi_ki_exponent;
|
|||
*/
|
||||
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
|
||||
|
|
1
ptp4l.c
1
ptp4l.c
|
@ -103,7 +103,6 @@ static struct config cfg_settings = {
|
|||
.transport = TRANS_UDP_IPV4,
|
||||
.clock_servo = CLOCK_SERVO_PI,
|
||||
|
||||
.pi_proportional_const = &configured_pi_kp,
|
||||
.pi_integral_const = &configured_pi_ki,
|
||||
.pi_proportional_scale = &configured_pi_kp_scale,
|
||||
.pi_proportional_exponent = &configured_pi_kp_exponent,
|
||||
|
|
Loading…
Reference in New Issue