CARMA C++
Drives.h
Go to the documentation of this file.
1 
11 #ifndef CARMA_ANTENNA_BIMA_DRIVES_H
12 #define CARMA_ANTENNA_BIMA_DRIVES_H
13 
14 #include <vector>
15 #include <cmath>
16 #include <string>
17 #include <algorithm>
18 #include <cctype>
19 
20 
21 // System includes
22 #include <unistd.h>
23 #include <time.h>
24 #include <sys/time.h>
25 
26 // CARMA includes
27 #include "carma/util/Program.h"
28 #include "carma/services/Table.h"
29 #include "carma/util/QuadraticInterpolatorNormal.h"
30 #include "carma/util/Time.h"
34 #include "carma/util/Logger.h"
35 
36 // This is included so that if we get near the zenith, we can move
37 // the ambient flap into place to avoid frying the receiver
38 // with the radar signal from Cloudsat which points straight
39 // down at the earth and tx's at 94GHz to look at, you guessed
40 // it, clouds!
41 #include "carma/antenna/bima/Rx.h"
42 
43 
44 // This needs to be defined in some globals .h, see Telemetry.h TILTSAMPLES
45 #define TILTSAMPLES 100
46 
47 namespace carma
48 {
49  namespace antenna
50  {
51  namespace bima
52  {
53  class Drives : public TelemetryClient
54  {
55 
56  public:
57  Drives( Configuration& config, bool checkTelemHost = true );
58 
59  typedef enum { UP, DOWN } ElDir;
60  typedef enum { CLOCKWISE, COUNTERCLOCKWISE } AzDir;
61  typedef enum
62  {
63  TRACK, CLOSE, SLEW, STOW, SNOW, STOP, DISABLE, HWLIMIT, SWLIMIT, ERROR
64  } StateType;
65  typedef enum { AZEL, EQUAT, STOWMODE, SNOWMODE, STOPMODE } ModeType;
66  typedef enum { ZERO, ADD, SUB } WrapLogic;
67  typedef enum { OPTICAL, RADIO } RefractModel;
68  typedef enum { KEYENABLE, KEYDISABLE } KeySwitch;
69  typedef enum { COMPUTER, MANUAL } ControlSwitch;
70 
71  bool areFaultBits();
72  bool isKeyOn();
73 
74  void pegAz( bool peggit );
75  void pegEl( bool peggit );
76 
77  bool isAzPegged();
78  bool isElPegged();
79 
80  void pegVelocities( int limit );
81  void markAzVel( int vel );
82  void markElVel( int vel );
83  int getAzVel();
84  int getElVel();
85 
86  WrapLogic getWrapLogic();
87  void setWrapLogic( WrapLogic logic);
88  void setOverTheTop( bool overTop );
89  bool getOverTheTop();
90 
91  StateType getState();
92  void setState( StateType state);
93  StateType getActiveState();
94  void setActiveState( StateType state);
95 
96  ModeType getMode();
97  void setMode( ModeType mode );
98 
99  RefractModel getModel();
100  void setModel( RefractModel model );
101  float getRefract();
102  void setRefract( float refract);
103 
104  double getConstantChange();
105 
106  double getOneSecRateAz();
107  double getOneSecRateEl();
108  void markOneSecAzRate( double rate );
109  void markOneSecElRate( double rate );
110 
111  bool isAzStalled();
112  bool isElStalled();
113  void markAzStallMJD();
114  void markAzStalls( int stalls );
115  int getAzStalls();
116  void markElStalls( int stalls );
117  int getElStalls();
118  void markElStallMJD();
119  void zeroStallMJD();
120  double getAzStallMJD();
121  double getElStallMJD();
122  void setStallRetries( int cnt );
123  int getStallRetries();
124 
125  bool onTarget();
126  bool onTargetAz();
127  bool onTargetEl();
128 
129  void slew();
130  void stop();
131  void stow();
132  void setStowPosition( DriveCommand::PositionType );
133  DriveCommand::PositionType getStowPosition();
134  void snow();
135  void servo();
136  void toggle();
137 
138  void setSoftLimit();
139  void setHardLimit();
140 
141  double getTargetAz( double mjd = 0);
142  double getRawTargetAz();
143  double getTargetEl( double mjd = 0);
144  double getRawTargetEl();
145 
146  void setTargetAz( int whence, double mjd, double az, bool discontinuity );
147  void setRawTargetAz( double az );
148  void setTargetEl( double mjd, double el, bool discontinuity );
149  void setRawTargetEl( double el );
150 
151  int getInstantAzResolver();
152  int getSmoothedAzResolver();
153  double getAzFine();
154  int getAzDigVeFilter();
155  int getAzDigVeFilterWriteOut();
156  int getInstantAzCosEnc();
157  int getSmoothAzCosEnc();
158  int getInstantAzSinEnc();
159  int getSmoothAzSinEnc();
160  void setAzCheckDrivePower( bool status );
161  bool getAzCheckDrivePower();
162 
163  int getInstantElResolver();
164  int getSmoothedElResolver();
165  double getElFine();
166  int getElDigVeFilter();
167  int getElDigVeFilterWriteOut();
168  int getInstantElCosEnc();
169  int getSmoothElCosEnc();
170  int getInstantElSinEnc();
171  int getSmoothElSinEnc();
172  void setElCheckDrivePower( bool status );
173  bool getElCheckDrivePower();
174 
175  double getAzRequested();
176  double getElRequested();
177  void setAzRequested( double az );
178  void setElRequested( double el );
179 
180  double getAz();
181  double getEl();
182 
183  double getAzErr();
184  double getElErr();
185 
186  double getAzErrSky();
187 
188  double getAzRate();
189  double getElRate();
190 
191  std::string* getSource();
192  void setSource( std::string *name );
193 
194  double getRA();
195  void setRA( double angle );
196  double getDec();
197  void setDec( double angle );
198 
199  // All offsets are actually handled by DriveMgrThread
200  // and it's internal use of the ephemeris object
201  // the following are purely for monitor info reporting
202  double getOffsetAz();
203  void setOffsetAz( double angle ); // arcmin
204  double getOffsetEl();
205  void setOffsetEl( double angle ); // arcmin
206 
207  double getMountOffsetAz();
208  void setMountOffsetAz( double angle );
209  double getMountOffsetEl();
210  void setMountOffsetEl( double angle );
211 
212  void setAperture( DriveCommand::ApertureType ap );
213  DriveCommand::ApertureType getAperture();
214  double getApertureOffsetAz( DriveCommand::ApertureType ap );
215  void setApertureOffsetAz( DriveCommand::ApertureType ap, double angle );
216  double getApertureOffsetEl( DriveCommand::ApertureType ap );
217  void setApertureOffsetEl( DriveCommand::ApertureType ap, double angle );
218  double getApertureOffsetSag( DriveCommand::ApertureType ap );
219  void setApertureOffsetSag( DriveCommand::ApertureType ap, double angle );
220 
221  float getAzRateAdjust();
222  float getElRateAdjust();
223  void setAzRateAdjust();
224  void setElRateAdjust();
225 
226  float getMaxAzRate();
227  void setMaxAzRate( float rate );
228  float getMaxElRate();
229  void setMaxElRate( float rate );
230 
231  float getWindDir();
232  void setWindDir( float dir );
233 
234  double getTiltMag();
235  double getTiltDir();
236 
237  double getTilt1Arcmin();
238  double getTilt2Arcmin();
239 
240  void setTiltOutliers( const char *name, int outliers );
241  void setTilt1Outliers( int outliers );
242  int getTilt1Outliers();
243  void setTilt2Outliers( int outliers );
244  int getTilt2Outliers();
245 
246  int getTilt1Counts();
247  int getTilt2Counts();
248  int getTiltCounts( const char *name, int &outliers, int &rms1 );
249  void getAveRms( int *samples, int size, int &ave, int &rms );
250 
251  int computeAzCoarseOffset( int degrees );
252  int computeElCoarseOffset( int degrees );
253 
254  void setPointingModelCoefs(
255  double * dazCoefs, unsigned int dazCoefCount,
256  double * delCoefs, unsigned int delCoefCount);
257 
258  void setTolerance( double beamWidth );
259  double getTolerance();
260 
261  void setNextSequenceNo( unsigned long seq );
262  unsigned long getNextSequenceNo();
263  void setCurSequenceNo( unsigned long seq );
264  unsigned long getCurSequenceNo();
265 
266  void setCoefChange( double mjd );
267  double getCoefChange();
268 
269  int limitAxisAccel( int &stalls, int curcounts, int lastcounts, int &accelLim, int origLim,
270  int &maxSlew, int origMax, float slewMod, struct timeval &tv1 );
271 
272  bool settled();
273  void updateSettle();
274  void resetSettle();
275 
276  double getAzSansPointing();
277  double getElSansPointing();
278 
279  // ew.
280  double getObsFreq();
281 
282  void setLatitude( double lat );
283  double getLatitude();
284  void setLongitude( double longi );
285  double getLongitude();
286  void setAltitude( double alt );
287  double getAltitude();
288 
289  // Used primarily for diagnostics
290  int getAzMaxSlew() { return _azMaxSlew; }
291  int getElMaxSlew() { return _elMaxSlew; }
292  double getAzRampDown() { return _azRampDown; }
293  double getElRampDown() { return _elRampDown; }
294  int getAzRampStartSpeed() { return _azRampStartSpeed; }
295  int getElRampStartSpeed() { return _elRampStartSpeed; }
296  int getAzCoarseOffset() { return _azCoarseOffset; }
297  int getElCoarseOffset() { return _elCoarseOffset; }
298  double getswAzHiLim() { return _swAzHiLim; }
299  double getswElHiLim() { return _swElHiLim; }
300  double getswAzLoLim() { return _swAzLoLim; }
301  double getswElLoLim() { return _swElLoLim; }
302  bool getswSlewLim() { return _limitAccel; }
303  int getAzAccelLim() { return _azAccelLim; }
304  int getElAccelLim() { return _elAccelLim; }
305  float getAzSlewMod() { return _azSlewMod; }
306  float getElSlewMod() { return _elSlewMod; }
307  float getGain() { return _gain; }
308  unsigned int getWaitInUSec() { return _waitInUsec; }
309 
310  void setAmbWeatherTemp( float temp );
311  float getAmbWeatherTemp();
312 
313  void setSafeCalled( int safe )
314  {
315  putData( "SAFECALLED", &safe );
316  }
317 
318  bool safeCalled()
319  {
320  int safeCalled = 0;
321  getData( "SAFECALLED", &safeCalled );
322  return ( safeCalled != 0 );
323  }
324 
325  void setSafeRange( float azLow, float azHigh,
326  float elLow, float elHigh )
327  {
328  setSafeCalled(1);
329 
330  _azSafeLow = azLow; _azSafeHigh = azHigh;
331  _elSafeLow = elLow; _elSafeHigh = elHigh;
332 
333  putData( "AZSAFELO", &_azSafeLow );
334  putData( "AZSAFEHI", &_azSafeHigh );
335  putData( "ELSAFELO", &_elSafeLow );
336  putData( "ELSAFEHI", &_elSafeHigh );
337  };
338 
339  void getSafeRange( float &azLow, float &azHigh,
340  float &elLow, float &elHigh )
341  {
342  getData( "AZSAFELO", &azLow );
343  getData( "AZSAFEHI", &azHigh );
344  getData( "ELSAFELO", &elLow );
345  getData( "ELSAFEHI", &elHigh );
346  };
347 
348  void setSoftLimits( float &azlo, float &azhi, float &ello, float &elhi )
349  {
350  float sl[4];
351 
352  sl[0] = azlo;
353  sl[1] = azhi;
354  sl[2] = ello;
355  sl[3] = elhi;
356 
357  putData( "SOFTLIM", sl, 4 );
358  }
359 
360  void getSoftLimits( float &azlo, float &azhi, float &ello, float &elhi )
361  {
362  float sl[4];
363 
364  getData( "SOFTLIM", sl, 4 );
365 
366  azlo = sl[0];
367  azhi = sl[1];
368  ello = sl[2];
369  elhi = sl[3];
370  }
371 
372  void setHardLimits( float azlo, float azhi, float ello, float elhi )
373  {
374  float hl[4];
375 
376  hl[0] = azlo;
377  hl[1] = azhi;
378  hl[2] = ello;
379  hl[3] = elhi;
380 
381  putData( "HARDLIM", hl, 4 );
382  }
383 
384  void getHardLimits( float &azlo, float &azhi, float &ello, float &elhi )
385  {
386  float hl[4];
387 
388  getData( "HARDLIM", hl, 4 );
389 
390  azlo = hl[0];
391  azhi = hl[1];
392  ello = hl[2];
393  elhi = hl[3];
394  }
395 
396  void getSafeTarget( float &az, float &el )
397  {
398  // This does not check if setSafeRange has been called
399  // as the upper layers will have checked that that method
400  // has been called. In the miraculous happenstance that
401  // we arrive here without setSafeRange called, this method
402  // defaults to az 0, el 85
403 
404  if ( safeCalled() )
405  {
406  az = _azSafeLow + ((_azSafeHigh - _azSafeLow) / 2.0);
407  el = _elSafeLow + ((_elSafeHigh - _elSafeLow) / 2.0);
408  }
409  else
410  {
411  // If this has happened, we're sticking to the current
412  // pointing, because it's the safest thing to do
413  az = getAz();
414  el = getEl();
415  }
416 
417  }
418 
419 
420  protected:
421  double getFastPacketRxMJD();
422 
423 
424  private:
425 
426  void loadDrivesConfig();
427 
428  std::string _name;
429  const char *_dir;
430  // TODO Remove these two
431  //double _targetAz;
432  //double _targetEl;
433  double _distAz;
434  double _distEl;
435  int _azMaxSlew, _azOrigMaxSlew, _elMaxSlew, _elOrigMaxSlew;
436  int _lastiAzVel, _lastiElVel;
437  int _azDigWOMismatch, _elDigWOMismatch;
438  float _gain, _mjdGainLookAhead, _gainConst;
439  unsigned int _waitInUsec;
440  float _azSlewMod, _elSlewMod;
441  float _azSafeLow, _azSafeHigh, _elSafeLow, _elSafeHigh;
442  float _azHardLow, _azHardHigh, _elHardLow, _elHardHigh;
443  double _azMaxRate, _elMazRate;
444  double _azRate, _elRate, _lastAzRate, _lastElRate;
445  double _azRampDown, _elRampDown;
446  int _azRampStartSpeed, _elRampStartSpeed;
447  int _azCoarseOffset, _elCoarseOffset;
448  int _azVel, _elVel, _forceVelLimit;
449  int _azAccelLim, _azOrigAccelLim;
450  int _elAccelLim, _elOrigAccelLim;
451  struct timeval _lastLimChkAz;
452  struct timeval _lastLimChkEl;
453  bool _limitAccel;
454  int _toggle, _lastToggle;
455  time_t _lastToggleUpdate;
456  time_t _lastManWarn;
457 
458  int *_rawTilts;
459 
460  bool _peggedAz;
461  bool _peggedEl;
462 
463  double _hardLoLimitAz, _hardHiLimitAz;
464  double _hardLoLimitEl, _hardHiLimitEl;
465 
466  float _swAzLoLim, _swAzHiLim;
467  float _swElLoLim, _swElHiLim;
468 
469  double _tolerance;
470 
471  Rx *_rx;
472  CalWheel *_calwheel;
473 
474  void dataInvert( int &value )
475  {
476  if ( ( value & 0x8000 ) != 0 )
477  value = ~( value & 0x7fff ) + 1;
478  };
479 
480  static const double DR = 0.01745329251994; // M_PI/180.0
481  static const double RD = 57.2957795130823; // 180.0/M_PI
482 
483  int _azStalls, _azStallCnt, _azRetries;
484  int _elStalls, _elStallCnt, _elRetries;
485  double _azLastStallChk, _elLastStallChk;
486 
487  time_t _settle;
488  time_t _stallsStarted;
489 
490  Configuration &_config;
491  log4cpp::Category &_logger;
492 
493  }; // class Drives
494  } // namespace bima
495  } // namespace antenna
496 } // namespace carma
497 
498 ::std::ostream& operator<<( ::std::ostream& os,
499  ::carma::antenna::bima::Drives& drives );
500 
501 #endif // CARMA_ANTENNA_BIMA_DRIVES_H
502 
503 // vim: set expandtab sw=2 ts=2 cindent :
std::ostream & operator<<(::std::ostream &os, const carma::dbms::Table &table)
Common time functions.
Subtract a turn.
Definition: AzWrapMode.idl:14
Add a turn.
Definition: AzWrapMode.idl:13
modeType getMode(idType id)
Extract the address mode from a 29 bit can id.
Class definition for DriveCommand on the BIMA antennas.
ModeType
Correlator operational modes.
Definition: CorDataBase.idl:54
Class definition for Stepper Motors for BIMA systems.
Common table functions.
Don&#39;t add or subtract.
Definition: AzWrapMode.idl:15
Class definition for TelemetryClient on the BIMA antennas.
Class definition for Stepper Motors for BIMA systems.