Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tracking code #2105

Merged
merged 9 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions drivers/dome/universal_ror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ bool UniversalROR::initProperties()
InputTP.fill(getDeviceName(), "INPUT_INDEX", "Input Indexes", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);
InputTP.load();

// Limit Switch Indicators
LimitSwitchLP[FullyOpened].fill("FULLY_OPENED", "Fully Opened", IPS_IDLE);
LimitSwitchLP[FullyClosed].fill("FULLY_CLOSED", "Fully Closed", IPS_IDLE);
LimitSwitchLP.fill(getDeviceName(), "LIMIT_SWITCHES", "Limit Switches", MAIN_CONTROL_TAB, IPS_IDLE);

// Output Indexes
OutputTP[OpenRoof].fill("OPEN_ROOF", "Open Roof", "Comma separated indexes");
OutputTP[CloseRoof].fill("CLOSE_ROOF", "Close Roof", "Comma separated indexes");
Expand Down Expand Up @@ -117,6 +122,8 @@ bool UniversalROR::Connect()
////////////////////////////////////////////////////////////////////////////////
bool UniversalROR::Disconnect()
{
m_InputFullyOpened.clear();
m_InputFullyClosed.clear();
return true;
}

Expand Down Expand Up @@ -182,11 +189,13 @@ bool UniversalROR::updateProperties()

defineProperty(InputTP);
defineProperty(OutputTP);
defineProperty(LimitSwitchLP);
}
else
{
deleteProperty(InputTP);
deleteProperty(OutputTP);
deleteProperty(LimitSwitchLP);
}

return true;
Expand Down Expand Up @@ -366,10 +375,14 @@ void UniversalROR::ActiveDevicesUpdated()
m_Client->setFullyClosedCallback([&](bool on)
{
m_FullClosedLimitSwitch = on;
LimitSwitchLP[FullyClosed].setState(on ? IPS_OK : IPS_IDLE);
LimitSwitchLP.apply();
});
m_Client->setFullyOpenedCallback([&](bool on)
{
m_FullOpenLimitSwitch = on;
LimitSwitchLP[FullyOpened].setState(on ? IPS_OK : IPS_IDLE);
LimitSwitchLP.apply();
});
m_Client->watchDevice(input.c_str());
m_Client->watchDevice(output.c_str());
Expand Down
1 change: 1 addition & 0 deletions drivers/dome/universal_ror.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class UniversalROR : public INDI::Dome
bool m_FullOpenLimitSwitch {false}, m_FullClosedLimitSwitch {false};

INDI::PropertyText InputTP {2};
INDI::PropertyLight LimitSwitchLP {2};
enum
{
FullyOpened,
Expand Down
1 change: 1 addition & 0 deletions drivers/dome/universal_ror_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void UniversalRORClient::newProperty(INDI::Property property)
///////////////////////////////////////////////////////////////////////////////////////////
void UniversalRORClient::serverDisconnected(int exitCode)
{
INDI_UNUSED(exitCode);
m_InputReady = m_OutputReady = false;
}

Expand Down
694 changes: 471 additions & 223 deletions drivers/telescope/skywatcherAPIMount.cpp

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions drivers/telescope/skywatcherAPIMount.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class SkywatcherAPIMount :
long &Axis2Microsteps);
const INDI::AlignmentSubsystem::TelescopeDirectionVector
TelescopeDirectionVectorFromSkywatcherMicrosteps(long Axis1Microsteps, long Axis2Microsteps);
double AzimuthToDegrees(double degree);
double DegreesToAzimuth(double degree);
bool isNorthHemisphere() const
{
return m_Location.latitude >= 0;
}

/////////////////////////////////////////////////////////////////////////////////////
/// Misc
Expand All @@ -124,6 +130,23 @@ class SkywatcherAPIMount :
bool getCurrentRADE(INDI::IHorizontalCoordinates altaz, INDI::IEquatorialCoordinates &rade);
// Reset tracking timer to account for drift compensation
void resetTracking();
// Classical tracking via PID control loop
bool trackUsingPID();
// Simpler tracking loop develped by Paweł T. Jochym
bool trackUsingPredictiveRates();
// Get guide ticks
void getGuidePulses(double &az, double &alt);

/**
* @brief TrackByRate Set axis tracking rate in arcsecs/sec.
* @param axis AXIS1 AZ or AXIS2 ALT
* @param rate arcsecs/s. Zero would stop tracking.
* For AZ, negative means left while positive means right.
* For Alt, negative is down while positive is up.
* @return True if successful, false otherwise.
*/
bool trackByRate(AXISID axis, double rate);

inline double average(const std::vector<double> &values)
{
return values.empty() ? 0 : std::accumulate(values.begin(), values.end(), 0.0) / values.size();
Expand Down Expand Up @@ -233,16 +256,16 @@ class SkywatcherAPIMount :
AZSteps,
ALSteps,
JulianOffset,
};
};

// Axis 1 Direct Track Control
INDI::PropertyNumber Axis1TrackRateNP {2};
INDI::PropertyNumber Axis2TrackRateNP {2};
enum
{
// Axis 1 Direct Track Control
INDI::PropertyNumber Axis1TrackRateNP {2};
INDI::PropertyNumber Axis2TrackRateNP {2};
enum
{
TrackDirection,
TrackClockRate,
};
};

// AUX Encoders
INDI::PropertySwitch AUXEncoderSP {2};
Expand All @@ -261,13 +284,16 @@ class SkywatcherAPIMount :
std::unique_ptr<PID> m_Controllers[2];

// Maximum delta to track. If drift is above 5 degrees, we abort tracking.
static constexpr double MAX_TRACKING_DELTA {5};
static constexpr double MAX_TRACKING_DELTA {5};
static constexpr const char *TRACKING_TAB = "Tracking";

INDI::ElapsedTimer m_TrackingRateTimer;
int32_t m_LastTrackRate[2] = {-1, -1};
uint8_t m_LastCustomDirection[2];
double GuideDeltaAlt { 0 };
double GuideDeltaAz { 0 };
double m_LastOffset[2] = {0, 0};
uint8_t m_OffsetSwitchSettle[2] = {0, 0};

GuidingPulse NorthPulse;
GuidingPulse WestPulse;
Expand Down
10 changes: 10 additions & 0 deletions libs/indicore/indicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,16 @@ double range360(double r)
return res;
}

double range180(double r)
{
double res = r;
while (res < -180.0)
res += 360.0;
while (res > 180.0)
res -= 360.0;
return res;
}

double rangeDec(double decdegrees)
{
if ((decdegrees >= 270.0) && (decdegrees <= 360.0))
Expand Down
7 changes: 7 additions & 0 deletions libs/indicore/indicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ double range24(double r);
*/
double range360(double r);

/**
* \brief range180 Limits an angle to be between -180 to +180 degrees
* \param r angle in degrees
* \return Limited angle
*/
double range180(double r);

/** \brief rangeDec Limits declination value to be in -90 to 90 range.
* \param r declination angle
* \return limited declination
Expand Down
Loading