Skip to content

Commit

Permalink
Merge pull request #27 from ClutchplateDude/oopthescope
Browse files Browse the repository at this point in the history
Fixes to Arduino and ASCOM drive code
  • Loading branch information
OpenAstroTech authored Apr 18, 2020
2 parents 50b4d6e + 25ff292 commit 37f3c76
Show file tree
Hide file tree
Showing 25 changed files with 490 additions and 315 deletions.
10 changes: 10 additions & 0 deletions Software/Arduino code/OpenAstroTracker/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ extern bool inSerialControl;
//
////////////////////////////////////////////////////////////////

// If you do not have a LCD shield on your Arduino Uno, uncomment the line below. This is
// useful if you are always going to run the mount from a laptop anyway.
// #define HEADLESS_CLIENT

// Uncomment this to enable the heating menu
// NOTE: Heating is currently not supported!
// #define SUPPORT_HEATING
Expand All @@ -58,4 +62,10 @@ extern bool inSerialControl;
// Uncomment to support Serial Meade LX200 protocol support
// #define SUPPORT_SERIAL_CONTROL


// If we are making a headleass (no screen, no keyboard) client, always enable Serial.
#ifdef HEADLESS_CLIENT
#define SUPPORT_SERIAL_CONTROL
#endif

#endif
32 changes: 32 additions & 0 deletions Software/Arduino code/OpenAstroTracker/LcdMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Utility.h"
#include "LcdMenu.hpp"

#ifndef HEADLESS_CLIENT

// Class that drives the LCD screen with a menu
// You add a string and an id item and this class handles the display and navigation
// Create a new menu, using the given number of LCD display columns and rows
Expand Down Expand Up @@ -235,3 +237,33 @@ byte LcdMenu::MinutesBitmap[8] = {
B00000,
B00000
};
#else

LcdMenu::LcdMenu(byte cols, byte rows, int maxItems) {
}

MenuItem* LcdMenu::findById(byte id) {
return NULL;
}

void LcdMenu::addItem(const char *disp, byte id) {}

byte LcdMenu::getActive() {
return 0;
}

void LcdMenu::setActive(byte id) {}

void LcdMenu::setCursor(byte col, byte row) {}

void LcdMenu::clear() {}

void LcdMenu::setNextActive() {}

void LcdMenu::updateDisplay() {}

void LcdMenu::printMenu(String line) {}

void LcdMenu::printChar(char ch) {}

#endif
4 changes: 4 additions & 0 deletions Software/Arduino code/OpenAstroTracker/LcdMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define _LCDMENU_HPP_

#include <Arduino.h>
#ifndef HEADLESS_CLIENT
#include <LiquidCrystal.h>
#endif
#include "Globals.h"

// A single menu item (like RA, HEAT, POL, etc.)
Expand Down Expand Up @@ -67,6 +69,7 @@ class LcdMenu {
void printChar(char ch);

private:
#ifndef HEADLESS_CLIENT
LiquidCrystal _lcd; // The LCD screen that we'll display the menu on
MenuItem** _menuItems; // The first menu item (linked list)
byte _numMenuItems;
Expand All @@ -89,6 +92,7 @@ class LcdMenu {
static byte DownArrowBitmap[8];
static byte DegreesBitmap[8];
static byte MinutesBitmap[8];
#endif
};

#endif
134 changes: 130 additions & 4 deletions Software/Arduino code/OpenAstroTracker/Mount.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "LcdMenu.hpp"

#include "Mount.hpp"

//mountstatus
Expand All @@ -8,6 +9,11 @@
#define STATUS_SLEWING_FREE B00000010
#define STATUS_TRACKING B00001000
#define STATUS_PARKING B00010000
#define STATUS_GUIDE_PULSE B10000000
#define STATUS_GUIDE_PULSE_DIR B01100000
#define STATUS_GUIDE_PULSE_RA B01000000
#define STATUS_GUIDE_PULSE_DEC B00100000
#define STATUS_GUIDE_PULSE_MASK B11100000

// slewingStatus()
#define SLEWING_DEC B00000010
Expand Down Expand Up @@ -69,6 +75,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;

// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
_stepperTRK = new AccelStepper(HALFSTEP, pin1, pin2, pin3, pin4);
Expand All @@ -86,6 +94,8 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
_stepperDEC = new AccelStepper(stepMode, pin4, pin3, pin2, pin1);
_stepperDEC->setMaxSpeed(maxSpeed);
_stepperDEC->setAcceleration(maxAcceleration);
_maxDECSpeed = maxSpeed;
_maxDECAcceleration = maxAcceleration;
}

float Mount::getSpeedCalibration() {
Expand Down Expand Up @@ -254,6 +264,25 @@ 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 @@ -262,6 +291,10 @@ void Mount::syncDEC(int degree, int minute, int second) {
// Calculates movement parameters and program steppers to move
// there. Must call loop() frequently to actually move.
void Mount::startSlewingToTarget() {
if (isGuiding()) {
stopGuiding();
}

// Calculate new RA stepper target (and DEC)
_currentDECStepperPosition = _stepperDEC->currentPosition();
_currentRAStepperPosition = _stepperRA->currentPosition();
Expand All @@ -274,15 +307,66 @@ void Mount::startSlewingToTarget() {
_totalRAMove = 1.0f * _stepperRA->distanceToGo();
}

/////////////////////////////////
//
// 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;

float decTrackingSpeed = _stepsPerDECDegree * siderealDegreesInHour / 3600.0f;
float raTrackingSpeed = _stepsPerRADegree * siderealDegreesInHour / 3600.0f;

long raPos = _stepperRA->currentPosition();
long decPos = _stepperDEC->currentPosition();

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

case SOUTH:
_stepperDEC->setMaxSpeed(decTrackingSpeed * 1.2);
_stepperDEC->setSpeed(decTrackingSpeed);
_stepperDEC->moveTo(decPos - decStepsForDuration);
_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;

case EAST:
_stepperTRK->setMaxSpeed(raTrackingSpeed * 2.2);
_stepperTRK->setSpeed(0);
_mountStatus |= STATUS_GUIDE_PULSE | STATUS_GUIDE_PULSE_RA;
break;
}

_guideEndTime = millis() + duration;
}

/////////////////////////////////
//
// park
//
// Targets the mount to move to the home position and
// Targets the mount to move to the home position and
// turns off all motors once it gets there.
/////////////////////////////////
void Mount::park()
{
void Mount::park() {
stopGuiding();
stopSlewing(ALL_DIRECTIONS | TRACKING);
waitUntilStopped(ALL_DIRECTIONS);
setTargetToHome();
Expand All @@ -294,11 +378,12 @@ void Mount::park()
//
// goHome
//
// Synchronously moves mount to home position and
// Synchronously moves mount to home position and
// sets Tracking mode according to argument
/////////////////////////////////
void Mount::goHome(bool tracking)
{
stopGuiding();
stopSlewing(TRACKING);
setTargetToHome();
startSlewingToTarget();
Expand Down Expand Up @@ -332,6 +417,9 @@ String Mount::mountStatusString() {
if (_mountStatus & STATUS_PARKING) {
disp = "PARKNG ";
}
else if (isGuiding()){
disp = "GUIDING ";
}
else {
if (_mountStatus & STATUS_TRACKING) disp += "TRK ";
if (_mountStatus & STATUS_SLEWING) disp += "SLW ";
Expand Down Expand Up @@ -365,13 +453,26 @@ byte Mount::slewStatus() {
if (_mountStatus == STATUS_PARKED) {
return NOT_SLEWING;
}
if (isGuiding()) {
return NOT_SLEWING;
}
byte slewState = _stepperRA->isRunning() ? SLEWING_RA : NOT_SLEWING;
slewState |= _stepperDEC->isRunning() ? SLEWING_DEC : NOT_SLEWING;

slewState |= (_mountStatus & STATUS_TRACKING) ? SLEWING_TRACKING : NOT_SLEWING;
return slewState;
}

/////////////////////////////////
//
// isGuiding
//
/////////////////////////////////
bool Mount::isGuiding()
{
return (_mountStatus & STATUS_GUIDE_PULSE);
}

/////////////////////////////////
//
// isSlewingDEC
Expand Down Expand Up @@ -449,6 +550,10 @@ bool Mount::isParking() {
void Mount::startSlewing(int direction) {
if (!isParking())
{
if (isGuiding()) {
stopGuiding();
}

if (direction & TRACKING) {
_stepperTRK->setSpeed(_trackingSpeed);

Expand Down Expand Up @@ -561,6 +666,22 @@ void Mount::loop() {
_lastMountPrint = now;
}
#endif
if (isGuiding()) {
if (millis() > _guideEndTime) {
stopGuiding();
}
else
{
if (_mountStatus & STATUS_GUIDE_PULSE_RA) {
_stepperTRK->runSpeed();
}
if (_mountStatus & STATUS_GUIDE_PULSE_DEC) {
_stepperDEC->runSpeed();
}
}
return;
}

if (_mountStatus & STATUS_TRACKING) {
_stepperTRK->runSpeed();
}
Expand Down Expand Up @@ -740,6 +861,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
//
/////////////////////////////////
void Mount::displayStepperPosition() {
#ifndef HEADLESS_CLIENT

String disp ;

if ((abs(_totalDECMove) > 0.001) && (abs(_totalRAMove) > 0.001)) {
Expand Down Expand Up @@ -794,6 +917,7 @@ void Mount::displayStepperPosition() {
_lcdMenu->printMenu(disp);
#endif
}
#endif
}

/////////////////////////////////
Expand All @@ -802,11 +926,13 @@ void Mount::displayStepperPosition() {
//
/////////////////////////////////
void Mount::displayStepperPositionThrottled() {
#ifndef HEADLESS_CLIENT
long elapsed = millis() - _lastDisplayUpdate;
if (elapsed > DISPLAY_UPDATE_TIME) {
displayStepperPosition();
_lastDisplayUpdate = millis();
}
#endif
}

/////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions Software/Arduino code/OpenAstroTracker/Mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Mount {
bool isSlewingTRK();
bool isParked();
bool isParking();
bool isGuiding();

// Starts manual slewing in one of eight directions or tracking
void startSlewing(int direction);
Expand Down Expand Up @@ -111,6 +112,11 @@ class Mount {
// Asynchronously parks the mount. Moves to the home position and stops all motors.
void park();

// Runs the RA motor at twice the speed (or stops it), or the DEC motor at tracking speed for the given duration in ms.
void guidePulse(byte direction, int duration);

// Stops any guide operation in progress.
void stopGuiding();

// Return a string of DEC in the given format. For LCDSTRING, active determines where the cursor is
String DECString(byte type, byte active = 0);
Expand Down Expand Up @@ -144,6 +150,11 @@ class Mount {
LcdMenu* _lcdMenu;
int _stepsPerRADegree;
int _stepsPerDECDegree;
//int _maxRASpeed;
int _maxDECSpeed;
//int _maxRAAcceleration;
int _maxDECAcceleration;

long _lastHASet;
DayTime _HAAdjust;

Expand All @@ -163,6 +174,7 @@ class Mount {
AccelStepper* _stepperDEC;
AccelStepper* _stepperTRK;

unsigned long _guideEndTime;
unsigned long _lastMountPrint = 0;
DayTime _HATime;
DayTime _HACorrection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#include "Globals.h"

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

///////////////////////////////////////////////////////////////////////////
// Please see the Globals.h file for configuration of the firmware.
Expand Down
Loading

0 comments on commit 37f3c76

Please sign in to comment.