Skip to content

Commit

Permalink
Avalon StarGO V 1.14 | auto tracking adjustment added (#952)
Browse files Browse the repository at this point in the history
* Logging averaged RA pulse values

* INDI property for auto tracking adjustment added

* Version info updated

* First version of automatic tracking adjustment implemented

---------

Co-authored-by: Wolfgang Reissenberger <[email protected]>
  • Loading branch information
sterne-jaeger and Wolfgang Reissenberger authored Jul 31, 2024
1 parent 45b5153 commit dc8edd5
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
6 changes: 6 additions & 0 deletions debian/indi-avalon/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
indi-avalon (1.14) UNRELEASED; urgency=medium

* Automatic tracking adjustment implemented

-- Wolfgang Reissenberger <[email protected]> Tue, 06 Feb 2024 20:19:18 +0100

indi-avalon (1.13.3) jammy; urgency=medium

* Manufacturer changed to Avalon-Instruments
Expand Down
2 changes: 1 addition & 1 deletion indi-avalon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include_directories(${NOVA_INCLUDE_DIR})
include(CMakeCommon)

set(AVALON_VERSION_MAJOR 1)
set(AVALON_VERSION_MINOR 13)
set(AVALON_VERSION_MINOR 14)

set(INDI_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/indi")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
Expand Down
88 changes: 87 additions & 1 deletion indi-avalon/lx200stargo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <memory>
#include <cstring>
#include <unistd.h>
#include <numeric>
#ifndef _WIN32
#include <termios.h>
#endif
Expand Down Expand Up @@ -292,6 +293,18 @@ bool LX200StarGo::ISNewSwitch(const char *dev, const char *name, ISState *states
return false;
}
}
else if (!strcmp(name, TrackingAutoAdjustmentSP.name))
{
if (IUUpdateSwitch(&TrackingAutoAdjustmentSP, states, names, n) < 0)
return false;

LOGF_INFO("Automatic tracking adjustment %s", isTrackingAutoAdjustmentEnabled() ? "enabled" : "disabled");

// The tracking state is stored directly in the property
TrackingAutoAdjustmentSP.s = IPS_OK;
IDSetSwitch(&TrackingAutoAdjustmentSP, nullptr);
return true;
}
}

bool result = true;
Expand Down Expand Up @@ -427,6 +440,10 @@ bool LX200StarGo::initProperties()
IUFillNumber(&TrackingAdjustment[0], "ADJUSTMENT_RA", "Adj. (max +/- 5%)", "%.2f", -5.0, 5.0, 0.01, 0.0);
IUFillNumberVector(&TrackingAdjustmentNP, TrackingAdjustment, 1, getDeviceName(), "TRACKING_ADJUSTMENT", "Tracking",
RA_DEC_TAB, IP_RW, 60.0, IPS_IDLE);
IUFillSwitch(&TrackingAutoAdjustmentS[INDI_ENABLED], "INDI_ENABLED", "Enabled", ISS_OFF);
IUFillSwitch(&TrackingAutoAdjustmentS[INDI_DISABLED], "INDI_DISABLED", "Disabled", ISS_ON);
IUFillSwitchVector(&TrackingAutoAdjustmentSP, TrackingAutoAdjustmentS, 2, getDeviceName(), "TRACKING_AUTO_ADJUSTMENT",
"Tracking Auto Adj.", RA_DEC_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);

// meridian flip
IUFillSwitch(&MeridianFlipModeS[0], "MERIDIAN_FLIP_AUTO", "auto", ISS_OFF);
Expand Down Expand Up @@ -460,6 +477,7 @@ bool LX200StarGo::updateProperties()
defineProperty(&KeypadStatusSP);
defineProperty(&SystemSpeedSlewSP);
defineProperty(&TrackingAdjustmentNP);
defineProperty(&TrackingAutoAdjustmentSP);
defineProperty(&MeridianFlipModeSP);
defineProperty(&MountRequestDelayNP);
defineProperty(&MountFirmwareInfoTP);
Expand All @@ -474,6 +492,7 @@ bool LX200StarGo::updateProperties()
deleteProperty(GuidingSpeedNP.name);
deleteProperty(ST4StatusSP.name);
deleteProperty(KeypadStatusSP.name);
deleteProperty(TrackingAutoAdjustmentSP.name);
deleteProperty(TrackingAdjustmentNP.name);
deleteProperty(SystemSpeedSlewSP.name);
deleteProperty(MeridianFlipModeSP.name);
Expand Down Expand Up @@ -1134,6 +1153,7 @@ bool LX200StarGo::saveConfigItems(FILE *fp)
IUSaveConfigText(fp, &SiteNameTP);
IUSaveConfigSwitch(fp, &Aux1FocuserSP);
IUSaveConfigNumber(fp, &MountRequestDelayNP);
IUSaveConfigSwitch(fp, &TrackingAutoAdjustmentSP);

if (loader.isFocuserAux1Activated())
loader.getFocuserAux1()->saveConfigItems(fp);
Expand Down Expand Up @@ -2284,6 +2304,9 @@ IPState LX200StarGo::GuideEast(uint32_t ms)
MoveWE(DIRECTION_EAST, MOTION_START);
}

// update statistics for tracking optimization
updateGuidingStatistics(LX200_EAST, ms);

// Set slew to guiding
IUResetSwitch(&SlewRateSP);
SlewRateS[SLEW_GUIDE].s = ISS_ON;
Expand Down Expand Up @@ -2332,6 +2355,8 @@ IPState LX200StarGo::GuideWest(uint32_t ms)
MovementWES[DIRECTION_WEST].s = ISS_ON;
MoveWE(DIRECTION_WEST, MOTION_START);
}
// update statistics for tracking optimization
updateGuidingStatistics(LX200_WEST, ms);

// Set slew to guiding
IUResetSwitch(&SlewRateSP);
Expand All @@ -2342,6 +2367,25 @@ IPState LX200StarGo::GuideWest(uint32_t ms)
return IPS_BUSY;
}

void LX200StarGo::updateGuidingStatistics(TDirection direction, uint32_t ms)
{
// skip if automatic tracking adjustment is disabled
if (!isTrackingAutoAdjustmentEnabled())
return;

switch (direction)
{
case LX200_WEST:
raPulsesList.push_back(ms);
break;
case LX200_EAST:
raPulsesList.push_back(-ms);
break;
default:
break;
}
}

int LX200StarGo::SendPulseCmd(int8_t direction, uint32_t duration_msec)
{
LOGF_DEBUG("%s dir=%d dur=%d ms", __FUNCTION__, direction, duration_msec );
Expand Down Expand Up @@ -2788,7 +2832,49 @@ bool LX200StarGo::getUTFOffset(double *offset)
return true;
}

bool LX200StarGo::getTrackFrequency(double *value)
void LX200StarGo::TimerHit()
{
const int n = raPulsesList.size();

// update regularly the evaluation of the guiding statistics
// and optimize the tracking
if (isTrackingAutoAdjustmentEnabled() && isConnected() && n >= 15)
{
// sort the list first
raPulsesList.sort();

const int delta = n / 10;
auto start = raPulsesList.begin();
auto end = raPulsesList.end();
// skip first and last 10%
start.operator++(delta);
end.operator--(delta);

// take the average value of the pulses, cutting off 10% min and max values
int average = accumulate(start, end, 0) / (n - 2 * delta);
LOGF_INFO("Average RA pulse duration: %dms", average);

if (TrackingAdjustmentNP.s == IPS_OK)
{
// adjustment of the tracking speed
// 100ms --> 1% adjustment
// We take only 50%
double diff = 0.5 * static_cast<double>(average) / 100.0;
double adj = TrackingAdjustment[0].value + diff;
// ensure that -5 <= adj <= 5
adj = std::min(adj, 5.0);
adj = std::max(adj, -5.0);
setTrackingAdjustment(adj);
}
// reset values
raPulsesList.clear();
}

// hand over to base class
Telescope::TimerHit();
}

bool LX200StarGo::getTrackFrequency(double * value)
{
LOG_DEBUG(__FUNCTION__);
float Freq;
Expand Down
24 changes: 24 additions & 0 deletions indi-avalon/lx200stargo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <cstring>
#include <string>
#include <unistd.h>
#include <queue>
#include <list>

#define LX200_TIMEOUT 5 /* FD timeout in seconds */
#define RB_MAX_LEN 64
Expand Down Expand Up @@ -141,6 +143,8 @@ class LX200StarGo : public LX200Telescope
// tracking adjustment setting
INumberVectorProperty TrackingAdjustmentNP;
INumber TrackingAdjustment[1];
ISwitchVectorProperty TrackingAutoAdjustmentSP;
ISwitch TrackingAutoAdjustmentS[2];

// meridian flip
ISwitchVectorProperty MeridianFlipModeSP;
Expand Down Expand Up @@ -241,6 +245,7 @@ class LX200StarGo : public LX200Telescope
virtual bool getLocalTime(char *timeString) override;
virtual bool getLocalDate(char *dateString) override;
virtual bool getUTFOffset(double *offset) override;
virtual void TimerHit() override;

// Abort ALL motion
virtual bool Abort() override;
Expand All @@ -255,6 +260,25 @@ class LX200StarGo : public LX200Telescope
// AUX1 focuser
bool activateFocuserAux1(bool activate);

/**
* @brief updateGuidingStatistics Update guiding statistics for optimizing the
* tracking adustments.
* @param direction direction of the guiding pulse
* @param ms pulse duration in milliseconds
*/
void updateGuidingStatistics(TDirection direction, uint32_t ms);
// list holding all recent pulses
std::list<int32_t> raPulsesList;

/**
* @brief isTrackingAutoAdjustmentEnabled helper function checking if the automatic
* tracking adjustment is enabled
*/
bool isTrackingAutoAdjustmentEnabled()
{
return (IUFindOnSwitchIndex(&TrackingAutoAdjustmentSP) == DefaultDevice::INDI_ENABLED);
}

};
inline bool LX200StarGo::sendQuery(const char* cmd, char* response, int wait)
{
Expand Down

0 comments on commit dc8edd5

Please sign in to comment.