Commit 4a83129a authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add aliases to ctrl file parser

Introduce first two position aliases
Allow string variables to be used almost anywhere
parent c8682463
......@@ -45,6 +45,9 @@ void controller_load_frequency(double frequency);
int controller_load_include(char *file_name);
int controller_load_import(char *file_name);
char * controller_load_variable_alias_get_block(char *varname);
char * controller_load_variable_alias_get_term(char *varname);
void controller_load_variable_alias_set(char *varname, char *block, char *term);
double controller_load_variable_double_get(char *varname);
void controller_load_variable_double_set(char *varname, double val);
char * controller_load_variable_string_get(char *varname);
......
......@@ -44,6 +44,7 @@ string "\""[^"]*"\""
variablename [a-zA-Z\_][0-9a-zA-Z\-\_]*
aliasvariable "\$<"{variablename}">"
intvariable "\$["{variablename}"]"
doublevariable "\$("{variablename}")"
stringvariable "\${"{variablename}"}"
......@@ -78,6 +79,7 @@ boolcast "("[ \t]*"bool"[ \t]*")"
"+" { return PLUSSYM; }
"-" { return MINSYM; }
"alias" { return ALIASSYM; }
"frequency" { return FREQUENCYSYM; }
"trigger" { return TRIGGERSYM; }
"blocks" { return BLOCKSSYM; }
......@@ -107,6 +109,12 @@ boolcast "("[ \t]*"bool"[ \t]*")"
return STRINGSYM;
}
{aliasvariable} {
yylval->string = strdup(yytext + 2);
yylval->string[strlen(yylval->string)-1] = 0;
return ALIASVARIABLESYM;
}
{intvariable} {
yylval->string = strdup(yytext + 2);
yylval->string[strlen(yylval->string)-1] = 0;
......
......@@ -46,9 +46,11 @@ void yyerror(yyscan_t *scanner, char const *s);
%start ctrllist
%token ALIASSYM
%token BRACEOPENSYM
%token BRACECLOSESYM
%token COMMASYM
%token <string> ALIASVARIABLESYM
%token <string> STRINGSYM
%token <string> VARIABLENAMESYM
%token <string> INTVARIABLESYM
......@@ -108,7 +110,8 @@ ctrllist: ctrl
| ctrl ctrllist
;
ctrl : frequency
ctrl : aliases
| frequency
| triggers
| links
| blocks
......@@ -125,7 +128,7 @@ frequency: FREQUENCYSYM DOUBLESYM
{ controller_load_frequency($2); }
;
include: INCLUDESYM STRINGSYM
include: INCLUDESYM stringvar
{
if (controller_load_include($2)) {
yyerror(scanner, "Failed to parse include");
......@@ -134,7 +137,7 @@ include: INCLUDESYM STRINGSYM
}
;
import: IMPORTSYM STRINGSYM
import: IMPORTSYM stringvar
{
if (controller_load_import($2)) {
yyerror(scanner, "Failed to parse import");
......@@ -143,6 +146,22 @@ import: IMPORTSYM STRINGSYM
}
;
aliases: ALIASSYM BRACEOPENSYM aliaslist BRACECLOSESYM
aliaslist: alias
| alias aliaslist
;
alias: BRACEOPENSYM
stringvar COMMASYM
stringvar COMMASYM
stringvar
BRACECLOSESYM
{
controller_load_variable_alias_set($2, $4, $6);
}
triggers: TRIGGERSYM BRACEOPENSYM triggerlist BRACECLOSESYM
triggerlist: trigger
......@@ -150,7 +169,7 @@ triggerlist: trigger
;
trigger : BRACEOPENSYM
STRINGSYM varlist
stringvar varlist
BRACECLOSESYM
{
if(controller_load_trigger($2, scanner)) {
......@@ -169,8 +188,8 @@ blocklist: block
;
block : BRACEOPENSYM
STRINGSYM COMMASYM
STRINGSYM varlist
stringvar COMMASYM
stringvar varlist
BRACECLOSESYM
{
if(controller_load_block_create($2, $4, scanner)) {
......@@ -190,8 +209,8 @@ paramlist: param
;
param : BRACEOPENSYM
STRINGSYM COMMASYM
STRINGSYM
stringvar COMMASYM
stringvar
varlist
BRACECLOSESYM
{
......@@ -329,10 +348,10 @@ linklist: link
;
link : BRACEOPENSYM
STRINGSYM COMMASYM
STRINGSYM COMMASYM
STRINGSYM COMMASYM
STRINGSYM COMMASYM
stringvar COMMASYM
stringvar COMMASYM
stringvar COMMASYM
stringvar COMMASYM
BOOLSYM
BRACECLOSESYM
{
......@@ -345,6 +364,54 @@ link : BRACEOPENSYM
free($6);
free($8);
}
| BRACEOPENSYM
ALIASVARIABLESYM COMMASYM
ALIASVARIABLESYM COMMASYM
BOOLSYM
BRACECLOSESYM
{
if (controller_block_connect(
controller_load_variable_alias_get_block($2),
controller_load_variable_alias_get_term($2),
controller_load_variable_alias_get_block($4),
controller_load_variable_alias_get_term($4), $6)) {
yyerror(scanner, "Error connecting blocks");
YYERROR;
}
}
| BRACEOPENSYM
stringvar COMMASYM
stringvar COMMASYM
ALIASVARIABLESYM COMMASYM
BOOLSYM
BRACECLOSESYM
{
if (controller_block_connect($2, $4,
controller_load_variable_alias_get_block($6),
controller_load_variable_alias_get_term($6), $8)) {
yyerror(scanner, "Error connecting blocks");
YYERROR;
}
free($2);
free($4);
}
| BRACEOPENSYM
ALIASVARIABLESYM COMMASYM
stringvar COMMASYM
stringvar COMMASYM
BOOLSYM
BRACECLOSESYM
{
if (controller_block_connect(
controller_load_variable_alias_get_block($2),
controller_load_variable_alias_get_term($2),
$4, $6, $8)) {
yyerror(scanner, "Error connecting blocks");
YYERROR;
}
free($2);
free($4);
}
;
traces : TRACESSYM BRACEOPENSYM tracelist BRACECLOSESYM
......@@ -354,10 +421,10 @@ tracelist: trace
;
trace : BRACEOPENSYM
STRINGSYM COMMASYM
STRINGSYM COMMASYM
STRINGSYM COMMASYM
STRINGSYM
stringvar COMMASYM
stringvar COMMASYM
stringvar COMMASYM
stringvar
BRACECLOSESYM
{
struct controller_trace_name trace;
......@@ -367,6 +434,21 @@ trace : BRACEOPENSYM
trace.blockname = $6;
trace.termname = $8;
controller_trace_list_add(&trace);
}
| BRACEOPENSYM
stringvar COMMASYM
stringvar COMMASYM
ALIASVARIABLESYM
BRACECLOSESYM
{
struct controller_trace_name trace;
trace.name = $2;
trace.unit = $4;
trace.blockname = controller_load_variable_alias_get_block($6);
trace.termname = controller_load_variable_alias_get_term($6);
controller_trace_list_add(&trace);
}
;
......@@ -24,6 +24,7 @@
#include <controller/controller_load.h>
enum variable_type {
VARIABLE_ALIAS,
VARIABLE_STRING,
VARIABLE_DOUBLE,
VARIABLE_INT,
......@@ -37,12 +38,70 @@ struct variable {
char *stringval;
int intval;
char *block;
char *term;
struct variable *next;
};
static struct variable *variables = NULL;
char * controller_load_variable_alias_get_block(char *varname)
{
struct variable *entry;
for (entry = variables; entry; entry = entry->next) {
if (!strcmp(entry->name, varname) &&
entry->type == VARIABLE_ALIAS)
return entry->block;
}
log_send(LOG_T_ERROR, "String variable %s does not exist", varname);
return "";
}
char * controller_load_variable_alias_get_term(char *varname)
{
struct variable *entry;
for (entry = variables; entry; entry = entry->next) {
if (!strcmp(entry->name, varname) &&
entry->type == VARIABLE_ALIAS)
return entry->term;
}
log_send(LOG_T_ERROR, "String variable %s does not exist", varname);
return "";
}
void controller_load_variable_alias_set(char *varname, char *block, char *term)
{
struct variable *entry;
for (entry = variables; entry; entry = entry->next) {
if (!strcmp(entry->name, varname)) {
if (entry->type == VARIABLE_ALIAS) {
free(entry->block);
free(entry->term);
}
break;
}
}
if (!entry) {
entry = calloc(sizeof(struct variable), 1);
entry->name = strdup(varname);
entry->next = variables;
variables = entry;
}
entry->type = VARIABLE_ALIAS;
entry->block = strdup(block);
entry->term = strdup(term);
}
int controller_load_variable_int_get(char *varname)
{
struct variable *entry;
......
......@@ -83,13 +83,18 @@ blocks {
{ "value_bool", "false" }
}
alias {
{ "Azimuth_Position", "azimuth_position_offset_sum", "out" }
{ "Elevation_Position", "elevation_input_matrix", "out0" }
}
links {
{ "dt_az", "position", "azimuth_position_gain", "in" , true }
{ "azimuth_position_gain", "out", "azimuth_position_offset_sum", "in0" , true }
{ "azimuth_position_offset", "value", "azimuth_position_offset_sum", "in1" , true }
{ "azimuth_position_offset_sum", "out", "azimuth_error", "negative" , true }
{ $<Azimuth_Position>, "azimuth_error", "negative" , true }
{ "azimuth_servo_state", "reset", "azimuth_spg", "reset" , false }
{ "azimuth_position_offset_sum", "out", "azimuth_spg", "reset_x" , true }
{ $<Azimuth_Position>, "azimuth_spg", "reset_x" , true }
{ "azimuth_spg", "x", "azimuth_servo_state", "spg_x" , true }
{ "azimuth_spg", "v", "azimuth_servo_state", "spg_v" , true }
{ "azimuth_spg", "a", "azimuth_servo_state", "spg_a" , true }
......@@ -98,7 +103,7 @@ links {
{ "azimuth_safe_and", "q", "azimuth_servo_state", "safe" , true }
{ "azimuth_safety", "recover", "azimuth_servo_state", "override" , false }
{ "azimuth_servo_state", "out_x", "azimuth_error", "positive" , true }
{ "azimuth_position_offset_sum", "out", "azimuth_setpoint_error", "negative" , true }
{ $<Azimuth_Position>, "azimuth_setpoint_error", "negative" , true }
{ "azimuth_spg", "setpoint", "azimuth_setpoint_error", "positive" , true }
{ "azimuth_servo_state", "out_v", "azimuth_speed_ff", "in0" , true }
{ "azimuth_error", "difference", "azimuth_pid", "in" , true }
......@@ -109,7 +114,7 @@ links {
{ "azimuth_pid_filter", "out", "azimuth_speed_ff", "in1" , true }
{ "azimuth_speed_ff", "out", "azimuth_speed_limit", "in" , true }
{ "azimuth_speed_limit", "out", "azimuth_safety", "speed_in" , true }
{ "azimuth_position_offset_sum", "out", "azimuth_safety", "position_in" , true }
{ $<Azimuth_Position>, "azimuth_safety", "position_in" , true }
{ "azimuth_torque", "value", "azimuth_safety", "torque_in" , true }
{ "dt_az", "be4", "azimuth_safety", "safety_in_positive", true }
{ "dt_az", "be2", "azimuth_safety", "safety_in_negative", true }
......@@ -123,7 +128,7 @@ links {
{ "false", "value", "dt_az", "ba2" , true }
{ "elevation_servo_state", "reset", "elevation_spg", "reset" , false }
{ "elevation_input_matrix", "out0", "elevation_spg", "reset_x" , true }
{ $<Elevation_Position>, "elevation_spg", "reset_x" , true }
{ "elevation_spg", "x", "elevation_servo_state", "spg_x" , true }
{ "elevation_spg", "v", "elevation_servo_state", "spg_v" , true }
{ "elevation_spg", "a", "elevation_servo_state", "spg_a" , true }
......@@ -139,9 +144,9 @@ links {
{ "elevation_position_offset_l", "value", "elevation_position_offset_l_sum", "in1" , true }
{ "elevation_position_offset_r_sum","out", "elevation_input_matrix", "in0" , true }
{ "elevation_position_offset_l_sum","out", "elevation_input_matrix", "in1" , true }
{ "elevation_input_matrix", "out0", "elevation_error", "negative" , true }
{ $<Elevation_Position>, "elevation_error", "negative" , true }
{ "elevation_spg", "setpoint", "elevation_setpoint_error", "positive" , true }
{ "elevation_input_matrix", "out0", "elevation_setpoint_error", "negative" , true }
{ $<Elevation_Position>, "elevation_setpoint_error", "negative" , true }
{ "elevation_error", "difference", "elevation_pid", "in" , true }
{ "elevation_servo_state", "enable", "elevation_pid", "enable" , true }
{ "elevation_pid", "out", "elevation_speed_ff", "in1" , true }
......@@ -199,7 +204,7 @@ traces {
{ "Azimuth_PID", "rad/s", "azimuth_pid", "out" }
{ "Azimuth_I", "rad/s", "azimuth_pid", "outi" }
{ "Azimuth_PID_filtered", "rad/s", "azimuth_pid_filter", "out" }
{ "Azimuth_Position", "rad", "azimuth_position_offset_sum", "out" }
{ "Azimuth_Position", "rad", $<Azimuth_Position> }
{ "Azimuth_Speed", "rad/s", "dt_az", "speed" }
{ "Azimuth_Torque", "Nm", "dt_az", "torque" }
{ "Azimuth_Safe", "Boolean", "azimuth_safety", "safe_out" }
......@@ -210,7 +215,7 @@ traces {
{ "Focusbox_Position", "Volt", "dt_az", "ae1" }
{ "Elevation_Position", "rad", "elevation_input_matrix", "out0" }
{ "Elevation_Position", "rad", $<Elevation_Position> }
{ "Elevation_Torsion", "rad", "elevation_input_matrix", "out1" }
{ "Elevation_Setpoint", "rad", "elevation_spg", "setpoint" }
{ "Elevation_Spg0", "rad", "elevation_spg", "x" }
......
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