Skip to content
Snippets Groups Projects
Commit 211c5385 authored by dawehr's avatar dawehr
Browse files

Added ability to get/set PID constants. Passes regression tests, and is...

Added ability to get/set PID constants. Passes regression tests, and is backwards-compatible. Does not support setpoints, because they will be set via a different interface
parent 09d34631
No related branches found
No related tags found
1 merge request!8Controller network
...@@ -128,6 +128,13 @@ int graph_set_param_val(struct computation_graph *graph, int node_id, int param_ ...@@ -128,6 +128,13 @@ int graph_set_param_val(struct computation_graph *graph, int node_id, int param_
return 0; return 0;
} }
double graph_get_param_val(struct computation_graph *graph, int node_id, int param_id) {
if (node_id >= graph->n_nodes || param_id >= graph->nodes[node_id].type->n_params) {
return NAN;
}
return graph->nodes[node_id].param_values[param_id];
}
double graph_get_output(const struct computation_graph *graph, int node_id, int output_id) { double graph_get_output(const struct computation_graph *graph, int node_id, int output_id) {
if (node_id >= graph->n_nodes || output_id >= graph->nodes[node_id].type->n_outputs) { if (node_id >= graph->n_nodes || output_id >= graph->nodes[node_id].type->n_outputs) {
return 0; return 0;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define __COMPUTATION_GRAPH_H__ #define __COMPUTATION_GRAPH_H__
#include <stdio.h> #include <stdio.h>
#include <math.h>
typedef void (*execute_node_t)(void *state, typedef void (*execute_node_t)(void *state,
const double* params, const double* params,
...@@ -88,6 +89,12 @@ double graph_get_output(const struct computation_graph *graph, int node_id, int ...@@ -88,6 +89,12 @@ double graph_get_output(const struct computation_graph *graph, int node_id, int
*/ */
int graph_set_param_val(struct computation_graph *graph, int node_id, int param_id, double value); int graph_set_param_val(struct computation_graph *graph, int node_id, int param_id, double value);
/*
* Returns the value of the param at param_id for the given node
* Will return NaN if the given node or parameter IDs are not valid
*/
double graph_get_param_val(struct computation_graph *graph, int node_id, int param_id);
/* /*
* Computes the nodes given by node_id. * Computes the nodes given by node_id.
* To do so, computes all nodes which are ancestors of each given node_id in topological order, with * To do so, computes all nodes which are ancestors of each given node_id in topological order, with
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "commands.h" #include "commands.h"
#include "type_def.h" #include "type_def.h"
#include "uart.h" #include "uart.h"
#include "computation_graph.h"
/* /*
* Static variables used to keep track of packet counts * Static variables used to keep track of packet counts
...@@ -116,34 +117,14 @@ int cb_setparam(modular_structs_t *structs) ...@@ -116,34 +117,14 @@ int cb_setparam(modular_structs_t *structs)
{ {
return -1; return -1;
} }
struct computation_graph* graph = structs->parameter_struct.graph;
// Get the controller ID, parameter ID, parameter value // Get the node ID, parameter ID, parameter value
u8 controller_id = uart_buff_data_get_u8(0); u8 node_id = uart_buff_data_get_u8(0);
u8 param_id = uart_buff_data_get_u8(1); u8 param_id = uart_buff_data_get_u8(1);
float param_val = uart_buff_data_get_float(2); float param_val = uart_buff_data_get_float(2);
// Check to make sure the IDs are in bounds // Set the value for that parameter on that node
if (controller_id >= MAX_CONTROLLER_ID || graph_set_param_val(graph, node_id, param_id, param_val);
param_id >= MAX_CONTROL_PARAM_ID)
{
return -1;
}
// Set the param_val into the controller by controller_id, param_id
switch(param_id)
{
case KP_ID:
structs->parameter_struct.pid_controllers[controller_id].Kp = param_val;
break;
case KI_ID:
structs->parameter_struct.pid_controllers[controller_id].Ki = param_val;
break;
case KD_ID:
structs->parameter_struct.pid_controllers[controller_id].Kd = param_val;
break;
case SP_ID:
structs->parameter_struct.pid_controllers[controller_id].setpoint = param_val;
break;
}
return 0; return 0;
} }
...@@ -184,39 +165,15 @@ int cb_getparam(modular_structs_t* structs) ...@@ -184,39 +165,15 @@ int cb_getparam(modular_structs_t* structs)
} }
// Get the controller ID, parameter ID // Get the controller ID, parameter ID
u8 controller_id = uart_buff_data_get_u8(0); u8 node_id = uart_buff_data_get_u8(0);
u8 param_id = uart_buff_data_get_u8(1); u8 param_id = uart_buff_data_get_u8(1);
// Check to make sure the IDs are in bounds struct computation_graph* graph = structs->parameter_struct.graph;
if (controller_id >= MAX_CONTROLLER_ID || float param_val = graph_get_param_val(graph, node_id, param_id);
param_id >= MAX_CONTROL_PARAM_ID)
{
return -1;
}
// Make the variable to send
float param_val;
// Set the param_val equal to the parameter value stored in the controller by
// controller_id, param_id
switch(param_id)
{
case KP_ID:
param_val = structs->parameter_struct.pid_controllers[controller_id].Kp;
break;
case KI_ID:
param_val = structs->parameter_struct.pid_controllers[controller_id].Ki;
break;
case KD_ID:
param_val = structs->parameter_struct.pid_controllers[controller_id].Kd;
break;
case SP_ID:
param_val = structs->parameter_struct.pid_controllers[controller_id].setpoint;
break;
}
// Format the response data // Format the response data
char resp_data[6]; char resp_data[6];
// Controller ID // Controller ID
resp_data[0] = controller_id; resp_data[0] = node_id;
// Parameter ID // Parameter ID
resp_data[1] = param_id; resp_data[1] = param_id;
// Parameter value (4 byte float) // Parameter value (4 byte float)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "initialize_components.h" #include "initialize_components.h"
#include "communication.h" #include "communication.h"
//#define BENCH_TEST #define BENCH_TEST
extern int Xil_AssertWait; extern int Xil_AssertWait;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "send_actuator_commands.h" #include "send_actuator_commands.h"
#include "update_gui.h" #include "update_gui.h"
//#define BENCH_TEST #define BENCH_TEST
//#define UART_BENCHMARK //#define UART_BENCHMARK
int main() int main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment