Changeset 17512


Ignore:
Timestamp:
01/16/14 18:50:47 (11 years ago)
Author:
tbretz
Message:
Allow change of ramp target vals durimg ramping; added a shutdown command with lock state; added automatic shutdown at end of nautical twilight.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/biasctrl.cc

    r17174 r17512  
    16051605
    16061606    bool fExpertMode;
     1607    bool fEmergencyShutdown;
     1608
     1609    Time fSunRise;
    16071610
    16081611    // --------------------------------------------------------------------
     
    18611864    }
    18621865
     1866    int Shutdown()
     1867    {
     1868        fBias.RampAllDacs(0);
     1869        fEmergencyShutdown = true;
     1870        T::Info("Emergency Sutdown initiated.");
     1871        return T::GetCurrentState();
     1872    }
     1873
     1874    int Unlock()
     1875    {
     1876        fEmergencyShutdown = false;
     1877        return T::GetCurrentState();
     1878    }
     1879
    18631880    int Execute()
    18641881    {
    1865         return fExpertMode && fBias.GetStatus()>=State::kConnected ?
    1866             State::kExpertMode : fBias.GetStatus();
     1882        const int state = fBias.GetStatus();
     1883
     1884        const Time now;
     1885        if (now>fSunRise)
     1886        {
     1887            if (state==State::kRamping       ||
     1888                state==State::kVoltageOn     ||
     1889                state==State::kNotReferenced)
     1890                return Shutdown();
     1891
     1892            if (state==State::kLocked)
     1893            {
     1894                fSunRise = now.GetNextSunRise(-6);
     1895
     1896                ostringstream msg;
     1897                msg << "Next sun-rise will be at " << fSunRise;
     1898                T::Info(msg);
     1899
     1900                return T::GetCurrentState();
     1901            }
     1902        }
     1903
     1904        if (T::GetCurrentState()==State::kVoltageOff && T::GetCurrentState()==State::kLocked)
     1905            return State::kLocked;
     1906 
     1907        if (fExpertMode && state>=State::kLocked)
     1908            return State::kExpertMode;
     1909
     1910        return state;
    18671911    }
    18681912
    18691913public:
    18701914    StateMachineBias(ostream &out=cout) :
    1871         StateMachineAsio<T>(out, "BIAS_CONTROL"), fBias(*this, *this), fExpertMode(false)
     1915        StateMachineAsio<T>(out, "BIAS_CONTROL"), fBias(*this, *this),
     1916        fExpertMode(false), fEmergencyShutdown(false),
     1917        fSunRise(Time().GetNextSunRise(-6))
    18721918    {
    18731919        // State names
     
    19011947        T::AddStateName(State::kRamping, "Ramping",
    19021948                        "Voltage ramping in progress.");
     1949
     1950        T::AddStateName(State::kLocked, "Locked",
     1951                        "Locked, no commands accepted except UNLOCK.");
    19031952
    19041953        // Verbosity commands
     
    19391988
    19401989
    1941         T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     1990        T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19421991            (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1))
    19431992            ("Set a new target value in DAC counts for a single channel. Starts ramping if necessary."
    19441993             "|channel[short]:Channel for which to set the target voltage [0-415]"
    19451994             "|voltage[dac]:Target voltage in DAC units for the given channel");
    1946         T::AddEvent("SET_GLOBAL_DAC", "S:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     1995        T::AddEvent("SET_GLOBAL_DAC", "S:1")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19471996            (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1))
    19481997            ("Set a new target value for all channels in DAC counts. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
     
    19501999
    19512000
    1952         T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     2001        T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19532002            (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1))
    19542003            ("Set a new target voltage for a single channel. Starts ramping if necessary."
    19552004             "|channel[short]:Channel for which to set the target voltage [0-415]"
    19562005             "|voltage[V]:Target voltage in volts for the given channel (will be converted to DAC units)");
    1957         T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     2006        T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19582007            (bind(&StateMachineBias::SetGlobalVolt, this, placeholders::_1))
    19592008            ("Set a new target voltage for all channels. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"
    19602009             "|voltage[V]:Global target voltage in volts (will be converted to DAC units)");
    1961         T::AddEvent("SET_ALL_CHANNELS_VOLTAGE", "F:416", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     2010        T::AddEvent("SET_ALL_CHANNELS_VOLTAGE", "F:416")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19622011            (bind(&StateMachineBias::SetAllChannelsVolt, this, placeholders::_1))
    19632012            ("Set all channels to the given new reference voltage. Starts ramping if necessary."
     
    19822031
    19832032
    1984         T::AddEvent("SET_ZERO_VOLTAGE", State::kConnected, State::kVoltageOff, State::kVoltageOn, State::kNotReferenced, State::kOverCurrent)
     2033        T::AddEvent("SET_ZERO_VOLTAGE")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
    19852034            (Wrapper(bind(&ConnectionBias::RampAllDacs, &fBias, 0)))
    19862035            ("Set all channels to a zero reference voltage. Starts ramping if necessary.");
     2036        T::AddEvent("SHUTDOWN")(State::kConnected)(State::kVoltageOff)(State::kVoltageOn)(State::kNotReferenced)(State::kOverCurrent)(State::kRamping)
     2037            (bind(&StateMachineBias::Shutdown, this))
     2038            ("Same as SET_ZERO_VOLTAGE; but goes to locked state afterwards.");
     2039
     2040        T::AddEvent("UNLOCK", State::kLocked)
     2041            (bind(&StateMachineBias::Unlock, this))
     2042            ("Unlock if in locked state.");
    19872043
    19882044
Note: See TracChangeset for help on using the changeset viewer.