Telescope Control Library
Diff: EquatorialMount.cpp
- Revision:
- 17:7e47bc1630c0
- Parent:
- 10:e356188d208e
- Child:
- 19:fd854309cb4c
--- a/EquatorialMount.cpp Fri Sep 14 03:05:47 2018 -0400 +++ b/EquatorialMount.cpp Fri Sep 14 21:09:02 2018 -0400 @@ -139,8 +139,7 @@ } osStatus s = osOK; mutex_execution.lock(); - if (newdir == NUDGE_NONE) // Stop nudging if being nudged - { + if (newdir == NUDGE_NONE) { // Stop nudging if being nudged if (status & MOUNT_NUDGING) { mountstatus_t oldstatus = status; stopAsync(); // Stop the mount @@ -234,7 +233,7 @@ // Now RA if (ra_changed && s == osOK) { - if (status & MOUNT_TRACKING) { // In tracking mode now + if (status & MOUNT_TRACKING) { // In tracking mode now, need to calculate differential rate if (ra_dir == AXIS_ROTATE_STOP) { // resume tracking s = ra.startTracking(AXIS_ROTATE_POSITIVE); } else { @@ -385,11 +384,61 @@ } void EquatorialMount::setSlewSpeed(double rate) { -// mutex_execution.lock(); - ra.setSlewSpeed(rate); + if (status & MOUNT_NUDGING) { + // Need to lock the mutex if mount is being nudged, to update the nudgeSpeed + mutex_execution.lock(); + nudgeSpeed = rate; // Update nudgeSpeed + if ((status == MOUNT_NUDGING_TRACKING) + && ((curr_nudge_dir & (NUDGE_EAST | NUDGE_WEST)) != 0)) { // Need to take special care in nudging_tracking mode that affects RA (i.e. indefinite slew w/ tracking) + axisrotdir_t ra_dir = AXIS_ROTATE_STOP, curr_dir; + // Get RA rotation direction (on top of tracking rate) + if (curr_nudge_dir & NUDGE_EAST) { + // Nudge east + ra_dir = AXIS_ROTATE_NEGATIVE; + } else if (curr_nudge_dir & NUDGE_WEST) { + // Nudge west + ra_dir = AXIS_ROTATE_POSITIVE; + } + + curr_dir = ra.getCurrentDirection(); // Current direction + + double trackSpeed = ra.getTrackSpeedSidereal() * sidereal_speed; + double absSpeed = nudgeSpeed; + + if (ra_dir == AXIS_ROTATE_POSITIVE) { + // Same direction as tracking + absSpeed = nudgeSpeed + trackSpeed; + // keep ra_dir + } else if (nudgeSpeed < trackSpeed) { // ra_dir == AXIS_ROTATE_NEGATIVE + // Partially canceling the tracking speed + absSpeed = trackSpeed - nudgeSpeed; + } else if (nudgeSpeed > trackSpeed) {// ra_dir == AXIS_ROTATE_NEGATIVE + // Direction inverted + absSpeed = nudgeSpeed - trackSpeed; + ra_dir = AXIS_ROTATE_NEGATIVE; // Invert the rotation + } else { // nudgeSpeed == trackSpeed + absSpeed = 0; // Set speed to zero, although effective the speed would be a tiny value + } + + if (ra_dir != curr_dir) { + ra.stop(); + } + ra.setSlewSpeed(absSpeed); + if (ra_dir != curr_dir) { + ra.startSlewingIndefinite(ra_dir); + } + + } else { + // Simply update rate + ra.setSlewSpeed(rate); + } + mutex_execution.unlock(); + } else { + // Simply update rate + ra.setSlewSpeed(rate); + } + // Simply update rate for DEC dec.setSlewSpeed(rate); - nudgeSpeed = rate; // If this happens during nudging, this is necessary to keep the nudging speed correct -// mutex_execution.unlock(); } void EquatorialMount::setTrackSpeedSidereal(double rate) {