dt_model.c 3.42 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
/*
	dt_model.c
	Dwingeloo Telescope correction model.
	
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2011
	Copyright Stichting C.A. Muller Radioastronomiestation, 2011

	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 <unistd.h>
#include <math.h>
25
26
27
28
29
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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

#include "dt_model.h"

/*
	Pointing model made by Paul Boven
	Version 2010-08 taken from:
	http://www.xs4all.nl/~epboven/Camras/pointing.html

Het pointing model:
 
d-az = a0 + c1 / cos(el) - c2 * tan(el) - za * sin(az - aa) * tan(el)
d-el = e0 + b * cos(el) - r / sin(el) - za * cos(az - aa)
 
az, el: azimut, elevatie
 
a0: noord offset
c1: horizontale scheefstand beam
c2: hoogteverschil elevatie lagers
 
e0: elevatie offset
b: doorbuiging
r: refractie
 
za: scheefstand rail
aa: kompasrichting scheefstand

*/

58
59
60
61
static struct dt_model_params dt_model_default;

struct dt_model_params *params = &dt_model_default;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
62
63
64
65

double dt_model_azimuth_delta(double az, double el)
{
	double delta_az;
66
	double c1_div_cos_el = params->c1 / cos(el);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
67
68
69
70
71
	
	if (isnan(c1_div_cos_el))
		c1_div_cos_el = 0.0;
	
	delta_az = 
72
73
74
75
	    params->a0 
	    + params->c1 / cos(el) 
	    - params->c2 * tan(el) 
	    - params->za * sin(az - params->aa) * tan(el);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

	return delta_az;
}

double dt_model_azimuth_delta_rev(double az, double el)
{
	/* No reverse model available, (ab)use the forward model */
	return -dt_model_azimuth_delta(az, el);
}

double dt_model_elevation_delta(double az, double el)
{
	double delta_el;

	delta_el =
91
92
93
	     params->e0 
	     + params->b * cos(el) 
	     - params->za * cos(az - params->aa);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
94
95
96
97
98
99
100
101
102
	
	return delta_el;
}

double dt_model_elevation_delta_rev(double az, double el)
{
	/* No reverse model available, (ab)use the forward model */
	return -dt_model_elevation_delta(az, el);
}
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

int dt_model_init(void)
{
	int fd;
	
	fd = shm_open("/dt_model", 
	    O_RDWR | O_CREAT,
	    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	if (fd < 0)
		return -1;
	
	if((ftruncate(fd, sizeof(struct dt_model_params))) == -1){
		printf("ftruncate failure\n");
		return -1;
	}
	
	params = mmap(NULL, sizeof(struct dt_model_params), 
	    PROT_READ,
	    MAP_SHARED, fd, 0);

	return params != NULL;
}

int dt_model_init_server(void)
{
	int fd;
	
	fd = shm_open("/dt_model", 
	    O_RDWR | O_CREAT,
	    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	if (fd < 0)
		return -1;
	
	if((ftruncate(fd, sizeof(struct dt_model_params))) == -1){
		printf("ftruncate failure\n");
		return -1;
	}
	
	params = mmap(NULL, sizeof(struct dt_model_params), 
	    PROT_READ | PROT_WRITE,
	    MAP_SHARED, fd, 0);

	return params != NULL;
}

int dt_model_params_set(struct dt_model_params *newparams)
{
	memcpy(params, newparams, sizeof(struct dt_model_params));
	
	return 0;
}

int dt_model_params_get(struct dt_model_params *getparams)
{
	memcpy(getparams, params, sizeof(struct dt_model_params));
}