Skip to content

Commit d6ffeef

Browse files
Merge pull request #55 from CTetford/develop
Reorganize NEMA pins & AutoPA Update
2 parents 3dc600d + 80d41f9 commit d6ffeef

File tree

4 files changed

+92
-94
lines changed

4 files changed

+92
-94
lines changed

Software/Addons/AutoPA/altaz.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55

66
def altaz(axis, errorvalue, serialport):
7-
if not re.match(r"^[-+]?([0-9]*\.[0-9]+|[0-9]+)$", errorvalue):
7+
if not re.match(r"^[-+]?([0-9]*\.[0-9]+|[0-9]+)$", str(errorvalue)):
88
print("Error value not valid")
99
return
1010

@@ -20,9 +20,7 @@ def altaz(axis, errorvalue, serialport):
2020
return
2121

2222
#print(command) #For debugging
23-
2423
ser = serial.Serial(serialport, 57600, timeout = 1)
25-
#commandToSend = ':Sr16:00:00#:MS#'
2624
ser.write(str(commandToSend).encode())
2725
return
2826

Software/Addons/AutoPA/polaralign.py

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,64 @@
66
from astropy.utils import iers
77
import sys, subprocess
88

9-
def polarcalc(mylat, mylong, myelev, time, p1RA, p1DEC, p2RA, p2DEC, p3RA, p3DEC):
10-
#iers.conf.auto_download = False
11-
#iers.conf.auto_max_age = None
12-
13-
#Create time object based on given time
14-
observing_time = Time('2020-08-10 3:00:05')
15-
16-
#Create location object based on lat/long/elev
17-
observing_location = EarthLocation(lat=mylat*u.deg, lon=mylong*u.deg, height=177*u.m)
18-
19-
#Create coordinate objects for each point
20-
p1 = SkyCoord(p1RA, p1DEC, unit='deg')
21-
p2 = SkyCoord(p2RA, p2DEC, unit='deg')
22-
p3 = SkyCoord(p3RA, p3DEC, unit='deg')
23-
p1X = (90 - p1.dec.degree) * math.cos(p1.ra.radian)
24-
p1Y = (90 - p1.dec.degree) * math.sin(p1.ra.radian)
25-
p2X = (90 - p2.dec.degree) * math.cos(p2.ra.radian)
26-
p2Y = (90 - p2.dec.degree) * math.sin(p2.ra.radian)
27-
p3X = (90 - p3.dec.degree) * math.cos(p3.ra.radian)
28-
p3Y = (90 - p3.dec.degree) * math.sin(p3.ra.radian)
29-
30-
#Calculate center of circle using three points in the complex plane. DEC is treated as unitless for the purposes of the calculation.
31-
x, y, z = complex(p1X,p1Y), complex(p2X,p2Y), complex(p3X,p3Y)
32-
w = z-x
33-
w /= y-x
34-
c = (x-y)*(w-abs(w)**2)/2j/w.imag-x
35-
resultX = -c.real
36-
resultY = c.imag
37-
38-
#Convert X/Y values of circle into RA/DEC
39-
resultDEC = (90 - math.sqrt(resultX**2 + resultY**2))
40-
resultRA = math.atan2(resultY, resultX)*360 / (2*math.pi)
41-
if resultRA < 0:
42-
resultRA = (180-abs(resultRA))+180
43-
44-
#Create coordinate object for current alignment offset
45-
offset = SkyCoord(resultRA, resultDEC, frame='icrs', unit='deg')
46-
print(f"Current alignment in RA/DEC: {offset.ra.to_string(u.hour, precision=2)}/{offset.dec.to_string(u.deg, precision=2)}.")
47-
48-
#Create coordinate object for pole
49-
pole = SkyCoord(0, 90, frame='icrs', unit='deg')
50-
51-
#Create coordinate object for pole
52-
poleAzAlt = pole.transform_to(AltAz(obstime=observing_time,location=observing_location))
53-
print(f"True polar alignment in Az./Alt.: 0h00m00s/{Angle(mylat*u.degree).to_string(u.degree, sep=('d', 'm', 's'), precision=2)}.")
54-
55-
#Transform current alignment to Alt/Az coordinate system
56-
#offsetAzAlt = offset.transform_to(AltAz(obstime=observing_time,location=observing_location, temperature=25*u.deg_C, pressure=101325*u.Pa, relative_humidity=0.5))
57-
offsetAzAlt = offset.transform_to(AltAz(obstime=observing_time,location=observing_location))
58-
print(f"Current alignment in Az./Alt.: {offsetAzAlt.az.to_string(u.hour, precision=2)}/{offsetAzAlt.alt.to_string(u.deg, precision=2)}.")
59-
60-
#Calculate offset deltas from pole
61-
if offsetAzAlt.az.deg < 180:
62-
errorAz = -offsetAzAlt.az.deg*60
63-
else:
64-
errorAz = (360-offsetAzAlt.az.deg)*60
65-
print(f"Azimuth error correction is: {errorAz:.4f} arcminutes.")
66-
errorAlt = (mylat - offsetAzAlt.alt.deg)*60
67-
print(f"Altitude error correction is: {errorAlt:.4f} arcminutes.")
68-
69-
return errorAz, errorAlt
9+
def polarcalc(mylat, mylong, myelev, observing_time, p1RA, p1DEC, p2RA, p2DEC, p3RA, p3DEC):
10+
#iers.conf.auto_download = False
11+
#iers.conf.auto_max_age = None
12+
13+
#Create time object based on given time
14+
observing_time = Time(observing_time)
15+
16+
#Create location object based on lat/long/elev
17+
observing_location = EarthLocation(lat=mylat*u.deg, lon=mylong*u.deg, height=myelev*u.m)
18+
19+
#Create coordinate objects for each point
20+
p1 = SkyCoord(p1RA, p1DEC, unit='deg')
21+
p2 = SkyCoord(p2RA, p2DEC, unit='deg')
22+
p3 = SkyCoord(p3RA, p3DEC, unit='deg')
23+
p1X = (90 - p1.dec.degree) * math.cos(p1.ra.radian)
24+
p1Y = (90 - p1.dec.degree) * math.sin(p1.ra.radian)
25+
p2X = (90 - p2.dec.degree) * math.cos(p2.ra.radian)
26+
p2Y = (90 - p2.dec.degree) * math.sin(p2.ra.radian)
27+
p3X = (90 - p3.dec.degree) * math.cos(p3.ra.radian)
28+
p3Y = (90 - p3.dec.degree) * math.sin(p3.ra.radian)
29+
30+
#Calculate center of circle using three points in the complex plane. DEC is treated as unitless for the purposes of the calculation.
31+
x, y, z = complex(p1X,p1Y), complex(p2X,p2Y), complex(p3X,p3Y)
32+
w = z-x
33+
w /= y-x
34+
c = (x-y)*(w-abs(w)**2)/2j/w.imag-x
35+
resultX = -c.real
36+
resultY = c.imag
37+
38+
#Convert X/Y values of circle into RA/DEC
39+
resultDEC = (90 - math.sqrt(resultX**2 + resultY**2))
40+
resultRA = math.atan2(resultY, resultX)*360 / (2*math.pi)
41+
if resultRA < 0:
42+
resultRA = (180-abs(resultRA))+180
43+
44+
#Create coordinate object for current alignment offset
45+
offset = SkyCoord(resultRA, resultDEC, frame='itrs', unit='deg', representation_type='spherical', obstime=Time(observing_time))
46+
print(f"Current alignment in RA/DEC: {Angle(resultRA*u.deg).to_string(u.hour, precision=2)}/{Angle(resultDEC*u.deg).to_string(u.degree, precision=2)}.")
47+
48+
#Create coordinate object for pole
49+
pole = SkyCoord(0, 90, frame='itrs', unit='deg', representation_type='spherical', obstime=Time(observing_time))
50+
51+
#Create coordinate object for pole
52+
poleAzAlt = pole.transform_to(AltAz(obstime=Time(observing_time),location=observing_location))
53+
print(f"True polar alignment in Az./Alt.: 0h00m00s/{poleAzAlt.alt.to_string(u.degree, precision=2)}.")
54+
55+
#Transform current alignment to Alt/Az coordinate system
56+
offsetAzAlt = offset.transform_to(AltAz(obstime=Time(observing_time),location=observing_location))
57+
print(f"Current alignment in Az./Alt.: {offsetAzAlt.az.to_string(u.hour, precision=2)}/{offsetAzAlt.alt.to_string(u.degree, precision=2)}.")
58+
59+
#Calculate offset deltas from pole
60+
#Normalize the azimuth values to between -180 and 180 degrees prior to determining offset.
61+
errorAz = (((poleAzAlt.az.deg + 180) % 360 - 180)-((offsetAzAlt.az.deg + 180) % 360 - 180))*60
62+
print(f"Azimuth error correction is: {errorAz:.4f} arcminutes.")
63+
errorAlt = (poleAzAlt.alt.deg-offsetAzAlt.alt.deg)*60
64+
print(f"Altitude error correction is: {errorAlt:.4f} arcminutes.")
65+
66+
return errorAz, errorAlt
7067

7168
#Latitude in degrees
7269
mylat = float(sys.argv[1])
@@ -75,42 +72,45 @@ def polarcalc(mylat, mylong, myelev, time, p1RA, p1DEC, p2RA, p2DEC, p3RA, p3DEC
7572
mylong = float(sys.argv[2])
7673

7774
#Elevation in meters
78-
myelev = sys.argv[3]
75+
myelev = float(sys.argv[3])
7976

8077
#YYYY-MM-DD HH:MM:SS format
8178
time = sys.argv[4]
8279

8380
#All RA/DEC values must be in compatible format to Astropy.coordinates library.
8481
#Preferrably degrees, but 00h00m00.0s and 00d00m00.0s should also work
85-
p1RA = sys.argv[5]
86-
p1DEC = sys.argv[6]
87-
p2RA = sys.argv[7]
88-
p2DEC = sys.argv[8]
89-
p3RA = sys.argv[9]
90-
p3DEC = sys.argv[10]
82+
p1RA = float(sys.argv[5])
83+
p1DEC = float(sys.argv[6])
84+
p2RA = float(sys.argv[7])
85+
p2DEC = float(sys.argv[8])
86+
p3RA = float(sys.argv[9])
87+
p3DEC = float(sys.argv[10])
9188

9289
#Serial port address for Arduino, typically /dev/ttyACM0 in Astroberry, possibly /dev/ttyACM1
93-
serialport = sys.argv[11]
90+
if len(sys.argv) <= 11:
91+
serialport = "/dev/ttyACM0"
92+
else:
93+
serialport = sys.argv[11]
9494

9595
result = polarcalc(mylat, mylong, myelev, time, p1RA, p1DEC, p2RA, p2DEC, p3RA, p3DEC)
9696

97-
#Verify error correction values can be handled by AutoPA hardware (assuming it is in home/centered position)
97+
#Verify error correction can be handled by AutoPA hardware (assuming it is in home/centered position)
9898
moveAz = "N"
9999
if abs(result[0]) > 120:
100-
moveAz = input("Azimuth error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
100+
moveAz = input("Azimuth error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
101101
else:
102-
moveAz = "Y"
102+
moveAz = "Y"
103103
if moveAz.upper() == "Y":
104-
#Call process to move azimuth using elevated privileges to override any existing serial connection
105-
subprocess.call(['sudo', './altaz.py', "az", str(result[0]), serialport])
104+
#Call process to move azimuth using elevated privileges to override any existing serial connection
105+
subprocess.call(['sudo', './altaz.py', "az", str(result[0]), serialport])
106106

107107
moveAlt = "N"
108108
if result[1] > 168:
109-
moveAz = input("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
109+
moveAz = input("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
110110
elif result[1] > 432:
111-
moveAz = input("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
111+
moveAz = input("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): ")
112112
else:
113-
moveAlt = "Y"
113+
moveAlt = "Y"
114114
if moveAlt.upper() == "Y":
115-
#Call process to move altitude using elevated privileges to override any existing serial connection
116-
subprocess.call(['sudo', './altaz.py', "alt", str(result[1]), serialport])
115+
#Call process to move altitude using elevated privileges to override any existing serial connection
116+
subprocess.call(['sudo', './altaz.py', "alt", str(result[1]), serialport])

Software/Addons/AutoPA/polaralign_calibration.py renamed to Software/Addons/AutoPA/polaralign_manualcalibration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def polarcalibrate(mylat, mylong, myelev):
1111
#iers.conf.auto_max_age = None
1212

1313
#Create location object based on lat/long/elev
14-
observing_location = EarthLocation(lat=mylat*u.deg, lon=mylong*u.deg, height=177*u.m)
14+
observing_location = EarthLocation(lat=mylat*u.deg, lon=mylong*u.deg, height=myelev*u.m)
1515

1616
p1RA = input("Enter first RA value in 00h00m00.0s format: ")
1717
p1DEC = input("Enter first DEC value in 00d00m00.0s format: ")
@@ -52,6 +52,6 @@ def polarcalibrate(mylat, mylong, myelev):
5252
mylong = float(sys.argv[2])
5353

5454
#Elevation in meters
55-
myelev = sys.argv[3]
55+
myelev = float(sys.argv[3])
5656

5757
polarcalibrate(mylat, mylong, myelev)

Software/Arduino code/OpenAstroTracker/Configuration_pins.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@
1717
// If using NEMA steppers
1818
#define RA_STEP_PIN 22 // STEP
1919
#define RA_DIR_PIN 24 // DIR
20-
#define RA_EN_PIN 25 // Enable
20+
#define RA_EN_PIN 26 // Enable
21+
#define RA_DIAG_PIN 28 // only needed for autohome function
2122
#define RA_MS0_PIN 30, HIGH //
2223
#define RA_MS1_PIN 32, HIGH
2324
#define RA_MS2_PIN 34, HIGH
2425
//RA TMC2209 UART specific pins
2526
#define RA_SERIAL_PORT Serial3 // HardwareSerial port, wire to TX3 for write-only
2627
#define RA_DRIVER_ADDRESS 0b00 // Set by MS1/MS2. LOW/LOW in this case
27-
#define RA_DIAG_PIN 40 // only needed for autohome function
2828

29-
#define DEC_STEP_PIN 26 // STEP
30-
#define DEC_DIR_PIN 28 // DIR
31-
#define DEC_EN_PIN 29 // Enable
29+
#define DEC_STEP_PIN 23 // STEP
30+
#define DEC_DIR_PIN 25 // DIR
31+
#define DEC_EN_PIN 27 // Enable
32+
#define DEC_DIAG_PIN 29 // only needed for autohome function
3233
#define DEC_MS0_PIN 31 //
3334
#define DEC_MS1_PIN 33
3435
#define DEC_MS2_PIN 35
3536
//DEC TMC2209 UART specific pins
3637
#define DEC_SERIAL_PORT Serial3 // HardwareSerial port, wire to TX2 for write-only
3738
#define DEC_DRIVER_ADDRESS 0b01 // Set by MS1/MS2 (MS1 HIGH, MS2 LOW)
38-
#define DEC_DIAG_PIN 41 // only needed for autohome function
3939

4040
#if AZIMUTH_ALTITUDE_MOTORS == 1
4141
// Azimuth and Altitude pins
42-
#define AZ_IN1_PIN 38
43-
#define AZ_IN2_PIN 40
44-
#define AZ_IN3_PIN 42
45-
#define AZ_IN4_PIN 44
4642
#define ALT_IN1_PIN 46
4743
#define ALT_IN2_PIN 48
4844
#define ALT_IN3_PIN 50
4945
#define ALT_IN4_PIN 52
46+
#define AZ_IN1_PIN 47
47+
#define AZ_IN2_PIN 49
48+
#define AZ_IN3_PIN 51
49+
#define AZ_IN4_PIN 53
5050
#endif
5151
//---------------
5252
// MISC PINS amd SETTINGS

0 commit comments

Comments
 (0)