Changeset 13795 for trunk/FACT++
- Timestamp:
- 05/19/12 09:16:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r13778 r13795 33 33 // ------------------------------------------------------------------------ 34 34 35 const static string kHtmlWhite = "#ffffff"; 36 const static string kHtmlYellow = "#fffff0"; 37 const static string kHtmlRed = "#fff8f0"; 38 const static string kHtmlGreen = "#f0fff0"; 39 const static string kHtmlBlue = "#f0f0ff"; 40 35 41 #ifdef HAVE_LIBNOVA 36 42 37 43 class Astro 38 44 { 45 public: 46 Time time; 47 39 48 Time fSunRiseDayTime; 40 49 Time fSunRiseCivil; … … 47 56 Time fSunSetDarkTime; 48 57 49 ln_rst_time moon; 50 51 ln_equ_posn moon_position; 52 double moon_disk; 53 58 int state; 54 59 string description; 55 56 //observer.lng = -(17.+53./60+26.525/3600); 57 //observer.lat = 28.+45./60+42.462/3600; 60 string color; 61 62 bool isday; 63 58 64 public: 59 Astro(double lon, double lat, /*const*/ Time/* &*/time=Time()) 60 { 61 // observers location (Edinburgh), used to calc rst 62 struct ln_lnlat_posn observer; 63 observer.lng = -(17.+53./60+26.525/3600); 64 observer.lat = 28.+45./60+42.462/3600; 65 66 time = Time(2012, 5, 18, 23, 30); 65 Astro(double lon, double lat, const Time &t=Time()) : time(t) 66 { 67 ln_lnlat_posn observer; 68 observer.lng = lon; 69 observer.lat = lat; 67 70 68 71 // get Julian day from local time … … 75 78 76 79 // Warning: return code of 1 means circumpolar and is not checked! 77 ln_get_lunar_rst (JD-0.5, &observer, &moon);80 //ln_get_lunar_rst (JD-0.5, &observer, &moon); 78 81 ln_get_solar_rst (JD-0.5, &observer, &sun_day); 79 82 ln_get_solar_rst_horizon(JD-0.5, &observer, - 6, &sun_civil); … … 94 97 const bool is_night = JD>sun_dark.set; 95 98 96 ln_get_lunar_rst (JD+0.5, &observer, &moon);99 //ln_get_lunar_rst (JD+0.5, &observer, &moon); 97 100 ln_get_solar_rst (JD+0.5, &observer, &sun_day); 98 101 ln_get_solar_rst_horizon(JD+0.5, &observer, - 6, &sun_civil); … … 119 122 // case 1: sun-rise to sun-set | is_day && !is_night | set /rise 120 123 // case 2: sun-set to midnight | is_day && is_night | rise/set 121 124 /* 122 125 if (is_day^is_night) 123 126 { … … 129 132 cout << "SunRise: " << fSunRiseDayTime << endl; 130 133 cout << "SunSet: " << fSunSetDayTime << endl; 131 } 132 133 //const double mjd = Time(JD-2400000.5).Mjd();134 135 int state = is_day^is_night? 4 : 0;134 }*/ 135 136 isday = is_day^is_night; 137 138 state = isday ? 4 : 0; 136 139 if (time>fSunSetDayTime) state++; 137 140 if (time>fSunSetCivil) state++; … … 147 150 { 148 151 "dark time", 149 "astron omicaltwilight",152 "astron. twilight", 150 153 "civil twilight", 151 154 "sunrise", … … 153 156 "sunset", 154 157 "civil twilight", 155 "astron omicaltwilight",158 "astron. twilight", 156 159 "dark time" 157 160 }; … … 159 162 description = state[name]; 160 163 161 162 cout << "NOW: " << name[state] << " [" << state << "]" << endl << endl; 163 164 /* 165 // RA, DEC 166 ln_get_lunar_equ_coords(JD, &moon_position); 167 //cout << "MoonRa: " << equ.ra << "\n"; 168 //cout << "MoonDec: " << equ.dec << "\n"; 169 170 // lunar disk, phase and bright limb 171 moon_disk = ln_get_lunar_disk(JD); 172 173 if (JD>sun_dark.set || JD<sun_normal.rise) 174 { 175 cout << "Sunrise will be at:" << endl; 176 cout << "Astronom. TwL: " << Time(sun_dark.rise -2400000.5).GetAsStr() << endl; 177 cout << "Civil TwL: " << Time(sun_astronomical.rise-2400000.5).GetAsStr() << endl; 178 cout << "Sunrise: " << Time(sun_civil.rise -2400000.5).GetAsStr() << endl; 179 cout << "Day time: " << Time(sun_normal.rise -2400000.5).GetAsStr() << endl; 164 string arr; 165 ostringstream out; 166 if (isday) 167 { 168 out << fSunSetDarkTime-time; 169 arr = "↓"; 180 170 } 181 171 else 182 172 { 183 cout << "Sunset will be at:" << endl; 184 cout << "Sunset: " << Time(sun_normal.set -2400000.5).GetAsStr() << endl; 185 cout << "Civil TwL: " << Time(sun_civil.set -2400000.5).GetAsStr() << endl; 186 cout << "Astronom. TwL: " << Time(sun_astronomical.set-2400000.5).GetAsStr() << endl; 187 cout << "Dark time: " << Time(sun_dark.set -2400000.5).GetAsStr() << endl; 188 } 189 190 if (JD>moon.rise && JD<moon.set) 191 cout << "Moon: VISIBLE (" << setprecision(2) << moon_disk*100 << "%)" << endl; 192 193 if (JD<moon.rise) 194 cout << "MoonRise: " << Time(moon.rise -2400000.5) << endl; 195 if (JD<moon.transit) 196 cout << "MoonCulm: " << Time(moon.transit-2400000.5) << endl; 197 if (JD<moon.set) 198 cout << "MoonSet: " << Time(moon.set -2400000.5) << endl; 199 */ 200 } 201 202 /* 203 204 Always show the next event: 205 206 What do we have now? 207 time between sunset and civil: sunset 208 time between civial and astronominal: civil 209 time between astronominal and dark: astronomical 210 time above dark: dark 211 212 213 */ 214 173 out << fSunRiseDayTime-time; 174 arr = "↑"; 175 } 176 177 description += " ["+out.str().substr(0, 5)+arr+"]"; 178 179 switch (state) 180 { 181 case 0: case 1: color = kHtmlGreen; break; 182 case 2: case 3: color = kHtmlYellow; break; 183 case 4: color = kHtmlRed; break; 184 case 5: case 6: color = kHtmlYellow; break; 185 case 7: case 8: color = kHtmlGreen; break; 186 } 187 } 215 188 }; 216 189 190 class Moon 191 { 192 public: 193 double ra; 194 double dec; 195 196 double disk; 197 198 bool visible; 199 200 Time fMoonRise; 201 Time fMoonTransit; 202 Time fMoonSet; 203 204 string description; 205 string color; 206 207 Time time; 208 209 Moon(double lon, double lat, const Time &t=Time()) : time(t) 210 { 211 const double JD = time.JD(); 212 213 ln_lnlat_posn observer; 214 observer.lng = lon; 215 observer.lat = lat; 216 217 ln_rst_time moon; 218 ln_get_lunar_rst(JD-0.5, &observer, &moon); 219 220 fMoonRise = Time(moon.rise); 221 fMoonTransit = Time(moon.transit); 222 fMoonSet = Time(moon.set); 223 224 visible = 225 (JD>moon.rise && JD<moon.set && moon.rise<moon.set) || 226 ((JD<moon.set || JD>moon.rise) && moon.rise>moon.set); 227 228 const bool is_up = JD>moon.rise; 229 const bool is_sinking = JD>moon.transit; 230 const bool is_dn = JD>moon.set; 231 232 ln_get_lunar_rst(JD+0.5, &observer, &moon); 233 if (is_up) 234 fMoonRise = Time(moon.rise); 235 if (is_sinking) 236 fMoonTransit = Time(moon.transit); 237 if (is_dn) 238 fMoonSet = Time(moon.set); 239 240 ln_equ_posn pos; 241 ln_get_lunar_equ_coords(JD, &pos); 242 243 ra = pos.ra/15; 244 dec = pos.dec; 245 246 disk = ln_get_lunar_disk(JD)*100; 247 248 if (!visible || disk<25) 249 color = kHtmlGreen; 250 else 251 color = disk>75 ? kHtmlRed : kHtmlYellow; 252 253 string arr; 254 ostringstream dt; 255 if (fMoonSet<fMoonRise) 256 { 257 dt << fMoonSet-time; 258 arr = "↓"; 259 } 260 else 261 { 262 dt << fMoonRise-time; 263 arr = "↑"; 264 } 265 266 ostringstream out; 267 out << setprecision(2); 268 out << (visible?"visible ":"") << disk << "% [" << dt.str().substr(0,5) << arr << "]"; 269 270 description = out.str(); 271 } 272 273 double Angle(double r, double d) 274 { 275 const double theta0 = M_PI/2-d*M_PI/180; 276 const double phi0 = r*M_PI/12; 277 278 const double theta1 = M_PI/2-dec*M_PI/180; 279 const double phi1 = ra*M_PI/12; 280 281 const double x0 = sin(theta0) * cos(phi0); 282 const double y0 = sin(theta0) * sin(phi0); 283 const double z0 = cos(theta0); 284 285 const double x1 = sin(theta1) * cos(phi1); 286 const double y1 = sin(theta1) * sin(phi1); 287 const double z1 = cos(theta1); 288 289 double arg = x0*x1 + y0*y1 + z0*z1; 290 if(arg > 1.0) arg = 1.0; 291 if(arg < -1.0) arg = -1.0; 292 293 return acos(arg) * 180/M_PI; 294 } 295 }; 296 217 297 #endif 218 298 219 299 // ------------------------------------------------------------------------ 220 300 221 const static string kHtmlWhite = "#ffffff";222 const static string kHtmlYellow = "#fffff0";223 const static string kHtmlRed = "#fff8f0";224 const static string kHtmlGreen = "#f0fff0";225 const static string kHtmlBlue = "#f0f0ff";226 301 227 302 class StateMachineSmartFACT : public StateMachineDim, public DimInfoHandler … … 594 669 const uint16_t idx = uint16_t(floor(fmod(fMagicWeatherHist[kDir].back()+360+11.25, 360)/22.5)); 595 670 671 Astro astro(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600); 672 Moon moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600); 673 596 674 ostringstream out; 597 675 out << d.time.JavaDate() << '\n'; 676 out << astro.color << '\t' << astro.description << '\n'; 677 out << setprecision(2); 678 out << (astro.isday?kHtmlWhite:moon.color) << '\t' << moon.description << '\n'; 679 out << setprecision(3); 598 680 for (int i=0; i<6; i++) 599 681 out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n'; 600 682 out << "#ffffff\t" << dir[idx] << '\n'; 601 683 602 //Astro a(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);603 604 684 ofstream(fPath+"/magicweather.txt") << out.str(); 685 686 out.str(""); 687 out << astro.time.JavaDate() << '\n'; 688 out << kHtmlWhite << '\t' << astro.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n'; 689 out << kHtmlWhite << '\t' << astro.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n'; 690 out << kHtmlWhite << '\t' << astro.fSunRiseCivil.GetAsStr("%H:%M") << '\n'; 691 out << kHtmlWhite << '\t' << astro.fSunRiseDayTime.GetAsStr("%H:%M") << '\n'; 692 693 out << kHtmlWhite << '\t' << astro.fSunSetDayTime.GetAsStr("%H:%M") << '\n'; 694 out << kHtmlWhite << '\t' << astro.fSunSetCivil.GetAsStr("%H:%M") << '\n'; 695 out << kHtmlWhite << '\t' << astro.fSunSetAstronomical.GetAsStr("%H:%M") << '\n'; 696 out << kHtmlWhite << '\t' << astro.fSunSetDarkTime.GetAsStr("%H:%M") << '\n'; 697 698 out << kHtmlWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n'; 699 out << kHtmlWhite << '\t' << moon.fMoonTransit.GetAsStr("%H:%M") << '\n'; 700 out << kHtmlWhite << '\t' << moon.fMoonSet.GetAsStr("%H:%M") << '\n'; 701 702 ofstream(fPath+"/astro.txt") << out.str(); 605 703 606 704 WriteWeather(d, "temp", kTemp, -5, 35); … … 672 770 out << d.time.JavaDate() << '\n'; 673 771 674 out << "#ffffff\t"<< fDriveControlSourceName << '\n';772 out << kHtmlWhite << '\t' << fDriveControlSourceName << '\n'; 675 773 out << setprecision(5); 676 out << "#ffffff\t"<< Ra << '\n';677 out << "#ffffff\t"<< Dec << '\n';774 out << kHtmlWhite << '\t' << Ra << '\n'; 775 out << kHtmlWhite << '\t' << Dec << '\n'; 678 776 out << setprecision(3); 679 out << "#ffffff\t" << Zd << '\n'; 680 out << "#ffffff\t" << Az << '\n'; 681 out << "#ffffff\t" << dev << '\n'; 777 out << kHtmlWhite << '\t' << Zd << '\n'; 778 out << kHtmlWhite << '\t' << Az << '\n'; 779 out << kHtmlWhite << '\t' << dev << '\n'; 780 781 Moon moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600); 782 if (moon.visible) 783 { 784 const double angle = moon.Angle(Ra, Dec); 785 786 string col = kHtmlGreen; 787 if (angle<35 || angle>145) 788 col = kHtmlYellow; 789 if (angle<25 || angle>155) 790 col = kHtmlRed; 791 out << col << '\t' << setprecision(3) << angle << '\n'; 792 } 793 else 794 out << kHtmlWhite << "\t— \n"; 682 795 683 796 ofstream(fPath+"/tracking.txt") << out.str(); … … 1336 1449 { 1337 1450 string col = kHtmlBlue; 1451 /* 1338 1452 if (fMcpConfigurationState!= 5 && // Idle 1339 1453 fMcpConfigurationState!=11 && // Trigger On 1340 fMcpConfigurationState!=12) // Taking Data 1454 fMcpConfigurationState!=12) // Taking Data*/ 1455 if (fDimMcp.state()!= 5 && // Idle 1456 fDimMcp.state()!=11 && // Trigger On 1457 fDimMcp.state()!=12) // Taking Data 1341 1458 col = kHtmlYellow; 1342 1459 else … … 1345 1462 1346 1463 out << col << '\t'; 1347 /* 1348 out << fDimRateControl.state() << "/"; 1349 out << fDimRateScan.state() << "/"; 1350 out << fMcpConfigurationState << "/"; 1351 */ 1352 1353 if (fDimRateControl.state()!=5 && 1354 fDimRateScan.state()!=5) 1464 1465 if (fDimRateControl.state()!=5 && fDimRateScan.state()!=5) 1355 1466 { 1356 if (fMcpConfigurationState!=5 && 1357 fMcpConfigurationState!=11 && 1358 fMcpConfigurationState!=12) 1359 out << "Configuring "; 1360 out << fMcpConfigurationName; 1467 switch (fDimMcp.state()/*fMcpConfigurationState*/) 1468 { 1469 // kStateIdle 1470 case 5: out << "Idle [" << fMcpConfigurationName << "]"; break; 1471 // Configuring1 - Configuring3 1472 case 7: 1473 case 8: 1474 case 9: out << "Configuring [" << fMcpConfigurationName << "]"; break; 1475 // Configured 1476 case 10: out << "Configured [" << fMcpConfigurationName << "]"; break; 1477 // TriggerOn / Taking Data 1478 case 11: 1479 case 12: out << fMcpConfigurationName; break; 1480 } 1361 1481 } 1362 1482 else … … 1368 1488 out << "Rate scan in progress"; 1369 1489 1370 if (fDimMcp.state()> 5&& fDimRateControl.state()!=5)1490 if (fDimMcp.state()>10 && fDimRateControl.state()!=5) 1371 1491 { 1372 1492 if (fMcpConfigurationMaxEvents>0 || fMcpConfigurationMaxTime>0 || fMcpConfigurationState==12)
Note:
See TracChangeset
for help on using the changeset viewer.