Skip to content

Commit

Permalink
Display rotator on Star Tracker and Satellite Tracker polar charts for
Browse files Browse the repository at this point in the history
  • Loading branch information
srcejon committed Apr 3, 2023
1 parent 4ac5e72 commit f7ed662
Show file tree
Hide file tree
Showing 15 changed files with 692 additions and 368 deletions.
5 changes: 4 additions & 1 deletion plugins/feature/satellitetracker/readme.md
Expand Up @@ -116,7 +116,10 @@ On the display tab, you can set:
* The default frequency in MHz that is used for calculating Doppler and free space path loss in the Satellite Data table.
* The units used to display azimuth and elevation to the target satellite. This can be in degrees, minutes and seconds or decimal degrees.
* The number of points used for ground tracks on the map. More points result in smoother tracks, but require more processing.
* Whether times are displayrf in the local time zone or UTC.
* Which rotators are displayed on the polar chart. This can be All, None or Matching target. When Matching target is selected, the rotator will
only be displayed if the source in the Rotator Controller is set to this Satellite Tracker and Track is enabled.
* The format used for displaying dates. E.g. yyyy/MM/dd
* Whether times are displayed in the local time zone or UTC.
* Whether to draw the satellites on the map.

<h3>9: Latitude</h3>
Expand Down
121 changes: 118 additions & 3 deletions plugins/feature/satellitetracker/satellitetrackergui.cpp
Expand Up @@ -28,8 +28,10 @@

#include "device/deviceapi.h"
#include "device/deviceset.h"
#include "channel/channelwebapiutils.h"
#include "feature/featureset.h"
#include "feature/featureuiset.h"
#include "feature/featureutils.h"
#include "feature/featurewebapiutils.h"
#include "gui/basicfeaturesettingsdialog.h"
#include "gui/dialogpositioner.h"
Expand Down Expand Up @@ -295,6 +297,8 @@ SatelliteTrackerGUI::SatelliteTrackerGUI(PluginAPI* pluginAPI, FeatureUISet *fea
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(1000);

connect(&m_redrawTimer, &QTimer::timeout, this, &SatelliteTrackerGUI::plotChart);

// Intialise charts
m_emptyChart.layout()->setContentsMargins(0, 0, 0, 0);
m_emptyChart.setMargins(QMargins(1, 1, 1, 1));
Expand Down Expand Up @@ -534,6 +538,7 @@ void SatelliteTrackerGUI::on_displaySettings_clicked()
m_settingsKeys.append("defaultFrequency");
m_settingsKeys.append("azElUnits");
m_settingsKeys.append("groundTrackPoints");
m_settingsKeys.append("drawRotators");
m_settingsKeys.append("dateFormat");
m_settingsKeys.append("utc");
m_settingsKeys.append("tles");
Expand Down Expand Up @@ -792,6 +797,26 @@ static double interpolate(double x0, double y0, double x1, double y1, double x)
return (y0*(x1-x) + y1*(x-x0)) / (x1-x0);
}

// Reduce az/el range from 450,180 to 360,90
void SatelliteTrackerGUI::limitAzElRange(double& azimuth, double& elevation) const
{
if (elevation > 90.0)
{
elevation = 180.0 - elevation;
if (azimuth < 180.0) {
azimuth += 180.0;
} else {
azimuth -= 180.0;
}
}
if (azimuth > 360.0) {
azimuth -= 360.0f;
}
if (azimuth == 0) {
azimuth = 360.0;
}
}

// Plot pass in polar coords
void SatelliteTrackerGUI::plotPolarChart()
{
Expand Down Expand Up @@ -916,6 +941,86 @@ void SatelliteTrackerGUI::plotPolarChart()
series[i]->attachAxis(radialAxis);
}

int redrawTime = 0;

if (m_settings.m_drawRotators != SatelliteTrackerSettings::NO_ROTATORS)
{
// Plot rotator position
QString ourSourceName = QString("F0:%1 %2").arg(m_satelliteTracker->getIndexInFeatureSet()).arg(m_satelliteTracker->getIdentifier()); // Only one feature set in practice?
std::vector<FeatureSet*>& featureSets = MainCore::instance()->getFeatureeSets();
for (int featureSetIndex = 0; featureSetIndex < featureSets.size(); featureSetIndex++)
{
FeatureSet *featureSet = featureSets[featureSetIndex];
for (int featureIndex = 0; featureIndex < featureSet->getNumberOfFeatures(); featureIndex++)
{
Feature *feature = featureSet->getFeatureAt(featureIndex);
if (FeatureUtils::compareFeatureURIs(feature->getURI(), "sdrangel.feature.gs232controller"))
{
QString source;
ChannelWebAPIUtils::getFeatureSetting(featureSetIndex, featureIndex, "source", source); // Will return false if source isn't set in Controller
int track = 0;
ChannelWebAPIUtils::getFeatureSetting(featureSetIndex, featureIndex, "track", track);
if ((m_settings.m_drawRotators == SatelliteTrackerSettings::ALL_ROTATORS) || ((source == ourSourceName) && track))
{
int onTarget = 0;
ChannelWebAPIUtils::getFeatureReportValue(featureSetIndex, featureIndex, "onTarget", onTarget);

if (!onTarget)
{
// Target azimuth red dotted line
double targetAzimuth, targetElevation;
bool targetAzimuthOk = ChannelWebAPIUtils::getFeatureReportValue(featureSetIndex, featureIndex, "targetAzimuth", targetAzimuth);
bool targetElevationOk = ChannelWebAPIUtils::getFeatureReportValue(featureSetIndex, featureIndex, "targetElevation", targetElevation);
if (targetAzimuthOk && targetElevationOk)
{
limitAzElRange(targetAzimuth, targetElevation);

QScatterSeries *rotatorSeries = new QScatterSeries();
QColor color(255, 0, 0, 150);
QPen pen(color);
rotatorSeries->setPen(pen);
rotatorSeries->setColor(color.darker());
rotatorSeries->setMarkerSize(20);
rotatorSeries->append(targetAzimuth, 90-targetElevation);
m_polarChart->addSeries(rotatorSeries);
rotatorSeries->attachAxis(angularAxis);
rotatorSeries->attachAxis(radialAxis);

redrawTime = 333;
}
}

// Current azimuth line. Yellow while off target, green on target.
double currentAzimuth, currentElevation;
bool currentAzimuthOk = ChannelWebAPIUtils::getFeatureReportValue(featureSetIndex, featureIndex, "currentAzimuth", currentAzimuth);
bool currentElevationOk = ChannelWebAPIUtils::getFeatureReportValue(featureSetIndex, featureIndex, "currentElevation", currentElevation);
if (currentAzimuthOk && currentElevationOk)
{
limitAzElRange(currentAzimuth, currentElevation);

QScatterSeries *rotatorSeries = new QScatterSeries();
QColor color;
if (onTarget) {
color = QColor(0, 255, 0, 150);
} else {
color = QColor(255, 255, 0, 150);
}
rotatorSeries->setPen(QPen(color));
rotatorSeries->setColor(color.darker());
rotatorSeries->setMarkerSize(20);
rotatorSeries->append(currentAzimuth, 90-currentElevation);
m_polarChart->addSeries(rotatorSeries);
rotatorSeries->attachAxis(angularAxis);
rotatorSeries->attachAxis(radialAxis);

redrawTime = 333;
}
}
}
}
}
}

// Create series with single point, so we can plot time of AOS
QLineSeries *aosSeries = new QLineSeries();
aosSeries->append(polarSeries->at(0));
Expand Down Expand Up @@ -967,7 +1072,8 @@ void SatelliteTrackerGUI::plotPolarChart()
if ((currentTime >= pass.m_aos) && (currentTime <= pass.m_los))
{
// Create series with single point, so we can plot current time
QLineSeries *nowSeries = new QLineSeries();
QScatterSeries *nowSeries = new QScatterSeries();
nowSeries->setMarkerSize(3);
// Find closest point to current time
int idx = std::round(polarSeries->count() * (currentTime.toMSecsSinceEpoch() - pass.m_aos.toMSecsSinceEpoch())
/ (pass.m_los.toMSecsSinceEpoch() - pass.m_aos.toMSecsSinceEpoch()));
Expand All @@ -978,8 +1084,16 @@ void SatelliteTrackerGUI::plotPolarChart()
m_polarChart->addSeries(nowSeries);
nowSeries->attachAxis(angularAxis);
nowSeries->attachAxis(radialAxis);
// Redraw in 5 seconds (call plotChart, incase user selects a different chart)
QTimer::singleShot(5000, this, &SatelliteTrackerGUI::plotChart);
if (!redrawTime) {
redrawTime = 5000;
}
}

if (redrawTime > 0)
{
// Redraw to show updated satellite position or rotator position
m_redrawTimer.setSingleShot(true);
m_redrawTimer.start(redrawTime);
}

delete polarSeries;
Expand Down Expand Up @@ -1567,3 +1681,4 @@ void SatelliteTrackerGUI::makeUIConnections()
QObject::connect(ui->satTable->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &SatelliteTrackerGUI::on_satTableHeader_sortIndicatorChanged);
QObject::connect(ui->deviceFeatureSelect, qOverload<int>(&QComboBox::currentIndexChanged), this, &SatelliteTrackerGUI::on_deviceFeatureSelect_currentIndexChanged);
}

2 changes: 2 additions & 0 deletions plugins/feature/satellitetracker/satellitetrackergui.h
Expand Up @@ -82,6 +82,7 @@ class SatelliteTrackerGUI : public FeatureGUI {
QChart m_emptyChart;
QChart *m_lineChart;
QPolarChart *m_polarChart;
QTimer m_redrawTimer;

QDateTime m_nextTargetAOS;
QDateTime m_nextTargetLOS;
Expand Down Expand Up @@ -138,6 +139,7 @@ class SatelliteTrackerGUI : public FeatureGUI {
void updateFileInputList();
void updateMapList();
void makeUIConnections();
void limitAzElRange(double& azimuth, double& elevation) const;

private slots:
void onMenuDialogCalled(const QPoint &p);
Expand Down

0 comments on commit f7ed662

Please sign in to comment.