Skip to content

Commit

Permalink
Teld: separate tarAltAz from telAltAz
Browse files Browse the repository at this point in the history
Some smaller patches and repairs are also included.
  • Loading branch information
jstrobl committed Jun 21, 2022
1 parent 6293c78 commit 02a7da4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
16 changes: 14 additions & 2 deletions include/teld.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ class Telescope:public rts2core::Device
*
* @see moveAltAz()
*/
void setTargetAltAz (double alt, double az) { telAltAz->setValueAltAz (alt, az); }
void setTargetAltAz (double alt, double az) { tarAltAz->setValueAltAz (alt, az); }

/**
* Return target position. This is equal to ORI[RA|DEC] +
Expand Down Expand Up @@ -744,6 +744,18 @@ class Telescope:public rts2core::Device
*/
void getTargetAltAz (struct ln_hrz_posn *hrz, double jd);

/**
* Returns ALT AZ coordinates of previously set "ALTAZ" target (only returns coordinates, stored in tarAltAz variable).
* Don't confuse this with getTargetAltAz (), which really recomputes coordinates of the current target stored in OBJ.
*
* @param hrz ALT AZ coordinates of target.
*/
void getTarAltAz (struct ln_hrz_posn *hrz)
{
hrz->alt = tarAltAz->getAlt ();
hrz->az = tarAltAz->getAz ();
}

double getTargetHa ();
double getTargetHa (double jd);

Expand Down Expand Up @@ -1296,7 +1308,7 @@ class Telescope:public rts2core::Device
/**
* Target HRZ coordinates.
*/
struct ln_hrz_posn tarAltAz;
rts2core::ValueAltAz *tarAltAz;

/**
* Target HRZ coordinates with corrections applied.
Expand Down
48 changes: 38 additions & 10 deletions lib/rts2tel/teld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Telescope::Telescope (int in_argc, char **in_argv, bool diffTrack, bool hasTrack
}

createValue (tarRaDec, "TAR", "target position with computed corrections (precession, refraction, aberation) applied", true);
createValue (tarAltAz, "TAR_ALTAZ", "target position when set in horizontal coordinates", true, RTS2_VALUE_WRITABLE);

createValue (corrRaDec, "CORR_", "correction from closed loop", true, RTS2_DT_DEG_DIST_180 | RTS2_VALUE_WRITABLE, 0);
corrRaDec->setValueRaDec (0, 0);
Expand Down Expand Up @@ -274,7 +275,7 @@ Telescope::Telescope (int in_argc, char **in_argv, bool diffTrack, bool hasTrack
break;
}

createValue (telAltAz, "TEL_", "horizontal telescope coordinates", true, RTS2_VALUE_WRITABLE);
createValue (telAltAz, "TEL_", "horizontal telescope coordinates", true);

createValue (mpec, "mpec_target", "MPEC string (used for target calculation, if set)", false, RTS2_VALUE_WRITABLE);
createValue (mpec_refresh, "mpec_refresh", "refresh MPEC ra_diff and dec_diff every mpec_refresh seconds", false, RTS2_VALUE_WRITABLE);
Expand Down Expand Up @@ -435,7 +436,7 @@ Telescope::Telescope (int in_argc, char **in_argv, bool diffTrack, bool hasTrack

addOption ('r', NULL, 1, "telescope rotang");
addOption (OPT_HORIZON, "horizon", 1, "telescope hard horizon");
addOption (OPT_CORRECTION, "max-correction", 1, "correction limit (in arcsec)");
addOption (OPT_CORRECTION, "max-correction", 1, "correction limit (in degrees)");
addOption (OPT_WCS_MULTI, "wcs-multi", 1, "letter for multiple WCS (A-Z,-)");
addOption (OPT_DEC_UPPER_LIMIT, "dec-upper-limit", 1, "maximal declination the telescope is able to point to");
addOption (OPT_DUT1_USNO, "dut1-filename", 1, "filename of USNO DUT1 offset file");
Expand Down Expand Up @@ -793,6 +794,7 @@ void Telescope::calculateCorrAltAz ()
{
struct ln_equ_posn equ_target;
struct ln_equ_posn equ_corr;
struct ln_hrz_posn targetAltAz;

struct ln_lnlat_posn observer;

Expand All @@ -809,14 +811,17 @@ void Telescope::calculateCorrAltAz ()
observer.lng = telLongitude->getValueDouble ();
observer.lat = telLatitude->getValueDouble ();

targetAltAz.alt = tarAltAz->getAlt ();
targetAltAz.az = tarAltAz->getAz ();

double ast = ln_get_apparent_sidereal_time(jd);

ln_get_hrz_from_equ_sidereal_time (&equ_target, &observer, ast, &tarAltAz);
ln_get_hrz_from_equ_sidereal_time (&equ_target, &observer, ast, &targetAltAz);

if (corrRaDec->getRa () == 0 && corrRaDec->getDec () == 0)
{
corrAltAz.alt = tarAltAz.alt;
corrAltAz.az = tarAltAz.az;
corrAltAz.alt = targetAltAz.alt;
corrAltAz.az = targetAltAz.az;
}
else
{
Expand All @@ -831,7 +836,7 @@ double Telescope::getCorrZd ()

calculateCorrAltAz ();

return corrAltAz.alt - tarAltAz.alt;
return corrAltAz.alt - tarAltAz->getAlt ();
}

double Telescope::getCorrAz ()
Expand All @@ -841,7 +846,7 @@ double Telescope::getCorrAz ()

calculateCorrAltAz ();

return tarAltAz.az - corrAltAz.az;
return tarAltAz->getAz () - corrAltAz.az;
}

double Telescope::getTargetDistance ()
Expand Down Expand Up @@ -1037,6 +1042,7 @@ void Telescope::valueChanged (rts2core::Value * changed_value)
if (changed_value == oriRaDec)
{
mpec->setValueString ("");
tarAltAz->setValueAltAz (NAN, NAN);
startResyncMove (NULL, 0);
}
if (changed_value == mpec)
Expand All @@ -1048,7 +1054,7 @@ void Telescope::valueChanged (rts2core::Value * changed_value)
{
startOffseting (changed_value);
}
if (changed_value == telAltAz)
if (changed_value == tarAltAz)
{
moveAltAz ();
}
Expand Down Expand Up @@ -1426,6 +1432,7 @@ int Telescope::initValues ()
#endif
modelRaDec->setValueRaDec (0, 0);
telTargetRaDec->setFromValue (telRaDec);
tarAltAz->setValueAltAz (NAN, NAN);

if (wcs_crval1 && wcs_crval2)
{
Expand Down Expand Up @@ -2340,6 +2347,7 @@ int Telescope::startResyncMove (rts2core::Connection * conn, int correction)
setOri (NAN, NAN);
objRaDec->setValueRaDec (NAN, NAN);
tarRaDec->setValueRaDec (NAN, NAN);
tarAltAz->setValueAltAz (NAN, NAN);
stopMove ();
stopTracking (NULL);
maskState (TEL_MASK_CORRECTING | TEL_MASK_MOVING | BOP_EXPOSURE | TEL_MASK_TRACK, TEL_NOT_CORRECTING | TEL_OBSERVING | TEL_NOTRACK, "cannot perform move");
Expand All @@ -2359,6 +2367,7 @@ int Telescope::startResyncMove (rts2core::Connection * conn, int correction)
setOri (NAN, NAN);
objRaDec->setValueRaDec (NAN, NAN);
tarRaDec->setValueRaDec (NAN, NAN);
tarAltAz->setValueAltAz (NAN, NAN);
stopMove ();
stopTracking (NULL);
maskState (TEL_MASK_CORRECTING | TEL_MASK_MOVING | BOP_EXPOSURE | TEL_MASK_TRACK, TEL_NOT_CORRECTING | TEL_OBSERVING | TEL_NOTRACK, "cannot perform move");
Expand Down Expand Up @@ -2474,6 +2483,11 @@ int Telescope::setToPark (rts2core::Connection * conn)

int Telescope::startPark (rts2core::Connection * conn)
{
if ((getState () & TEL_MASK_MOVING) == TEL_PARKING)
{
return 0; // the "park" command could easily be repeated, e.g. by dome in some cases
}

if (blockMove->getValueBool () == true)
{
logStream (MESSAGE_ERROR) << "Telescope parking blocked" << sendLog;
Expand Down Expand Up @@ -2520,6 +2534,8 @@ int Telescope::startPark (rts2core::Connection * conn)
telTargetRaDec->resetValueChanged ();
oriRaDec->setValueRaDec (NAN, NAN);
oriRaDec->resetValueChanged ();
tarAltAz->setValueAltAz (NAN, NAN);
tarAltAz->resetValueChanged ();
}

incMoveNum ();
Expand Down Expand Up @@ -2594,7 +2610,12 @@ int Telescope::peek (double ra, double dec)
int Telescope::moveAltAz ()
{
struct ln_hrz_posn hrz;
telAltAz->getAltAz (&hrz);
tarAltAz->getAltAz (&hrz);
if (std::isnan (hrz.alt) || std::isnan (hrz.az))
{
logStream (MESSAGE_ERROR) << "cannot move, null Alt or Az" << sendLog;
return -1;
}
struct ln_lnlat_posn observer;
observer.lng = telLongitude->getValueDouble ();
observer.lat = telLatitude->getValueDouble ();
Expand All @@ -2620,6 +2641,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
return DEVDEM_E_PARAMSNUM;
modelOn ();
setOri (obj_ra, obj_dec);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2634,6 +2656,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
return DEVDEM_E_PARAMSNUM;
modelOn ();
setOri (obj_ra, obj_dec, 2000.0, pmRa / 3600.0, pmDec / 3600.0);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2649,6 +2672,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)

modelOn ();
setOri (obj_ra, obj_dec, epoch, 0, 0);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2666,6 +2690,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)

modelOn ();
setOri (obj_ra, obj_dec, epoch, pmRa / 3600.0, pmDec / 3600.0);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2681,6 +2706,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
obj_ra = getLocSidTime (JD) * 15.0 - obj_ha;

setOri (obj_ra, obj_dec);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2694,6 +2720,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
return DEVDEM_E_PARAMSNUM;
modelOff ();
setOri (obj_ra, obj_dec);
tarAltAz->setValueAltAz (NAN, NAN);
resetMpecTLE ();
startTracking (true);
ret = startResyncMove (conn, 0);
Expand All @@ -2707,6 +2734,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
if (conn->paramNextString (&str) || !conn->paramEnd ())
return DEVDEM_E_PARAMSNUM;
modelOn ();
tarAltAz->setValueAltAz (NAN, NAN);
mpec->setValueString (str);
std::string desc;
if (LibnovaEllFromMPC (&mpec_orbit, desc, str))
Expand All @@ -2730,7 +2758,7 @@ int Telescope::commandAuthorized (rts2core::Connection * conn)
{
if (conn->paramNextDMS (&obj_ra) || conn->paramNextDMS (&obj_dec) || !conn->paramEnd ())
return DEVDEM_E_PARAMSNUM;
telAltAz->setValueAltAz (obj_ra, obj_dec);
tarAltAz->setValueAltAz (obj_ra, obj_dec);
resetMpecTLE (conn->isCommand (COMMAND_TELD_ALTAZ_NC));
stopTracking ("stop tracking while in AltAz");
return moveAltAz () == 0 ? DEVDEM_OK : DEVDEM_E_PARAMSVAL;
Expand Down
2 changes: 1 addition & 1 deletion src/teld/nexstar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int NexStar::startResync ()
int NexStar::moveAltAz ()
{
struct ln_hrz_posn hrz;
telAltAz->getAltAz (&hrz);
getTarAltAz (&hrz);
setPreciseDeg ('b', hrz.az, hrz.alt);
maskState (TEL_MASK_MOVING | TEL_MASK_CORRECTING | TEL_MASK_NEED_STOP | BOP_EXPOSURE, TEL_MOVING | BOP_EXPOSURE, "move started");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/teld/sitech-altaz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ int SitechAltAz::startResync ()
int SitechAltAz::moveAltAz ()
{
struct ln_hrz_posn hrz;
telAltAz->getAltAz (&hrz);
getTarAltAz (&hrz);

int32_t taz = r_az_pos->getValueLong ();
int32_t talt = r_alt_pos->getValueLong ();
Expand Down

0 comments on commit 02a7da4

Please sign in to comment.