Telescope Control Library

Dependents:   PushToGo-F429

Committer:
caoyu@caoyuan9642-desktop.MIT.EDU
Date:
Mon Sep 24 19:36:48 2018 -0400
Revision:
19:fd854309cb4c
Parent:
10:e356188d208e
Fix bug in nudging with small speeds mentioned in the last commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 1 /*
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 2 * PEC.h
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 3 *
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 4 * Created on: Sep 9, 2018
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 5 * Author: caoyu
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 6 */
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 7
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 8 #ifndef PUSHTOGO_PEC_H_
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 9 #define PUSHTOGO_PEC_H_
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 10 #include "mbed.h"
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 11
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 12 // Maximum correctable error per step, in arcsecond
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 13 #define MAX_PEC_VALUE 20
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 14
caoyu@caoyuan9642-desktop.MIT.EDU 10:e356188d208e 15 class Axis;
caoyu@caoyuan9642-desktop.MIT.EDU 10:e356188d208e 16
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 17 class PEC {
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 18 public:
caoyu@caoyuan9642-desktop.MIT.EDU 10:e356188d208e 19 PEC(Axis &a);
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 20 virtual ~PEC() {
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 21 thread->terminate();
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 22 delete thread;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 23 delete[] pecData;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 24 }
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 25
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 26 bool isEnabled() const {
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 27 return enabled;
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 28 }
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 29
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 30 void setEnabled(bool enabled) {
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 31 this->enabled = enabled;
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 32 }
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 33
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 34 int getSize() const {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 35 return granularity;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 36 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 37
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 38 float getPECData(int index) const {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 39 if (index >= 0 && index < granularity) {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 40 return pecData[index];
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 41 } else
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 42 return NAN;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 43 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 44
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 45 void setPECData(int index, float value) {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 46 if (index >= 0 && index < granularity && fabsf(value) < MAX_PEC_VALUE) {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 47 pecData[index] = value;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 48 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 49 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 50
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 51 float getIndexOffset() const {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 52 return indexOffset;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 53 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 54
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 55 /**
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 56 * Index offset is the phase on the worm cycle at the reference time for the PEC
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 57 * When axis.getAngleDeg() equals indexOffset, the first bin of PEC data will be executed, etc.
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 58 */
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 59 void setIndexOffset(float indexOffset) {
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 60 this->indexOffset = indexOffset;
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 61 }
caoyu@caoyuan9642-desktop.MIT.EDU 9:d0413a9b1386 62
caoyu@caoyuan9642-desktop.MIT.EDU 7:9daa589c92c8 63 protected:
caoyu@caoyuan9642-desktop.MIT.EDU 10:e356188d208e 64 Axis &axis;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 65 volatile bool enabled;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 66 Thread *thread;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 67
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 68 float indexOffset;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 69
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 70 float *pecData;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 71 int granularity;
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 72
caoyu@caoyuan9642-desktop.MIT.EDU 8:21a33760bf10 73 void task();
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 74 };
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 75
caoyu@caoyuan9642-desktop.MIT.EDU 6:85b9d9a3903a 76 #endif /* PUSHTOGO_PEC_H_ */