Telescope Control Library

Dependents:   PushToGo-F429

Revision:
9:d0413a9b1386
Parent:
4:b8ad57bbf9e1
Child:
10:e356188d208e
--- a/EquatorialMount.h	Sun Sep 09 17:31:20 2018 -0400
+++ b/EquatorialMount.h	Mon Sep 10 02:41:05 2018 -0400
@@ -8,14 +8,14 @@
 #include "UTCClock.h"
 #include "LocationProvider.h"
 #include "CelestialMath.h"
+#include "PEC.h"
 
 #define MAX_AS_N 10 // Max number of alignment stars
 
 /**
  * Direction of nudge
  */
-typedef enum
-{
+typedef enum {
 	NUDGE_NONE = 0,
 	NUDGE_EAST = 1,
 	NUDGE_WEST = 2,
@@ -31,27 +31,27 @@
 /**
  * Direction of guide
  */
-typedef enum
-{
+typedef enum {
 	GUIDE_EAST = 1, GUIDE_WEST = 2, GUIDE_NORTH = 3, GUIDE_SOUTH = 4,
 } guidedir_t;
 
 /**
  * Object that represents an equatorial mount with two perpendicular axis called RA and Dec.
  */
-class EquatorialMount: public Mount
-{
+class EquatorialMount: public Mount {
 
 protected:
 	Axis &ra;   /// RA Axis
 	Axis &dec;  /// DEC Axis
 
+	PEC pec; /// PEC function
+
 	UTCClock &clock; /// Clock
 
 	Mutex mutex_update; /// Mutex to lock position updating
 	Mutex mutex_execution; /// Mutex to lock motion related functions
 
-	LocationCoordinates location;   /// Current location (GPS coordinates)
+	LocationProvider loc;   /// Current location (GPS coordinates)
 	bool south;	/// If we are in south semisphere
 	MountCoordinates curr_pos; /// Current Position in mount coordinates (offset from the index positions)
 	EquatorialCoordinates curr_pos_eq; /// Current Position in the equatorial coordinates (absolute pointing direction in the sky)
@@ -74,10 +74,8 @@
 	 *       This should be done using the invert option when initializing the RotationAxis objects
 	 * @sa RotationAxis
 	 */
-	EquatorialMount(Axis &ra, Axis &dec, UTCClock &clk,
-			LocationCoordinates loc);
-	virtual ~EquatorialMount()
-	{
+	EquatorialMount(Axis &ra, Axis &dec, UTCClock &clk, LocationProvider &loc);
+	virtual ~EquatorialMount() {
 	}
 
 	/**
@@ -88,8 +86,7 @@
 	osStatus goTo(double ra_dest, double dec_dest);
 	osStatus goTo(EquatorialCoordinates dest);
 	osStatus goToMount(MountCoordinates mc, bool withCorrection = true);
-	osStatus goToIndex()
-	{
+	osStatus goToIndex() {
 		return goToMount(MountCoordinates(0, 0));
 	}
 
@@ -106,78 +103,68 @@
 	osStatus guide(guidedir_t dir, int ms);
 
 	/*Calibration related functions*/
-	
+
 	/**
 	 * Clear calibration, use current latitude for the polar axis
 	 */
-	void clearCalibration()
-	{
+	void clearCalibration() {
 		num_alignment_stars = 0;
 		calibration = EqCalibration();
-		calibration.pa.alt = location.lat;
+		calibration.pa.alt = loc.getLatitude();
 	}
-	
+
 	/** 
 	 * Clear calibration except axis offsets, use current latitude for the polar axis
 	 */
-	void clearCalibrationExceptOffsets()
-	{
+	void clearCalibrationExceptOffsets() {
 		num_alignment_stars = 0;
 		calibration.cone = 0;
-		calibration.pa.alt = location.lat;
+		calibration.pa.alt = loc.getLatitude();
 		calibration.pa.azi = 0;
 	}
 
 	/**
-	* Get calibration
-	* @return Current calibration
-	*/
-	const EqCalibration &getCalibration() const
-	{
+	 * Get calibration
+	 * @return Current calibration
+	 */
+	const EqCalibration &getCalibration() const {
 		return calibration;
 	}
-	
+
 	/**
-	* Set calibration
-	* @param calib New Calibration
-	*/
-	void setCalibration(const EqCalibration &calib){
+	 * Set calibration
+	 * @param calib New Calibration
+	 */
+	void setCalibration(const EqCalibration &calib) {
 		calibration = calib;
 	}
 
 	/** @return number of alignment stars
-	*/
-	int getNumAlignmentStar()
-	{
+	 */
+	int getNumAlignmentStar() {
 		return num_alignment_stars;
 	}
 
 	/** Add an alignment star
-	* @return osStatus error if no more star can be added
-	*/
-	osStatus addAlignmentStar(const AlignmentStar &as)
-	{
-		if (num_alignment_stars < MAX_AS_N)
-		{
+	 * @return osStatus error if no more star can be added
+	 */
+	osStatus addAlignmentStar(const AlignmentStar &as) {
+		if (num_alignment_stars < MAX_AS_N) {
 			alignment_stars[num_alignment_stars++] = as;
 			return recalibrate();
-		}
-		else
+		} else
 			return osErrorResource;
 	}
 
 	/** Remove an alignment star
-	* @param index # of star to remove, starting from 0
-	* @return osStatus error if no more star can be deleted
-	*/
-	osStatus removeAlignmentStar(int index)
-	{
-		if (index < 0 || index >= num_alignment_stars)
-		{
+	 * @param index # of star to remove, starting from 0
+	 * @return osStatus error if no more star can be deleted
+	 */
+	osStatus removeAlignmentStar(int index) {
+		if (index < 0 || index >= num_alignment_stars) {
 			return osErrorParameter;
 		}
-		for (; index < num_alignment_stars - 1; index++)
-		{
+		for (; index < num_alignment_stars - 1; index++) {
 			alignment_stars[index] = alignment_stars[index + 1];
 		}
 		num_alignment_stars--;
@@ -185,51 +172,48 @@
 	}
 
 	/** Get alignment star
-	* @param index # of star to get
-	* @return pointer to that alignment star if found, NULL if doesn't exist
-	*/
-	AlignmentStar *getAlignmentStar(int index)
-	{
-		if (index < 0 || index >= num_alignment_stars)
-		{
+	 * @param index # of star to get
+	 * @return pointer to that alignment star if found, NULL if doesn't exist
+	 */
+	AlignmentStar *getAlignmentStar(int index) {
+		if (index < 0 || index >= num_alignment_stars) {
 			return NULL;
 		}
 		return &alignment_stars[index];
 	}
 
 	/** Replace an alignment star with another
-	* @param index # of star to replace
-	* @param as new star to add. Will be copied by value
-	* @return error if star not found
-	*/
-	osStatus replaceAlignmentStar(int index, const AlignmentStar &as)
-	{
-		if (index < 0 || index >= num_alignment_stars)
-		{
+	 * @param index # of star to replace
+	 * @param as new star to add. Will be copied by value
+	 * @return error if star not found
+	 */
+	osStatus replaceAlignmentStar(int index, const AlignmentStar &as) {
+		if (index < 0 || index >= num_alignment_stars) {
 			return osErrorParameter;
 		}
 		alignment_stars[index] = as;
 		return recalibrate();
 	}
-	
+
 	/** Force all alignment stars to be perfected aligned according to the current calibration
-	* Useful during a polar alignment procedure
-	* @note This will throw off all the alignment stars if the error is too big or calibration is wrong
-	*/
+	 * Useful during a polar alignment procedure
+	 * @note This will throw off all the alignment stars if the error is too big or calibration is wrong
+	 */
 	void forceAlignment();
 
 	/**
-	* Convert EQ coordinates to mount coodinates using current calibration. Utility function
-	* @param eq EQ coordinate to convert
-	* @return mount coordinates
-	*/
-	MountCoordinates convertToMountCoordinates(const EquatorialCoordinates &eq)
-	{
+	 * Convert EQ coordinates to mount coodinates using current calibration. Utility function
+	 * @param eq EQ coordinate to convert
+	 * @return mount coordinates
+	 */
+	MountCoordinates convertToMountCoordinates(
+			const EquatorialCoordinates &eq) {
 		LocalEquatorialCoordinates leq =
 				CelestialMath::equatorialToLocalEquatorial(eq, clock.getTime(),
-						location);
+						loc.getLocation());
 		// Apply PA misalignment
-		leq = CelestialMath::applyMisalignment(leq, calibration.pa, location);
+		leq = CelestialMath::applyMisalignment(leq, calibration.pa,
+				loc.getLocation());
 		// Apply Cone error
 		leq = CelestialMath::applyConeError(leq, calibration.cone);
 		// Convert to Mount coordinates. Automatically determine the pier side, then apply offset
@@ -238,25 +222,23 @@
 	}
 
 	/**
-	* Convert mount coordinates to EQ coodinates using current calibration. Utility function
-	* @param mc Mount coordinate to convert
-	* @return EQ coordinates
-	*/
-	EquatorialCoordinates convertToEqCoordinates(const MountCoordinates &mc)
-	{
+	 * Convert mount coordinates to EQ coodinates using current calibration. Utility function
+	 * @param mc Mount coordinate to convert
+	 * @return EQ coordinates
+	 */
+	EquatorialCoordinates convertToEqCoordinates(const MountCoordinates &mc) {
 		LocalEquatorialCoordinates leq = CelestialMath::mountToLocalEquatorial(
 				mc - calibration.offset);
 		leq = CelestialMath::deapplyConeError(leq, calibration.cone);
-		leq = CelestialMath::deapplyMisalignment(leq, calibration.pa, location);
+		leq = CelestialMath::deapplyMisalignment(leq, calibration.pa, loc.getLocation());
 		return CelestialMath::localEquatorialToEquatorial(leq, clock.getTime(),
-				location);
+				loc.getLocation());
 	}
 
-
 	/**
-	* Use alignment stars to recalculate the calibration. 
-	* @return osStatus
-	*/
+	 * Use alignment stars to recalculate the calibration.
+	 * @return osStatus
+	 */
 	osStatus recalibrate();
 
 	/**
@@ -281,8 +263,7 @@
 	 * Get current equatorial coordinates
 	 * @return current equatorial coordinates
 	 */
-	const EquatorialCoordinates &getEquatorialCoordinates()
-	{
+	const EquatorialCoordinates &getEquatorialCoordinates() {
 		updatePosition();
 		return curr_pos_eq;
 	}
@@ -291,8 +272,7 @@
 	 * Get current mount coordinates
 	 * @return current mount coordinates
 	 */
-	const MountCoordinates &getMountCoordinates()
-	{
+	const MountCoordinates &getMountCoordinates() {
 		updatePosition();
 		return curr_pos;
 	}
@@ -302,8 +282,7 @@
 	 * @param star_ref Reference star position
 	 * @return AlignmentStar object representing the alignment star
 	 */
-	AlignmentStar makeAlignmentStar(const EquatorialCoordinates star_ref)
-	{
+	AlignmentStar makeAlignmentStar(const EquatorialCoordinates star_ref) {
 		updatePosition();
 		return AlignmentStar(star_ref, curr_pos, clock.getTime());
 	}
@@ -324,9 +303,9 @@
 	 * @param rate new speed
 	 */
 	void setSlewSpeed(double rate);
-	
+
 	/** @return current slew speed
-	*/
+	 */
 	double getSlewSpeed();
 
 	/**
@@ -334,9 +313,9 @@
 	 * @param rate new speed in sidereal rate
 	 */
 	void setTrackSpeedSidereal(double rate);
-	
+
 	/** @return current track speed in sidereal units
-	*/
+	 */
 	double getTrackSpeedSidereal();
 
 	/**
@@ -344,16 +323,15 @@
 	 * @param rate new speed in sidereal rate
 	 */
 	void setGuideSpeedSidereal(double rate);
-	
+
 	/** @return current guide speed in sidereal units
-	*/
+	 */
 	double getGuideSpeedSidereal();
 
 	/**
 	 * Print current position to stream. 
 	 */
-	void printPosition(FILE *stream = stdout)
-	{
+	void printPosition(FILE *stream = stdout) {
 		fprintf(stream, "Mount: RA=%7.2f, DEC=%7.2f %c\n", curr_pos.ra_delta,
 				curr_pos.dec_delta,
 				(curr_pos.side == PIER_SIDE_WEST) ? 'W' : 'E');
@@ -362,25 +340,23 @@
 	}
 
 	/**
-	* Update current pointing direction from low-level encoders/counters.
-	* @note should be called before printing the position using printPosition
-	*/
+	 * Update current pointing direction from low-level encoders/counters.
+	 * @note should be called before printing the position using printPosition
+	 */
 	void updatePosition();
 
 	/** Get current time source
-	*/
-	UTCClock& getClock() const
-	{
+	 */
+	UTCClock& getClock() const {
 		return clock;
 	}
 
 	/** @return get current location coodinates.
-	*/
-	const LocationCoordinates& getLocation() const
-	{
-		return location;
+	 */
+	const LocationCoordinates& getLocation() const {
+		return loc.getLocation();
 	}
-	
+
 };
 
 #endif /*EQUATORIALMOUNT_H_*/