spg_test.c 3.3 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#include "controller_block.h"
#include "controller_trace.h"
#include "controller_setpoint_command.h"
#include "controller_sample.h"
#include "block_setpoint_generator.h"

#define FREQ 1000.0

struct block {
	char *name;
	struct controller_block *(*create)(char *);
};

struct param_misc {
	char *blockname;
	char *paramname;
	void *value;
};

static struct block controller_blocks[] = {
	{ "spg",             block_setpoint_generator_create },
	{ NULL, NULL }
};

static struct param_misc controller_param[] = {
	{ "spg",           "setpoint",            &(float){ 0.0                  }},
	{ "spg",           "t",                   &(float){ 1.0 / FREQ           }},
	{ "spg",           "max",                 &(float){ 2.0             }},
	{ "spg",           "min",                 &(float){-2.0             }},
	{ "spg",           "max_extrapolate",     &(float){ 1.0                  }},

	{ NULL, NULL, NULL }
};

static struct controller_trace_name dt_trace_list[] = {
	{ "Setpoint",        "rad",   "spg",             "setpoint"   },
	{ "Spg_Der",         "rad/s", "spg",             "derivative" },
	
	{ NULL, NULL, NULL, NULL }
};

static struct controller_spg_name dt_spg_list[] = {
	{ "Setpoint",           "unit", "spg"           },

	{ NULL, NULL, NULL },
};


int main(int argc, char **argv)
{
	struct controller_block *block;
	int i;
	
	controller_block_param_init();
	
	/* Create blocks */

	for (i = 0; controller_blocks[i].name; i++) {
		block = controller_blocks[i].create(controller_blocks[i].name);
		if (!block)
			printf("Could not create block %s\n",
			    controller_blocks[i].name);
	}

	/* Set params */
	
	for (i = 0; controller_param[i].blockname; i++) {
		if (controller_block_param_set(
		    controller_param[i].blockname,
		    controller_param[i].paramname,
		    controller_param[i].value) < 0) {
			printf("Could not set %s.%s\n",
			    controller_param[i].blockname,
			    controller_param[i].paramname);
			return 1;
		}
	}

	
	/* Add traces to the trace interface */

	for (i = 0; dt_trace_list[i].name; i++)
		controller_trace_list_add(&dt_trace_list[i]);

	controller_trace_server_start(10000, 100);

	/* Add spg command handlers */

	for (i = 0; dt_spg_list[i].name; i++)
		controller_setpoint_command_server_add(&dt_spg_list[i]);

	controller_setpoint_command_server_start(11000, 100);

	/* Start 'sample' */

	controller_block_sample_init();

	controller_sample_frequency_set(FREQ);

	printf("Starting sample thread\n");
	controller_sample_start();

	while (1) {
		sleep(60);
	}

	return 0;
}