Changeset 14018 for trunk/FACT++/src
- Timestamp:
- 06/01/12 13:26:46 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/HeadersDrive.h
r13912 r14018 10 10 kDisconnected = 1, 11 11 kConnected, 12 kLocked, 12 13 kNotReady, 13 14 kReady, -
trunk/FACT++/src/drivectrl.cc
r14009 r14018 1 1 #include <boost/bind.hpp> 2 2 #include <boost/regex.hpp> 3 4 #ifdef HAVE_LIBNOVA 5 #include <libnova/solar.h> 6 #include <libnova/rise_set.h> 7 #endif 3 8 4 9 #include "FACT.h" … … 920 925 } 921 926 927 int Unlock() 928 { 929 return Drive::State::kNotReady; 930 } 931 922 932 int Print() 923 933 { … … 977 987 978 988 return T::GetCurrentState(); 989 } 990 991 Time fSunRise; 992 993 Time GetSunRise(const Time &time=Time()) 994 { 995 #ifdef HAVE_LIBNOVA 996 const double lon = -(17.+53./60+26.525/3600); 997 const double lat = 28.+45./60+42.462/3600; 998 999 ln_lnlat_posn observer; 1000 observer.lng = lon; 1001 observer.lat = lat; 1002 1003 // This caluclates the sun-rise of the next day after 12:00 noon 1004 ln_rst_time sun_day; 1005 if (ln_get_solar_rst(time.JD(), &observer, &sun_day)==1) 1006 { 1007 T::Fatal("GetSunRise reported the sun to be circumpolar!"); 1008 return Time(Time::none); 1009 } 1010 1011 if (Time(sun_day.rise)>=time) 1012 return Time(sun_day.rise); 1013 1014 if (ln_get_solar_rst(time.JD()+0.5, &observer, &sun_day)==1) 1015 { 1016 T::Fatal("GetSunRise reported the sun to be circumpolar!"); 1017 return Time(Time::none); 1018 } 1019 1020 return Time(sun_day.rise); 1021 #else 1022 return Time(boost::date_time::pos_infin); 1023 #endif 979 1024 } 980 1025 … … 988 1033 poll_one(); 989 1034 1035 if (T::GetCurrentState()==Drive::State::kLocked) 1036 return Drive::State::kLocked; 1037 1038 1039 if (T::GetCurrentState()>Drive::State::kLocked) 1040 { 1041 Time now; 1042 if (now>fSunRise) 1043 { 1044 SendCommand("PREPS Park", false); 1045 1046 fSunRise = GetSunRise(now); 1047 if (!fSunRise) 1048 return T::kSM_FatalError; 1049 1050 ostringstream msg; 1051 msg << "Next sun-rise will be at " << fSunRise; 1052 T::Info(msg); 1053 1054 return Drive::State::kLocked; 1055 } 1056 } 1057 990 1058 return fDrive.GetState(); 991 1059 } … … 995 1063 StateMachineDrive(ostream &out=cout) : 996 1064 T(out, "DRIVE_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)), 997 fDrive(*this, *this) 1065 fDrive(*this, *this), fSunRise(GetSunRise()) 998 1066 { 999 1067 // State names … … 1119 1187 // (""); 1120 1188 1189 T::AddEvent("UNLOCK", Drive::State::kLocked) 1190 (bind(&StateMachineDrive::Unlock, this)) 1191 ("Stop any kind of movement."); 1192 1121 1193 1122 1194 // Verbosity commands … … 1227 1299 int EvalOptions(Configuration &conf) 1228 1300 { 1301 if (!fSunRise) 1302 return 1; 1303 1229 1304 fDrive.SetVerbose(!conf.Get<bool>("quiet")); 1230 1305 … … 1272 1347 fDatabase = conf.Get<string>("source-database"); 1273 1348 ReadDatabase(); 1349 } 1350 1351 if (fSunRise.IsValid()) 1352 { 1353 ostringstream msg; 1354 msg << "Next sun-rise will be at " << fSunRise; 1355 T::Message(msg); 1274 1356 } 1275 1357
Note:
See TracChangeset
for help on using the changeset viewer.