FACT++  1.0
template<class T , class S >
void StateMachineDrive< T, S >::TrackingLoop ( const boost::system::error_code &  error = boost::system::error_code())
inlineprivate

Definition at line 2415 of file drivectrl.cc.

References Local::az, data, dev, Error(), Drive::State::kAllowedRangeExceeded, Drive::State::kOnTrack, Drive::State::kTracking, Time::Mjd(), PointingData::mount, PointingData::sky, str, and Local::zd.

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

2416  {
2417  if (error==ba::error::basic_errors::operation_aborted)
2418  return;
2419 
2420  if (error)
2421  {
2422  ostringstream str;
2423  str << "TrackingLoop: " << error.message() << " (" << error << ")";// << endl;
2424  T::Error(str);
2425  return;
2426  }
2427 
2428  if (T::GetCurrentState()!=State::kTracking &&
2429  T::GetCurrentState()!=State::kOnTrack)
2430  return;
2431 
2432  //
2433  // Update speed as often as possible.
2434  // make sure, that dt is around 10 times larger than the
2435  // update time
2436  //
2437  // The loop should not be executed faster than the ramp of
2438  // a change in the velocity can be followed.
2439  //
2440  fTrackingLoop.expires_from_now(boost::posix_time::milliseconds(250));
2441 
2442  const double mjd = Time().Mjd();
2443 
2444  // I assume that it takes about 50ms for the value to be
2445  // transmitted and the drive needs time to follow as well (maybe
2446  // more than 50ms), therefore the calculated speec is calculated
2447  // for a moment 50ms in the future
2448  const PointingData data = CalcPointingPos(fDrive.GetSeTime());
2449  const PointingData data0 = CalcPointingPos(mjd-0.45/24/3600);
2450  const PointingData data1 = CalcPointingPos(mjd+0.55/24/3600);
2451 
2452  const Encoder dest = data.mount *(1./360); // [rev]
2453  const Encoder dest0 = data0.mount*(1./360); // [rev]
2454  const Encoder dest1 = data1.mount*(1./360); // [rev]
2455 
2456  if (!CheckRange(data1.sky))
2457  {
2458  StopMovement();
2459  T::HandleNewState(State::kAllowedRangeExceeded, 0, "by TrackingLoop");
2460  return;
2461  }
2462 
2463  // Current position
2464  const Encoder sepos = fDrive.GetSePos(); // [rev]
2465 
2466  // Now calculate the current velocity
2467  const Encoder dist = dest1 - dest0; // [rev] Distance between t-1s and t+1s
2468  const Velocity vel = dist/(1./60); // [rev/min] Actual velocity of the pointing position
2469 
2470  const Encoder dev = sepos - dest; // [rev] Current control deviation
2471  const Velocity vt = vel - dev/(1./60); // [rev/min] Correct velocity by recent control deviation
2472  // correct control deviation with 5s
2473  if (fDrive.GetVerbosity()>1)
2474  {
2475  T::Out() << "Ideal position [deg] " << dest.zd *360 << " " << dest.az *360 << endl;
2476  T::Out() << "Encoder pos. [deg] " << sepos.zd*360 << " " << sepos.az*360 << endl;
2477  T::Out() << "Deviation [arcmin] " << dev.zd *360*60 << " " << dev.az *360*60 << endl;
2478  T::Out() << "Distance 1s [arcmin] " << dist.zd *360*60 << " " << dist.az *360*60 << endl;
2479  T::Out() << "Velocity 1s [rpm] " << vt.zd << " " << vt.az << endl;
2480  T::Out() << "Delta T (enc) [ms] " << fabs(mjd-fDrive.fPdoTime2[0].Mjd())*24*3600*1000 << endl;
2481  T::Out() << "Delta T (now) [ms] " << (Time().Mjd()-mjd)*24*3600*1000 << endl;
2482  }
2483 
2484  // Tracking loop every 250ms
2485  // Vorsteuerung 2s
2486  // Delta T (enc) 5ms, every 5th, 25ms
2487  // Delta T (now) equal dist 5ms-35 plus equal dist 25-55 (0.2%-2% of 2s)
2488 
2489  //
2490  // FIXME: check if the drive is fast enough to follow the star
2491  //
2492  // Velocity units (would be 100 for %)
2493 
2494  fDrive.SetTrackingVelocity(vt);
2495 
2496  fTrackingLoop.async_wait(boost::bind(&StateMachineDrive::TrackingLoop,
2497  this, ba::placeholders::error));
2498  }
ba::deadline_timer fTrackingLoop
Definition: drivectrl.cc:1566
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
double zd
Definition: drivectrl.cc:51
PointingData CalcPointingPos(double mjd)
Definition: drivectrl.cc:1815
double az
Definition: drivectrl.cc:52
void Mjd(double mjd)
Definition: Time.cc:145
Encoder mount
Definition: drivectrl.cc:168
void TrackingLoop(const boost::system::error_code &error=boost::system::error_code())
Definition: drivectrl.cc:2415
float data[4 *1440]
Return to feeserver c CVS log Up to[MAIN] dcscvs FeeServer feeserver src Wed FeeServer_v0 v0 dev
Definition: feeserver.c:5
Error()
Definition: HeadersFTM.h:197
bool CheckRange(ZdAz pos)
Definition: drivectrl.cc:1786

+ Here is the call graph for this function:

+ Here is the caller graph for this function: