29#include <libnova/julian_day.h>
30#include <libnova/sidereal_time.h>
46 angle = range(value * 15.0);
49 angle = range(value * 180.0 /
M_PI);
56 return this->angle *
M_PI / 180.0;
76 this->target = degrees;
82 this->target = hours * 15.0;
101 switch (trackingRate)
133 guideRateDegSec = (360.0 / 86400) * rate;
134 guideDuration = durationMs / 1000.0;
135 LOGF_DEBUG(
"%s StartGuide rate %f=>%f, dur %d =>%f",
axisName, rate, guideRateDegSec.
Degrees(), durationMs, guideDuration);
140 struct timeval currentTime
146 gettimeofday(¤tTime,
nullptr);
148 if (lastTime.tv_sec == 0 && lastTime.tv_usec == 0)
149 lastTime = currentTime;
152 double interval = currentTime.tv_sec - lastTime.tv_sec + (currentTime.tv_usec - lastTime.tv_usec) / 1e6;
153 lastTime = currentTime;
170 Angle trc = target - rotateCentre;
174 double fastChange = mcRates[4].
Degrees() * interval;
175 double slowChange = fastChange / 5;
178 if (delta < -fastChange)
180 change = -fastChange;
182 else if (delta < -slowChange)
184 change = -slowChange;
186 else if (delta > fastChange)
190 else if (delta > slowChange)
204 int rate = std::max(-4,std::min(4,
mcRate));
212 change = -mcRates[-rate].
Degrees() * interval;
218 change = mcRates[rate].
Degrees() * interval;
224 if (guideDuration > 0)
226 change = guideRateDegSec.
Degrees() * (guideDuration > interval ? interval : guideDuration);
227 guideDuration -= interval;
228 LOGF_DEBUG(
"guide rate %f, remaining duration %f, change %f", guideRateDegSec.
Degrees(), guideDuration, change);
260 seco = (
latitude >= 0) ? secondary : -secondary;
264 seco = (
latitude >= 0) ? secondary : -secondary;
266 if (seco > 90 || seco < -90)
270 prio = primary +
Angle(180.0);
271 seco =
Angle(180.0) - seco;
283 Vector trueAzAlt(*apparentHa -
Angle(180.0), *apparentDec);
301 *apparentRa =
lst() - ha;
320 *instrumentHa = haDec.
primary();
325 *instrumentDec = (
latitude >= 0) ? secondary : -secondary;
326 *instrumentHa = primary;
333 *instrumentHa = primary +
Angle(180.0);
334 *instrumentDec =
Angle(180.0) - seco;
338 *instrumentHa = primary;
339 *instrumentDec = seco;
363 *primary = instrumentHa;
364 *secondary = (
latitude >= 0) ? instrumentDec : -instrumentDec;
367 if (instrumentHa < flipHourAngle)
371 *primary = instrumentHa +
Angle(180);
372 *secondary =
Angle(180) - instrumentDec;
376 *primary = instrumentHa;
377 *secondary = instrumentDec;
380 *secondary = -*secondary;
398 Angle instrumentAz, instrumentAlt;
401 *primary = instrumentAz;
402 *secondary = instrumentAlt;
409 Angle instrumentHa, instrumentDec;
432 *observedHa = instrumentHa + IH;
433 *observedDec = instrumentDec + ID;
436 double cosDec = *observedDec < maxDec ? std::cos(observedDec->
radians()) : std::cos(maxDec.
radians());
437 double tanDec = *observedDec < maxDec ? std::tan(observedDec->
radians()) : std::tan(maxDec.
radians());
439 *observedHa += (CH / cosDec);
441 *observedHa += (NP * tanDec);
473 double tanDec = *instrumentDec < maxDec ? std::tan(instrumentDec->
radians()) : std::tan(maxDec.
radians());
474 *instrumentHa -= (NP * tanDec);
476 double cosDec = *instrumentDec < maxDec ? std::cos(instrumentDec->
radians()) : std::cos(maxDec.
radians());
477 *instrumentHa -= (CH / cosDec);
481 *instrumentDec -= ID;
486 Angle correctionHa, correctionDec;
487 correction(observedHa, observedDec, &correctionHa, &correctionDec);
489 *instrumentHa = observedHa - correctionHa;
490 *instrumentDec = observedDec - correctionDec;
492 static const Angle minDelta(1.0 / 3600.0);
500 correction(*instrumentHa, *instrumentDec, &correctionHa, &correctionDec);
501 newHa = *instrumentHa + correctionHa;
502 newDec = *instrumentDec + correctionDec;
504 dHa = observedHa - newHa;
505 dDec = observedDec - newDec;
514 *instrumentHa += dHa;
515 *instrumentDec += dDec;
524void Alignment::correction(
Angle instrumentHa,
Angle instrumentDec,
Angle * correctionHa,
Angle * correctionDec)
531 static const double minCos = 0.01;
532 static const double maxTan = 100.0;
534 double cosDec = std::cos(instrumentDec.
radians());
535 if (cosDec >= 0 && cosDec < minCos) cosDec = minCos;
536 else if (cosDec <= 0 && cosDec > -minCos) cosDec = -minCos;
538 double tanDec = std::tan(instrumentDec.
radians());
539 if (tanDec > maxTan) tanDec = maxTan;
540 if (tanDec < -maxTan) tanDec = -maxTan;
542 double cosHa = std::cos(instrumentHa.
radians());
543 double sinHa = std::sin(instrumentHa.
radians());
546 *correctionHa += (CH / cosDec);
548 *correctionHa += (NP * tanDec);
551 *correctionHa += (-MA * cosHa * tanDec);
552 *correctionDec += (MA * sinHa);
555 *correctionHa += (ME * sinHa * tanDec);
556 *correctionDec += (ME * cosHa);
578 LOGF_DEBUG(
"setCorrections IH %f, ID %f, CH %f, NP %f, MA %f, ME %f", IH, ID, CH, NP, MA, ME);
587 double len = std::sqrt(x * x + y * y + z * z);
629 double ca = std::cos(angle.
radians());
630 double sa = std::sin(angle.
radians());
631 return Vector(
L,
M * ca +
N * sa,
N * ca -
M * sa);
636 double ca = std::cos(angle.
radians());
637 double sa = std::sin(angle.
radians());
638 return Vector(
L * ca -
N * sa,
M,
L * sa +
N * ca);
643 double ca = std::cos(angle.
radians());
644 double sa = std::sin(angle.
radians());
645 return Vector(
L * ca +
M * sa,
M * ca -
L * sa,
N);
void setCorrections(double ih, double id, double ch, double np, double ma, double me)
setCorrections set the values of the six corrections
void instrumentHaDecToMount(Angle instrumentHa, Angle instrumentDec, Angle *primary, Angle *secondary)
void apparentRaDecToMount(Angle apparentRa, Angle apparentDec, Angle *primary, Angle *secondary)
void mountToApparentHaDec(Angle primary, Angle secondary, Angle *apparentHa, Angle *apparentDec)
mountToApparentHaDec: convert mount position to apparent Ha, Dec
void apparentHaDecToMount(Angle apparentHa, Angle apparentDec, Angle *primary, Angle *secondary)
apparentHaDecToMount
void observedToInstrument(Angle observedHa, Angle observedDec, Angle *instrumentHa, Angle *instrumentDec)
void mountToApparentRaDec(Angle primary, Angle secondary, Angle *apparentRa, Angle *apparentDec)
mountToApparentRaDec: convert mount position to apparent Ra, Dec
void instrumentToObserved(Angle instrumentHa, Angle instrumentDec, Angle *observedHa, Angle *observedDec)
void mountToInstrumentHaDec(Angle primary, Angle secondary, Angle *instrumentHa, Angle *instrumentDec)
mountToInstrumentHaDec: convert mount axis positions to instrument (encoder) HA/Dec without applying ...
The Angle class This class implements an angle type. This holds an angle that is always in the range ...
double Degrees360()
Degrees360.
double difference(Angle a)
bool operator==(const Angle &a)
bool operator!=(const Angle &a)
Angle TrackingRateDegSec
TrackingRateDegSec.
void setDegrees(double degrees)
void StartGuide(double rate, uint32_t durationMs)
StartGuide start guiding.
void Tracking(bool enabled)
AXIS_TRACK_RATE TrackRate()
TrackRate returns the AXIS_TRACK_RATE property.
void StartSlew(Angle angle)
double getTrackingRateDegSec()
AXIS_TRACK_RATE
The AXIS_TRACK_RATE enum defines the common track rates.
void setHours(double hours)
The Vector class This implements the Directional Cosine used by Taki in his Matrix method....
Vector rotateY(Angle angle)
rotateY rotates this vector through angle about the Y axis
Vector rotateX(Angle angle)
rotateX rotates this vector through angle about the X axis
Vector()
Vector creates an empty vector.
Vector rotateZ(Angle angle)
rotateZ rotates this vector through angle about the Z axis
Angle secondary()
secondary returns the secondary angle (dec, altitude) from this vector
Angle primary()
primary returns the primary angle (Ra, Ha, Azimuth) from this vector
double range24(double r)
range24 Limits a number to be between 0-24 range.
Implementations for common driver routines.
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
#define LOGF_EXTRA1(fmt,...)
char device_str[64]
The transformations are based on the paper "Matrix Method for Coordinates Transformation" written by ...