Commit 8ee183e4 authored by Daniel Brown's avatar Daniel Brown

Issue #8: Adding in ability to set lock command offsets. Example:

l l1 1 0 0.0 n1

m m1 0 1 0 n1 n2

pd P n2
set P.re P re

lock test $P.re -0.1 1e-6 -1

put l1 P $test

noxaxis
parent ac3896c7
......@@ -2164,7 +2164,8 @@ typedef struct lock_command {
double value; //!< lock value
double gain; //!< lock gain
double accuracy; //!< accuracy of lock
double offset;
double last1; //!< last lock value (for gradient calculation)
double last2; //!< second to last lock value (for grad calcn)
......
......@@ -3327,7 +3327,7 @@ void autogain(int lock_index, int counter) {
if (inter.lock_list[lock_index].once != -1) {
input = *(inter.lock_list[lock_index].input) /
input = (*(inter.lock_list[lock_index].input) + inter.lock_list[lock_index].offset) /
inter.lock_list[lock_index].accuracy;
finput = fabs(input) + 1.0e-9;
......@@ -3385,15 +3385,17 @@ void do_locks(int lock_index) {
assert(lock_index >= 0);
assert(lock_index < inter.num_locks);
double total_input = *(inter.lock_list[lock_index].input) + inter.lock_list[lock_index].offset;
if (inter.lock_list[lock_index].once != -1) {
inter.lock_list[lock_index].last2 = inter.lock_list[lock_index].last1;
inter.lock_list[lock_index].last1 = *(inter.lock_list[lock_index].input);
inter.lock_list[lock_index].last1 = total_input;
if (is_not_locked(lock_index)){
inter.lock_list[lock_index].value +=
inter.lock_list[lock_index].gain * (*(inter.lock_list[lock_index].input));
inter.lock_list[lock_index].value += inter.lock_list[lock_index].gain * total_input;
if (inter.debug & 2048) {
debug_msg("lock no. %d, input=%g, value = %g\n",lock_index,*inter.lock_list[lock_index].input, inter.lock_list[lock_index].value);
debug_msg("lock no. %d, input=%g, value = %g\n", lock_index, total_input, inter.lock_list[lock_index].value);
}
}
}
......@@ -3415,13 +3417,13 @@ int is_not_locked(int lock_index) {
assert(lock_index < inter.num_locks);
// assumed 'locked' for loops stat have stopped (lock* command)
if (inter.lock_list[lock_index].once == -1)
if (inter.lock_list[lock_index].once == -1){
return 0;
}
input = *(inter.lock_list[lock_index].input) /
inter.lock_list[lock_index].accuracy;
input = (*(inter.lock_list[lock_index].input) + inter.lock_list[lock_index].offset) / inter.lock_list[lock_index].accuracy;
finput = fabs(input) + 1.0e-9;
if (finput > 1.0) {
return 1;
}
......@@ -3706,7 +3708,7 @@ void tune_parameters(void) {
int i;
for (i = 0; i < inter.num_locks; i++) {
message("%d: in=%g out=%g ", i,
*(inter.lock_list[i].input), inter.lock_list[i].value);
*(inter.lock_list[i].input) + inter.lock_list[i].offset, inter.lock_list[i].value);
}
message("\n");
subcounter = 0;
......@@ -3741,7 +3743,7 @@ void tune_parameters(void) {
for (i = 0; i < inter.num_locks; i++) {
message("%d %s: error signal =%11.4g, "
"gain = %11.4g, feedback =%19.12g\n",
i, inter.lock_list[i].name, *(inter.lock_list[i].input),
i, inter.lock_list[i].name, *(inter.lock_list[i].input) + inter.lock_list[i].offset,
inter.lock_list[i].gain, inter.lock_list[i].value);
}
inter.showiterate = 0;
......
......@@ -311,6 +311,7 @@
#define MECH_RY_TF 1048576
#define HOM_ANGLE 2097152
#define BACKSCATTER 4194304
#define OFFSET 8388608
/* phase amplitude map atributes */
#define NO_MAP_SET 0 //!< Default map value
......
......@@ -2293,7 +2293,7 @@ void print_help() {
" var name value - tunabel variable $name\n"
" set name component parameter - variable $name\n"
" func name = function-string - function $name\n"
" lock[*] name $var gain accuracy - lock: make $var to 0\n"
" lock[*] name $var gain accuracy [offset] - lock: make $var+offset to 0\n"
" put[*] component parameter $var/$x1/$x2/$fs/$mfs - updates parameter\n"
" noplot output - no plot for 'output'\n"
" trace verbosity - verbose tracing\n"
......
......@@ -7759,14 +7759,12 @@ int get_attribute_type(const char *parameter_name,
attribute_type = HOM_ANGLE;
} else if (strncasecmp("backscatter", parameter_name, 11) == 0) {
attribute_type = BACKSCATTER;
} else if (strncasecmp("offset", parameter_name, 6) == 0) {
attribute_type = OFFSET;
} else {
gerror("Line `%s':\nno attribute named '%s', "
"use Rap, map_deg, M, Rc, Rcx, Rcy, gx, gy, xbeta, ybeta, alpha, eta or rho!\n",
"use Rap, map_deg, M, Rc, Rcx, Rcy, gx, gy, xbeta, yaw, ybeta, pitch, alpha, eta or rho, offset!\n",
command_string, parameter_name);
// replace above error message with one below when noise attribute made public
//gerror("Line `%s':\nno attribute named '%s', "
//"use M, Rc, Rcx, Rcy, gx, gy, xbeta, ybeta, alpha, eta, rho or noise!\n",
//command_string, parameter);
}
return attribute_type;
}
......@@ -9693,6 +9691,8 @@ void read_lock_command(const char *command_string) {
char gain_string[LINE_LEN] = {0};
char accuracy_string[LINE_LEN] = {0};
char rest_string[REST_STRING_LEN] = {0};
char offset_srting[LINE_LEN] = {0};
lock_command_t *lock_command;
output_data_t *output_data;
......@@ -9703,19 +9703,30 @@ void read_lock_command(const char *command_string) {
output_data = &(inter.output_data_list[inter.num_outputs]);
lock_command = &inter.lock_list[inter.num_locks];
int num_vars_read = sscanf(command_string, "%s %s %s %s %s %80s",
int num_vars_read = sscanf(command_string, "%s %s %s %s %s %s %80s",
command_name, object_name, func_or_set_name,
gain_string, accuracy_string, rest_string);
int num_vars_expected = 5;
if (num_vars_read < num_vars_expected) {
gerror("Line `%s':\nexpected 'lock name function/set gain accuracy'\n",
command_string);
} else if (num_vars_read > num_vars_expected) {
gain_string, accuracy_string, offset_srting, rest_string);
if (!(num_vars_read == 5 || num_vars_read == 6)) {
gerror("Line `%s':\nexpected 'lock name function/set gain accuracy [offset]'\n", command_string);
} else if (num_vars_read > 6) {
warn("Line `%s':\ntext '%s' ignored\n", command_string, rest_string);
}
if (num_vars_read >= 6){
double offset;
if (atod(offset_srting, &offset)) {
gerror("Line `%s':\nUnable to read offset\n", command_string);
}
lock_command->offset = offset;
} else {
lock_command->offset = 0;
}
// get the accuracy value and check it
double accuracy;
if (atod(accuracy_string, &accuracy)) {
gerror("Line `%s':\nUnable to read accuracy\n", command_string);
}
......@@ -9723,16 +9734,20 @@ void read_lock_command(const char *command_string) {
if (accuracy <= 0) {
gerror("Line `%s':\naccuracy must be >0.\n", command_string);
}
lock_command->accuracy = accuracy;
// get the gain value and check it
double gain;
if (atod(gain_string, &gain)) {
gerror("Line `%s':\nUnable to read gain\n", command_string);
}
if (gain == 0) {
gerror("Line `%s':\ngain must not be 0.\n", command_string);
}
lock_command->gain = gain;
check_funcname(object_name, command_string);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment