Skip to content

Commit 96020e3

Browse files
author
openastrotech
committed
NEMA bump to .56
1 parent 8645e5d commit 96020e3

File tree

6 files changed

+345
-241
lines changed

6 files changed

+345
-241
lines changed

Software/Arduino code/OpenAstroTracker/Globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ void EEPROMupdate(int loc, byte val);
1212
// Time in ms between LCD screen updates during slewing operations
1313
#define DISPLAY_UPDATE_TIME 200
1414

15+
// Stepper selection ///////////
16+
#define RA_Stepper_TYPE 1 // 28BYJ-48 = 0 | NEMA = 1
17+
#define DEC_Stepper_TYPE 0 // 28BYJ-48 = 0 | NEMA = 1
18+
1519
// Make some variables in the sketch files available to the C++ code.
1620
extern bool inSerialControl;
1721
extern String version;

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 132 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ Mount::Mount(int stepsPerRADegree, int stepsPerDECDegree, LcdMenu* lcdMenu) {
6767
_stepperWasRunning = false;
6868
_totalDECMove = 0;
6969
_totalRAMove = 0;
70+
#if RA_Stepper_TYPE == 1
7071
_backlashCorrectionSteps = 16;
72+
#else
73+
_backlashCorrectionSteps = 0;
74+
#endif
7175
_correctForBacklash = false;
7276
_slewingToHome = false;
7377
readPersistentData();
@@ -145,36 +149,36 @@ void Mount::writePersistentData(int which, int val)
145149
}
146150
switch (which) {
147151
case RA_STEPS:
148-
{
149-
// ... set bit 0 to indicate RA value has been written to 6/7
150-
flag |= 0x01;
151-
loByteLocation = 6;
152-
hiByteLocation = 7;
153-
}
154-
break;
152+
{
153+
// ... set bit 0 to indicate RA value has been written to 6/7
154+
flag |= 0x01;
155+
loByteLocation = 6;
156+
hiByteLocation = 7;
157+
}
158+
break;
155159
case DEC_STEPS:
156-
{
157-
// ... set bit 1 to indicate DEC value has been written to 8/9
158-
flag |= 0x02;
159-
loByteLocation = 8;
160-
hiByteLocation = 9;
161-
}
162-
break;
160+
{
161+
// ... set bit 1 to indicate DEC value has been written to 8/9
162+
flag |= 0x02;
163+
loByteLocation = 8;
164+
hiByteLocation = 9;
165+
}
166+
break;
163167
case SPEED_FACTOR_DECIMALS:
164-
{
165-
// ... set bit 2 to indicate speed factor value has been written to 0/3
166-
flag |= 0x04;
167-
loByteLocation = 0;
168-
hiByteLocation = 3;
169-
}
168+
{
169+
// ... set bit 2 to indicate speed factor value has been written to 0/3
170+
flag |= 0x04;
171+
loByteLocation = 0;
172+
hiByteLocation = 3;
173+
}
170174
case BACKLASH_CORRECTION:
171-
{
172-
// ... set bit 2 to indicate speed factor value has been written to 0/3
173-
flag |= 0x08;
174-
loByteLocation = 10;
175-
hiByteLocation = 11;
176-
}
177-
break;
175+
{
176+
// ... set bit 2 to indicate speed factor value has been written to 0/3
177+
flag |= 0x08;
178+
loByteLocation = 10;
179+
hiByteLocation = 11;
180+
}
181+
break;
178182
}
179183

180184

@@ -190,6 +194,8 @@ void Mount::writePersistentData(int which, int val)
190194
// configureRAStepper
191195
//
192196
/////////////////////////////////
197+
198+
#if RA_Stepper_TYPE == 0 // 28BYJ
193199
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
194200
{
195201
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
@@ -203,12 +209,30 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
203209
_stepperTRK->setMaxSpeed(10);
204210
_stepperTRK->setAcceleration(2500);
205211
}
212+
#endif
213+
#if RA_Stepper_TYPE == 1 //NEMA
214+
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
215+
{
216+
_stepperRA = new AccelStepper(stepMode, pin1, pin2);
217+
_stepperRA->setMaxSpeed(maxSpeed);
218+
_stepperRA->setAcceleration(maxAcceleration);
219+
_maxRASpeed = maxSpeed;
220+
_maxRAAcceleration = maxAcceleration;
221+
222+
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
223+
_stepperTRK = new AccelStepper(DRIVER, pin1, pin2);
224+
_stepperTRK->setMaxSpeed(10);
225+
_stepperTRK->setAcceleration(2500);
226+
}
227+
#endif
206228

207229
/////////////////////////////////
208230
//
209231
// configureDECStepper
210232
//
211233
/////////////////////////////////
234+
235+
#if DEC_Stepper_TYPE == 0
212236
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
213237
{
214238
_stepperDEC = new AccelStepper(stepMode, pin4, pin3, pin2, pin1);
@@ -217,6 +241,17 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
217241
_maxDECSpeed = maxSpeed;
218242
_maxDECAcceleration = maxAcceleration;
219243
}
244+
#endif
245+
#if DEC_Stepper_TYPE == 1
246+
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
247+
{
248+
_stepperDEC = new AccelStepper(stepMode, pin2, pin1);
249+
_stepperDEC->setMaxSpeed(maxSpeed);
250+
_stepperDEC->setAcceleration(maxAcceleration);
251+
_maxDECSpeed = maxSpeed;
252+
_maxDECAcceleration = maxAcceleration;
253+
}
254+
#endif
220255

221256
/////////////////////////////////
222257
//
@@ -328,7 +363,7 @@ const DayTime Mount::HA() const {
328363
#ifdef DEBUG_MODE
329364
logv("Mount: Get HA.");
330365
logv("Mount: Polaris adjust: %s", DayTime(PolarisRAHour, PolarisRAMinute, PolarisRASecond).ToString());
331-
#endif
366+
#endif
332367
DayTime ha = _LST;
333368
#ifdef DEBUG_MODE
334369
logv("Mount: LST: %s", _LST.ToString());
@@ -424,7 +459,7 @@ const DegreeTime Mount::currentDEC() const {
424459
// syncPosition
425460
//
426461
/////////////////////////////////
427-
// Set the current RA and DEC position to be the given coordinate. We do this by settign the stepper motor coordinate
462+
// Set the current RA and DEC position to be the given coordinate. We do this by settign the stepper motor coordinate
428463
// to be at the calculated positions (that they would be if we were slewing there).
429464
void Mount::syncPosition(int raHour, int raMinute, int raSecond, int decDegree, int decMinute, int decSecond)
430465
{
@@ -501,30 +536,30 @@ void Mount::guidePulse(byte direction, int duration) {
501536

502537
switch (direction) {
503538
case NORTH:
504-
_stepperDEC->setAcceleration(2500);
505-
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
506-
_stepperDEC->setSpeed(decTrackingSpeed);
507-
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC;
508-
break;
539+
_stepperDEC->setAcceleration(2500);
540+
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
541+
_stepperDEC->setSpeed(decTrackingSpeed);
542+
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC;
543+
break;
509544

510545
case SOUTH:
511-
_stepperDEC->setAcceleration(2500);
512-
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
513-
_stepperDEC->setSpeed(-decTrackingSpeed);
514-
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC;
515-
break;
546+
_stepperDEC->setAcceleration(2500);
547+
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
548+
_stepperDEC->setSpeed(-decTrackingSpeed);
549+
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC;
550+
break;
516551

517552
case WEST:
518-
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
519-
_stepperTRK->setSpeed(raTrackingSpeed * 2);
520-
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
521-
break;
553+
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
554+
_stepperTRK->setSpeed(raTrackingSpeed * 2);
555+
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
556+
break;
522557

523558
case EAST:
524-
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
525-
_stepperTRK->setSpeed(0);
526-
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
527-
break;
559+
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
560+
_stepperTRK->setSpeed(0);
561+
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
562+
break;
528563
}
529564

530565
_guideEndTime = millis() + duration;
@@ -544,43 +579,43 @@ void Mount::runDriftAlignmentPhase(int direction, int durationSecs) {
544579
float speed = 400.0 / durationSecs;
545580
switch (direction) {
546581
case EAST:
547-
// Move 400 steps east at the calculated speed, synchronously
548-
_stepperRA->setAcceleration(1500);
549-
_stepperRA->setMaxSpeed(speed);
550-
_stepperRA->move(400);
551-
while (_stepperRA->run()) {
552-
yield();
553-
}
582+
// Move 400 steps east at the calculated speed, synchronously
583+
_stepperRA->setAcceleration(1500);
584+
_stepperRA->setMaxSpeed(speed);
585+
_stepperRA->move(400);
586+
while (_stepperRA->run()) {
587+
yield();
588+
}
554589

555-
// Overcome the gearing gap
556-
_stepperRA->setMaxSpeed(300);
557-
_stepperRA->move(-20);
558-
while (_stepperRA->run()) {
559-
yield();
560-
}
561-
break;
590+
// Overcome the gearing gap
591+
_stepperRA->setMaxSpeed(300);
592+
_stepperRA->move(-20);
593+
while (_stepperRA->run()) {
594+
yield();
595+
}
596+
break;
562597

563598
case WEST:
564-
// Move 400 steps west at the calculated speed, synchronously
565-
_stepperRA->setMaxSpeed(speed);
566-
_stepperRA->move(-400);
567-
while (_stepperRA->run()) {
568-
yield();
569-
}
570-
break;
599+
// Move 400 steps west at the calculated speed, synchronously
600+
_stepperRA->setMaxSpeed(speed);
601+
_stepperRA->move(-400);
602+
while (_stepperRA->run()) {
603+
yield();
604+
}
605+
break;
571606

572607
case 0:
573-
// Fix the gearing to go back the other way
574-
_stepperRA->setMaxSpeed(300);
575-
_stepperRA->move(20);
576-
while (_stepperRA->run()) {
577-
yield();
578-
}
608+
// Fix the gearing to go back the other way
609+
_stepperRA->setMaxSpeed(300);
610+
_stepperRA->move(20);
611+
while (_stepperRA->run()) {
612+
yield();
613+
}
579614

580-
// Re-configure the stepper to the correct parameters.
581-
_stepperRA->setAcceleration(_maxRAAcceleration);
582-
_stepperRA->setMaxSpeed(_maxRASpeed);
583-
break;
615+
// Re-configure the stepper to the correct parameters.
616+
_stepperRA->setAcceleration(_maxRAAcceleration);
617+
_stepperRA->setMaxSpeed(_maxRASpeed);
618+
break;
584619
}
585620
}
586621

@@ -643,7 +678,7 @@ void Mount::park() {
643678
//
644679
// goHome
645680
//
646-
// Synchronously moves mount to home position
681+
// Synchronously moves mount to home position
647682
/////////////////////////////////
648683
void Mount::goHome()
649684
{
@@ -928,7 +963,7 @@ void Mount::waitUntilStopped(byte direction) {
928963
while (((direction & (EAST | WEST)) && _stepperRA->isRunning())
929964
|| ((direction & (NORTH | SOUTH)) && _stepperDEC->isRunning())
930965
|| ((direction & TRACKING) && (((_mountStatus & STATUS_TRACKING) == 0) && _stepperTRK->isRunning()))
931-
) {
966+
) {
932967
loop();
933968
yield();
934969
}
@@ -1149,7 +1184,7 @@ void Mount::setTargetToHome() {
11491184
// Set DEC to pole
11501185
_targetDEC.set(0, 0, 0);
11511186
_slewingToHome = true;
1152-
// Stop the tracking stepper
1187+
// Stop the tracking stepper
11531188
stopSlewing(TRACKING);
11541189
}
11551190

@@ -1205,8 +1240,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12051240
float stepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
12061241

12071242
// Where do we want to move RA to?
1243+
#if RA_Stepper_TYPE == 0
12081244
float moveRA = hourPos * stepsPerSiderealHour / 2;
1209-
1245+
#else
1246+
float moveRA = hourPos * stepsPerSiderealHour;
1247+
#endif
12101248
// Where do we want to move DEC to?
12111249
// the variable targetDEC 0deg for the celestial pole (90deg), and goes negative only.
12121250
float moveDEC = -_targetDEC.getTotalDegrees() * _stepsPerDECDegree;
@@ -1217,8 +1255,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12171255
#endif
12181256

12191257
// We can move 6 hours in either direction. Outside of that we need to flip directions.
1258+
#if RA_Stepper_TYPE == 0
12201259
float RALimit = (6.0f * stepsPerSiderealHour / 2);
1221-
1260+
#else
1261+
float RALimit = (6.0f * stepsPerSiderealHour);
1262+
#endif
12221263
// If we reach the limit in the positive direction ...
12231264
if (moveRA > RALimit) {
12241265
#ifdef DEBUG_MODE
@@ -1227,7 +1268,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12271268

12281269
// ... turn both RA and DEC axis around
12291270
float oldRA = moveRA;
1271+
#if RA_Stepper_TYPE == 0
12301272
moveRA -= long(12.0f * stepsPerSiderealHour / 2);
1273+
#else
1274+
moveRA -= long(12.0f * stepsPerSiderealHour);
1275+
#endif
12311276
moveDEC = -moveDEC;
12321277
#ifdef DEBUG_MODE
12331278
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
@@ -1240,7 +1285,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12401285
#endif
12411286
// ... turn both RA and DEC axis around
12421287
float oldRA = moveRA;
1288+
#if RA_Stepper_TYPE == 0
12431289
moveRA += long(12.0f * stepsPerSiderealHour / 2);
1290+
#else
1291+
moveRA += long(12.0f * stepsPerSiderealHour);
1292+
#endif
12441293
moveDEC = -moveDEC;
12451294
#ifdef DEBUG_MODE
12461295
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);

0 commit comments

Comments
 (0)