Changeset 14018 for trunk/FACT++


Ignore:
Timestamp:
06/01/12 13:26:46 (12 years ago)
Author:
tbretz
Message:
Added automatic parking if sun-rise has been passed and a locked state to ensure that no other command will be accepted for example from a running script.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/HeadersDrive.h

    r13912 r14018  
    1010            kDisconnected = 1,
    1111            kConnected,
     12            kLocked,
    1213            kNotReady,
    1314            kReady,
  • trunk/FACT++/src/drivectrl.cc

    r14009 r14018  
    11#include <boost/bind.hpp>
    22#include <boost/regex.hpp>
     3
     4#ifdef HAVE_LIBNOVA
     5#include <libnova/solar.h>
     6#include <libnova/rise_set.h>
     7#endif
    38
    49#include "FACT.h"
     
    920925    }
    921926
     927    int Unlock()
     928    {
     929        return Drive::State::kNotReady;
     930    }
     931
    922932    int Print()
    923933    {
     
    977987
    978988        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
    9791024    }
    9801025
     
    9881033        poll_one();
    9891034
     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
    9901058        return fDrive.GetState();
    9911059    }
     
    9951063    StateMachineDrive(ostream &out=cout) :
    9961064        T(out, "DRIVE_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    997         fDrive(*this, *this)
     1065        fDrive(*this, *this), fSunRise(GetSunRise())
    9981066    {
    9991067        // State names
     
    11191187//            ("");
    11201188
     1189        T::AddEvent("UNLOCK", Drive::State::kLocked)
     1190            (bind(&StateMachineDrive::Unlock, this))
     1191            ("Stop any kind of movement.");
     1192
    11211193
    11221194        // Verbosity commands
     
    12271299    int EvalOptions(Configuration &conf)
    12281300    {
     1301        if (!fSunRise)
     1302            return 1;
     1303
    12291304        fDrive.SetVerbose(!conf.Get<bool>("quiet"));
    12301305
     
    12721347            fDatabase = conf.Get<string>("source-database");
    12731348            ReadDatabase();
     1349        }
     1350
     1351        if (fSunRise.IsValid())
     1352        {
     1353            ostringstream msg;
     1354            msg << "Next sun-rise will be at " << fSunRise;
     1355            T::Message(msg);
    12741356        }
    12751357
Note: See TracChangeset for help on using the changeset viewer.