77#define STATUS_SLEWING_TO_TARGET B00000100
88#define STATUS_SLEWING_FREE B00000010
99#define STATUS_TRACKING B00001000
10+ #define STATUS_PARKING B00010000
1011
1112// slewingStatus()
1213#define SLEWING_DEC B00000010
@@ -273,6 +274,20 @@ void Mount::startSlewingToTarget() {
273274 _totalRAMove = 1 .0f * _stepperRA->distanceToGo ();
274275}
275276
277+ // ///////////////////////////////
278+ //
279+ // park
280+ //
281+ // ///////////////////////////////
282+ void Mount::park ()
283+ {
284+ stopSlewing (ALL_DIRECTIONS | TRACKING);
285+ waitUntilStopped (ALL_DIRECTIONS);
286+ setTargetToHome ();
287+ startSlewingToTarget ();
288+ _mountStatus |= STATUS_PARKING;
289+ }
290+
276291// ///////////////////////////////
277292//
278293// mountStatus
@@ -290,19 +305,24 @@ byte Mount::mountStatus() {
290305// ///////////////////////////////
291306String Mount::mountStatusString () {
292307 if (_mountStatus == STATUS_PARKED) {
293- return " PRKD " ;
308+ return " PARKED " ;
294309 }
295310 String disp = " " ;
296- if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
297- if (_mountStatus & STATUS_SLEWING) disp += " SLW " ;
298- if (_mountStatus & STATUS_SLEWING_TO_TARGET) disp += " 2TRG " ;
299- if (_mountStatus & STATUS_SLEWING_FREE) disp += " FR " ;
300-
301- if (_mountStatus & STATUS_SLEWING) {
302- byte slew = slewStatus ();
303- if (slew & SLEWING_RA) disp += " SRA " ;
304- if (slew & SLEWING_DEC) disp += " SDEC " ;
305- if (slew & SLEWING_TRACKING) disp += " STRK " ;
311+ if (_mountStatus & STATUS_PARKING) {
312+ disp = " PARKNG " ;
313+ }
314+ else {
315+ if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
316+ if (_mountStatus & STATUS_SLEWING) disp += " SLW " ;
317+ if (_mountStatus & STATUS_SLEWING_TO_TARGET) disp += " 2TRG " ;
318+ if (_mountStatus & STATUS_SLEWING_FREE) disp += " FR " ;
319+
320+ if (_mountStatus & STATUS_SLEWING) {
321+ byte slew = slewStatus ();
322+ if (slew & SLEWING_RA) disp += " SRA " ;
323+ if (slew & SLEWING_DEC) disp += " SDEC " ;
324+ if (slew & SLEWING_TRACKING) disp += " STRK " ;
325+ }
306326 }
307327
308328 disp += " RA:" + String (_stepperRA->currentPosition ());
@@ -337,6 +357,7 @@ byte Mount::slewStatus() {
337357//
338358// ///////////////////////////////
339359bool Mount::isSlewingDEC () {
360+ if (isParking ()) return true ;
340361 return (slewStatus () & SLEWING_DEC) != 0 ;
341362}
342363
@@ -346,6 +367,7 @@ bool Mount::isSlewingDEC() {
346367//
347368// ///////////////////////////////
348369bool Mount::isSlewingRA () {
370+ if (isParking ()) return true ;
349371 return (slewStatus () & SLEWING_RA) != 0 ;
350372}
351373
@@ -355,6 +377,7 @@ bool Mount::isSlewingRA() {
355377//
356378// ///////////////////////////////
357379bool Mount::isSlewingRAorDEC () {
380+ if (isParking ()) return true ;
358381 return (slewStatus () & (SLEWING_DEC | SLEWING_RA)) != 0 ;
359382}
360383
@@ -364,6 +387,7 @@ bool Mount::isSlewingRAorDEC() {
364387//
365388// ///////////////////////////////
366389bool Mount::isSlewingIdle () {
390+ if (isParking ()) return false ;
367391 return (slewStatus () & (SLEWING_DEC | SLEWING_RA)) == 0 ;
368392}
369393
@@ -382,38 +406,51 @@ bool Mount::isSlewingTRK() {
382406//
383407// ///////////////////////////////
384408bool Mount::isParked () {
385- return slewStatus () == NOT_SLEWING;
409+ return (slewStatus () == NOT_SLEWING) && (_mountStatus == STATUS_PARKED);
410+ }
411+
412+ // ///////////////////////////////
413+ //
414+ // isParking
415+ //
416+ // ///////////////////////////////
417+ bool Mount::isParking () {
418+ return _mountStatus & STATUS_PARKING;
386419}
387420
388421// ///////////////////////////////
389422//
390423// startSlewing
391424//
392- // Starts manual slewing in one of eight directions or tracking
425+ // Starts manual slewing in one of eight directions or
426+ // tracking, but only if not currently parking!
393427// ///////////////////////////////
394428void Mount::startSlewing (int direction) {
395- if (direction & TRACKING) {
396- _stepperTRK->setSpeed (_trackingSpeed);
429+ if (!isParking ())
430+ {
431+ if (direction & TRACKING) {
432+ _stepperTRK->setSpeed (_trackingSpeed);
397433
398- // Turn on tracking
399- _mountStatus |= STATUS_TRACKING;
400- }
401- else {
402- if (direction & NORTH) {
403- _stepperDEC->moveTo (30000 );
404- _mountStatus |= STATUS_SLEWING;
405- }
406- if (direction & SOUTH ) {
407- _stepperDEC->moveTo (-30000 );
408- _mountStatus |= STATUS_SLEWING;
409- }
410- if (direction & EAST ) {
411- _stepperRA->moveTo (-30000 );
412- _mountStatus |= STATUS_SLEWING;
434+ // Turn on tracking
435+ _mountStatus |= STATUS_TRACKING;
413436 }
414- if (direction & WEST) {
415- _stepperRA->moveTo (30000 );
416- _mountStatus |= STATUS_SLEWING;
437+ else {
438+ if (direction & NORTH) {
439+ _stepperDEC->moveTo (30000 );
440+ _mountStatus |= STATUS_SLEWING;
441+ }
442+ if (direction & SOUTH ) {
443+ _stepperDEC->moveTo (-30000 );
444+ _mountStatus |= STATUS_SLEWING;
445+ }
446+ if (direction & EAST ) {
447+ _stepperRA->moveTo (-30000 );
448+ _mountStatus |= STATUS_SLEWING;
449+ }
450+ if (direction & WEST) {
451+ _stepperRA->moveTo (30000 );
452+ _mountStatus |= STATUS_SLEWING;
453+ }
417454 }
418455 }
419456}
@@ -450,7 +487,6 @@ void Mount::waitUntilStopped(byte direction) {
450487 || ((direction & (NORTH | SOUTH)) && _stepperDEC->isRunning ())
451488 || ((direction & TRACKING) && (((_mountStatus & STATUS_TRACKING) == 0 ) && _stepperTRK->isRunning ()))
452489 ) {
453- // //Serial.print("W4Stp: ");
454490 loop ();
455491 }
456492}
@@ -536,6 +572,14 @@ void Mount::loop() {
536572 // Mount is at Target!
537573 _currentRA = _targetRA;
538574 _currentDEC = _targetDEC;
575+
576+ // If we we're parking, we just reached home. Clear the flag, reset the motors and stop tracking.
577+ if (isParking ()) {
578+ _mountStatus &= ~STATUS_PARKING;
579+ stopSlewing (TRACKING);
580+ setHome ();
581+ }
582+
539583 _currentDECStepperPosition = _stepperDEC->currentPosition ();
540584 _currentRAStepperPosition = _stepperRA->currentPosition ();
541585 _totalDECMove = _totalRAMove = 0 ;
@@ -560,7 +604,6 @@ void Mount::setHome() {
560604 _stepperRA->setCurrentPosition (0 );
561605 _stepperDEC->setCurrentPosition (0 );
562606 _stepperTRK->setCurrentPosition (0 );
563- startSlewing (TRACKING);
564607}
565608
566609// ///////////////////////////////
0 commit comments