-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsatelliteHunter.ino
127 lines (108 loc) · 5.06 KB
/
satelliteHunter.ino
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
/*
* Sergey Novikov, 19.02.23;
* Rotary device for antennas for tracking satellites;
* Take the project as a basis https://sarcnet.org/rotator-mk1.html;
* The original project uses a sensor for orientation in space LSM303DLHC (azimuth, elevation);
* In this project, the sensor is excluded and stepper motors are used;
* Dignities:
* 1) no more need to suffer with calibration LSM303DLHC
* Disadvantages:
* 1) it is necessary to manually set the rotary system in the direction of "north" and 0 degrees in elevation;
* 2) in the satellite guidance mode, when the system passes through 0 degrees, the following will happen:
* the system will reach 0 degrees and then rotate 360 degrees to the preset position
* an example can be seen on the video https://disk.yandex.ru/i/ca2uF6rEpf4c-g (35 seconds)
*/
#define SerialPort Serial //Please uncomment this line to use the USB port.
#include "motor.h"
const int MotorType = STEPMOT18DEG;
//Motor pins - Don't change? :)
const int azStepPin = 3;
const int azDirPin = 2;
const int elStepPin = 7;
const int elDirPin = 8;
//Global variables
float az; //Antenna azimuth
float el; //Antenna elevation
String line; //Command line
float azSet; //Antenna azimuth set point
float elSet; //Antenna elevation set point
Mot azMot(MotorType, azStepPin, azDirPin); //AZ motor driver object
Mot elMot(MotorType, elStepPin, elDirPin); //EL motor driver object
//Non-blocking Timer object
int azPosition = 0;
int elPosition = 0;
void printAzEl() {
//Print the rotator feedback data in Easycomm II format
Serial.print("AZ");
Serial.print((az < 0) ? (az + 360) : az, 1);
Serial.print(" EL");
Serial.print(el, 1);
Serial.print("\n");
}
void processEasycommCommands(String line) {
//Process Easycomm II rotator commands
//Easycomm II position command: AZnn.n ELnn.n UP000 XXX DN000 XXX\n
//Easycomm II query command: AZ EL \n
String param; //Parameter value
int firstSpace; //Position of the first space in the command line
int secondSpace; //Position of the second space in the command line
if (line.startsWith("AZ EL")) { //Query command received
printAzEl(); //Send the current Azimuth and Elevation
} else {
if (line.startsWith("AZ")) { //Position command received: Parse the line.
firstSpace = line.indexOf(' '); //Get the position of the first space
secondSpace = line.indexOf(' ', firstSpace + 1); //Get the position of the second space
param = line.substring(2, firstSpace); //Get the first parameter
azSet = param.toFloat(); //Set the azSet value
//if (azSet > 180) azSet = azSet - 360; //Convert 0..360 to -180..180 degrees format
param = line.substring(firstSpace + 3, secondSpace);//Get the second parameter
elSet = param.toFloat(); //Set the elSet value
}
}
}
void processCommands(void) {
//Process incoming data from the control computer
//User commands are entered by the user and are terminated with a carriage return
//Easycomm commands are generated by a tracking program and are terminated with a line feed
while (Serial.available() > 0) {
char ch = Serial.read(); //Read a single character from the serial buffer
switch (ch) {
case 13: //Carriage return received
//processUserCommands(line); //Process user commands
line = ""; //Command processed: Clear the command line
break;
case 10: //Line feed received
processEasycommCommands(line); //Process Easycomm commands
line = ""; //Command processed: Clear the command line
break;
default: //Any other character received
line += ch; //Add this character to the command line
break;
}
}
}
void processMotors() {
//Drive the motors to reduce the azimuth and elevation error to zero
int azPos = azSet;
int elPos = elSet;
azPos = map(azPos, 0, 360, 0, 32000);
elPos = map(elPos, 0, 360, 0, 32000);
digitalWrite(azDirPin, ((azPos-azPosition)>0?HIGH:LOW));
digitalWrite(elDirPin, ((elPos-elPosition)>0?HIGH:LOW));
azMot.drive(abs(azPos-azPosition));
elMot.drive(abs(elPos-elPosition));
azPosition=azPos;
elPosition=elPos;
az=azSet;
el=elSet;
}
void setup() {
//Initialize the serial port
SerialPort.begin(9600);
}
void loop() {
//Repeat continuously
processCommands(); //Process commands from the control computer
processMotors(); //Process motor drive
}