修复两行根数创建卫星轨道
parent
151d878e61
commit
2c7e64e370
|
|
@ -1,4 +1,5 @@
|
||||||
#include "SPG4Function.h"
|
#include "SPG4Function.h"
|
||||||
|
#include "SPG4Tool.h"
|
||||||
#include <Tle.h>
|
#include <Tle.h>
|
||||||
#include <SGP4.h>
|
#include <SGP4.h>
|
||||||
#include <Observer.h>
|
#include <Observer.h>
|
||||||
|
|
@ -12,16 +13,23 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag)
|
std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag, bool running, bool first_run)
|
||||||
{
|
{
|
||||||
|
std::cout << "RunTle\t" ;
|
||||||
|
std::cout << "Start time:\t" << start;
|
||||||
|
std::cout << "End time:\t" << end;
|
||||||
|
std::cout << "inc time:\t" << inc << std::endl;
|
||||||
|
|
||||||
std::vector<SatelliteAntPos> resultpos(0);
|
std::vector<SatelliteAntPos> resultpos(0);
|
||||||
double current = start;
|
double current = start;
|
||||||
libsgp4::SGP4 model(tle);
|
libsgp4::SGP4 model(tle);
|
||||||
bool running = true;
|
//bool running = true;
|
||||||
bool first_run = true;
|
//bool first_run = true;
|
||||||
|
|
||||||
std::cout << std::setprecision(0) << tle.NoradNumber() << " xx"
|
std::cout << std::setprecision(0) << tle.NoradNumber() << " xx"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
@ -53,16 +61,17 @@ std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end,
|
||||||
libsgp4::Eci eci = model.FindPosition(tsince);
|
libsgp4::Eci eci = model.FindPosition(tsince);
|
||||||
position = eci.Position();
|
position = eci.Position();
|
||||||
velocity = eci.Velocity();
|
velocity = eci.Velocity();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (libsgp4::SatelliteException& e)
|
catch (libsgp4::SatelliteException& e)
|
||||||
{
|
{
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << "SatelliteException:\t" << e.what() << std::endl;
|
||||||
error = true;
|
error = true;
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
catch (libsgp4::DecayedException& e)
|
catch (libsgp4::DecayedException& e)
|
||||||
{
|
{
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr <<"DecayedException:\t" << e.what() << std::endl;
|
||||||
|
|
||||||
position = e.Position();
|
position = e.Position();
|
||||||
velocity = e.Velocity();
|
velocity = e.Velocity();
|
||||||
|
|
@ -83,8 +92,8 @@ std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end,
|
||||||
antpos.Px = position.x;
|
antpos.Px = position.x;
|
||||||
antpos.Py = position.y;
|
antpos.Py = position.y;
|
||||||
antpos.Pz = position.z;
|
antpos.Pz = position.z;
|
||||||
antpos.Vx = velocity.z;
|
antpos.Vx = velocity.x;
|
||||||
antpos.Vy = velocity.z;
|
antpos.Vy = velocity.y;
|
||||||
antpos.Vz = velocity.z;
|
antpos.Vz = velocity.z;
|
||||||
|
|
||||||
resultpos.push_back(antpos);
|
resultpos.push_back(antpos);
|
||||||
|
|
@ -114,7 +123,7 @@ std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end,
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
else if (current + inc > end)
|
else if ((current + inc) > end)
|
||||||
{
|
{
|
||||||
current = end;
|
current = end;
|
||||||
}
|
}
|
||||||
|
|
@ -130,12 +139,40 @@ std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end,
|
||||||
return resultpos;
|
return resultpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPG4TOOL_EXPORT std::vector<SatelliteAntPos> getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag)
|
std::vector<SatelliteAntPos> getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag, bool running , bool first_run )
|
||||||
{
|
{
|
||||||
libsgp4::Tle tle("GF3", line1, line2);
|
libsgp4::Tle tle("satellites", line1, line2);
|
||||||
return RunTle( tle, start, end, inc, printfinfoflag);
|
std::cout << "Start time:\t" << start;
|
||||||
|
std::cout << "End time:\t" << end;
|
||||||
|
std::cout << "inc time:\t" << inc << std::endl;
|
||||||
|
std::vector<SatelliteAntPos> result= RunTle(tle, start, end, inc, printfinfoflag);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double parseTLETimeOffset(const std::string& tle) {
|
||||||
|
// 假设TLE字符串的时间信息在特定位置
|
||||||
|
// 例如,TLE的第19到32个字符表示纪元时间
|
||||||
|
if (tle.length() < 32) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string epochStr = tle.substr(18, 14);
|
||||||
|
int year = std::stoi(epochStr.substr(0, 2));
|
||||||
|
double dayOfYear = std::stod(epochStr.substr(2));
|
||||||
|
|
||||||
|
// 将两位数年份转换为四位数年份
|
||||||
|
if (year < 57) {
|
||||||
|
year += 2000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
year += 1900;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算从纪元开始到指定日期的毫秒数
|
||||||
|
QDate date(year, 1, 1);
|
||||||
|
QDateTime dateTime(date.addDays(static_cast<int>(dayOfYear) - 1), QTime(0, 0), Qt::UTC);
|
||||||
|
qint64 millisecondsSinceEpoch = dateTime.toMSecsSinceEpoch() + static_cast<qint64>((dayOfYear - static_cast<int>(dayOfYear)) * 86400000);
|
||||||
|
|
||||||
|
return millisecondsSinceEpoch / 1000.0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,18 @@
|
||||||
//void RunTle(libsgp4::Tle tle, double start, double end, double inc);
|
//void RunTle(libsgp4::Tle tle, double start, double end, double inc);
|
||||||
|
|
||||||
|
|
||||||
|
SPG4TOOL_EXPORT double parseTLETimeOffset(const std::string& tle);
|
||||||
SPG4TOOL_EXPORT std::vector<SatelliteAntPos> getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false);
|
/// <summary>
|
||||||
|
/// 根据两行根数生成坐标与速度,请注意返回的单位是 km
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="line1"></param>
|
||||||
|
/// <param name="line2"></param>
|
||||||
|
/// <param name="start"></param>
|
||||||
|
/// <param name="end"></param>
|
||||||
|
/// <param name="inc"></param>
|
||||||
|
/// <param name="printfinfoflag"></param>
|
||||||
|
/// <param name="running"></param>
|
||||||
|
/// <param name="first_run"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
SPG4TOOL_EXPORT std::vector<SatelliteAntPos> getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false, bool running = true, bool first_run = true);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
#include <Tle.h>
|
||||||
|
#include <SGP4.h>
|
||||||
|
#include <Observer.h>
|
||||||
|
#include <CoordGeodetic.h>
|
||||||
|
#include <CoordTopocentric.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include "BaseConstVariable.h"
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<SatelliteAntPos> RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag, bool running = true, bool first_run = true);
|
||||||
|
|
@ -67,6 +67,7 @@
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;SPG4TOOL_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;SPG4TOOL_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||||
|
|
@ -92,7 +93,7 @@
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
@ -135,6 +136,7 @@
|
||||||
<ClInclude Include="libsgp4\Util.h" />
|
<ClInclude Include="libsgp4\Util.h" />
|
||||||
<ClInclude Include="libsgp4\Vector.h" />
|
<ClInclude Include="libsgp4\Vector.h" />
|
||||||
<ClInclude Include="SPG4Function.h" />
|
<ClInclude Include="SPG4Function.h" />
|
||||||
|
<ClInclude Include="SPG4Tool.h" />
|
||||||
<ClInclude Include="SPG4Tool_global.h" />
|
<ClInclude Include="SPG4Tool_global.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -136,5 +136,8 @@
|
||||||
<ClInclude Include="SPG4Tool_global.h">
|
<ClInclude Include="SPG4Tool_global.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="SPG4Tool.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -57,7 +57,7 @@ void QtCreateGPSPointsDialog::onoutGPSxmlSelectBtnClicked()
|
||||||
|
|
||||||
// 如果用户选择了文件
|
// 如果用户选择了文件
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
this->ui->outGPSxmlSelectBtn->setText(fileName);
|
this->ui->lineEditoutGPSxml->setText(fileName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
|
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
|
||||||
|
|
@ -67,7 +67,7 @@ void QtCreateGPSPointsDialog::onoutGPSxmlSelectBtnClicked()
|
||||||
void QtCreateGPSPointsDialog::onaccepted()
|
void QtCreateGPSPointsDialog::onaccepted()
|
||||||
{
|
{
|
||||||
QString inLTEPath = this->ui->lineEditLTE->text();
|
QString inLTEPath = this->ui->lineEditLTE->text();
|
||||||
QString outGPSxmlPath = this->ui->outGPSxmlSelectBtn->text();
|
QString outGPSxmlPath = this->ui->lineEditoutGPSxml->text();
|
||||||
|
|
||||||
double start = this->ui->StartimedateTimeEdit->dateTime().toTime_t();
|
double start = this->ui->StartimedateTimeEdit->dateTime().toTime_t();
|
||||||
double end = this->ui->EndimedateTimeEdit->dateTime().toTime_t();
|
double end = this->ui->EndimedateTimeEdit->dateTime().toTime_t();
|
||||||
|
|
@ -100,9 +100,20 @@ void QtCreateGPSPointsDialog::onaccepted()
|
||||||
}
|
}
|
||||||
|
|
||||||
ifs.close();
|
ifs.close();
|
||||||
std::vector<SatelliteAntPos> gpspoints = getGPSPoints(tle1, tle2, start, end, gpsoint, true);
|
|
||||||
|
|
||||||
|
// 根据两行根数计算时间偏移情况
|
||||||
|
// 这里假设tle1和tle2包含时间信息,并且可以解析为时间偏移量
|
||||||
|
double tle1TimeOffset = parseTLETimeOffset(tle1);
|
||||||
|
//double tle2TimeOffset = parseTLETimeOffset(tle2);
|
||||||
|
|
||||||
|
start = start- tle1TimeOffset;
|
||||||
|
end = end- tle1TimeOffset;
|
||||||
|
|
||||||
|
double inc = (end - start) / (gpsoint-1);
|
||||||
|
|
||||||
|
std::vector<SatelliteAntPos> gpspoints = getGPSPoints(tle1, tle2, start, end, inc, true,true,false);
|
||||||
|
|
||||||
|
qDebug() << "create gpspoints size:" << gpspoints.size();
|
||||||
// 计算GPS点
|
// 计算GPS点
|
||||||
std::ofstream ofs(outGPSxmlPath.toLocal8Bit().constData());
|
std::ofstream ofs(outGPSxmlPath.toLocal8Bit().constData());
|
||||||
if (!ofs.is_open()) {
|
if (!ofs.is_open()) {
|
||||||
|
|
@ -111,19 +122,19 @@ void QtCreateGPSPointsDialog::onaccepted()
|
||||||
}
|
}
|
||||||
|
|
||||||
ofs << "<root>\n<GPS>\n";
|
ofs << "<root>\n<GPS>\n";
|
||||||
for (const auto& point : gpspoints) {
|
for (const auto& point : gpspoints) { // 缩放单位
|
||||||
ofs << "<GPSParam>\n";
|
ofs << "<GPSParam>\n";
|
||||||
ofs << "<TimeStamp>" << QDateTime::fromTime_t(point.time).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "</TimeStamp>\n";
|
ofs << "<TimeStamp>" << QDateTime::fromTime_t(point.time+ tle1TimeOffset).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "</TimeStamp>\n";
|
||||||
ofs << "<xPosition>" << point.Px << "</xPosition>\n";
|
ofs << "<xPosition>" << point.Px*1000.0 << "</xPosition>\n";
|
||||||
ofs << "<yPosition>" << point.Py << "</yPosition>\n";
|
ofs << "<yPosition>" << point.Py*1000.0 << "</yPosition>\n";
|
||||||
ofs << "<zPosition>" << point.Pz << "</zPosition>\n";
|
ofs << "<zPosition>" << point.Pz*1000.0 << "</zPosition>\n";
|
||||||
ofs << "<xVelocity>" << point.Vx << "</xVelocity>\n";
|
ofs << "<xVelocity>" << point.Vx*1000.0 << "</xVelocity>\n";
|
||||||
ofs << "<yVelocity>" << point.Vy << "</yVelocity>\n";
|
ofs << "<yVelocity>" << point.Vy*1000.0 << "</yVelocity>\n";
|
||||||
ofs << "<zVelocity>" << point.Vz << "</zVelocity>\n";
|
ofs << "<zVelocity>" << point.Vz*1000.0 << "</zVelocity>\n";
|
||||||
ofs << "</GPSParam>\n";
|
ofs << "</GPSParam>\n";
|
||||||
}
|
}
|
||||||
ofs << "</GPS>\n</root>\n";
|
ofs << "</GPS>\n</root>\n";
|
||||||
|
ofs.flush();
|
||||||
ofs.close();
|
ofs.close();
|
||||||
|
|
||||||
QMessageBox::warning(this, tr(u8"提示"), tr(u8"completed!!"));
|
QMessageBox::warning(this, tr(u8"提示"), tr(u8"completed!!"));
|
||||||
|
|
@ -134,3 +145,6 @@ void QtCreateGPSPointsDialog::onrejected()
|
||||||
{
|
{
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,6 +71,16 @@
|
||||||
<height>30</height>
|
<height>30</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="dateTime">
|
||||||
|
<datetime>
|
||||||
|
<hour>19</hour>
|
||||||
|
<minute>56</minute>
|
||||||
|
<second>21</second>
|
||||||
|
<year>2025</year>
|
||||||
|
<month>3</month>
|
||||||
|
<day>14</day>
|
||||||
|
</datetime>
|
||||||
|
</property>
|
||||||
<property name="displayFormat">
|
<property name="displayFormat">
|
||||||
<string>yyyy/M/d H:mm:ss.zzz</string>
|
<string>yyyy/M/d H:mm:ss.zzz</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -84,6 +94,16 @@
|
||||||
<height>30</height>
|
<height>30</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="dateTime">
|
||||||
|
<datetime>
|
||||||
|
<hour>19</hour>
|
||||||
|
<minute>55</minute>
|
||||||
|
<second>11</second>
|
||||||
|
<year>2025</year>
|
||||||
|
<month>3</month>
|
||||||
|
<day>14</day>
|
||||||
|
</datetime>
|
||||||
|
</property>
|
||||||
<property name="currentSection">
|
<property name="currentSection">
|
||||||
<enum>QDateTimeEdit::YearSection</enum>
|
<enum>QDateTimeEdit::YearSection</enum>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -129,6 +149,9 @@
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>1000</number>
|
<number>1000</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>71</number>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue