Skip to content

Commit 37f3c76

Browse files
author
OpenAstroTech
authored
Merge pull request #27 from ClutchplateDude/oopthescope
Fixes to Arduino and ASCOM drive code
2 parents 50b4d6e + 25ff292 commit 37f3c76

25 files changed

+490
-315
lines changed

Software/Arduino code/OpenAstroTracker/Globals.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ extern bool inSerialControl;
3838
//
3939
////////////////////////////////////////////////////////////////
4040

41+
// If you do not have a LCD shield on your Arduino Uno, uncomment the line below. This is
42+
// useful if you are always going to run the mount from a laptop anyway.
43+
// #define HEADLESS_CLIENT
44+
4145
// Uncomment this to enable the heating menu
4246
// NOTE: Heating is currently not supported!
4347
// #define SUPPORT_HEATING
@@ -58,4 +62,10 @@ extern bool inSerialControl;
5862
// Uncomment to support Serial Meade LX200 protocol support
5963
// #define SUPPORT_SERIAL_CONTROL
6064

65+
66+
// If we are making a headleass (no screen, no keyboard) client, always enable Serial.
67+
#ifdef HEADLESS_CLIENT
68+
#define SUPPORT_SERIAL_CONTROL
69+
#endif
70+
6171
#endif

Software/Arduino code/OpenAstroTracker/LcdMenu.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "Utility.h"
22
#include "LcdMenu.hpp"
33

4+
#ifndef HEADLESS_CLIENT
5+
46
// Class that drives the LCD screen with a menu
57
// You add a string and an id item and this class handles the display and navigation
68
// Create a new menu, using the given number of LCD display columns and rows
@@ -235,3 +237,33 @@ byte LcdMenu::MinutesBitmap[8] = {
235237
B00000,
236238
B00000
237239
};
240+
#else
241+
242+
LcdMenu::LcdMenu(byte cols, byte rows, int maxItems) {
243+
}
244+
245+
MenuItem* LcdMenu::findById(byte id) {
246+
return NULL;
247+
}
248+
249+
void LcdMenu::addItem(const char *disp, byte id) {}
250+
251+
byte LcdMenu::getActive() {
252+
return 0;
253+
}
254+
255+
void LcdMenu::setActive(byte id) {}
256+
257+
void LcdMenu::setCursor(byte col, byte row) {}
258+
259+
void LcdMenu::clear() {}
260+
261+
void LcdMenu::setNextActive() {}
262+
263+
void LcdMenu::updateDisplay() {}
264+
265+
void LcdMenu::printMenu(String line) {}
266+
267+
void LcdMenu::printChar(char ch) {}
268+
269+
#endif

Software/Arduino code/OpenAstroTracker/LcdMenu.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define _LCDMENU_HPP_
33

44
#include <Arduino.h>
5+
#ifndef HEADLESS_CLIENT
56
#include <LiquidCrystal.h>
7+
#endif
68
#include "Globals.h"
79

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

6971
private:
72+
#ifndef HEADLESS_CLIENT
7073
LiquidCrystal _lcd; // The LCD screen that we'll display the menu on
7174
MenuItem** _menuItems; // The first menu item (linked list)
7275
byte _numMenuItems;
@@ -89,6 +92,7 @@ class LcdMenu {
8992
static byte DownArrowBitmap[8];
9093
static byte DegreesBitmap[8];
9194
static byte MinutesBitmap[8];
95+
#endif
9296
};
9397

9498
#endif

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "LcdMenu.hpp"
2+
23
#include "Mount.hpp"
34

45
//mountstatus
@@ -8,6 +9,11 @@
89
#define STATUS_SLEWING_FREE B00000010
910
#define STATUS_TRACKING B00001000
1011
#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
1117

1218
// slewingStatus()
1319
#define SLEWING_DEC B00000010
@@ -69,6 +75,8 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
6975
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
7076
_stepperRA->setMaxSpeed(maxSpeed);
7177
_stepperRA->setAcceleration(maxAcceleration);
78+
// _maxRASpeed = maxSpeed;
79+
// _maxRAAcceleration = maxAcceleration;
7280

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

91101
float Mount::getSpeedCalibration() {
@@ -254,6 +264,25 @@ void Mount::syncDEC(int degree, int minute, int second) {
254264
_stepperDEC->setCurrentPosition(targetDEC);
255265
}
256266

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+
257286
/////////////////////////////////
258287
//
259288
// startSlewingToTarget
@@ -262,6 +291,10 @@ void Mount::syncDEC(int degree, int minute, int second) {
262291
// Calculates movement parameters and program steppers to move
263292
// there. Must call loop() frequently to actually move.
264293
void Mount::startSlewingToTarget() {
294+
if (isGuiding()) {
295+
stopGuiding();
296+
}
297+
265298
// Calculate new RA stepper target (and DEC)
266299
_currentDECStepperPosition = _stepperDEC->currentPosition();
267300
_currentRAStepperPosition = _stepperRA->currentPosition();
@@ -274,15 +307,66 @@ void Mount::startSlewingToTarget() {
274307
_totalRAMove = 1.0f * _stepperRA->distanceToGo();
275308
}
276309

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+
277361
/////////////////////////////////
278362
//
279363
// park
280364
//
281-
// Targets the mount to move to the home position and
365+
// Targets the mount to move to the home position and
282366
// turns off all motors once it gets there.
283367
/////////////////////////////////
284-
void Mount::park()
285-
{
368+
void Mount::park() {
369+
stopGuiding();
286370
stopSlewing(ALL_DIRECTIONS | TRACKING);
287371
waitUntilStopped(ALL_DIRECTIONS);
288372
setTargetToHome();
@@ -294,11 +378,12 @@ void Mount::park()
294378
//
295379
// goHome
296380
//
297-
// Synchronously moves mount to home position and
381+
// Synchronously moves mount to home position and
298382
// sets Tracking mode according to argument
299383
/////////////////////////////////
300384
void Mount::goHome(bool tracking)
301385
{
386+
stopGuiding();
302387
stopSlewing(TRACKING);
303388
setTargetToHome();
304389
startSlewingToTarget();
@@ -332,6 +417,9 @@ String Mount::mountStatusString() {
332417
if (_mountStatus & STATUS_PARKING) {
333418
disp = "PARKNG ";
334419
}
420+
else if (isGuiding()){
421+
disp = "GUIDING ";
422+
}
335423
else {
336424
if (_mountStatus & STATUS_TRACKING) disp += "TRK ";
337425
if (_mountStatus & STATUS_SLEWING) disp += "SLW ";
@@ -365,13 +453,26 @@ byte Mount::slewStatus() {
365453
if (_mountStatus == STATUS_PARKED) {
366454
return NOT_SLEWING;
367455
}
456+
if (isGuiding()) {
457+
return NOT_SLEWING;
458+
}
368459
byte slewState = _stepperRA->isRunning() ? SLEWING_RA : NOT_SLEWING;
369460
slewState |= _stepperDEC->isRunning() ? SLEWING_DEC : NOT_SLEWING;
370461

371462
slewState |= (_mountStatus & STATUS_TRACKING) ? SLEWING_TRACKING : NOT_SLEWING;
372463
return slewState;
373464
}
374465

466+
/////////////////////////////////
467+
//
468+
// isGuiding
469+
//
470+
/////////////////////////////////
471+
bool Mount::isGuiding()
472+
{
473+
return (_mountStatus & STATUS_GUIDE_PULSE);
474+
}
475+
375476
/////////////////////////////////
376477
//
377478
// isSlewingDEC
@@ -449,6 +550,10 @@ bool Mount::isParking() {
449550
void Mount::startSlewing(int direction) {
450551
if (!isParking())
451552
{
553+
if (isGuiding()) {
554+
stopGuiding();
555+
}
556+
452557
if (direction & TRACKING) {
453558
_stepperTRK->setSpeed(_trackingSpeed);
454559

@@ -561,6 +666,22 @@ void Mount::loop() {
561666
_lastMountPrint = now;
562667
}
563668
#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+
564685
if (_mountStatus & STATUS_TRACKING) {
565686
_stepperTRK->runSpeed();
566687
}
@@ -740,6 +861,8 @@ void Mount::moveSteppersTo(float targetRA, float targetDEC) {
740861
//
741862
/////////////////////////////////
742863
void Mount::displayStepperPosition() {
864+
#ifndef HEADLESS_CLIENT
865+
743866
String disp ;
744867

745868
if ((abs(_totalDECMove) > 0.001) && (abs(_totalRAMove) > 0.001)) {
@@ -794,6 +917,7 @@ void Mount::displayStepperPosition() {
794917
_lcdMenu->printMenu(disp);
795918
#endif
796919
}
920+
#endif
797921
}
798922

799923
/////////////////////////////////
@@ -802,11 +926,13 @@ void Mount::displayStepperPosition() {
802926
//
803927
/////////////////////////////////
804928
void Mount::displayStepperPositionThrottled() {
929+
#ifndef HEADLESS_CLIENT
805930
long elapsed = millis() - _lastDisplayUpdate;
806931
if (elapsed > DISPLAY_UPDATE_TIME) {
807932
displayStepperPosition();
808933
_lastDisplayUpdate = millis();
809934
}
935+
#endif
810936
}
811937

812938
/////////////////////////////////

Software/Arduino code/OpenAstroTracker/Mount.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Mount {
8080
bool isSlewingTRK();
8181
bool isParked();
8282
bool isParking();
83+
bool isGuiding();
8384

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

115+
// Runs the RA motor at twice the speed (or stops it), or the DEC motor at tracking speed for the given duration in ms.
116+
void guidePulse(byte direction, int duration);
117+
118+
// Stops any guide operation in progress.
119+
void stopGuiding();
114120

115121
// Return a string of DEC in the given format. For LCDSTRING, active determines where the cursor is
116122
String DECString(byte type, byte active = 0);
@@ -144,6 +150,11 @@ class Mount {
144150
LcdMenu* _lcdMenu;
145151
int _stepsPerRADegree;
146152
int _stepsPerDECDegree;
153+
//int _maxRASpeed;
154+
int _maxDECSpeed;
155+
//int _maxRAAcceleration;
156+
int _maxDECAcceleration;
157+
147158
long _lastHASet;
148159
DayTime _HAAdjust;
149160

@@ -163,6 +174,7 @@ class Mount {
163174
AccelStepper* _stepperDEC;
164175
AccelStepper* _stepperTRK;
165176

177+
unsigned long _guideEndTime;
166178
unsigned long _lastMountPrint = 0;
167179
DayTime _HATime;
168180
DayTime _HACorrection;

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.25";
19+
String version = "V1.6.28";
2020

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

0 commit comments

Comments
 (0)