Skip to content

Commit

Permalink
Merge pull request #29 from ClutchplateDude/oopthescope
Browse files Browse the repository at this point in the history
Changes since V1.6.28 and new ASCOM Driver
  • Loading branch information
OpenAstroTech authored Apr 23, 2020
2 parents a9bbf88 + 6e793d9 commit b90eb70
Show file tree
Hide file tree
Showing 78 changed files with 4,467 additions and 4,109 deletions.
2 changes: 1 addition & 1 deletion Software/Arduino code/OpenAstroTracker/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern bool inSerialControl;
#define SUPPORT_MANUAL_CONTROL

// Uncomment to support INFO menu that displays various pieces of information about the mount.
#define SUPPORT_INFO_DISPLAY
// #define SUPPORT_INFO_DISPLAY

// Uncomment to support Serial Meade LX200 protocol support
// #define SUPPORT_SERIAL_CONTROL
Expand Down
179 changes: 138 additions & 41 deletions Software/Arduino code/OpenAstroTracker/Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ char* formatStringsDEC[] = {
"%c%02d*%02d'%02d#", // Meade
"%c%02d %02d'%02d\"", // Print
"%c%02d@%02d'%02d\"", // LCD display only
"%c%02d%02d%02d", // Compact
};

char* formatStringsRA[] = {
Expand All @@ -45,6 +46,7 @@ char* formatStringsRA[] = {
"%02d:%02d:%02d#", // Meade
"%02dh %02dm %02ds", // Print
"%02dh%02dm%02ds", // LCD display only
"%02d%02d%02d", // Compact
};

const float siderealDegreesInHour = 14.95902778;
Expand Down Expand Up @@ -75,8 +77,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
_stepperRA->setMaxSpeed(maxSpeed);
_stepperRA->setAcceleration(maxAcceleration);
// _maxRASpeed = maxSpeed;
// _maxRAAcceleration = maxAcceleration;
_maxRASpeed = maxSpeed;
_maxRAAcceleration = maxAcceleration;

// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
_stepperTRK = new AccelStepper(HALFSTEP, pin1, pin2, pin3, pin4);
Expand Down Expand Up @@ -264,25 +266,6 @@ void Mount::syncDEC(int degree, int minute, int second) {
_stepperDEC->setCurrentPosition(targetDEC);
}

/////////////////////////////////
//
// stopGuiding
//
/////////////////////////////////
void Mount::stopGuiding() {
_stepperDEC->stop();
while (_stepperDEC->isRunning()) {
_stepperDEC->run();
}
_stepperDEC->setMaxSpeed(_maxDECSpeed);
_stepperDEC->setAcceleration(_maxDECAcceleration);
_stepperTRK->setMaxSpeed(10);
_stepperTRK->setAcceleration(2500);
_stepperTRK->setSpeed(_trackingSpeed);
_stepperTRK->runSpeed();
_mountStatus &= ~STATUS_GUIDE_PULSE_MASK;
}

/////////////////////////////////
//
// startSlewingToTarget
Expand All @@ -307,44 +290,61 @@ void Mount::startSlewingToTarget() {
_totalRAMove = 1.0f * _stepperRA->distanceToGo();
}

/////////////////////////////////
//
// stopGuiding
//
/////////////////////////////////
void Mount::stopGuiding() {
_stepperDEC->stop();
while (_stepperDEC->isRunning()) {
_stepperDEC->run();
}

_stepperDEC->setMaxSpeed(_maxDECSpeed);
_stepperDEC->setAcceleration(_maxDECAcceleration);
_stepperTRK->setMaxSpeed(10);
_stepperTRK->setAcceleration(2500);
_stepperTRK->setSpeed(_trackingSpeed);
_mountStatus &= ~STATUS_GUIDE_PULSE_MASK;
}

/////////////////////////////////
//
// guidePulse
//
/////////////////////////////////
void Mount::guidePulse(byte direction, int duration) {
// How many steps moves the RA ring one sidereal hour along. One sidereal hour moves just shy of 15 degrees
// NOTE: May need to adjust with _trackingSpeedCalibration
float decStepsPerSiderealHour = _stepsPerDECDegree * siderealDegreesInHour;
float decStepsForDuration = decStepsPerSiderealHour * duration / 3600000;
float raStepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
float raStepsForDuration = raStepsPerSiderealHour * duration / 3600000;

// DEC stepper moves at sidereal rate in both directions
// RA stepper moves at either 2x sidereal rate or stops.
// TODO: Do we need to adjust with _trackingSpeedCalibration?
float decTrackingSpeed = _stepsPerDECDegree * siderealDegreesInHour / 3600.0f;
float raTrackingSpeed = _stepsPerRADegree * siderealDegreesInHour / 3600.0f;

long raPos = _stepperRA->currentPosition();
long decPos = _stepperDEC->currentPosition();
// TODO: Do we need to track how many steps the steppers took and add them to the GoHome calculation?
// If so, we need to remember where we were when we started the guide pulse. Then at the end,
// we can calculate the difference.
// long raPos = _stepperTRK->currentPosition();
// long decPos = _stepperDEC->currentPosition();

switch (direction) {
case NORTH:
_stepperDEC->setAcceleration(2500);
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
_stepperDEC->setSpeed(decTrackingSpeed);
_stepperDEC->moveTo(decPos + decStepsForDuration);
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
break;

case SOUTH:
_stepperDEC->setAcceleration(2500);
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
_stepperDEC->setSpeed(decTrackingSpeed);
_stepperDEC->moveTo(decPos - decStepsForDuration);
_stepperDEC->setSpeed(-decTrackingSpeed);
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_DEC ;
break;

case WEST:
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
_stepperTRK->setSpeed(raTrackingSpeed * 2);
_stepperTRK->moveTo(raPos + raStepsForDuration);
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
break;

Expand All @@ -358,6 +358,52 @@ void Mount::guidePulse(byte direction, int duration) {
_guideEndTime = millis() + duration;
}

/////////////////////////////////
//
// runDriftAlignmentPhase
//
// Runs one of the phases of the Drift alignment
// This runs the RA motor 400 steps (about 5.3 arcminutes) in the given duration
// This function should be callsed 3 times:
// The first time with EAST, second with WEST and then with 0.
/////////////////////////////////
void Mount::runDriftAlignmentPhase(int direction, int durationSecs) {
// Calculate the speed at which it takes the given duration to cover 400 steps.
float speed = 400.0 / durationSecs;
switch (direction) {
case EAST:
// Move 400 steps east at the calculated speed, synchronously
_stepperRA->setAcceleration(1500);
_stepperRA->setMaxSpeed(speed);
_stepperRA->move(400);
_stepperRA->runToPosition();

// Overcome the gearing gap
_stepperRA->setMaxSpeed(300);
_stepperRA->move(-20);
_stepperRA->runToPosition();
break;

case WEST:
// Move 400 steps west at the calculated speed, synchronously
_stepperRA->setMaxSpeed(speed);
_stepperRA->move(-400);
_stepperRA->runToPosition();
break;

case 0 :
// Fix the gearing to go back the other way
_stepperRA->setMaxSpeed(300);
_stepperRA->move(20);
_stepperRA->runToPosition();

// Re-configure the stepper to the correct parameters.
_stepperRA->setAcceleration(_maxRAAcceleration);
_stepperRA->setMaxSpeed(_maxRASpeed);
break;
}
}

/////////////////////////////////
//
// park
Expand Down Expand Up @@ -417,8 +463,8 @@ String Mount::mountStatusString() {
if (_mountStatus & STATUS_PARKING) {
disp = "PARKNG ";
}
else if (isGuiding()){
disp = "GUIDING ";
else if (isGuiding()) {
disp = "GUIDING ";
}
else {
if (_mountStatus & STATUS_TRACKING) disp += "TRK ";
Expand All @@ -442,6 +488,57 @@ String Mount::mountStatusString() {
}
#endif

/////////////////////////////////
//
// getStatusString
//
/////////////////////////////////
String Mount::getStatusString() {
String status;
if (_mountStatus == STATUS_PARKED) {
status = "Parked,";
}
else if (_mountStatus & STATUS_PARKING) {
status = "Parking,";
}
else if (isGuiding()) {
status = "Guiding,";
}
else if (slewStatus() & SLEW_MASK_ANY) {
if (_mountStatus & STATUS_SLEWING_TO_TARGET) {
status = "SlewToTarget,";
}
else if (_mountStatus & STATUS_SLEWING_FREE) {
status = "FreeSlew,";
}
else {
status = "Idle,";
}
} else {
status = "Idle,";
}

String disp = "---,";
if (_mountStatus & STATUS_SLEWING) {
byte slew = slewStatus();
if (slew & SLEWING_RA) disp[0] = _stepperRA->speed() < 0 ? 'R' : 'r';
if (slew & SLEWING_DEC) disp[1] = _stepperDEC->speed() < 0 ? 'D' : 'd';
if (slew & SLEWING_TRACKING) disp[2] = 'T';
} else if (isSlewingTRK()) {
disp[2] = 'T';
}

status += disp;
status += String(_stepperRA->currentPosition()) + ",";
status += String(_stepperDEC->currentPosition()) + ",";
status += String(_stepperTRK->currentPosition()) + ",";

status += RAString(COMPACT_STRING | CURRENT_STRING) + ",";
status += DECString(COMPACT_STRING | CURRENT_STRING) + ",";

return status ;
}

/////////////////////////////////
//
// slewingStatus
Expand Down Expand Up @@ -861,8 +958,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
//
/////////////////////////////////
void Mount::displayStepperPosition() {
#ifndef HEADLESS_CLIENT
#ifndef HEADLESS_CLIENT

String disp ;

if ((abs(_totalDECMove) > 0.001) && (abs(_totalRAMove) > 0.001)) {
Expand Down Expand Up @@ -893,7 +990,7 @@ void Mount::displayStepperPosition() {
else {
#ifdef SUPPORT_SERIAL_CONTROL
if (inSerialControl) {
sprintf(scratchBuffer, " RA: %s", RAString(LCD_STRING | CURRENT_STRING).c_str());
sprintf(scratchBuffer, " RA: %s", RAString(LCD_STRING | CURRENT_STRING).c_str());
_lcdMenu->setCursor(0, 0);
_lcdMenu->printMenu(scratchBuffer);
sprintf(scratchBuffer, "DEC: %s", DECString(LCD_STRING | CURRENT_STRING).c_str());
Expand Down Expand Up @@ -926,13 +1023,13 @@ void Mount::displayStepperPosition() {
//
/////////////////////////////////
void Mount::displayStepperPositionThrottled() {
#ifndef HEADLESS_CLIENT
#ifndef HEADLESS_CLIENT
long elapsed = millis() - _lastDisplayUpdate;
if (elapsed > DISPLAY_UPDATE_TIME) {
displayStepperPosition();
_lastDisplayUpdate = millis();
}
#endif
#endif
}

/////////////////////////////////
Expand Down
10 changes: 8 additions & 2 deletions Software/Arduino code/OpenAstroTracker/Mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MEADE_STRING B0010
#define PRINT_STRING B0011
#define LCD_STRING B0100
#define COMPACT_STRING B0101
#define FORMAT_STRING_MASK B0111

#define TARGET_STRING B01000
Expand Down Expand Up @@ -124,11 +125,16 @@ class Mount {
// Return a string of DEC in the given format. For LCDSTRING, active determines where the cursor is
String RAString(byte type, byte active = 0);

// Returns a comma-delimited string with all the mounts' information
String getStatusString();

// Get the current speed of the stepper. NORTH, WEST, TRACKING
float getSpeed(int direction);

void displayStepperPositionThrottled();

void runDriftAlignmentPhase(int direction, int durationSecs);

private:
void calculateRAandDECSteppers(float& targetRA, float& targetDEC);
void displayStepperPosition();
Expand All @@ -150,9 +156,9 @@ class Mount {
LcdMenu* _lcdMenu;
int _stepsPerRADegree;
int _stepsPerDECDegree;
//int _maxRASpeed;
int _maxRASpeed;
int _maxDECSpeed;
//int _maxRAAcceleration;
int _maxRAAcceleration;
int _maxDECAcceleration;

long _lastHASet;
Expand Down
12 changes: 6 additions & 6 deletions Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#include "Globals.h"

String version = "V1.6.28";
String version = "V1.6.33";

///////////////////////////////////////////////////////////////////////////
// Please see the Globals.h file for configuration of the firmware.
Expand Down Expand Up @@ -69,10 +69,10 @@ float DECStepperDownLimit = 10000; // Going much more than this will make the
float DECStepperUpLimit = -22000; // Going much more than this is going below the horizon.

// These values are needed to calculate the current position during initial alignment.
int PolarisRAHour = 21;
int PolarisRAMinute = 2;
int PolarisRASecond = 25;
// You get these values by calculating 24h minus the current (not J2000) RA of Polaris.
int PolarisRAHour = 2;
int PolarisRAMinute = 58;
int PolarisRASecond = 0;
// Use something like Stellarium to look up the RA of Polaris in JNow (on date) variant.
// This changes slightly over weeks, so adjust every couple of months.
// This value is from 27.Nov.19, I suggest next adjustment in mid 2020
// This value is from 18.Apr.2020, next adjustment suggested at end 2020
// The same could be done for the DEC coordinates but they dont change significantly for the next 5 years
10 changes: 3 additions & 7 deletions Software/Arduino code/OpenAstroTracker/b_setup.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
LcdMenu lcdMenu(16, 2, MAXMENUITEMS);
LcdButtons lcdButtons(0);

// Create the variables to track RA time, RA display time and HA time
//DayTime RATime;
//DayTime RADisplayTime;
//DayTime HATime;
//DayTime HACorrection;

Mount mount(RAStepsPerDegree, DECStepsPerDegree, &lcdMenu);

void setup() {
Expand Down Expand Up @@ -35,7 +29,9 @@ void setup() {

// Configure the mount
// Set the global HA correction
mount.setHACorrection(PolarisRAHour, PolarisRAMinute, PolarisRASecond);
DayTime polaris = DayTime(24,0,0);
polaris.subtractTime(DayTime(PolarisRAHour, PolarisRAMinute, PolarisRASecond));
mount.setHACorrection(polaris.getHours(), polaris.getMinutes(), polaris.getSeconds());

// Set the stepper motor parameters
mount.configureRAStepper(FULLSTEP, RAmotorPin1, RAmotorPin2, RAmotorPin3, RAmotorPin4, RAspeed, RAacceleration);
Expand Down
2 changes: 1 addition & 1 deletion Software/Arduino code/OpenAstroTracker/c722_menuPOI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PointOfInterest {
PointOfInterest pointOfInterest[] = {
// Name (15chars) RA (hms) DEC (dms)
// 012345678901234
{ ">Polaris" , 2, 57, 56, 89, 21, 2 },
{ ">Polaris" , PolarisRAHour, PolarisRAMinute, PolarisRASecond, 89, 21, 2 },
{ ">Big Dipper" , 12, 16, 26, 56, 55, 7 },
{ ">M31 Andromeda" , 0, 43, 52, 41, 22, 53 },
{ ">M42 Orion Nbula", 5, 36, 18, -5, 22, 44 },
Expand Down
Loading

0 comments on commit b90eb70

Please sign in to comment.