Telescope Control Library
EquatorialMount.h@19:fd854309cb4c, 2018-09-24 (annotated)
- Committer:
- caoyu@caoyuan9642-desktop.MIT.EDU
- Date:
- Mon Sep 24 19:36:48 2018 -0400
- Revision:
- 19:fd854309cb4c
- Parent:
- 18:3ea58b079adc
Fix bug in nudging with small speeds mentioned in the last commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caoyuan9642 | 0:6cb2eaf8b133 | 1 | #ifndef EQUATORIALMOUNT_H_ |
caoyuan9642 | 0:6cb2eaf8b133 | 2 | #define EQUATORIALMOUNT_H_ |
caoyuan9642 | 0:6cb2eaf8b133 | 3 | #include "Axis.h" |
caoyuan9642 | 0:6cb2eaf8b133 | 4 | #include "Mount.h" |
caoyuan9642 | 0:6cb2eaf8b133 | 5 | #include "UTCClock.h" |
caoyuan9642 | 0:6cb2eaf8b133 | 6 | #include "LocationProvider.h" |
caoyuan9642 | 0:6cb2eaf8b133 | 7 | #include "CelestialMath.h" |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 8 | #include "PEC.h" |
caoyuan9642 | 0:6cb2eaf8b133 | 9 | |
caoyuan9642 | 0:6cb2eaf8b133 | 10 | #define MAX_AS_N 10 // Max number of alignment stars |
caoyuan9642 | 0:6cb2eaf8b133 | 11 | |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 12 | class Axis; |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 13 | class PEC; |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 14 | |
caoyuan9642 | 0:6cb2eaf8b133 | 15 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 16 | * Direction of nudge |
caoyuan9642 | 0:6cb2eaf8b133 | 17 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 18 | typedef enum { |
caoyuan9642 | 0:6cb2eaf8b133 | 19 | NUDGE_NONE = 0, |
caoyuan9642 | 0:6cb2eaf8b133 | 20 | NUDGE_EAST = 1, |
caoyuan9642 | 0:6cb2eaf8b133 | 21 | NUDGE_WEST = 2, |
caoyuan9642 | 0:6cb2eaf8b133 | 22 | NUDGE_NORTH = 4, |
caoyuan9642 | 0:6cb2eaf8b133 | 23 | NUDGE_SOUTH = 8, |
caoyuan9642 | 0:6cb2eaf8b133 | 24 | |
caoyuan9642 | 0:6cb2eaf8b133 | 25 | NUDGE_NORTHWEST = NUDGE_NORTH | NUDGE_WEST, |
caoyuan9642 | 0:6cb2eaf8b133 | 26 | NUDGE_SOUTHWEST = NUDGE_SOUTH | NUDGE_WEST, |
caoyuan9642 | 0:6cb2eaf8b133 | 27 | NUDGE_NORTHEAST = NUDGE_NORTH | NUDGE_EAST, |
caoyuan9642 | 0:6cb2eaf8b133 | 28 | NUDGE_SOUTHEAST = NUDGE_SOUTH | NUDGE_EAST, |
caoyuan9642 | 0:6cb2eaf8b133 | 29 | } nudgedir_t; |
caoyuan9642 | 0:6cb2eaf8b133 | 30 | |
caoyuan9642 | 0:6cb2eaf8b133 | 31 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 32 | * Direction of guide |
caoyuan9642 | 0:6cb2eaf8b133 | 33 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 34 | typedef enum { |
caoyuan9642 | 0:6cb2eaf8b133 | 35 | GUIDE_EAST = 1, GUIDE_WEST = 2, GUIDE_NORTH = 3, GUIDE_SOUTH = 4, |
caoyuan9642 | 0:6cb2eaf8b133 | 36 | } guidedir_t; |
caoyuan9642 | 0:6cb2eaf8b133 | 37 | |
caoyuan9642 | 0:6cb2eaf8b133 | 38 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 39 | * Object that represents an equatorial mount with two perpendicular axis called RA and Dec. |
caoyuan9642 | 0:6cb2eaf8b133 | 40 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 41 | class EquatorialMount: public Mount { |
caoyuan9642 | 0:6cb2eaf8b133 | 42 | |
caoyuan9642 | 0:6cb2eaf8b133 | 43 | protected: |
caoyuan9642 | 0:6cb2eaf8b133 | 44 | Axis &ra; /// RA Axis |
caoyuan9642 | 0:6cb2eaf8b133 | 45 | Axis &dec; /// DEC Axis |
caoyuan9642 | 0:6cb2eaf8b133 | 46 | |
caoyuan9642 | 0:6cb2eaf8b133 | 47 | UTCClock &clock; /// Clock |
caoyuan9642 | 0:6cb2eaf8b133 | 48 | |
caoyuan9642 | 0:6cb2eaf8b133 | 49 | Mutex mutex_update; /// Mutex to lock position updating |
caoyuan9642 | 0:6cb2eaf8b133 | 50 | Mutex mutex_execution; /// Mutex to lock motion related functions |
caoyuan9642 | 0:6cb2eaf8b133 | 51 | |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 52 | LocationProvider loc; /// Current location (GPS coordinates) |
caoyuan9642 | 0:6cb2eaf8b133 | 53 | bool south; /// If we are in south semisphere |
caoyuan9642 | 0:6cb2eaf8b133 | 54 | MountCoordinates curr_pos; /// Current Position in mount coordinates (offset from the index positions) |
caoyuan9642 | 0:6cb2eaf8b133 | 55 | EquatorialCoordinates curr_pos_eq; /// Current Position in the equatorial coordinates (absolute pointing direction in the sky) |
caoyuan9642 | 0:6cb2eaf8b133 | 56 | nudgedir_t curr_nudge_dir; |
caoyuan9642 | 0:6cb2eaf8b133 | 57 | double nudgeSpeed; |
caoyuan9642 | 0:6cb2eaf8b133 | 58 | |
caoyuan9642 | 0:6cb2eaf8b133 | 59 | pierside_t pier_side; /// Side of pier. 1: East |
caoyuan9642 | 0:6cb2eaf8b133 | 60 | EqCalibration calibration; |
caoyuan9642 | 0:6cb2eaf8b133 | 61 | AlignmentStar alignment_stars[MAX_AS_N]; |
caoyuan9642 | 0:6cb2eaf8b133 | 62 | int num_alignment_stars; |
caoyuan9642 | 0:6cb2eaf8b133 | 63 | |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 64 | PEC pec; /// PEC function |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 65 | |
caoyuan9642 | 0:6cb2eaf8b133 | 66 | public: |
caoyuan9642 | 0:6cb2eaf8b133 | 67 | |
caoyuan9642 | 0:6cb2eaf8b133 | 68 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 69 | * Create an EquatorialMount object which controls two axis |
caoyuan9642 | 0:6cb2eaf8b133 | 70 | * @param ra RA Axis |
caoyuan9642 | 0:6cb2eaf8b133 | 71 | * @param dec DEC Axis |
caoyuan9642 | 0:6cb2eaf8b133 | 72 | * @note cone_value, ma_alt, ma_azi,off_ra, off_dec will be init to zero, i.e. assuming a perfectly aligned mount pointing at RA=DEC=0 |
caoyuan9642 | 0:6cb2eaf8b133 | 73 | * @note This class assumes that the rotating direction of both axis are correct. |
caoyuan9642 | 0:6cb2eaf8b133 | 74 | * This should be done using the invert option when initializing the RotationAxis objects |
caoyuan9642 | 0:6cb2eaf8b133 | 75 | * @sa RotationAxis |
caoyuan9642 | 0:6cb2eaf8b133 | 76 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 77 | EquatorialMount(Axis &ra, Axis &dec, UTCClock &clk, LocationProvider &loc); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 78 | virtual ~EquatorialMount() { |
caoyuan9642 | 0:6cb2eaf8b133 | 79 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 80 | |
caoyuan9642 | 0:6cb2eaf8b133 | 81 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 82 | * Perform a Go-To to specified equatorial coordinates in the sky |
caoyuan9642 | 0:6cb2eaf8b133 | 83 | * @param ra_dest RA coordinate in degree. |
caoyuan9642 | 0:6cb2eaf8b133 | 84 | * @return osOK if no error |
caoyuan9642 | 0:6cb2eaf8b133 | 85 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 86 | osStatus goTo(double ra_dest, double dec_dest); |
caoyuan9642 | 0:6cb2eaf8b133 | 87 | osStatus goTo(EquatorialCoordinates dest); |
caoyuan9642 | 0:6cb2eaf8b133 | 88 | osStatus goToMount(MountCoordinates mc, bool withCorrection = true); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 89 | osStatus goToIndex() { |
caoyuan9642 | 0:6cb2eaf8b133 | 90 | return goToMount(MountCoordinates(0, 0)); |
caoyuan9642 | 0:6cb2eaf8b133 | 91 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 92 | |
caoyuan9642 | 0:6cb2eaf8b133 | 93 | osStatus startNudge(nudgedir_t); |
caoyuan9642 | 0:6cb2eaf8b133 | 94 | osStatus stopNudge(); |
caoyuan9642 | 0:6cb2eaf8b133 | 95 | |
caoyuan9642 | 0:6cb2eaf8b133 | 96 | osStatus startTracking(); |
caoyuan9642 | 0:6cb2eaf8b133 | 97 | osStatus stopTracking(); |
caoyuan9642 | 0:6cb2eaf8b133 | 98 | |
caoyuan9642 | 2:2ee28add0821 | 99 | mountstatus_t getStatus(); |
caoyuan9642 | 0:6cb2eaf8b133 | 100 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 101 | * Guide on specified direction for specified time |
caoyuan9642 | 0:6cb2eaf8b133 | 102 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 103 | osStatus guide(guidedir_t dir, int ms); |
caoyuan9642 | 0:6cb2eaf8b133 | 104 | |
caoyuan9642 | 0:6cb2eaf8b133 | 105 | /*Calibration related functions*/ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 106 | |
caoyuan9642 | 0:6cb2eaf8b133 | 107 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 108 | * Clear calibration, use current latitude for the polar axis |
caoyuan9642 | 0:6cb2eaf8b133 | 109 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 110 | void clearCalibration() { |
caoyuan9642 | 0:6cb2eaf8b133 | 111 | num_alignment_stars = 0; |
caoyuan9642 | 0:6cb2eaf8b133 | 112 | calibration = EqCalibration(); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 113 | calibration.pa.alt = loc.getLatitude(); |
caoyuan9642 | 0:6cb2eaf8b133 | 114 | } |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 115 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 116 | /** |
caoyuan9642 | 4:b8ad57bbf9e1 | 117 | * Clear calibration except axis offsets, use current latitude for the polar axis |
caoyuan9642 | 4:b8ad57bbf9e1 | 118 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 119 | void clearCalibrationExceptOffsets() { |
caoyuan9642 | 4:b8ad57bbf9e1 | 120 | num_alignment_stars = 0; |
caoyuan9642 | 4:b8ad57bbf9e1 | 121 | calibration.cone = 0; |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 122 | calibration.pa.alt = loc.getLatitude(); |
caoyuan9642 | 4:b8ad57bbf9e1 | 123 | calibration.pa.azi = 0; |
caoyuan9642 | 4:b8ad57bbf9e1 | 124 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 125 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 126 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 127 | * Get calibration |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 128 | * @return Current calibration |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 129 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 130 | const EqCalibration &getCalibration() const { |
caoyuan9642 | 0:6cb2eaf8b133 | 131 | return calibration; |
caoyuan9642 | 0:6cb2eaf8b133 | 132 | } |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 133 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 134 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 135 | * Set calibration |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 136 | * @param calib New Calibration |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 137 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 138 | void setCalibration(const EqCalibration &calib) { |
caoyuan9642 | 4:b8ad57bbf9e1 | 139 | calibration = calib; |
caoyuan9642 | 4:b8ad57bbf9e1 | 140 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 141 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 142 | /** @return number of alignment stars |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 143 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 144 | int getNumAlignmentStar() { |
caoyuan9642 | 0:6cb2eaf8b133 | 145 | return num_alignment_stars; |
caoyuan9642 | 0:6cb2eaf8b133 | 146 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 147 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 148 | /** Add an alignment star |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 149 | * @return osStatus error if no more star can be added |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 150 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 151 | osStatus addAlignmentStar(const AlignmentStar &as) { |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 152 | if (num_alignment_stars < MAX_AS_N) { |
caoyuan9642 | 0:6cb2eaf8b133 | 153 | alignment_stars[num_alignment_stars++] = as; |
caoyuan9642 | 0:6cb2eaf8b133 | 154 | return recalibrate(); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 155 | } else |
caoyuan9642 | 0:6cb2eaf8b133 | 156 | return osErrorResource; |
caoyuan9642 | 0:6cb2eaf8b133 | 157 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 158 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 159 | /** Remove an alignment star |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 160 | * @param index # of star to remove, starting from 0 |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 161 | * @return osStatus error if no more star can be deleted |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 162 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 163 | osStatus removeAlignmentStar(int index) { |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 164 | if (index < 0 || index >= num_alignment_stars) { |
caoyuan9642 | 0:6cb2eaf8b133 | 165 | return osErrorParameter; |
caoyuan9642 | 0:6cb2eaf8b133 | 166 | } |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 167 | for (; index < num_alignment_stars - 1; index++) { |
caoyuan9642 | 0:6cb2eaf8b133 | 168 | alignment_stars[index] = alignment_stars[index + 1]; |
caoyuan9642 | 0:6cb2eaf8b133 | 169 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 170 | num_alignment_stars--; |
caoyuan9642 | 0:6cb2eaf8b133 | 171 | return recalibrate(); |
caoyuan9642 | 0:6cb2eaf8b133 | 172 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 173 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 174 | /** Get alignment star |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 175 | * @param index # of star to get |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 176 | * @return pointer to that alignment star if found, NULL if doesn't exist |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 177 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 178 | AlignmentStar *getAlignmentStar(int index) { |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 179 | if (index < 0 || index >= num_alignment_stars) { |
caoyuan9642 | 0:6cb2eaf8b133 | 180 | return NULL; |
caoyuan9642 | 0:6cb2eaf8b133 | 181 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 182 | return &alignment_stars[index]; |
caoyuan9642 | 0:6cb2eaf8b133 | 183 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 184 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 185 | /** Replace an alignment star with another |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 186 | * @param index # of star to replace |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 187 | * @param as new star to add. Will be copied by value |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 188 | * @return error if star not found |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 189 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 190 | osStatus replaceAlignmentStar(int index, const AlignmentStar &as) { |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 191 | if (index < 0 || index >= num_alignment_stars) { |
caoyuan9642 | 0:6cb2eaf8b133 | 192 | return osErrorParameter; |
caoyuan9642 | 0:6cb2eaf8b133 | 193 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 194 | alignment_stars[index] = as; |
caoyuan9642 | 0:6cb2eaf8b133 | 195 | return recalibrate(); |
caoyuan9642 | 0:6cb2eaf8b133 | 196 | } |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 197 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 198 | /** Force all alignment stars to be perfected aligned according to the current calibration |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 199 | * Useful during a polar alignment procedure |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 200 | * @note This will throw off all the alignment stars if the error is too big or calibration is wrong |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 201 | */ |
caoyuan9642 | 4:b8ad57bbf9e1 | 202 | void forceAlignment(); |
caoyuan9642 | 0:6cb2eaf8b133 | 203 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 204 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 205 | * Convert EQ coordinates to mount coodinates using current calibration. Utility function |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 206 | * @param eq EQ coordinate to convert |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 207 | * @return mount coordinates |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 208 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 209 | MountCoordinates convertToMountCoordinates( |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 210 | const EquatorialCoordinates &eq) { |
caoyuan9642 | 0:6cb2eaf8b133 | 211 | LocalEquatorialCoordinates leq = |
caoyu@caoyuan9642-desktop.MIT.EDU | 18:3ea58b079adc | 212 | CelestialMath::equatorialToLocalEquatorial(eq, clock.getTimeHighResolution(), |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 213 | loc.getLocation()); |
caoyuan9642 | 0:6cb2eaf8b133 | 214 | // Apply PA misalignment |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 215 | leq = CelestialMath::applyMisalignment(leq, calibration.pa, |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 216 | loc.getLocation()); |
caoyuan9642 | 0:6cb2eaf8b133 | 217 | // Apply Cone error |
caoyuan9642 | 0:6cb2eaf8b133 | 218 | leq = CelestialMath::applyConeError(leq, calibration.cone); |
caoyuan9642 | 0:6cb2eaf8b133 | 219 | // Convert to Mount coordinates. Automatically determine the pier side, then apply offset |
caoyuan9642 | 0:6cb2eaf8b133 | 220 | return CelestialMath::localEquatorialToMount(leq, PIER_SIDE_AUTO) |
caoyuan9642 | 0:6cb2eaf8b133 | 221 | + calibration.offset; |
caoyuan9642 | 0:6cb2eaf8b133 | 222 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 223 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 224 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 225 | * Convert mount coordinates to EQ coodinates using current calibration. Utility function |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 226 | * @param mc Mount coordinate to convert |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 227 | * @return EQ coordinates |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 228 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 229 | EquatorialCoordinates convertToEqCoordinates(const MountCoordinates &mc) { |
caoyuan9642 | 0:6cb2eaf8b133 | 230 | LocalEquatorialCoordinates leq = CelestialMath::mountToLocalEquatorial( |
caoyuan9642 | 0:6cb2eaf8b133 | 231 | mc - calibration.offset); |
caoyuan9642 | 0:6cb2eaf8b133 | 232 | leq = CelestialMath::deapplyConeError(leq, calibration.cone); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 233 | leq = CelestialMath::deapplyMisalignment(leq, calibration.pa, loc.getLocation()); |
caoyu@caoyuan9642-desktop.MIT.EDU | 18:3ea58b079adc | 234 | return CelestialMath::localEquatorialToEquatorial(leq, clock.getTimeHighResolution(), |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 235 | loc.getLocation()); |
caoyuan9642 | 0:6cb2eaf8b133 | 236 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 237 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 238 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 239 | * Use alignment stars to recalculate the calibration. |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 240 | * @return osStatus |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 241 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 242 | osStatus recalibrate(); |
caoyuan9642 | 0:6cb2eaf8b133 | 243 | |
caoyuan9642 | 0:6cb2eaf8b133 | 244 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 245 | * Call emergency stop of the Axis objects |
caoyuan9642 | 0:6cb2eaf8b133 | 246 | * @note This function can be called from any context (including ISR) to perform a hard stop of the mount |
caoyuan9642 | 0:6cb2eaf8b133 | 247 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 248 | void emergencyStop(); |
caoyuan9642 | 0:6cb2eaf8b133 | 249 | |
caoyuan9642 | 0:6cb2eaf8b133 | 250 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 251 | * Call stop of the Axis objects |
caoyuan9642 | 0:6cb2eaf8b133 | 252 | * @note This function can be called from any context (including ISR) to perform a soft stop of the mount |
caoyuan9642 | 0:6cb2eaf8b133 | 253 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 254 | void stopAsync(); |
caoyuan9642 | 0:6cb2eaf8b133 | 255 | |
caoyuan9642 | 0:6cb2eaf8b133 | 256 | /** BLOCKING. Cannot be called in ISR. |
caoyuan9642 | 0:6cb2eaf8b133 | 257 | * Call stop of the Axis objects and wait until they are stopped. |
caoyuan9642 | 0:6cb2eaf8b133 | 258 | * @note This function can be called from any context (including ISR) to perform a soft stop of the mount |
caoyuan9642 | 0:6cb2eaf8b133 | 259 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 260 | void stopSync(); |
caoyuan9642 | 0:6cb2eaf8b133 | 261 | |
caoyuan9642 | 0:6cb2eaf8b133 | 262 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 263 | * Get current equatorial coordinates |
caoyuan9642 | 0:6cb2eaf8b133 | 264 | * @return current equatorial coordinates |
caoyuan9642 | 0:6cb2eaf8b133 | 265 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 266 | const EquatorialCoordinates &getEquatorialCoordinates() { |
caoyuan9642 | 0:6cb2eaf8b133 | 267 | updatePosition(); |
caoyuan9642 | 0:6cb2eaf8b133 | 268 | return curr_pos_eq; |
caoyuan9642 | 0:6cb2eaf8b133 | 269 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 270 | |
caoyuan9642 | 0:6cb2eaf8b133 | 271 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 272 | * Get current mount coordinates |
caoyuan9642 | 0:6cb2eaf8b133 | 273 | * @return current mount coordinates |
caoyuan9642 | 0:6cb2eaf8b133 | 274 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 275 | const MountCoordinates &getMountCoordinates() { |
caoyuan9642 | 0:6cb2eaf8b133 | 276 | updatePosition(); |
caoyuan9642 | 0:6cb2eaf8b133 | 277 | return curr_pos; |
caoyuan9642 | 0:6cb2eaf8b133 | 278 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 279 | |
caoyuan9642 | 0:6cb2eaf8b133 | 280 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 281 | * Make an alignment star object using the provided reference star, current mount position, and current time |
caoyuan9642 | 0:6cb2eaf8b133 | 282 | * @param star_ref Reference star position |
caoyuan9642 | 0:6cb2eaf8b133 | 283 | * @return AlignmentStar object representing the alignment star |
caoyuan9642 | 0:6cb2eaf8b133 | 284 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 285 | AlignmentStar makeAlignmentStar(const EquatorialCoordinates star_ref) { |
caoyuan9642 | 0:6cb2eaf8b133 | 286 | updatePosition(); |
caoyu@caoyuan9642-desktop.MIT.EDU | 18:3ea58b079adc | 287 | return AlignmentStar(star_ref, curr_pos, clock.getTimeHighResolution()); |
caoyuan9642 | 0:6cb2eaf8b133 | 288 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 289 | |
caoyuan9642 | 0:6cb2eaf8b133 | 290 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 291 | * Align the current mount using an array of alignment stars. Support up to 10 stars. |
caoyuan9642 | 0:6cb2eaf8b133 | 292 | * @note If n=1, will only correct for Index offset |
caoyuan9642 | 0:6cb2eaf8b133 | 293 | * If n=2, will correct for index offset and polar misalignment |
caoyuan9642 | 0:6cb2eaf8b133 | 294 | * If n>=3, will correct for index offset, pa misalignment and cone error |
caoyuan9642 | 0:6cb2eaf8b133 | 295 | * @param n # of alignment stars to use |
caoyuan9642 | 0:6cb2eaf8b133 | 296 | * @param as Array of alignment stars |
caoyuan9642 | 0:6cb2eaf8b133 | 297 | * @return osOK if successfully converged and updated the values |
caoyuan9642 | 0:6cb2eaf8b133 | 298 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 299 | osStatus align(int n, const AlignmentStar as[]); |
caoyuan9642 | 0:6cb2eaf8b133 | 300 | |
caoyuan9642 | 0:6cb2eaf8b133 | 301 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 302 | * Set slew rate of both axis |
caoyuan9642 | 0:6cb2eaf8b133 | 303 | * @param rate new speed |
caoyuan9642 | 0:6cb2eaf8b133 | 304 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 305 | void setSlewSpeed(double rate); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 306 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 307 | /** @return current slew speed |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 308 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 309 | double getSlewSpeed(); |
caoyuan9642 | 0:6cb2eaf8b133 | 310 | |
caoyuan9642 | 0:6cb2eaf8b133 | 311 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 312 | * Set tracking speed of RA axis |
caoyuan9642 | 0:6cb2eaf8b133 | 313 | * @param rate new speed in sidereal rate |
caoyuan9642 | 0:6cb2eaf8b133 | 314 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 315 | void setTrackSpeedSidereal(double rate); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 316 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 317 | /** @return current track speed in sidereal units |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 318 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 319 | double getTrackSpeedSidereal(); |
caoyuan9642 | 0:6cb2eaf8b133 | 320 | |
caoyuan9642 | 0:6cb2eaf8b133 | 321 | /** |
caoyuan9642 | 0:6cb2eaf8b133 | 322 | * Set guiding speed of RA axis |
caoyuan9642 | 0:6cb2eaf8b133 | 323 | * @param rate new speed in sidereal rate |
caoyuan9642 | 0:6cb2eaf8b133 | 324 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 325 | void setGuideSpeedSidereal(double rate); |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 326 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 327 | /** @return current guide speed in sidereal units |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 328 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 329 | double getGuideSpeedSidereal(); |
caoyuan9642 | 0:6cb2eaf8b133 | 330 | |
caoyuan9642 | 0:6cb2eaf8b133 | 331 | /** |
caoyuan9642 | 4:b8ad57bbf9e1 | 332 | * Print current position to stream. |
caoyuan9642 | 0:6cb2eaf8b133 | 333 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 334 | void printPosition(FILE *stream = stdout) { |
caoyuan9642 | 0:6cb2eaf8b133 | 335 | fprintf(stream, "Mount: RA=%7.2f, DEC=%7.2f %c\n", curr_pos.ra_delta, |
caoyuan9642 | 0:6cb2eaf8b133 | 336 | curr_pos.dec_delta, |
caoyuan9642 | 0:6cb2eaf8b133 | 337 | (curr_pos.side == PIER_SIDE_WEST) ? 'W' : 'E'); |
caoyuan9642 | 0:6cb2eaf8b133 | 338 | fprintf(stream, "EQ: RA=%7.2f, DEC=%7.2f\n", curr_pos_eq.ra, |
caoyuan9642 | 0:6cb2eaf8b133 | 339 | curr_pos_eq.dec); |
caoyuan9642 | 0:6cb2eaf8b133 | 340 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 341 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 342 | /** |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 343 | * Update current pointing direction from low-level encoders/counters. |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 344 | * @note should be called before printing the position using printPosition |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 345 | */ |
caoyuan9642 | 0:6cb2eaf8b133 | 346 | void updatePosition(); |
caoyuan9642 | 0:6cb2eaf8b133 | 347 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 348 | /** Get current time source |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 349 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 350 | UTCClock& getClock() const { |
caoyuan9642 | 0:6cb2eaf8b133 | 351 | return clock; |
caoyuan9642 | 0:6cb2eaf8b133 | 352 | } |
caoyuan9642 | 0:6cb2eaf8b133 | 353 | |
caoyuan9642 | 4:b8ad57bbf9e1 | 354 | /** @return get current location coodinates. |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 355 | */ |
caoyu@caoyuan9642-desktop.MIT.EDU | 10:e356188d208e | 356 | LocationCoordinates getLocation() const { |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 357 | return loc.getLocation(); |
caoyuan9642 | 0:6cb2eaf8b133 | 358 | } |
caoyu@caoyuan9642-desktop.MIT.EDU | 9:d0413a9b1386 | 359 | |
caoyuan9642 | 0:6cb2eaf8b133 | 360 | }; |
caoyuan9642 | 0:6cb2eaf8b133 | 361 | |
caoyuan9642 | 0:6cb2eaf8b133 | 362 | #endif /*EQUATORIALMOUNT_H_*/ |
caoyuan9642 | 0:6cb2eaf8b133 | 363 |