-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpimoco_mount_track.cpp
136 lines (107 loc) · 4.31 KB
/
pimoco_mount_track.cpp
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
134
135
136
/*
PiMoCo: Raspberry Pi Telescope Mount and Focuser Control
Copyright (C) 2021 Markus Noga
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 <https://www.gnu.org/licenses/>.
*/
#include "pimoco_mount.h"
#include "pimoco_time.h"
#include <libindi/indilogger.h>
#include <libindi/indicom.h> // for rangeHA etc.
bool PimocoMount::Abort() {
LOG_INFO("Aborting all motion");
if(!stepperHA .setTargetVelocityArcsecPerSec(0) ||
!stepperDec.setTargetVelocityArcsecPerSec(0) ) {
LOG_ERROR("Aborting all motion");
return false;
}
manualSlewArcsecPerSecRA=manualSlewArcsecPerSecDec=0;
guiderActiveRA=guiderActiveDec=false;
if(TrackState!=SCOPE_PARKED)
TrackState=SCOPE_IDLE;
return true;
}
bool PimocoMount::SetTrackEnabled(bool enabled) {
LOG_INFO(enabled ? "Enabling tracking" : "Disabling tracking");
TrackState=enabled ? SCOPE_TRACKING : SCOPE_IDLE;
// caller resets this if return code is false
return applyTracking();
}
bool PimocoMount::SetTrackMode(uint8_t mode) {
if(mode>TRACK_KING) {
LOGF_ERROR("Invalid tracking mode %d", mode);
return false;
}
double rateRA=getTrackRateRA(), rateDec=getTrackRateDec();
LOGF_INFO("Selecting %s tracking (mode %d) with rate RA %.4f Dec %.4f arcsec/s",
trackRateLabels[mode], mode, rateRA, rateDec);
return applyTracking();
}
bool PimocoMount::syncTrackRate() {
// get time and position
Timestamp ts;
uint64_t now=ts.ms();
double deviceHA, deviceDec;
if(!stepperHA.getPositionHours(&deviceHA) || !stepperDec.getPositionDegrees(&deviceDec))
return false;
// update tracking rate if prior sync is available
if(SyncTrackRateS[0].s==ISS_ON) {
uint64_t deltaMs=now - syncTrackRateMs;
double arcsecPerSecRA =(deviceHA - syncTrackRateHA )*1000.0*60.0*60.0*15.0/(double) deltaMs; // HA is in hours
double arcsecPerSecDec=(deviceDec - syncTrackRateDec)*1000.0*60.0*60.0 /(double) deltaMs; // Dec is in degrees
SetTrackRate(arcsecPerSecRA, arcsecPerSecDec);
SyncTrackRateSP.s=IPS_OK;
} else
SyncTrackRateSP.s=IPS_BUSY;
// update sync position and and trigger GUI update
syncTrackRateHA =deviceHA;
syncTrackRateDec=deviceDec;
syncTrackRateMs =now;
SyncTrackRateS[0].s=ISS_ON;
IDSetSwitch(&SyncTrackRateSP, nullptr);
return true;
}
bool PimocoMount::SetTrackRate(double rateRA, double rateDec) {
trackRateCustomRA =rateRA;
trackRateCustomDec=rateDec;
LOGF_INFO("Setting custom tracking rate to RA %.3f Dec %.3f arcsec/s", rateRA, rateDec);
return applyTracking();
}
double PimocoMount::getArcsecPerSecHA() {
if(TrackState==SCOPE_IDLE && manualSlewArcsecPerSecRA!=0)
return manualSlewArcsecPerSecRA;
else if(TrackState==SCOPE_TRACKING && manualSlewArcsecPerSecRA!=0)
return manualSlewArcsecPerSecRA;
else if(TrackState==SCOPE_TRACKING)
return getTrackRateRA();
return 0;
}
double PimocoMount::getArcsecPerSecDec() {
if(TrackState==SCOPE_IDLE && manualSlewArcsecPerSecDec!=0)
return manualSlewArcsecPerSecDec;
else if(TrackState==SCOPE_TRACKING && manualSlewArcsecPerSecDec!=0)
return manualSlewArcsecPerSecDec;
else if(TrackState==SCOPE_TRACKING)
return getTrackRateDec();
return 0;
}
bool PimocoMount::applyTracking(bool updateRA, bool updateDec) {
double rateRA =(TrackState==SCOPE_TRACKING) ? getTrackRateRA() : 0;
double rateDec=(TrackState==SCOPE_TRACKING) ? getTrackRateDec() : 0;
if(!applyLimits(rateRA, rateDec))
return false;
if((updateRA && !stepperHA .setTargetVelocityArcsecPerSec(rateRA )) ||
(updateDec && !stepperDec.setTargetVelocityArcsecPerSec(rateDec)) ) {
LOG_ERROR("Setting tracking speed");
return false;
}
return true;
}