6 #include <boost/tr1/array.hpp>
10 #include "coordConv/coordConv.h"
42 double computeObjAzInstAng(
58 double porX0, porY0, porX1, porY1;
59 tcsQpor(&tcsPOrig0.
porig, &tscope, &porX0, &porY0);
60 tcsQpor(&tcsPOrig1.
porig, &tscope, &porX1, &porY1);
63 double astEquat0, astPolar0, astEquat1, astPolar1;
64 tcsVTsky(roll, pitch, &ast, rot, porX0, porY0, &tscope, ga, gb, &astEquat0, &astPolar0);
66 tcsVTsky(roll, pitch, &ast, rot, porX1, porY1, &tscope, ga, gb, &astEquat1, &astPolar1);
68 return -90 - (slaDbear(astEquat0, astPolar0, astEquat1, astPolar1) / coordConv::RadPerDeg);
89 double &roll,
double &pitch,
double &rot,
96 double predRoll,
double predPitch,
double predRot
99 double aimx, aimy, aimz;
100 double pox = porig.p[0] / tcsTScope.
tel.fl;
101 double poy = porig.p[1] / tcsTScope.
tel.fl;
103 targ.op0[0], targ.op0[1],
105 predRot, predRoll, predPitch,
110 &roll, &pitch, &duma, &dumb);
113 throw std::runtime_error(
"Too near pole (should not happen)");
115 std::cerr <<
"*** tcsTrack error: could not compute roll and pitch; here are the inputs and outputs:" << std::endl;
116 std::cerr <<
"targ.op0=" << targ.op0[0] <<
", " << targ.op0[1] << std::endl;
117 std::cerr <<
"tcsAstrom (only .m_ast is used)=" << tcsAstrom << std::endl;
118 std::cerr <<
"predRot=" << predRot << std::endl;
119 std::cerr <<
"predRoll=" << predPitch << std::endl;
120 std::cerr <<
"pox=" << pox << std::endl;
121 std::cerr <<
"poy=" << poy << std::endl;
122 std::cerr <<
"tcsTScope (only .tel is used)=" << tcsTScope << std::endl;
123 std::cerr <<
"ga=" << ga << std::endl;
124 std::cerr <<
"gb=" << gb << std::endl;
125 throw std::runtime_error(
"Could not compute roll and pitch");
131 predRot, roll, pitch,
140 throw std::runtime_error(
"Could not compute rotator angle");
162 TPMOD &tmod =
const_cast<TPMOD&
>(telMod.
_model);
168 coordConv::PVT netGuideOff[3];
169 for (
int i = 0; i < 3; ++i) {
173 bool computeOrientFromRotPhys =
false;
178 computeOrientFromRotPhys =
true;
181 coordConv::PVT
const rotMount = obj.
rotUser.copy(tai);
184 computeOrientFromRotPhys =
true;
194 computeOrientFromRotPhys =
true;
202 double rollArr[2], pitchArr[2], rotPhysArr[2], objAzInstAngArr[2];
203 for (
int tInd = 0; tInd < 2; ++tInd) {
204 double tempTAI = tai + (
static_cast<double>(tInd) *
DeltaTForVel);
205 double tempTAIDays = tempTAI / coordConv::SecPerDay;
231 std::ostringstream os;
232 os <<
"tcsIfld error: " << stat;
233 throw std::runtime_error(os.str());
256 if ((tInd == 0) || computeOrientFromRotPhys) {
261 predRotPhys = obj.
rotPhys.getPos(tempTAI);
262 }
else if (obj.
actMount[2].isfinite()) {
268 double predPitch, predRoll;
279 double *auxPtr =
const_cast<double *
>(tcsSite.
aux.data());
281 stat = tcsMedium(tempTAIDays, predRoll, predPitch,
tcspk::JBP, auxPtr,
284 std::ostringstream os;
285 os <<
"tcsMedium error: " << stat;
286 throw std::runtime_error(os.str());
293 int const MaxIter = 10;
294 double roll, pitch, rot;
295 bool didConverge =
false;
296 for (
int iter=0; iter < MaxIter; ++iter) {
298 computeMount(roll, pitch, rot,
299 tcsTScope, tcsAstrom, targ, tcsPOrig.porig, fldor, ga, gb, predRoll, predPitch, predRot);
307 if (computeOrientFromRotPhys) {
324 std::ostringstream os;
325 os <<
"computeMount iteration did not converge in " << MaxIter <<
" iterations"
326 <<
"; predRot=" << predRot <<
"; rot=" << rot
327 <<
"; predRoll=" << predRoll <<
"; roll=" << roll
328 <<
"; predPitch=" << predPitch <<
"; pitch=" << pitch;
329 throw std::runtime_error(os.str());
331 rollArr[tInd] = roll;
332 pitchArr[tInd] = pitch;
351 if (computeOrientFromRotPhys) {
354 rotPhysArr[tInd] = obj.
rotPhys.getPos(tempTAI);
355 objAzInstAngArr[tInd] = computeObjAzInstAng(
362 rollArr[tInd], pitchArr[tInd], predRot);
379 if (computeOrientFromRotPhys) {
387 std::cerr <<
"basicMountFromObs warning: obj.objUserInstAng=" << obj.
objUserInstAng
390 <<
"; objAzInstAngArr=" << objAzInstAngArr[0] <<
", " << objAzInstAngArr[1]
400 throw std::runtime_error(
"Bug: computeOrientFromRotPhys false for RotType_Mount");
438 for (
int i = 0; i < 2; ++i) {
441 coordConv::PVT rotObjInstDir, rotObjDist;
442 coordConv::polarFromXY(rotObjDist, rotObjInstDir, -objRotInstXY.
at(0), -objRotInstXY.
at(1),
tai);
443 coordConv::PVT fromDir = rotObjInstDir - obj.
objAzInstAng;
444 coordConv::PVT toDir;
445 coordConv::PVTCoord obsInstPos = obj.
obsPos.offset(toDir, fromDir, rotObjDist);
447 obj.
spiderInstAng = coordConv::wrapCtr(rotObjInstDir - toDir);
bool tcsFromPVT(double &pos, double &vel, coordConv::PVT const &pvt, double tai, bool isAz=false)
coordConv::PVT objAzInstAng
std::tr1::array< double, MAXAUX > aux
auxiliary data for pointing model terms
coordConv::PVT rotAzRotAng
std::tr1::array< coordConv::PVT, NAxes > actMount
double rot_fixed_phys
rotator ID, or 0 if no rotator
TSCOPE tel
telescope information
std::tr1::array< coordConv::PVT, 2 > objInstXY
double rot_scale
rotator mount offset (mount units)
ASTROM r_ast
rotator astrometry information
ASTROM m_ast
mount astrometry information
const double MAX_MOUNT_ERR_RAD
SITE tsite
site information
std::tr1::array< coordConv::PVT, NAxes > targetMount
void basicMountFromObs(Obj &obj, Inst const &inst, TelMod const &telMod, double tai)
std::tr1::array< double, 2 > rot_inst_xy
focus (secondary piston) offset due to instrument (um)
coordConv::PVT rotAzObjAzAng
PORIG porig
pointing origin
int const JBP
false: the telescope never goes below the horizon or beyond 90 alt
void pvtFromTCS(coordConv::PVT &pvt, double posArr[2], double tai, double deltaTAI, bool isAz=false)
const double DeltaTForVel
double rot_inst_ang
position of the center of the rotator in instrument frame (x,y deg)
coordConv::PVT objUserObjAzAng
coordConv::PVT spiderInstAng
double rot_offset
mount pos = offet + (scale * physical pos)
coordConv::PVT objUserInstAng
const float DELTA_ANGLE_DEG
double rotTcsFromPhys(double rotPhys, tcc::InstPosition const &instPos)
coordConv::PVTCoord obsPos
void initTarget(TARG &tar, coordConv::PVTCoord const &obsPos, double tai) const
std::tr1::array< coordConv::PVT, NAxes > calibOff
void update(double tai, coordConv::Site const &site)
std::tr1::array< coordConv::PVT, NAxes > guideOff
double rotPhysFromTcs(double rotTcs, tcc::InstPosition const &instPos)
reference at(size_type __n)