Skip to content

Commit c7d2c60

Browse files
author
AngelVeraHerrera
committed
feat: finished for stable 1.9 version -> 1.9.2
1 parent 1dfc945 commit c7d2c60

File tree

4 files changed

+105
-43
lines changed

4 files changed

+105
-43
lines changed

LibDegorasSLR/examples/TrackingMount/PredictorMountSLR/TrackingMount_PredictorMountSLR.cpp

Lines changed: 100 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ using dpslr::timing::timePointToModifiedJulianDateTime;
6363
using dpslr::math::units::Angle;
6464
using dpslr::math::units::DegreesU;
6565
using dpslr::math::units::Degrees;
66+
using dpslr::math::units::Seconds;
6667
using dpslr::math::units::MillisecondsU;
6768
using dpslr::math::units::Meters;
6869
// Geocentric and geodetic containers.
@@ -85,11 +86,12 @@ using dpslr::utils::PredictorSlrPtr;
8586
using dpslr::utils::PredictorSlrCPFPtr;
8687
// Mount predictor related.
8788
using dpslr::mount::PredictorMountSLR;
88-
// Helpers.
89-
using dpslr::helpers::strings::numberToStr;
90-
using dpslr::mount::PositionStatus;
89+
using dpslr::mount::MountPredictionSLRV;
9190
using dpslr::mount::MountTrackingSLR;
9291
using dpslr::mount::TrackingAnalyzerConfig;
92+
using dpslr::mount::PositionStatus;
93+
// Helpers.
94+
using dpslr::helpers::strings::numberToStr;
9395
// ---------------------------------------------------------------------------------------------------------------------
9496

9597
// ---------------------------------------------------------------------------------------------------------------------
@@ -159,7 +161,6 @@ int main()
159161
std::string python_plot_analysis(current_dir+"/python_scripts/Helper_Plotting_Analysis.py");
160162
std::string python_plot_track(current_dir+"/python_scripts/Helper_Plotting_Track.py");
161163
std::string python_cmd_analysis = "python \"" + python_plot_analysis + "\" ";
162-
std::string python_cmd_track = "python \"" + python_plot_track + "\" ";
163164

164165
// Create the ouput directory.
165166
if (!dpslr::helpers::files::directoryExists(output_dir))
@@ -238,7 +239,8 @@ int main()
238239
std::string example_alias = examples[example_selector].example_alias;
239240
PredictorSunPtr predictor_sun = examples[example_selector].predictor_sun;
240241
TrackingAnalyzerConfig analyzer_cfg = examples[example_selector].analyzer_cfg;
241-
std::string track_csv_filename = example_alias + "_track.csv";
242+
std::string track_csv_filename = example_alias + "_track_analyzed.csv";
243+
std::string realtime_csv_filename = example_alias + "_track_realtime.csv";
242244

243245
// -------------------- PREDICTOR MOUNT PREPARATION ---------------------------------------------------------------
244246

@@ -276,9 +278,6 @@ int main()
276278
// Get the specializated SLR predictor to get useful information.
277279
PredictorSlrCPFPtr pred_cpf_recover = PredictorSlrBase::specialization<PredictorSlrCPF>(predictor_cpf);
278280

279-
// Get the new tracking start and end date. If there is sun overlapping at start or end, the affected date
280-
// is changed so the tracking will start or end after/before the sun security sector.
281-
282281
// Get the analyzed mount track with all the relevant data. You can use this data for example to print
283282
// a polar plot with the space object pass, the mount track and the Sun position. In the example folder,
284283
// you can see a Python illustrative example using the data of this struct.
@@ -356,8 +355,6 @@ int main()
356355
file_analyzed_track << numberToStr(pred.sun_pred->altaz_coord.az, 7, 4) <<";";
357356
file_analyzed_track << numberToStr(pred.sun_pred->altaz_coord.el, 7, 4);
358357
}
359-
//
360-
361358
}
362359
//
363360
// Close the file.
@@ -367,8 +364,7 @@ int main()
367364
if(plot_data)
368365
{
369366
std::cout<<"Plotting analyzed data using Python helpers..."<<std::endl;
370-
python_cmd_analysis += (output_dir + "/" + track_csv_filename);
371-
if(system(python_cmd_analysis.c_str()))
367+
if(system(std::string(python_cmd_analysis + output_dir + "/" + track_csv_filename).c_str()))
372368
std::cout<<"Plotting failed!!"<<std::endl;
373369
}
374370

@@ -377,52 +373,127 @@ int main()
377373
// TODO
378374
// We have some issues at this momment in the real time predictor.
379375

380-
/*
376+
// Get the new tracking start and end date. If there is sun overlapping at start or end, the affected date
377+
// is changed so the tracking will start or end after/before the sun security sector.
378+
MJDateTime track_start = predictor_mount.getMountTrackingSLR().track_info.mjdt_start;
379+
MJDateTime track_end = predictor_mount.getMountTrackingSLR().track_info.mjdt_end;
380+
381+
// Store the real time track data into a CSV file (only part of the data for easy usage).
382+
// TODO: Store the full track data as JSON.
383+
// --
384+
// Create the file and header.
385+
std::ofstream file_realtime_track(output_dir + "/" + realtime_csv_filename, std::ios_base::out);
386+
file_realtime_track << data.str();
387+
file_realtime_track << "mjd;sod;pass_az;pass_el;track_az;track_el;sun_az;sun_el";
381388

382-
// Real time.
389+
// Now, we are simulating real time prediction operations. We can now predict any position within the valid
390+
// tracking time window (stored in TrackingInfo struct). For the example, we will ask predictions from start to
391+
// end with a step of 0.1 (simulating real time operations at 10 Hz in the tracking mount).
383392

384-
// Now, we have the tracking configured, so we can ask the tracking to predict any position within the valid
385-
// tracking time window (determined by tracking start and tracking end). For the example, we will ask
386-
// predictions from start to end with a step of 0.5 s.
387-
MJDateTime mjd = mjd_start;
388-
PredictorMountSLR::MountPredictionSLRs results;
393+
// Containers.
394+
MJDateTime mjd = track_start;
395+
MountPredictionSLRV results;
389396

390-
while (mjd < mjd_end)
397+
while (mjd < track_end)
391398
{
392399
// Store the resulting prediction
393400
results.push_back({});
394401
auto status = predictor_mount.predict(mjd, results.back());
395402

396-
if (status == PredictorMountSLR::PositionStatus::INSIDE_SUN)
403+
if (status == PositionStatus::ELEVATION_CLIPPED)
404+
{
405+
//
406+
}
407+
else if (status == PositionStatus::OUTSIDE_SUN)
408+
{
409+
// In this case the position predicted is valid and it is going outside a sun security sector. This is the
410+
// normal case.
411+
}
412+
else if (status == PositionStatus::INSIDE_SUN)
397413
{
398414
// In this case the position predicted is valid, but it is going through a sun security sector.
399415
// This case is only possible if sun avoid algorithm is disabled.
400416
// BEWARE. If the mount points directly to this position it could be dangerous.
401417
}
402-
else if (status == PredictorMountSLR::PositionStatus::OUTSIDE_SUN)
418+
419+
else if (status == PositionStatus::AVOIDING_SUN)
403420
{
404-
// In this case the position predicted is valid and it is going outside a sun security sector. This is the
405-
// normal case.
421+
// In this case the position predicted is valid and it is going through an alternative way to avoid a sun
422+
// security sector. While the tracking returns this status, the tracking_position member in result
423+
// represents the position used to avoid the sun (the secure position), while prediction_result contains
424+
// the true position of the object (not secure).
425+
406426
}
407-
else if (status == PredictorMountSLR::PositionStatus::AVOIDING_SUN)
427+
else if (status == PositionStatus::CANT_AVOID_SUN)
408428
{
409429
// In this case the position predicted is valid and it is going through an alternative way to avoid a sun
410430
// security sector. While the tracking returns this status, the tracking_position member in result
411431
// represents the position used to avoid the sun (the secure position), while prediction_result contains
412432
// the true position of the object (not secure).
413433

414434
}
415-
else
435+
else if (status == PositionStatus::OUT_OF_TRACK)
416436
{
417-
//std::cout << "Error at getting position " << status;
437+
// Bad situation, the prediction time requested is out of track. Stop the tracking and notify to client.
438+
// However, this should not happen if all is ok in the mount tracking controller software. Maybe if
439+
// something is wrong with the CPF or in the timing tracking mount subsystem or in the SLR station system.
440+
std::cerr << "Module: TrackingMount | Example: PredictorMountSLR" << std::endl;
441+
std::cerr << "Error: The requested position is in OUT_OF_TRACK state." << std::endl;
442+
std::cerr << "Example finished. Press Enter to exit..." << std::endl;
443+
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
444+
return -1;
445+
}
446+
else if (status == PositionStatus::PREDICTION_ERROR)
447+
{
448+
// Bad situation, stop the tracking and notify to client. However, this should not happen if all is ok in
449+
// the mount tracking controller software. Maybe if something is wrong with the with the CPF or in the
450+
// timing tracking mount subsystem or in the SLR station system.
451+
std::cerr << "Module: TrackingMount | Example: PredictorMountSLR" << std::endl;
452+
std::cerr << "Error: The requested position is in PREDICTION_ERROR state." << std::endl;
453+
std::cerr << "Example finished. Press Enter to exit..." << std::endl;
454+
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
418455
return -1;
419456
}
420457

421458
// Advance to next position
422-
mjd.add(0.5L);
459+
mjd.add(Seconds(0.1L));
460+
}
461+
462+
// Iterate the real time simulated predictions.
463+
for(const auto& pred : results)
464+
{
465+
// Auxiliar container for track data.
466+
std::string track_az = "";
467+
std::string track_el = "";
468+
//
469+
// At this point, you only must check if the prediction is outside track. This is becaouse, for example,
470+
// the beginning of the real satellite pass may coincide with the Sun sector, so at those points there
471+
// would be no data from the mount's track, only the real pass.
472+
if(pred.status != PositionStatus::OUT_OF_TRACK)
473+
{
474+
track_az = numberToStr(pred.mount_pos->altaz_coord.az,7, 4);
475+
track_el = numberToStr(pred.mount_pos->altaz_coord.el,7, 4);
476+
477+
// Store the data.
478+
file_realtime_track <<'\n';
479+
file_realtime_track << std::to_string(pred.mjdt.datetime()) <<";";
480+
file_realtime_track << numberToStr(pred.slr_pred->instant_data->altaz_coord.az, 7, 4) <<";";
481+
file_realtime_track << numberToStr(pred.slr_pred->instant_data->altaz_coord.el, 7, 4) <<";";
482+
file_realtime_track << track_az <<";";
483+
file_realtime_track << track_el <<";";
484+
file_realtime_track << numberToStr(pred.sun_pred->altaz_coord.az, 7, 4) <<";";
485+
file_realtime_track << numberToStr(pred.sun_pred->altaz_coord.el, 7, 4);
486+
}
423487
}
488+
// Close the file.
489+
file_realtime_track.close();
424490

425-
*/
491+
if(plot_data)
492+
{
493+
std::cout<<"Plotting real time simulated data using Python helpers..."<<std::endl;
494+
if(system(std::string(python_cmd_analysis + output_dir + "/" + realtime_csv_filename).c_str()))
495+
std::cout<<"Plotting failed!!"<<std::endl;
496+
}
426497

427498
// Final wait.
428499
std::cout << "Example finished. Press Enter to exit..." << std::endl;

LibDegorasSLR/includes/LibDegorasSLR/TrackingMount/types/tracking_types.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct TrackingAnalyzerConfig
108108
*/
109109
enum class PositionStatus
110110
{
111+
ELEVATION_CLIPPED, ///< The final mount position was clipped due to maximum elevation configuration.
111112
OUTSIDE_SUN, ///< The final mount position is outside the sun.
112113
INSIDE_SUN, ///< The final mount position is in the Sun and is configured for not avoiding.
113114
AVOIDING_SUN, ///< The final mount position is avoiding sun security sector.
@@ -343,14 +344,9 @@ struct MountTrackingSLR
343344
MJDateTime pass_mjdt_end;
344345

345346
// Tracking data
346-
TrackingAnalyzerConfig config; ///< Contains the tracking user configuration.
347-
TrackingInfo track_info; ///< Contains the analyzed tracking information.
348-
MountPredictionSLRV predictions; ///< Predicted data for the required time interval.
349-
350-
351-
// Begin and end iterators.
352-
MountPredictionSLRV::iterator tracking_begin_; ///< Iterator to tracking begining
353-
MountPredictionSLRV::iterator tracking_end_; ///< Iterator to tracking end
347+
TrackingAnalyzerConfig config; ///< Contains the tracking user configuration.
348+
TrackingInfo track_info; ///< Contains the analyzed tracking information.
349+
MountPredictionSLRV predictions; ///< Predicted data for the required time interval.
354350

355351
// Predictors.
356352
PredictorSlrPtr predictor_slr; ///< Internal PredictorSLR predictor.

LibDegorasSLR/sources/TrackingMount/predictors/predictor_mount_slr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ PositionStatus PredictorMountSLR::predict(const timing::HRTimePointStd& tp_time,
115115

116116
PositionStatus PredictorMountSLR::predict(const MJDateTime &mjdt, MountPredictionSLR &tracking_result) const
117117
{
118-
119118
// Calculates the Sun position.
120119
long double j2000 = dpslr::timing::modifiedJulianDateToJ2000DateTime(mjdt).datetime();
121120
PredictionSun sun_pos = this->mount_track_.predictor_sun->predict(j2000, false);
@@ -160,7 +159,6 @@ PositionStatus PredictorMountSLR::predict(const MJDateTime &mjdt, MountPredictio
160159
}
161160

162161
return tracking_result.status;
163-
164162
}
165163

166164
void PredictorMountSLR::analyzeTracking()
@@ -204,7 +202,6 @@ void PredictorMountSLR::analyzeTracking()
204202
results_sun = this->mount_track_.predictor_sun->predict(
205203
j2000_start, j2000_end, this->mount_track_.config.time_delta, false);
206204

207-
208205
// Create tracking predictions for TrackingAnalyzer
209206
TrackingPredictionV tr_predictions(results_slr.size());
210207
for (std::size_t i = 0; i < results_slr.size(); i++)

LibDegorasSLR/sources/TrackingMount/tracking_analyzer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
408408
if(it->pos.altaz_coord.el > cfg_max_el)
409409
{
410410
it->pos.altaz_coord.el = cfg_max_el;
411+
it->status = PositionStatus::ELEVATION_CLIPPED;
411412
this->track_info_.el_deviation = true;
412413
this->track_info_.max_el = cfg_max_el;
413414
}
@@ -438,9 +439,6 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
438439
auto sun_min_el_it = std::min_element(this->begin_, this->end_,
439440
[](const auto& a, const auto& b){return a.sun_pred.altaz_coord.el < b.sun_pred.altaz_coord.el;});
440441
long double limit_el = sun_min_el_it->sun_pred.altaz_coord.el - sun_avoid_angle;
441-
// TODO: if cfg_max_el is less than limit_el, then this position should not be called AVOIDING_SUN
442-
// Maybe there should be a position status LIMITED_ELEVATION or similar for this case and for the
443-
// case when elevation is clipped to max_el.
444442
limit_el = (limit_el < cfg_max_el) ? limit_el : cfg_max_el;
445443
this->track_info_.sun_deviation = true;
446444
this->track_info_.sun_collision_high_el = true;

0 commit comments

Comments
 (0)