Skip to content

Commit

Permalink
Draft: Reuse calibration after rotation (indilib#2153)
Browse files Browse the repository at this point in the history
* Fix moving and guiding directions in telescope simulator

* angle directions correction of comments
  • Loading branch information
escribana authored Dec 24, 2024
1 parent c6483e5 commit 76b5329
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
54 changes: 34 additions & 20 deletions drivers/telescope/scopesim_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Axis::StartSlew(Angle angle)
void Axis::Tracking(bool enabled)
{
tracking = enabled;
LOGF_EXTRA1("%s Teacking enabled %s", axisName, enabled ? "true" : "false");
LOGF_EXTRA1("%s Tracking enabled %s", axisName, enabled ? "true" : "false");
}

void Axis::TrackRate(AXIS_TRACK_RATE rate)
Expand Down Expand Up @@ -214,7 +214,7 @@ void Axis::update() // called about once a second to update the position
{
change = guideRateDegSec.Degrees() * (guideDuration > interval ? interval : guideDuration);
guideDuration -= interval;
//LOGF_DEBUG("guide rate %f, remaining duration %f, change %f", guideRateDegSec.Degrees(), guideDuration, change);
LOGF_DEBUG("guide rate %f, remaining duration %f, change %f", guideRateDegSec.Degrees(), guideDuration, change);
position += change;
}
}
Expand All @@ -230,6 +230,8 @@ Angle Alignment::lst()

void Alignment::mountToApparentHaDec(Angle primary, Angle secondary, Angle * apparentHa, Angle* apparentDec)
{
// Primary instrument axis: "Angle" is negative PA-system looking SCP
// Secondary instrument axis: "Angle" is negative PA-system looking E
Angle prio, seco;
// get instrument place
switch (mountType)
Expand All @@ -240,13 +242,16 @@ void Alignment::mountToApparentHaDec(Angle primary, Angle secondary, Angle * app
prio = primary;
break;
case MOUNT_TYPE::EQ_GEM:
seco = (latitude >= 0) ? secondary : -secondary;
prio = primary;
if (seco > 90 || seco < -90)
seco = (latitude >= 0) ? secondary : -secondary; // northern : southern hemisphere
if (seco > 90 || seco < -90) // pierside west/looking east (cf. apperentHaDecToMount())
{
// pointing state inverted
seco = Angle(180.0 - seco.Degrees());
prio += 180.0;
prio = primary + Angle(180.0); // Ha is negative PA-system looking SCP
seco = Angle(180.0) - seco; // Dec is positive PA-system looking E
}
else
{
prio = primary;
seco = secondary;
}
break;
}
Expand All @@ -262,14 +267,17 @@ void Alignment::mountToApparentHaDec(Angle primary, Angle secondary, Angle * app
LOGF_EXTRA1("m2a Azm Alt %f, %f Ha Dec %f, %f rot %f", prio.Degrees(), seco.Degrees(), apparentHa->Degrees(),
apparentDec->Degrees(), rot.Degrees());
}
else
LOGF_EXTRA1("mountToApparentHaDec: pri %f, sec %f to ha %f, dec %f", prio.Degrees(), seco.Degrees(), apparentHa->Degrees(),
apparentDec->Degrees());
}

void Alignment::mountToApparentRaDec(Angle primary, Angle secondary, Angle * apparentRa, Angle* apparentDec)
{
Angle ha;
mountToApparentHaDec(primary, secondary, &ha, apparentDec);
*apparentRa = lst() - ha;
LOGF_EXTRA1("mountToApparentRaDec %f, %f to ha %f, ra %f, %f", primary.Degrees(), secondary.Degrees(), ha.Degrees(),
LOGF_EXTRA1("mountToApparentRaDec: pri %f, sec %f to ha %f, ra %f, dec %f", primary.Degrees(), secondary.Degrees(), ha.Degrees(),
apparentRa->Degrees(), apparentDec->Degrees());
}

Expand All @@ -288,40 +296,46 @@ void Alignment::apparentHaDecToMount(Angle apparentHa, Angle apparentDec, Angle*
LOGF_EXTRA1("a2M haDec %f, %f Azm Alt %f, %f", apparentHa.Degrees(), apparentDec.Degrees(), primary->Degrees(),
secondary->Degrees() );
}
// Ha is negative PA-system looking SCP
// Dec is positive PA-system looking E
Angle instrumentHa, instrumentDec;
// ignore diurnal aberrations and refractions to get observed ha, dec
// apply telescope pointing to get instrument
Angle instrumentHa, instrumentDec;
observedToInstrument(apparentHa, apparentDec, &instrumentHa, &instrumentDec);

switch (mountType)
{
case MOUNT_TYPE::ALTAZ:
break;
case MOUNT_TYPE::EQ_FORK:
*secondary = (latitude >= 0) ? instrumentDec : -instrumentDec;
*primary = instrumentHa;
*secondary = (latitude >= 0) ? instrumentDec : -instrumentDec; // northern : southern hemisphere
break;
case MOUNT_TYPE::EQ_GEM:
*secondary = instrumentDec;
*primary = instrumentHa;
// use the instrument Ha to select the pointing state
if (instrumentHa < flipHourAngle)
if (instrumentHa < flipHourAngle) // pierside west (looking east)
{
// pointing state inverted
*primary += Angle(180);
*secondary = Angle(180) - instrumentDec;
*primary = instrumentHa + Angle(180); // Primary instrument axis: "Angle" is negative PA-system looking SCP
*secondary = Angle(180) - instrumentDec; // Secondary instrument axis: "Angle" is negative PA-system looking E
}
if (latitude < 0)
else
{
*primary = instrumentHa;
*secondary = instrumentDec;
}
if (latitude < 0) // southern hemisphere
*secondary = -*secondary;
break;
}
if (mountType != MOUNT_TYPE::ALTAZ)
LOGF_EXTRA1("apparentHaDecToMount: ha %f, dec %f to pri %f, sec %f", apparentHa.Degrees(), apparentDec.Degrees(), primary->Degrees(),
secondary->Degrees() );
}

void Alignment::apparentRaDecToMount(Angle apparentRa, Angle apparentDec, Angle* primary, Angle* secondary)
{
Angle ha = lst() - apparentRa;
apparentHaDecToMount(ha, apparentDec, primary, secondary);
LOGF_EXTRA1("apparentRaDecToMount ra %f, ha %f, %f to %f, %f", apparentRa.Degrees(), ha.Degrees(), apparentDec.Degrees(),
LOGF_EXTRA1("apparentRaDecToMount: ra %f, ha %f, dec %f to pri %f, sec %f", apparentRa.Degrees(), ha.Degrees(), apparentDec.Degrees(),
primary->Degrees(), secondary->Degrees());
}

Expand Down
6 changes: 6 additions & 0 deletions drivers/telescope/telescope_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ bool ScopeSim::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
mcRate = std::max(1,std::min(4,mcRate));

int rate = (dir == INDI_DIR_NS::DIRECTION_NORTH) ? mcRate : -mcRate;
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopesim_helper.cpp: alignment
rate = -rate;
LOGF_DEBUG("MoveNS dir %s, motion %s, rate %d", dir == DIRECTION_NORTH ? "N" : "S", command == 0 ? "start" : "stop", rate);

axisSecondary.mcRate = command == MOTION_START ? rate : 0;
Expand Down Expand Up @@ -523,6 +525,8 @@ bool ScopeSim::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
IPState ScopeSim::GuideNorth(uint32_t ms)
{
double rate = GuideRateNP[DEC_AXIS].getValue();
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
rate = -rate;
axisSecondary.StartGuide(rate, ms);
guidingNS = true;
return IPS_BUSY;
Expand All @@ -531,6 +535,8 @@ IPState ScopeSim::GuideNorth(uint32_t ms)
IPState ScopeSim::GuideSouth(uint32_t ms)
{
double rate = GuideRateNP[DEC_AXIS].getValue();
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
rate = -rate;
axisSecondary.StartGuide(-rate, ms);
guidingNS = true;
return IPS_BUSY;
Expand Down

0 comments on commit 76b5329

Please sign in to comment.