FACT++  1.0
template<class T , class S >
int StateMachineDrive< T, S >::HandleTPoint ( const EventImp evt)
inlineprivate

Definition at line 1630 of file drivectrl.cc.

References Local::az, PointingModel::CalcPointingPos(), data, RaDec::dec, dev, Drive::DimTPoint::fCenterMag, Drive::DimTPoint::fCenterX, Drive::DimTPoint::fCenterY, Drive::DimTPoint::fDec, Drive::DimTPoint::fDx, Drive::DimTPoint::fDy, Drive::DimTPoint::fFeedbackAz, Drive::DimTPoint::fFeedbackZd, Drive::DimTPoint::fNominalAz, Drive::DimTPoint::fNominalZd, Drive::DimTPoint::fNumLeds, Drive::DimTPoint::fNumRings, Drive::DimTPoint::fPointingAz, Drive::DimTPoint::fPointingZd, Drive::DimTPoint::fRa, Drive::DimTPoint::fRealMag, Drive::DimTPoint::fRotation, Drive::DimTPoint::fStarMag, Drive::DimTPoint::fStarX, Drive::DimTPoint::fStarY, EventImp::GetSize(), EventImp::GetTime(), Source::mag, Time::Mjd(), PointingData::mjd, PointingData::mount, Source::name, Time::NightAsInt(), PointingData::pointing, EventImp::Ptr(), RaDec::ra, PointingData::sky, PointingSetup::source, Time::UnixTime(), and Local::zd.

Referenced by StateMachineDrive< T, S >::StateMachineDrive().

1631  {
1632  // Skip disconnect events
1633  if (evt.GetSize()==0)
1634  return T::GetCurrentState();
1635 
1636  // skip invalid events
1637  if (!CheckEventSize(evt.GetSize(), "HandleTPoint", 11*8))
1638  return T::GetCurrentState();
1639 
1640  // skip event which are older than one minute
1641  if (Time().UnixTime()-evt.GetTime().UnixTime()>60)
1642  return T::GetCurrentState();
1643 
1644  // Original code in slaTps2c:
1645  //
1646  // From the tangent plane coordinates of a star of known RA,Dec,
1647  // determine the RA,Dec of the tangent point.
1648 
1649  const double *ptr = evt.Ptr<double>();
1650 
1651  // Tangent plane rectangular coordinates
1652  const double dx = ptr[0] * M_PI/648000; // [arcsec -> rad]
1653  const double dy = ptr[1] * M_PI/648000; // [arcsec -> rad]
1654 
1656 
1657  const double x2 = dx*dx;
1658  const double y2 = 1 + dy*dy;
1659 
1660  const double sd = cos(data.sky.zd);//sin(M_PI/2-sky.zd);
1661  const double cd = sin(data.sky.zd);//cos(M_PI/2-sky.zd);
1662  const double sdf = sd*sqrt(x2+y2);
1663  const double r2 = cd*cd*y2 - sd*sd*x2;
1664 
1665  // Case of no solution ("at the pole") or
1666  // two solutions ("over the pole solution")
1667  if (r2<0 || fabs(sdf)>=1)
1668  {
1669  T::Warn("Could not determine pointing direction from TPoint.");
1670  return T::GetCurrentState();
1671  }
1672 
1673  const double r = sqrt(r2);
1674  const double s = sdf - dy * r;
1675  const double c = sdf * dy + r;
1676  const double phi = atan2(dx, r);
1677 
1678  // Spherical coordinates of tangent point
1679  const double az = fmod(data.sky.az-phi + 2*M_PI, 2*M_PI);
1680  const double zd = M_PI/2 - atan2(s, c);
1681 
1682  const Encoder dev = fDrive.GetSePos()*360 - data.mount;
1683 
1684  // --- Output TPoint ---
1685 
1686  const string fname = "tpoints-"+to_string(evt.GetTime().NightAsInt())+".txt";
1687  //time.GetAsStr("/%Y/%m/%d");
1688 
1689  const bool exist = boost::filesystem::exists(fname);
1690 
1691  ofstream fout(fname, ios::app);
1692  if (!exist)
1693  {
1694  fout << "FACT Model TPOINT data file" << endl;
1695  fout << ": ALTAZ" << endl;
1696  fout << "49 48 0 ";
1697  fout << evt.GetTime() << endl;
1698  }
1699  fout << setprecision(7);
1700  fout << fmod(az*180/M_PI+360, 360) << " ";
1701  fout << 90-zd*180/M_PI << " ";
1702  fout << fmod(data.mount.az+360, 360) << " ";
1703  fout << 90-data.mount.zd << " ";
1704  fout << dev.az << " "; // delta az
1705  fout << -dev.zd << " "; // delta el
1706  fout << 90-data.sky.zd * 180/M_PI << " ";
1707  fout << data.sky.az * 180/M_PI << " ";
1708  fout << setprecision(10);
1709  fout << data.mjd << " ";
1710  fout << setprecision(7);
1711  fout << ptr[6] << " "; // center.mag
1712  fout << ptr[9] << " "; // star.mag
1713  fout << ptr[4] << " "; // center.x
1714  fout << ptr[5] << " "; // center.y
1715  fout << ptr[7] << " "; // star.x
1716  fout << ptr[8] << " "; // star.y
1717  fout << ptr[2] << " "; // num leds
1718  fout << ptr[3] << " "; // num rings
1719  fout << ptr[0] << " "; // dx (de-rotated)
1720  fout << ptr[1] << " "; // dy (de-rotated)
1721  fout << ptr[10] << " "; // rotation angle
1722  fout << fPointingSetup.source.mag << " ";
1723  fout << fPointingSetup.source.name;
1724  fout << endl;
1725 
1726  DimTPoint dim;
1727  dim.fRa = data.pointing.ra * 12/M_PI;
1728  dim.fDec = data.pointing.dec * 180/M_PI;
1729  dim.fNominalZd = data.sky.zd * 180/M_PI;
1730  dim.fNominalAz = data.sky.az * 180/M_PI;
1731  dim.fPointingZd = zd * 180/M_PI;
1732  dim.fPointingAz = az * 180/M_PI;
1733  dim.fFeedbackZd = data.mount.zd;
1734  dim.fFeedbackAz = data.mount.az;
1735  dim.fNumLeds = uint16_t(ptr[2]);
1736  dim.fNumRings = uint16_t(ptr[3]);
1737  dim.fCenterX = ptr[4];
1738  dim.fCenterY = ptr[5];
1739  dim.fCenterMag = ptr[6];
1740  dim.fStarX = ptr[7];
1741  dim.fStarY = ptr[8];
1742  dim.fStarMag = ptr[9];
1743  dim.fRotation = ptr[10];
1744  dim.fDx = ptr[0];
1745  dim.fDy = ptr[1];
1747 
1748  fDrive.UpdateTPoint(evt.GetTime(), dim, fPointingSetup.source.name);
1749 
1750  ostringstream txt;
1751  txt << "TPoint recorded [" << zd*180/M_PI << "/" << az*180/M_PI << " | "
1752  << data.sky.zd*180/M_PI << "/" << data.sky.az*180/M_PI << " | "
1753  << data.mount.zd << "/" << data.mount.az << " | "
1754  << dx*180/M_PI << "/" << dy*180/M_PI << "]";
1755  T::Info(txt);
1756 
1757  return T::GetCurrentState();
1758  }
double mag
Definition: drivectrl.cc:126
string name
Definition: drivectrl.cc:123
PointingSetup fPointingSetup
Definition: drivectrl.cc:1579
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
uint32_t NightAsInt() const
Definition: Time.cc:397
RaDec pointing
Definition: drivectrl.cc:165
double zd
Definition: drivectrl.cc:51
double az
Definition: drivectrl.cc:52
PointingData CalcPointingPos(const PointingSetup &setup, double _mjd, const Weather &weather, uint16_t timeout, bool tpoint=false)
Definition: drivectrl.cc:365
double dec
Definition: drivectrl.cc:37
uint16_t fNumRings
Definition: HeadersDrive.h:74
double UnixTime() const
Definition: Time.cc:195
void Mjd(double mjd)
Definition: Time.cc:145
virtual Time GetTime() const
Definition: EventImp.h:57
Encoder mount
Definition: drivectrl.cc:168
Source source
Definition: drivectrl.cc:151
float data[4 *1440]
PointingModel fPointingModel
Definition: drivectrl.cc:1578
Return to feeserver c CVS log Up to[MAIN] dcscvs FeeServer feeserver src Wed FeeServer_v0 v0 dev
Definition: feeserver.c:5
uint16_t fWeatherTimeout
Definition: drivectrl.cc:1574
bool CheckEventSize(size_t has, const char *name, size_t size)
Definition: cosyctrl.cc:804
const T * Ptr(size_t offset=0) const
Definition: EventImp.h:74
double ra
Definition: drivectrl.cc:36
double mjd
Definition: drivectrl.cc:169
virtual size_t GetSize() const
Definition: EventImp.h:55
uint16_t fNumLeds
Definition: HeadersDrive.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function: