Skip to content

Commit 6bdc67f

Browse files
author
openastrotech
committed
Merge branch 'develop' into NEMA-steppers
2 parents 4926ee1 + 81ebc09 commit 6bdc67f

File tree

6 files changed

+69
-44
lines changed

6 files changed

+69
-44
lines changed

Software/Arduino code/OpenAstroTracker/DayTime.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,25 @@ int DegreeTime::getDegrees() {
219219
}
220220

221221
int DegreeTime::getPrintDegrees() const {
222-
return NORTHERN_HEMISPHERE ? hours + 90 : hours - 90;
222+
return NORTHERN_HEMISPHERE ? hours + 90 : -90 - hours;
223223
}
224224

225225
float DegreeTime::getTotalDegrees() const {
226226
return getTotalHours();
227227
}
228228

229229
void DegreeTime::checkHours() {
230-
if (NORTHERN_HEMISPHERE) {
231-
if (hours > 0) hours = 0;
232-
if (hours < -180) hours = -180;
230+
if (hours > 0) {
231+
#ifdef DEBUG_MODE
232+
logv("CheckHours: Degrees is more than 0, clamping");
233+
#endif
234+
hours = 0;
233235
}
234-
else {
235-
if (hours > 180) hours = 180;
236-
if (hours < 0) hours = 0;
236+
if (hours < -180) {
237+
#ifdef DEBUG_MODE
238+
logv("CheckHours: Degrees is less than -180, clamping");
239+
#endif
240+
hours = -180;
237241
}
238242
}
239243

@@ -280,7 +284,7 @@ const char* DegreeTime::ToString() const
280284
*p++ = '0' + (secs % 10);
281285
*p++ = ' ';
282286
*p++ = '(';
283-
strcpy(p, String(NORTHERN_HEMISPHERE ? getTotalHours() + 90 : getTotalHours() - 90, 4).c_str());
287+
strcpy(p, String(NORTHERN_HEMISPHERE ? getTotalHours() + 90 : -90 - getTotalHours(), 4).c_str());
284288
strcat(p, ")");
285289

286290
return achBufDeg;

Software/Arduino code/OpenAstroTracker/Globals.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ extern int PolarisRAMinute;
2424
extern int PolarisRASecond;
2525
// Comment this out to save some code space
2626
// #define DEBUG_MODE
27-
27+
#ifdef DEBUG_MODE
28+
// #define SEND_PERIODIC_UPDATES
29+
#endif
2830
// Uncomment to run a key diagnostic. No tracker functions are on at all.
2931
// #define LCD_BUTTON_TEST
3032

3133
// Uncomment to reverse the direction of RA motor
32-
//#define INVERT_RA_DIR
34+
// #define INVERT_RA_DIR
3335

3436
// Uncomment to reverse the direction of DEC motor
35-
//#define INVERT_DEC_DIR
37+
// #define INVERT_DEC_DIR
3638

3739
////////////////////////////////////////////////////////////////
3840
//
@@ -91,15 +93,13 @@ extern int PolarisRASecond;
9193
// Uncomment to support CAL menu, allowing you to calibrate various things
9294
#define SUPPORT_CALIBRATION
9395

94-
#endif
95-
// Uncomment to support INFO menu that displays various pieces of information about the mount.
96-
// #define SUPPORT_INFO_DISPLAY
97-
98-
// Uncomment to support Serial Meade LX200 protocol support
99-
// #define SUPPORT_SERIAL_CONTROL
96+
// Uncomment to support INFO menu that displays various pieces of information about the mount.
97+
// #define SUPPORT_INFO_DISPLAY
10098

101-
// If we are making a headleass (no screen, no keyboard) client, always enable Serial.
102-
#ifdef HEADLESS_CLIENT
99+
// Uncomment to support Serial Meade LX200 protocol support
100+
// #define SUPPORT_SERIAL_CONTROL
101+
#else
102+
// If we are making a headleass (no screen, no keyboard) client, always enable Serial.
103103
#define SUPPORT_SERIAL_CONTROL
104104
#endif
105105

Software/Arduino code/OpenAstroTracker/MeadeCommandProcessor.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,17 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd) {
466466
int sgn = inCmd[1] == '+' ? 1 : -1;
467467
if ((inCmd[4] == '*') && (inCmd[7] == ':'))
468468
{
469-
int deg = inCmd.substring(2, 4).toInt();
470-
_mount->targetDEC().set(sgn * deg + (NORTHERN_HEMISPHERE ? -90 : 90), inCmd.substring(5, 7).toInt(), inCmd.substring(8, 10).toInt());
469+
int deg = sgn * inCmd.substring(2, 4).toInt();
470+
if (NORTHERN_HEMISPHERE) {
471+
deg = deg - 90;
472+
}
473+
else {
474+
deg = -90 - deg;
475+
}
476+
_mount->targetDEC().set(deg, inCmd.substring(5, 7).toInt(), inCmd.substring(8, 10).toInt());
477+
#ifdef DEBUG_MODE
478+
logv("MeadeSetInfo: Received Target DEC: %s", _mount->targetDEC().ToString());
479+
#endif
471480
return "1";
472481
}
473482
else {
@@ -483,6 +492,9 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd) {
483492
if ((inCmd[3] == ':') && (inCmd[6] == ':'))
484493
{
485494
_mount->targetRA().set(inCmd.substring(1, 3).toInt(), inCmd.substring(4, 6).toInt(), inCmd.substring(7, 9).toInt());
495+
#ifdef DEBUG_MODE
496+
logv("MeadeSetInfo: Received Target RA: %s", _mount->targetRA().ToString());
497+
#endif
486498
return "1";
487499
}
488500
else {
@@ -788,6 +800,7 @@ String MeadeCommandProcessor::handleMeadeSetSlewRate(String inCmd) {
788800
case 'C': // Center - 2nd Slowest
789801
case 'G': // Guide - Slowest
790802
default:
803+
break;
791804
}
792805
return "";
793806
}

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,21 @@ void Mount::writePersistentData(int which, int val)
196196
#if RA_Stepper_TYPE == 0 // 28BYJ
197197
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
198198
{
199-
#ifdef NORTHERN_HEMISPHERE
200-
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
201-
#else
199+
#if NORTHERN_HEMISPHERE
202200
_stepperRA = new AccelStepper(stepMode, pin4, pin3, pin2, pin1);
201+
#else
202+
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
203203
#endif
204204
_stepperRA->setMaxSpeed(maxSpeed);
205205
_stepperRA->setAcceleration(maxAcceleration);
206206
_maxRASpeed = maxSpeed;
207207
_maxRAAcceleration = maxAcceleration;
208208

209209
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
210-
#ifdef NORTHERN_HEMISPHERE
211-
_stepperTRK = new AccelStepper(HALFSTEP, pin1, pin2, pin3, pin4);
212-
#else
210+
#if NORTHERN_HEMISPHERE
213211
_stepperTRK = new AccelStepper(HALFSTEP, pin4, pin3, pin2, pin1);
212+
#else
213+
_stepperTRK = new AccelStepper(HALFSTEP, pin1, pin2, pin3, pin4);
214214
#endif
215215
_stepperTRK->setMaxSpeed(10);
216216
_stepperTRK->setAcceleration(2500);
@@ -241,7 +241,11 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed
241241
#if DEC_Stepper_TYPE == 0
242242
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
243243
{
244+
#if NORTHERN_HEMISPHERE
245+
_stepperDEC = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
246+
#else
244247
_stepperDEC = new AccelStepper(stepMode, pin4, pin3, pin2, pin1);
248+
#endif
245249
_stepperDEC->setMaxSpeed(maxSpeed);
246250
_stepperDEC->setAcceleration(maxAcceleration);
247251
_maxDECSpeed = maxSpeed;
@@ -408,15 +412,15 @@ void Mount::setLST(const DayTime& lst) {
408412
// setLatitude
409413
//
410414
/////////////////////////////////
411-
void Mount::setLatitude(float lat) {
415+
void Mount::setLatitude(float lat) {
412416
_latitude = lat;
413417
}
414418
/////////////////////////////////
415419
//
416420
// setLongitude
417421
//
418422
/////////////////////////////////
419-
void Mount::setLongitude(float lon) {
423+
void Mount::setLongitude(float lon) {
420424
_longitude = lon;
421425
}
422426

@@ -426,7 +430,7 @@ void Mount::setLongitude(float lon) {
426430
//
427431
/////////////////////////////////
428432
const float Mount::latitude() const {
429-
return _latitude ;
433+
return _latitude;
430434
}
431435
/////////////////////////////////
432436
//
@@ -478,8 +482,8 @@ const DayTime Mount::currentRA() const {
478482
logv("CurrentRA: POS (+zp) : %s", DayTime(hourPos).ToString());
479483
#endif
480484

481-
bool flipRA = NORTHERN_HEMISPHERE ?
482-
_stepperDEC->currentPosition() < 0
485+
bool flipRA = NORTHERN_HEMISPHERE ?
486+
_stepperDEC->currentPosition() < 0
483487
: _stepperDEC->currentPosition() > 0;
484488
if (flipRA)
485489
{
@@ -983,20 +987,21 @@ void Mount::startSlewing(int direction) {
983987
_mountStatus |= STATUS_TRACKING;
984988
}
985989
else {
990+
int sign = NORTHERN_HEMISPHERE ? 1 : -1;
986991
if (direction & NORTH) {
987-
_stepperDEC->moveTo(30000);
992+
_stepperDEC->moveTo(sign * 30000);
988993
_mountStatus |= STATUS_SLEWING;
989994
}
990995
if (direction & SOUTH) {
991-
_stepperDEC->moveTo(-30000);
996+
_stepperDEC->moveTo(-sign * 30000);
992997
_mountStatus |= STATUS_SLEWING;
993998
}
994999
if (direction & EAST) {
995-
_stepperRA->moveTo(-30000);
1000+
_stepperRA->moveTo(-sign * 30000);
9961001
_mountStatus |= STATUS_SLEWING;
9971002
}
9981003
if (direction & WEST) {
999-
_stepperRA->moveTo(30000);
1004+
_stepperRA->moveTo(sign * 30000);
10001005
_mountStatus |= STATUS_SLEWING;
10011006
}
10021007
}
@@ -1084,7 +1089,7 @@ void Mount::loop() {
10841089
bool decStillRunning = false;
10851090

10861091
unsigned long now = millis();
1087-
#ifdef DEBUG_MODE
1092+
#if defined DEBUG_MODE && defined SEND_PERIODIC_UPDATES
10881093
if (now - _lastMountPrint > 2000) {
10891094
Serial.println(getStatusString());
10901095
_lastMountPrint = now;
@@ -1315,8 +1320,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
13151320
#endif
13161321

13171322
float hourPos = raTarget.getTotalHours();
1323+
if (!NORTHERN_HEMISPHERE) {
1324+
hourPos += 12;
1325+
}
13181326
// Map [0 to 24] range to [-12 to +12] range
1319-
if (hourPos > 12) {
1327+
while (hourPos > 12) {
13201328
hourPos = hourPos - 24;
13211329
#ifdef DEBUG_MODE
13221330
logv("Mount::CalcSteppersIn: RA>12 so -24. New Target RA: %s, DEC: %s", DayTime(hourPos).ToString(), _targetDEC.ToString());
@@ -1509,7 +1517,7 @@ String Mount::DECString(byte type, byte active) {
15091517
#ifdef DEBUG_MODE
15101518
logv("DECString: TARGET!");
15111519
#endif
1512-
dec = DegreeTime(_targetDEC);
1520+
dec = _targetDEC;
15131521
}
15141522
else {
15151523
#ifdef DEBUG_MODE

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "Globals.h"
1818

19-
String version = "V1.6.61";
19+
String version = "V1.7.01";
2020

2121
///////////////////////////////////////////////////////////////////////////
2222
// Please see the Globals.h file for configuration of the firmware.

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
// DEC Motor pins
3838
#ifdef INVERT_DEC_DIR
3939
#define DECmotorPin1 D5 // IN1 auf ULN2003 driver 2
40-
#define DECmotorPin2 D6 // IN2 auf ULN2003 driver 2
41-
#define DECmotorPin3 D7 // IN3 auf ULN2003 driver 2
40+
#define DECmotorPin3 D6 // IN3 auf ULN2003 driver 2
41+
#define DECmotorPin2 D7 // IN2 auf ULN2003 driver 2
4242
#define DECmotorPin4 D8 // IN4 auf ULN2003 driver 2
4343
#else
4444
#define DECmotorPin1 D8 // IN1 auf ULN2003 driver 2
45-
#define DECmotorPin2 D7 // IN2 auf ULN2003 driver 2
46-
#define DECmotorPin3 D6 // IN3 auf ULN2003 driver 2
45+
#define DECmotorPin3 D7 // IN3 auf ULN2003 driver 2
46+
#define DECmotorPin2 D6 // IN2 auf ULN2003 driver 2
4747
#define DECmotorPin4 D5 // IN4 auf ULN2003 driver 2
4848
#endif
4949

0 commit comments

Comments
 (0)