@@ -399,7 +399,7 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
399399 MJDateTime max_elev_mjdt = 0 ;
400400 long double max_elev = -1 .0L ;
401401 const long double cfg_max_el = static_cast <long double >(this ->config_ .max_elev );
402- const long double sun_avoid_angle = static_cast <long double >(this ->config_ .sun_avoid_angle );
402+ long double sun_avoid_angle = static_cast <long double >(this ->config_ .sun_avoid_angle ) + kAvoidAngleOffset ;
403403 TrackingPredictionV::iterator sun_sector_start;
404404
405405 // Check the tracking maximum altitudes. Positions that trespasses will be clipped to maximum elevation.
@@ -435,13 +435,15 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
435435 if (inside_sun && sun_high)
436436 {
437437 bool stop = false ;
438- long double limit_el = it->sun_pred .altaz_coord .el - sun_avoid_angle;
438+ auto sun_min_el_it = std::min_element (this ->begin_ , this ->end_ ,
439+ [](const auto & a, const auto & b){return a.sun_pred .altaz_coord .el < b.sun_pred .altaz_coord .el ;});
440+ long double limit_el = sun_min_el_it->sun_pred .altaz_coord .el - sun_avoid_angle;
439441 // TODO: if cfg_max_el is less than limit_el, then this position should not be called AVOIDING_SUN
440442 // Maybe there should be a position status LIMITED_ELEVATION or similar for this case and for the
441443 // case when elevation is clipped to max_el.
442444 limit_el = (limit_el < cfg_max_el) ? limit_el : cfg_max_el;
443445 this ->track_info_ .sun_deviation = true ;
444- this ->track_info_ .sun_collision_high = true ;
446+ this ->track_info_ .sun_collision_high_el = true ;
445447
446448 // Check backward.
447449 for (auto it_internal = it; it_internal != this ->begin_ || !stop; it_internal--)
@@ -474,35 +476,32 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
474476 }
475477 }
476478 }
477-
478479 // If sun avoid is applied we have to store the data for each sector where the tracking goes through a sun
479480 // security sector.This data will be used for calculating an alternative trajetctory at those sectors.
480481 else if (inside_sun)
481482 {
482- // If there is a sun collision, start saving sun positions for this sector.
483- // The first position is the first position before entering
484- // the sector, i.e., it is ouside sun security sector.
483+ // If there is a sun collision, start saving sun positions for this sector. The first position is the
484+ // first position before entering the sector, i.e., it is ouside sun security sector.
485485 if (!in_sun_sector)
486486 {
487487 in_sun_sector = true ;
488488 sun_sector_start = it-1 ;
489489 sun_sector.altaz_entry = sun_sector_start->pos .altaz_coord ;
490490 sun_sector.mjdt_entry = sun_sector_start->mjdt ;
491-
492491 }
493492 }
494493 else if (!inside_sun && in_sun_sector)
495494 {
496- // If we were inside a sun sector, and we are going out of it,
497- // check sun sector rotation direction and positions within the sector and store the sector.
498- // The last position stored is the first position after exiting the sector,
499- // i.e., it is outside sun security sector.
495+ // If we were inside a sun sector, and we are going out of it, check sun sector rotation direction and
496+ // positions within the sector and store the sector. The last position stored is the first position
497+ // after exiting the sector, i.e., it is outside sun security sector.
500498 in_sun_sector = false ;
501499 sun_sector.altaz_exit = it->pos .altaz_coord ;
502500 sun_sector.mjdt_exit = it->mjdt ;
503501 // If sector has no valid rotation direction, mark tracking as not valid, since sun cannot be avoided.
504502 if (!this ->setSunSectorRotationDirection (sun_sector, sun_sector_start, it))
505503 return false ;
504+ // Check the Sun sector positions.
506505 this ->checkSunSectorPositions (sun_sector, sun_sector_start, it);
507506 this ->sun_sectors_ .push_back (std::move (sun_sector));
508507 sun_sector = {};
@@ -527,13 +526,13 @@ bool TrackingAnalyzer::analyzeTrackingMiddle()
527526
528527bool TrackingAnalyzer::insideSunSector (const AltAzPos& pass_pos, const AltAzPos& sun_pos) const
529528{
530-
531529 long double diff_az = pass_pos.az - sun_pos.az ;
532530 // If azimuth difference is greater than 180, then take the shorter way
533531 if (diff_az > 180 .L )
534532 diff_az = 360 .L - diff_az;
535533 long double diff_el = pass_pos.el - sun_pos.el ;
536- return std::sqrt (diff_az * diff_az + diff_el * diff_el) < this ->config_ .sun_avoid_angle ;
534+ long double sun_avoid_angle = static_cast <long double >(this ->config_ .sun_avoid_angle ) + kAvoidAngleOffset ;
535+ return std::sqrt (diff_az * diff_az + diff_el * diff_el) < sun_avoid_angle;
537536}
538537
539538bool TrackingAnalyzer::setSunSectorRotationDirection (SunCollisionSector §or,
@@ -607,10 +606,10 @@ bool TrackingAnalyzer::setSunSectorRotationDirection(SunCollisionSector §or,
607606 cw_angle = entry_angle + time_perc * cw_angle;
608607 ccw_angle = entry_angle + time_perc * ccw_angle;
609608
610- long double elev_cw = it-> sun_pred . altaz_coord . el +
611- this -> config_ . sun_avoid_angle * std::sin (cw_angle);
612- long double elev_ccw = it->sun_pred .altaz_coord .el +
613- this -> config_ . sun_avoid_angle * std::sin (ccw_angle);
609+ long double sun_avoid_angle = static_cast < long double >( this -> config_ . sun_avoid_angle ) + kAvoidAngleOffset ;
610+
611+ long double elev_cw = it->sun_pred .altaz_coord .el + sun_avoid_angle * std::sin (cw_angle);
612+ long double elev_ccw = it-> sun_pred . altaz_coord . el + sun_avoid_angle * std::sin (ccw_angle);
614613
615614 long double cfg_max_el = static_cast <long double >(this ->config_ .max_elev );
616615 long double cfg_min_el = static_cast <long double >(this ->config_ .min_elev );
@@ -768,17 +767,19 @@ long double TrackingAnalyzer::calcSunAvoidTrajectory(const MJDateTime &mjdt,
768767void TrackingAnalyzer::calcSunAvoidPos (TrackingPrediction &pred,
769768 const SunCollisionSector §or) const
770769{
770+ long double sun_avoid_angle = static_cast <long double >(this ->config_ .sun_avoid_angle ) + kAvoidAngleOffset ;
771+
771772 // Get the trajectory avoid angle.
772773 long double angle_avoid = this ->calcSunAvoidTrajectory (pred.mjdt , sector, pred.sun_pred .altaz_coord );
773774 // Calculate new azimuth and elevation using trajectory avoid angle
774- Degrees new_az = pred.sun_pred .altaz_coord .az + this -> config_ . sun_avoid_angle * std::cos (angle_avoid);
775+ Degrees new_az = pred.sun_pred .altaz_coord .az + sun_avoid_angle * std::cos (angle_avoid);
775776 // Normalize new azimuth
776777 if (new_az < 0 .L )
777778 new_az += 360 .L ;
778779 if (new_az > 360 .L )
779780 new_az -= 360 .L ;
780781
781- Degrees new_el = pred.sun_pred .altaz_coord .el + this -> config_ . sun_avoid_angle * std::sin (angle_avoid);
782+ Degrees new_el = pred.sun_pred .altaz_coord .el + sun_avoid_angle * std::sin (angle_avoid);
782783
783784 // Store difference between original position and new position
784785 pred.pos .diff_az = pred.pos .altaz_coord .az - new_az;
0 commit comments