@@ -63,6 +63,7 @@ using dpslr::timing::timePointToModifiedJulianDateTime;
6363using dpslr::math::units::Angle;
6464using dpslr::math::units::DegreesU;
6565using dpslr::math::units::Degrees;
66+ using dpslr::math::units::Seconds;
6667using dpslr::math::units::MillisecondsU;
6768using dpslr::math::units::Meters;
6869// Geocentric and geodetic containers.
@@ -85,11 +86,12 @@ using dpslr::utils::PredictorSlrPtr;
8586using dpslr::utils::PredictorSlrCPFPtr;
8687// Mount predictor related.
8788using dpslr::mount::PredictorMountSLR;
88- // Helpers.
89- using dpslr::helpers::strings::numberToStr;
90- using dpslr::mount::PositionStatus;
89+ using dpslr::mount::MountPredictionSLRV;
9190using dpslr::mount::MountTrackingSLR;
9291using 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;
0 commit comments