@@ -37,6 +37,7 @@ char* formatStringsDEC[] = {
3737 " %c%02d*%02d'%02d#" , // Meade
3838 " %c%02d %02d'%02d\" " , // Print
3939 " %c%02d@%02d'%02d\" " , // LCD display only
40+ " %c%02d%02d%02d" , // Compact
4041};
4142
4243char * formatStringsRA[] = {
@@ -45,6 +46,7 @@ char* formatStringsRA[] = {
4546 " %02d:%02d:%02d#" , // Meade
4647 " %02dh %02dm %02ds" , // Print
4748 " %02dh%02dm%02ds" , // LCD display only
49+ " %02d%02d%02d" , // Compact
4850};
4951
5052const float siderealDegreesInHour = 14.95902778 ;
@@ -75,8 +77,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
7577 _stepperRA = new AccelStepper (stepMode, pin1, pin2, pin3, pin4);
7678 _stepperRA->setMaxSpeed (maxSpeed);
7779 _stepperRA->setAcceleration (maxAcceleration);
78- // _maxRASpeed = maxSpeed;
79- // _maxRAAcceleration = maxAcceleration;
80+ _maxRASpeed = maxSpeed;
81+ _maxRAAcceleration = maxAcceleration;
8082
8183 // Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
8284 _stepperTRK = new AccelStepper (HALFSTEP, pin1, pin2, pin3, pin4);
@@ -264,25 +266,6 @@ void Mount::syncDEC(int degree, int minute, int second) {
264266 _stepperDEC->setCurrentPosition (targetDEC);
265267}
266268
267- // ///////////////////////////////
268- //
269- // stopGuiding
270- //
271- // ///////////////////////////////
272- void Mount::stopGuiding () {
273- _stepperDEC->stop ();
274- while (_stepperDEC->isRunning ()) {
275- _stepperDEC->run ();
276- }
277- _stepperDEC->setMaxSpeed (_maxDECSpeed);
278- _stepperDEC->setAcceleration (_maxDECAcceleration);
279- _stepperTRK->setMaxSpeed (10 );
280- _stepperTRK->setAcceleration (2500 );
281- _stepperTRK->setSpeed (_trackingSpeed);
282- _stepperTRK->runSpeed ();
283- _mountStatus &= ~STATUS_GUIDE_PULSE_MASK;
284- }
285-
286269// ///////////////////////////////
287270//
288271// startSlewingToTarget
@@ -307,44 +290,61 @@ void Mount::startSlewingToTarget() {
307290 _totalRAMove = 1 .0f * _stepperRA->distanceToGo ();
308291}
309292
293+ // ///////////////////////////////
294+ //
295+ // stopGuiding
296+ //
297+ // ///////////////////////////////
298+ void Mount::stopGuiding () {
299+ _stepperDEC->stop ();
300+ while (_stepperDEC->isRunning ()) {
301+ _stepperDEC->run ();
302+ }
303+
304+ _stepperDEC->setMaxSpeed (_maxDECSpeed);
305+ _stepperDEC->setAcceleration (_maxDECAcceleration);
306+ _stepperTRK->setMaxSpeed (10 );
307+ _stepperTRK->setAcceleration (2500 );
308+ _stepperTRK->setSpeed (_trackingSpeed);
309+ _mountStatus &= ~STATUS_GUIDE_PULSE_MASK;
310+ }
311+
310312// ///////////////////////////////
311313//
312314// guidePulse
313315//
314316// ///////////////////////////////
315317void Mount::guidePulse (byte direction, int duration) {
316- // How many steps moves the RA ring one sidereal hour along. One sidereal hour moves just shy of 15 degrees
317- // NOTE: May need to adjust with _trackingSpeedCalibration
318- float decStepsPerSiderealHour = _stepsPerDECDegree * siderealDegreesInHour;
319- float decStepsForDuration = decStepsPerSiderealHour * duration / 3600000 ;
320- float raStepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
321- float raStepsForDuration = raStepsPerSiderealHour * duration / 3600000 ;
322-
318+ // DEC stepper moves at sidereal rate in both directions
319+ // RA stepper moves at either 2x sidereal rate or stops.
320+ // TODO: Do we need to adjust with _trackingSpeedCalibration?
323321 float decTrackingSpeed = _stepsPerDECDegree * siderealDegreesInHour / 3600 .0f ;
324322 float raTrackingSpeed = _stepsPerRADegree * siderealDegreesInHour / 3600 .0f ;
325323
326- long raPos = _stepperRA->currentPosition ();
327- long decPos = _stepperDEC->currentPosition ();
324+ // TODO: Do we need to track how many steps the steppers took and add them to the GoHome calculation?
325+ // If so, we need to remember where we were when we started the guide pulse. Then at the end,
326+ // we can calculate the difference.
327+ // long raPos = _stepperTRK->currentPosition();
328+ // long decPos = _stepperDEC->currentPosition();
328329
329330 switch (direction) {
330331 case NORTH:
332+ _stepperDEC->setAcceleration (2500 );
331333 _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
332334 _stepperDEC->setSpeed (decTrackingSpeed);
333- _stepperDEC->moveTo (decPos + decStepsForDuration);
334335 _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
335336 break ;
336337
337338 case SOUTH:
339+ _stepperDEC->setAcceleration (2500 );
338340 _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
339- _stepperDEC->setSpeed (decTrackingSpeed);
340- _stepperDEC->moveTo (decPos - decStepsForDuration);
341+ _stepperDEC->setSpeed (-decTrackingSpeed);
341342 _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
342343 break ;
343344
344345 case WEST:
345346 _stepperTRK->setMaxSpeed (raTrackingSpeed * 2.2 );
346347 _stepperTRK->setSpeed (raTrackingSpeed * 2 );
347- _stepperTRK->moveTo (raPos + raStepsForDuration);
348348 _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
349349 break ;
350350
@@ -358,6 +358,52 @@ void Mount::guidePulse(byte direction, int duration) {
358358 _guideEndTime = millis () + duration;
359359}
360360
361+ // ///////////////////////////////
362+ //
363+ // runDriftAlignmentPhase
364+ //
365+ // Runs one of the phases of the Drift alignment
366+ // This runs the RA motor 400 steps (about 5.3 arcminutes) in the given duration
367+ // This function should be callsed 3 times:
368+ // The first time with EAST, second with WEST and then with 0.
369+ // ///////////////////////////////
370+ void Mount::runDriftAlignmentPhase (int direction, int durationSecs) {
371+ // Calculate the speed at which it takes the given duration to cover 400 steps.
372+ float speed = 400.0 / durationSecs;
373+ switch (direction) {
374+ case EAST:
375+ // Move 400 steps east at the calculated speed, synchronously
376+ _stepperRA->setAcceleration (1500 );
377+ _stepperRA->setMaxSpeed (speed);
378+ _stepperRA->move (400 );
379+ _stepperRA->runToPosition ();
380+
381+ // Overcome the gearing gap
382+ _stepperRA->setMaxSpeed (300 );
383+ _stepperRA->move (-20 );
384+ _stepperRA->runToPosition ();
385+ break ;
386+
387+ case WEST:
388+ // Move 400 steps west at the calculated speed, synchronously
389+ _stepperRA->setMaxSpeed (speed);
390+ _stepperRA->move (-400 );
391+ _stepperRA->runToPosition ();
392+ break ;
393+
394+ case 0 :
395+ // Fix the gearing to go back the other way
396+ _stepperRA->setMaxSpeed (300 );
397+ _stepperRA->move (20 );
398+ _stepperRA->runToPosition ();
399+
400+ // Re-configure the stepper to the correct parameters.
401+ _stepperRA->setAcceleration (_maxRAAcceleration);
402+ _stepperRA->setMaxSpeed (_maxRASpeed);
403+ break ;
404+ }
405+ }
406+
361407// ///////////////////////////////
362408//
363409// park
@@ -417,8 +463,8 @@ String Mount::mountStatusString() {
417463 if (_mountStatus & STATUS_PARKING) {
418464 disp = " PARKNG " ;
419465 }
420- else if (isGuiding ()){
421- disp = " GUIDING " ;
466+ else if (isGuiding ()) {
467+ disp = " GUIDING " ;
422468 }
423469 else {
424470 if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
@@ -442,6 +488,57 @@ String Mount::mountStatusString() {
442488}
443489#endif
444490
491+ // ///////////////////////////////
492+ //
493+ // getStatusString
494+ //
495+ // ///////////////////////////////
496+ String Mount::getStatusString () {
497+ String status;
498+ if (_mountStatus == STATUS_PARKED) {
499+ status = " Parked," ;
500+ }
501+ else if (_mountStatus & STATUS_PARKING) {
502+ status = " Parking," ;
503+ }
504+ else if (isGuiding ()) {
505+ status = " Guiding," ;
506+ }
507+ else if (slewStatus () & SLEW_MASK_ANY) {
508+ if (_mountStatus & STATUS_SLEWING_TO_TARGET) {
509+ status = " SlewToTarget," ;
510+ }
511+ else if (_mountStatus & STATUS_SLEWING_FREE) {
512+ status = " FreeSlew," ;
513+ }
514+ else {
515+ status = " Idle," ;
516+ }
517+ } else {
518+ status = " Idle," ;
519+ }
520+
521+ String disp = " ---," ;
522+ if (_mountStatus & STATUS_SLEWING) {
523+ byte slew = slewStatus ();
524+ if (slew & SLEWING_RA) disp[0 ] = _stepperRA->speed () < 0 ? ' R' : ' r' ;
525+ if (slew & SLEWING_DEC) disp[1 ] = _stepperDEC->speed () < 0 ? ' D' : ' d' ;
526+ if (slew & SLEWING_TRACKING) disp[2 ] = ' T' ;
527+ } else if (isSlewingTRK ()) {
528+ disp[2 ] = ' T' ;
529+ }
530+
531+ status += disp;
532+ status += String (_stepperRA->currentPosition ()) + " ," ;
533+ status += String (_stepperDEC->currentPosition ()) + " ," ;
534+ status += String (_stepperTRK->currentPosition ()) + " ," ;
535+
536+ status += RAString (COMPACT_STRING | CURRENT_STRING) + " ," ;
537+ status += DECString (COMPACT_STRING | CURRENT_STRING) + " ," ;
538+
539+ return status ;
540+ }
541+
445542// ///////////////////////////////
446543//
447544// slewingStatus
@@ -861,8 +958,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
861958//
862959// ///////////////////////////////
863960void Mount::displayStepperPosition () {
864- #ifndef HEADLESS_CLIENT
865-
961+ #ifndef HEADLESS_CLIENT
962+
866963 String disp ;
867964
868965 if ((abs (_totalDECMove) > 0.001 ) && (abs (_totalRAMove) > 0.001 )) {
@@ -893,7 +990,7 @@ void Mount::displayStepperPosition() {
893990 else {
894991#ifdef SUPPORT_SERIAL_CONTROL
895992 if (inSerialControl) {
896- sprintf (scratchBuffer, " RA: %s" , RAString (LCD_STRING | CURRENT_STRING).c_str ());
993+ sprintf (scratchBuffer, " RA: %s" , RAString (LCD_STRING | CURRENT_STRING).c_str ());
897994 _lcdMenu->setCursor (0 , 0 );
898995 _lcdMenu->printMenu (scratchBuffer);
899996 sprintf (scratchBuffer, " DEC: %s" , DECString (LCD_STRING | CURRENT_STRING).c_str ());
@@ -926,13 +1023,13 @@ void Mount::displayStepperPosition() {
9261023//
9271024// ///////////////////////////////
9281025void Mount::displayStepperPositionThrottled () {
929- #ifndef HEADLESS_CLIENT
1026+ #ifndef HEADLESS_CLIENT
9301027 long elapsed = millis () - _lastDisplayUpdate;
9311028 if (elapsed > DISPLAY_UPDATE_TIME) {
9321029 displayStepperPosition ();
9331030 _lastDisplayUpdate = millis ();
9341031 }
935- #endif
1032+ #endif
9361033}
9371034
9381035// ///////////////////////////////
0 commit comments