11#include " LcdMenu.hpp"
2+
23#include " Mount.hpp"
34
45// mountstatus
89#define STATUS_SLEWING_FREE B00000010
910#define STATUS_TRACKING B00001000
1011#define STATUS_PARKING B00010000
12+ #define STATUS_GUIDE_PULSE B10000000
13+ #define STATUS_GUIDE_PULSE_DIR B01100000
14+ #define STATUS_GUIDE_PULSE_RA B01000000
15+ #define STATUS_GUIDE_PULSE_DEC B00100000
16+ #define STATUS_GUIDE_PULSE_MASK B11100000
1117
1218// slewingStatus()
1319#define SLEWING_DEC B00000010
@@ -69,6 +75,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
6975 _stepperRA = new AccelStepper (stepMode, pin1, pin2, pin3, pin4);
7076 _stepperRA->setMaxSpeed (maxSpeed);
7177 _stepperRA->setAcceleration (maxAcceleration);
78+ // _maxRASpeed = maxSpeed;
79+ // _maxRAAcceleration = maxAcceleration;
7280
7381 // Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
7482 _stepperTRK = new AccelStepper (HALFSTEP, pin1, pin2, pin3, pin4);
@@ -86,6 +94,8 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
8694 _stepperDEC = new AccelStepper (stepMode, pin4, pin3, pin2, pin1);
8795 _stepperDEC->setMaxSpeed (maxSpeed);
8896 _stepperDEC->setAcceleration (maxAcceleration);
97+ _maxDECSpeed = maxSpeed;
98+ _maxDECAcceleration = maxAcceleration;
8999}
90100
91101float Mount::getSpeedCalibration () {
@@ -254,6 +264,25 @@ void Mount::syncDEC(int degree, int minute, int second) {
254264 _stepperDEC->setCurrentPosition (targetDEC);
255265}
256266
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+
257286// ///////////////////////////////
258287//
259288// startSlewingToTarget
@@ -262,6 +291,10 @@ void Mount::syncDEC(int degree, int minute, int second) {
262291// Calculates movement parameters and program steppers to move
263292// there. Must call loop() frequently to actually move.
264293void Mount::startSlewingToTarget () {
294+ if (isGuiding ()) {
295+ stopGuiding ();
296+ }
297+
265298 // Calculate new RA stepper target (and DEC)
266299 _currentDECStepperPosition = _stepperDEC->currentPosition ();
267300 _currentRAStepperPosition = _stepperRA->currentPosition ();
@@ -274,15 +307,66 @@ void Mount::startSlewingToTarget() {
274307 _totalRAMove = 1 .0f * _stepperRA->distanceToGo ();
275308}
276309
310+ // ///////////////////////////////
311+ //
312+ // guidePulse
313+ //
314+ // ///////////////////////////////
315+ void 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+
323+ float decTrackingSpeed = _stepsPerDECDegree * siderealDegreesInHour / 3600 .0f ;
324+ float raTrackingSpeed = _stepsPerRADegree * siderealDegreesInHour / 3600 .0f ;
325+
326+ long raPos = _stepperRA->currentPosition ();
327+ long decPos = _stepperDEC->currentPosition ();
328+
329+ switch (direction) {
330+ case NORTH:
331+ _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
332+ _stepperDEC->setSpeed (decTrackingSpeed);
333+ _stepperDEC->moveTo (decPos + decStepsForDuration);
334+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
335+ break ;
336+
337+ case SOUTH:
338+ _stepperDEC->setMaxSpeed (decTrackingSpeed * 1.2 );
339+ _stepperDEC->setSpeed (decTrackingSpeed);
340+ _stepperDEC->moveTo (decPos - decStepsForDuration);
341+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
342+ break ;
343+
344+ case WEST:
345+ _stepperTRK->setMaxSpeed (raTrackingSpeed * 2.2 );
346+ _stepperTRK->setSpeed (raTrackingSpeed * 2 );
347+ _stepperTRK->moveTo (raPos + raStepsForDuration);
348+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
349+ break ;
350+
351+ case EAST:
352+ _stepperTRK->setMaxSpeed (raTrackingSpeed * 2.2 );
353+ _stepperTRK->setSpeed (0 );
354+ _mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
355+ break ;
356+ }
357+
358+ _guideEndTime = millis () + duration;
359+ }
360+
277361// ///////////////////////////////
278362//
279363// park
280364//
281- // Targets the mount to move to the home position and
365+ // Targets the mount to move to the home position and
282366// turns off all motors once it gets there.
283367// ///////////////////////////////
284- void Mount::park ()
285- {
368+ void Mount::park () {
369+ stopGuiding ();
286370 stopSlewing (ALL_DIRECTIONS | TRACKING);
287371 waitUntilStopped (ALL_DIRECTIONS);
288372 setTargetToHome ();
@@ -294,11 +378,12 @@ void Mount::park()
294378//
295379// goHome
296380//
297- // Synchronously moves mount to home position and
381+ // Synchronously moves mount to home position and
298382// sets Tracking mode according to argument
299383// ///////////////////////////////
300384void Mount::goHome (bool tracking)
301385{
386+ stopGuiding ();
302387 stopSlewing (TRACKING);
303388 setTargetToHome ();
304389 startSlewingToTarget ();
@@ -332,6 +417,9 @@ String Mount::mountStatusString() {
332417 if (_mountStatus & STATUS_PARKING) {
333418 disp = " PARKNG " ;
334419 }
420+ else if (isGuiding ()){
421+ disp = " GUIDING " ;
422+ }
335423 else {
336424 if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
337425 if (_mountStatus & STATUS_SLEWING) disp += " SLW " ;
@@ -365,13 +453,26 @@ byte Mount::slewStatus() {
365453 if (_mountStatus == STATUS_PARKED) {
366454 return NOT_SLEWING;
367455 }
456+ if (isGuiding ()) {
457+ return NOT_SLEWING;
458+ }
368459 byte slewState = _stepperRA->isRunning () ? SLEWING_RA : NOT_SLEWING;
369460 slewState |= _stepperDEC->isRunning () ? SLEWING_DEC : NOT_SLEWING;
370461
371462 slewState |= (_mountStatus & STATUS_TRACKING) ? SLEWING_TRACKING : NOT_SLEWING;
372463 return slewState;
373464}
374465
466+ // ///////////////////////////////
467+ //
468+ // isGuiding
469+ //
470+ // ///////////////////////////////
471+ bool Mount::isGuiding ()
472+ {
473+ return (_mountStatus & STATUS_GUIDE_PULSE);
474+ }
475+
375476// ///////////////////////////////
376477//
377478// isSlewingDEC
@@ -449,6 +550,10 @@ bool Mount::isParking() {
449550void Mount::startSlewing (int direction) {
450551 if (!isParking ())
451552 {
553+ if (isGuiding ()) {
554+ stopGuiding ();
555+ }
556+
452557 if (direction & TRACKING) {
453558 _stepperTRK->setSpeed (_trackingSpeed);
454559
@@ -561,6 +666,22 @@ void Mount::loop() {
561666 _lastMountPrint = now;
562667 }
563668#endif
669+ if (isGuiding ()) {
670+ if (millis () > _guideEndTime) {
671+ stopGuiding ();
672+ }
673+ else
674+ {
675+ if (_mountStatus & STATUS_GUIDE_PULSE_RA) {
676+ _stepperTRK->runSpeed ();
677+ }
678+ if (_mountStatus & STATUS_GUIDE_PULSE_DEC) {
679+ _stepperDEC->runSpeed ();
680+ }
681+ }
682+ return ;
683+ }
684+
564685 if (_mountStatus & STATUS_TRACKING) {
565686 _stepperTRK->runSpeed ();
566687 }
@@ -740,6 +861,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
740861//
741862// ///////////////////////////////
742863void Mount::displayStepperPosition () {
864+ #ifndef HEADLESS_CLIENT
865+
743866 String disp ;
744867
745868 if ((abs (_totalDECMove) > 0.001 ) && (abs (_totalRAMove) > 0.001 )) {
@@ -794,6 +917,7 @@ void Mount::displayStepperPosition() {
794917 _lcdMenu->printMenu (disp);
795918#endif
796919 }
920+ #endif
797921}
798922
799923// ///////////////////////////////
@@ -802,11 +926,13 @@ void Mount::displayStepperPosition() {
802926//
803927// ///////////////////////////////
804928void Mount::displayStepperPositionThrottled () {
929+ #ifndef HEADLESS_CLIENT
805930 long elapsed = millis () - _lastDisplayUpdate;
806931 if (elapsed > DISPLAY_UPDATE_TIME) {
807932 displayStepperPosition ();
808933 _lastDisplayUpdate = millis ();
809934 }
935+ #endif
810936}
811937
812938// ///////////////////////////////
0 commit comments