-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotor.h
61 lines (50 loc) · 1.38 KB
/
rotor.h
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
#define AZ_CW_ON (PORTB |= 0x01)
#define AZ_CW_OFF (PORTB &= ~(0x01))
#define AZ_CCW_ON (PORTB |= 0x02)
#define AZ_CCW_OFF (PORTB &= ~(0x02))
#define EL_UP_ON (PORTB |= 0x04)
#define EL_UP_OFF (PORTB &= ~(0x04))
#define EL_DOWN_ON (PORTB |= 0x08)
#define EL_DOWN_OFF (PORTB &= ~(0x08))
#define MAX_AZ 54500 // 54.5s = 360 deg
#define AZ_TICKS_PER_DEG 151
#define AZ_LOW_LIMIT 0
#define AZ_HI_LIMIT 360
#define MAX_EL 22000 // 22s = 90 deg
#define EL_TICKS_PER_DEG 244
#define EL_LOW_LIMIT 0
#define EL_HI_LIMIT 90
#define AZ_ERR_MIN 100 // 250ms = 1.65 deg
#define AZ_ERR_MAX 2000
#define EL_ERR_MIN 100 // 250ms = 1 deg
#define EL_ERR_MAX 2000
typedef enum {
AZ_IDLE,
AZ_CW,
AZ_CCW
} az_drive_state_t;
typedef enum {
EL_IDLE,
EL_UP,
EL_DOWN
} el_drive_state_t;
typedef struct {
long az_ticks;
long el_ticks;
} rotor_pos_t;
typedef struct {
rotor_pos_t pos;
rotor_pos_t target_pos;
unsigned char track_target;
//
az_drive_state_t az_drive_state;
el_drive_state_t el_drive_state;
} rotor_state_t;
void reinit_rotor_pos (rotor_state_t *s);
void set_target_az_deg (rotor_state_t *s, unsigned int az);
void set_target_el_deg (rotor_state_t *s, unsigned int el);
int get_az_deg (rotor_state_t *s);
int get_el_deg (rotor_state_t *s);
void enable_tracking(rotor_state_t *s);
void disable_tracking(rotor_state_t *s);
void pos_controller (rotor_state_t *s);