88#define STATUS_SLEWING_FREE B00000010
99#define STATUS_TRACKING B00001000
1010#define STATUS_PARKING B00010000
11+ #define STATUS_GUIDE_PULSE B10000000
12+ #define STATUS_GUIDE_PULSE_DIR B01100000
13+ #define STATUS_GUIDE_PULSE_RA B01000000
14+ #define STATUS_GUIDE_PULSE_DEC B00100000
15+ #define STATUS_GUIDE_PULSE_MASK B11100000
1116
1217// slewingStatus()
1318#define SLEWING_DEC B00000010
@@ -69,6 +74,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
6974 _stepperRA = new AccelStepper (stepMode, pin1, pin2, pin3, pin4);
7075 _stepperRA->setMaxSpeed (maxSpeed);
7176 _stepperRA->setAcceleration (maxAcceleration);
77+ // _maxRASpeed = maxSpeed;
78+ // _maxRAAcceleration = maxAcceleration;
7279
7380 // Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
7481 _stepperTRK = new AccelStepper (HALFSTEP, pin1, pin2, pin3, pin4);
@@ -86,6 +93,8 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
8693 _stepperDEC = new AccelStepper (stepMode, pin4, pin3, pin2, pin1);
8794 _stepperDEC->setMaxSpeed (maxSpeed);
8895 _stepperDEC->setAcceleration (maxAcceleration);
96+ _maxDECSpeed = maxSpeed;
97+ _maxDECAcceleration = maxAcceleration;
8998}
9099
91100float Mount::getSpeedCalibration () {
@@ -254,6 +263,25 @@ void Mount::syncDEC(int degree, int minute, int second) {
254263 _stepperDEC->setCurrentPosition (targetDEC);
255264}
256265
266+ // ///////////////////////////////
267+ //
268+ // stopGuiding
269+ //
270+ // ///////////////////////////////
271+ void Mount::stopGuiding () {
272+ _stepperDEC->stop ();
273+ while (_stepperDEC->isRunning ()) {
274+ _stepperDEC->run ();
275+ }
276+ _stepperDEC->setMaxSpeed (_maxDECSpeed);
277+ _stepperDEC->setAcceleration (_maxDECAcceleration);
278+ _stepperTRK->setMaxSpeed (10 );
279+ _stepperTRK->setAcceleration (2500 );
280+ _stepperTRK->setSpeed (_trackingSpeed);
281+ _stepperTRK->runSpeed ();
282+ _mountStatus &= ~STATUS_GUIDE_PULSE_MASK;
283+ }
284+
257285// ///////////////////////////////
258286//
259287// startSlewingToTarget
@@ -262,6 +290,10 @@ void Mount::syncDEC(int degree, int minute, int second) {
262290// Calculates movement parameters and program steppers to move
263291// there. Must call loop() frequently to actually move.
264292void Mount::startSlewingToTarget () {
293+ if (isGuiding ()) {
294+ stopGuiding ();
295+ }
296+
265297 // Calculate new RA stepper target (and DEC)
266298 _currentDECStepperPosition = _stepperDEC->currentPosition ();
267299 _currentRAStepperPosition = _stepperRA->currentPosition ();
@@ -274,15 +306,66 @@ void Mount::startSlewingToTarget() {
274306 _totalRAMove = 1 .0f * _stepperRA->distanceToGo ();
275307}
276308
309+ // ///////////////////////////////
310+ //
311+ // guidePulse
312+ //
313+ // ///////////////////////////////
314+ void Mount::guidePulse (byte direction, int duration) {
315+ // How many steps moves the RA ring one sidereal hour along. One sidereal hour moves just shy of 15 degrees
316+ // NOTE: May need to adjust with _trackingSpeedCalibration
317+ float decStepsPerSiderealHour = _stepsPerDECDegree * siderealDegreesInHour;
318+ float decStepsForDuration = decStepsPerSiderealHour * duration / 3600000 ;
319+ float raStepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
320+ float raStepsForDuration = raStepsPerSiderealHour * duration / 3600000 ;
321+
322+ float decTrackingSpeed = _stepsPerDECDegree * siderealDegreesInHour / 3600 .0f ;
323+ float raTrackingSpeed = _stepsPerRADegree * siderealDegreesInHour / 3600 .0f ;
324+
325+ long raPos = _stepperRA->currentPosition ();
326+ long decPos = _stepperDEC->currentPosition ();
327+
328+ switch (direction) {
329+ case NORTH:
330+ _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
331+ _stepperDEC->setSpeed (decTrackingSpeed);
332+ _stepperDEC->moveTo (decPos + decStepsForDuration);
333+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
334+ break ;
335+
336+ case SOUTH:
337+ _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
338+ _stepperDEC->setSpeed (decTrackingSpeed);
339+ _stepperDEC->moveTo (decPos - decStepsForDuration);
340+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
341+ break ;
342+
343+ case WEST:
344+ _stepperTRK->setMaxSpeed (raTrackingSpeed * 2.2 );
345+ _stepperTRK->setSpeed (raTrackingSpeed * 2 );
346+ _stepperTRK->moveTo (raPos + raStepsForDuration);
347+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
348+ break ;
349+
350+ case EAST:
351+ _stepperTRK->setMaxSpeed (raTrackingSpeed * 2.2 );
352+ _stepperTRK->setSpeed (0 );
353+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
354+ break ;
355+ }
356+
357+ _guideEndTime = millis () + duration;
358+ }
359+
277360// ///////////////////////////////
278361//
279362// park
280363//
281- // Targets the mount to move to the home position and
364+ // Targets the mount to move to the home position and
282365// turns off all motors once it gets there.
283366// ///////////////////////////////
284- void Mount::park ()
285- {
367+ void Mount::park () {
368+ stopGuiding ();
286369 stopSlewing (ALL_DIRECTIONS | TRACKING);
287370 waitUntilStopped (ALL_DIRECTIONS);
288371 setTargetToHome ();
@@ -294,11 +377,12 @@ void Mount::park()
294377//
295378// goHome
296379//
297- // Synchronously moves mount to home position and
380+ // Synchronously moves mount to home position and
298381// sets Tracking mode according to argument
299382// ///////////////////////////////
300383void Mount::goHome (bool tracking)
301384{
385+ stopGuiding ();
302386 stopSlewing (TRACKING);
303387 setTargetToHome ();
304388 startSlewingToTarget ();
@@ -332,6 +416,9 @@ String Mount::mountStatusString() {
332416 if (_mountStatus & STATUS_PARKING) {
333417 disp = " PARKNG " ;
334418 }
419+ else if (isGuiding ()){
420+ disp = " GUIDING " ;
421+ }
335422 else {
336423 if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
337424 if (_mountStatus & STATUS_SLEWING) disp += " SLW " ;
@@ -365,13 +452,26 @@ byte Mount::slewStatus() {
365452 if (_mountStatus == STATUS_PARKED) {
366453 return NOT_SLEWING;
367454 }
455+ if (isGuiding ()) {
456+ return NOT_SLEWING;
457+ }
368458 byte slewState = _stepperRA->isRunning () ? SLEWING_RA : NOT_SLEWING;
369459 slewState |= _stepperDEC->isRunning () ? SLEWING_DEC : NOT_SLEWING;
370460
371461 slewState |= (_mountStatus & STATUS_TRACKING) ? SLEWING_TRACKING : NOT_SLEWING;
372462 return slewState;
373463}
374464
465+ // ///////////////////////////////
466+ //
467+ // isGuiding
468+ //
469+ // ///////////////////////////////
470+ bool Mount::isGuiding ()
471+ {
472+ return (_mountStatus & STATUS_GUIDE_PULSE);
473+ }
474+
375475// ///////////////////////////////
376476//
377477// isSlewingDEC
@@ -449,6 +549,10 @@ bool Mount::isParking() {
449549void Mount::startSlewing (int direction) {
450550 if (!isParking ())
451551 {
552+ if (isGuiding ()) {
553+ stopGuiding ();
554+ }
555+
452556 if (direction & TRACKING) {
453557 _stepperTRK->setSpeed (_trackingSpeed);
454558
@@ -561,6 +665,22 @@ void Mount::loop() {
561665 _lastMountPrint = now;
562666 }
563667#endif
668+ if (isGuiding ()) {
669+ if (millis () > _guideEndTime) {
670+ stopGuiding ();
671+ }
672+ else
673+ {
674+ if (_mountStatus & STATUS_GUIDE_PULSE_RA) {
675+ _stepperTRK->runSpeed ();
676+ }
677+ if (_mountStatus & STATUS_GUIDE_PULSE_DEC) {
678+ _stepperDEC->runSpeed ();
679+ }
680+ }
681+ return ;
682+ }
683+
564684 if (_mountStatus & STATUS_TRACKING) {
565685 _stepperTRK->runSpeed ();
566686 }
0 commit comments