1
1
#include " LcdMenu.hpp"
2
+
2
3
#include " Mount.hpp"
3
4
4
5
// mountstatus
8
9
#define STATUS_SLEWING_FREE B00000010
9
10
#define STATUS_TRACKING B00001000
10
11
#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
11
17
12
18
// slewingStatus()
13
19
#define SLEWING_DEC B00000010
@@ -69,6 +75,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
69
75
_stepperRA = new AccelStepper (stepMode, pin1, pin2, pin3, pin4);
70
76
_stepperRA->setMaxSpeed (maxSpeed);
71
77
_stepperRA->setAcceleration (maxAcceleration);
78
+ // _maxRASpeed = maxSpeed;
79
+ // _maxRAAcceleration = maxAcceleration;
72
80
73
81
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
74
82
_stepperTRK = new AccelStepper (HALFSTEP, pin1, pin2, pin3, pin4);
@@ -86,6 +94,8 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
86
94
_stepperDEC = new AccelStepper (stepMode, pin4, pin3, pin2, pin1);
87
95
_stepperDEC->setMaxSpeed (maxSpeed);
88
96
_stepperDEC->setAcceleration (maxAcceleration);
97
+ _maxDECSpeed = maxSpeed;
98
+ _maxDECAcceleration = maxAcceleration;
89
99
}
90
100
91
101
float Mount::getSpeedCalibration () {
@@ -254,6 +264,25 @@ void Mount::syncDEC(int degree, int minute, int second) {
254
264
_stepperDEC->setCurrentPosition (targetDEC);
255
265
}
256
266
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
+
257
286
// ///////////////////////////////
258
287
//
259
288
// startSlewingToTarget
@@ -262,6 +291,10 @@ void Mount::syncDEC(int degree, int minute, int second) {
262
291
// Calculates movement parameters and program steppers to move
263
292
// there. Must call loop() frequently to actually move.
264
293
void Mount::startSlewingToTarget () {
294
+ if (isGuiding ()) {
295
+ stopGuiding ();
296
+ }
297
+
265
298
// Calculate new RA stepper target (and DEC)
266
299
_currentDECStepperPosition = _stepperDEC->currentPosition ();
267
300
_currentRAStepperPosition = _stepperRA->currentPosition ();
@@ -274,15 +307,66 @@ void Mount::startSlewingToTarget() {
274
307
_totalRAMove = 1 .0f * _stepperRA->distanceToGo ();
275
308
}
276
309
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
+
277
361
// ///////////////////////////////
278
362
//
279
363
// park
280
364
//
281
- // Targets the mount to move to the home position and
365
+ // Targets the mount to move to the home position and
282
366
// turns off all motors once it gets there.
283
367
// ///////////////////////////////
284
- void Mount::park ()
285
- {
368
+ void Mount::park () {
369
+ stopGuiding ();
286
370
stopSlewing (ALL_DIRECTIONS | TRACKING);
287
371
waitUntilStopped (ALL_DIRECTIONS);
288
372
setTargetToHome ();
@@ -294,11 +378,12 @@ void Mount::park()
294
378
//
295
379
// goHome
296
380
//
297
- // Synchronously moves mount to home position and
381
+ // Synchronously moves mount to home position and
298
382
// sets Tracking mode according to argument
299
383
// ///////////////////////////////
300
384
void Mount::goHome (bool tracking)
301
385
{
386
+ stopGuiding ();
302
387
stopSlewing (TRACKING);
303
388
setTargetToHome ();
304
389
startSlewingToTarget ();
@@ -332,6 +417,9 @@ String Mount::mountStatusString() {
332
417
if (_mountStatus & STATUS_PARKING) {
333
418
disp = " PARKNG " ;
334
419
}
420
+ else if (isGuiding ()){
421
+ disp = " GUIDING " ;
422
+ }
335
423
else {
336
424
if (_mountStatus & STATUS_TRACKING) disp += " TRK " ;
337
425
if (_mountStatus & STATUS_SLEWING) disp += " SLW " ;
@@ -365,13 +453,26 @@ byte Mount::slewStatus() {
365
453
if (_mountStatus == STATUS_PARKED) {
366
454
return NOT_SLEWING;
367
455
}
456
+ if (isGuiding ()) {
457
+ return NOT_SLEWING;
458
+ }
368
459
byte slewState = _stepperRA->isRunning () ? SLEWING_RA : NOT_SLEWING;
369
460
slewState |= _stepperDEC->isRunning () ? SLEWING_DEC : NOT_SLEWING;
370
461
371
462
slewState |= (_mountStatus & STATUS_TRACKING) ? SLEWING_TRACKING : NOT_SLEWING;
372
463
return slewState;
373
464
}
374
465
466
+ // ///////////////////////////////
467
+ //
468
+ // isGuiding
469
+ //
470
+ // ///////////////////////////////
471
+ bool Mount::isGuiding ()
472
+ {
473
+ return (_mountStatus & STATUS_GUIDE_PULSE);
474
+ }
475
+
375
476
// ///////////////////////////////
376
477
//
377
478
// isSlewingDEC
@@ -449,6 +550,10 @@ bool Mount::isParking() {
449
550
void Mount::startSlewing (int direction) {
450
551
if (!isParking ())
451
552
{
553
+ if (isGuiding ()) {
554
+ stopGuiding ();
555
+ }
556
+
452
557
if (direction & TRACKING) {
453
558
_stepperTRK->setSpeed (_trackingSpeed);
454
559
@@ -561,6 +666,22 @@ void Mount::loop() {
561
666
_lastMountPrint = now;
562
667
}
563
668
#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
+
564
685
if (_mountStatus & STATUS_TRACKING) {
565
686
_stepperTRK->runSpeed ();
566
687
}
@@ -740,6 +861,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
740
861
//
741
862
// ///////////////////////////////
742
863
void Mount::displayStepperPosition () {
864
+ #ifndef HEADLESS_CLIENT
865
+
743
866
String disp ;
744
867
745
868
if ((abs (_totalDECMove) > 0.001 ) && (abs (_totalRAMove) > 0.001 )) {
@@ -794,6 +917,7 @@ void Mount::displayStepperPosition() {
794
917
_lcdMenu->printMenu (disp);
795
918
#endif
796
919
}
920
+ #endif
797
921
}
798
922
799
923
// ///////////////////////////////
@@ -802,11 +926,13 @@ void Mount::displayStepperPosition() {
802
926
//
803
927
// ///////////////////////////////
804
928
void Mount::displayStepperPositionThrottled () {
929
+ #ifndef HEADLESS_CLIENT
805
930
long elapsed = millis () - _lastDisplayUpdate;
806
931
if (elapsed > DISPLAY_UPDATE_TIME) {
807
932
displayStepperPosition ();
808
933
_lastDisplayUpdate = millis ();
809
934
}
935
+ #endif
810
936
}
811
937
812
938
// ///////////////////////////////
0 commit comments