Skip to content

Commit

Permalink
Add dome-d50, revise Dome functionality
Browse files Browse the repository at this point in the history
D50's dome added, implementing necessary coopreration between it's dome and mount.
Solved discovered issues with connections and general Dome behaviour.
  • Loading branch information
jstrobl committed Jul 26, 2022
1 parent c29050c commit 7692edd
Show file tree
Hide file tree
Showing 6 changed files with 770 additions and 37 deletions.
17 changes: 15 additions & 2 deletions include/dome.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "device.h"

#define DEF_WEATHER_TIMEOUT 10
#define DEF_CENTRALD_CONTACT_TIMEOUT 10
#define DEF_INITIAL_SETTLE_TIME 12

#define EVENT_DOMECLOSE_RETRY RTS2_LOCAL_EVENT + 402

/**
* Dome, copulas and roof controllers.
Expand All @@ -41,12 +45,14 @@ class Dome:public rts2core::Device
Dome (int argc, char **argv, int in_device_type = DEVICE_TYPE_DOME, bool inhibit_auto_close = false);
virtual ~Dome ();

virtual void postEvent (rts2core::Event * event);

virtual void changeMasterState (rts2_status_t old_state, rts2_status_t new_state);

/**
* Increases ignore timeout by given amount of seconds.
* Set ignore timeout to given amount of seconds from now
*
* @param _ignore_time Seconds by which a timeout will be increased.
* @param _ignore_time Seconds of timeout from now
*/
void setIgnoreTimeout (time_t _ignore_time);

Expand Down Expand Up @@ -174,6 +180,13 @@ class Dome:public rts2core::Device
rts2core::ValueString *stateMaster;

bool closeFailReported;

double centraldLastContactTime;

rts2core::ValueTime *closeRepeatTimeAfterPark;

// this is for not to close the dome right after the daemon initialization, so the connections have time to settle down
double initialSettleTime;
};

}
Expand Down
66 changes: 62 additions & 4 deletions lib/rts2/dome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Dome::Dome (int in_argc, char **in_argv, int in_device_type, bool inhibit_auto_c
addOption (OPT_STATE_MASTER, "state-master", 1, "state master - server which guverns opening and closing of dome for evening and morning");
addOption (OPT_DONOTCLOSE, "notclose", 0, "do not close (switch to bad weather) on startup");
addOption (OPT_IGNORETIMEOUT, "ignore-timeout", 1, "set initial ignore timeout to now + value in seconds");

createValue (closeRepeatTimeAfterPark, "close_repeat_time", "time [s] after which to retry the close (when equipment repositioning was necessary)", false, RTS2_VALUE_WRITABLE);
closeRepeatTimeAfterPark->setValueDouble (3);
}


Expand Down Expand Up @@ -110,14 +113,28 @@ int Dome::init ()
}
setMasterConn (conn);
}

centraldLastContactTime = getNow ();

initialSettleTime = getNow () + DEF_INITIAL_SETTLE_TIME;

setTimeout (5 * USEC_SEC);
setIdleInfoInterval (5);

return 0;
}


int Dome::domeOpenStart ()
{
deleteTimers (EVENT_DOMECLOSE_RETRY);

if (isOpened () == -2)
{
maskState (DOME_DOME_MASK | BOP_EXPOSURE | DEVICE_BLOCK_OPEN | DEVICE_BLOCK_CLOSE, DOME_OPENED | DEVICE_BLOCK_CLOSE, "dome opened");
logStream (MESSAGE_REPORTIT | MESSAGE_INFO) << "dome (already) opened" << sendLog;
return 0;
}

if (isGoodWeather () == false)
return -1;
Expand All @@ -137,8 +154,14 @@ int Dome::domeOpenStart ()

int Dome::domeCloseStart ()
{
deleteTimers (EVENT_DOMECLOSE_RETRY);

if (isClosed () == -2)
{
maskState (DOME_DOME_MASK | DEVICE_BLOCK_OPEN | DEVICE_BLOCK_CLOSE, DOME_CLOSED | DEVICE_BLOCK_OPEN, "dome closed");
//logStream (MESSAGE_INFO) << "dome (already) closed" << sendLog;
return 0;
}

int ret = startClose ();

Expand All @@ -153,9 +176,10 @@ int Dome::domeCloseStart ()
{
if ((getState () & DOME_DOME_MASK) != DOME_WAIT_CLOSING)
{
logStream (MESSAGE_REPORTIT | MESSAGE_INFO) << "wait for equipment to stow" << sendLog;
logStream (MESSAGE_REPORTIT | MESSAGE_INFO) << "waiting for devices to move into a position safe for dome to close" << sendLog;
}
maskState (DOME_DOME_MASK | BOP_EXPOSURE, DOME_WAIT_CLOSING, "wait for equipment to stow");
maskState (DOME_DOME_MASK | BOP_EXPOSURE, DOME_WAIT_CLOSING, "waiting for devices to move into a position safe for dome to close");
addTimer (closeRepeatTimeAfterPark->getValueDouble (), new rts2core::Event (EVENT_DOMECLOSE_RETRY));
return 0;
}

Expand All @@ -171,6 +195,8 @@ int Dome::domeCloseStart ()

int Dome::domeStop ()
{
deleteTimers (EVENT_DOMECLOSE_RETRY);

int ret = stop ();
if (ret < 0)
{
Expand Down Expand Up @@ -205,13 +231,15 @@ int Dome::checkOpening ()
}
if (ret == -1)
{
setTimeout (2 * USEC_SEC); // this can be "overloaded" by a value in local endOpen ();
endOpen ();
infoAll ();
logStream (MESSAGE_CRITICAL | MESSAGE_REPORTIT) << "dome opening interrupted" << sendLog;
maskState (DOME_DOME_MASK | BOP_EXPOSURE | DEVICE_BLOCK_OPEN | DEVICE_BLOCK_CLOSE, DOME_OPENED | DEVICE_BLOCK_CLOSE, "dome opening interrupted");
}
if (ret == -2)
{
setTimeout (2 * USEC_SEC); // this can be "overloaded" by a value in local endOpen ();
ret = endOpen ();
infoAll ();
if (ret)
Expand All @@ -237,13 +265,15 @@ int Dome::checkOpening ()
}
if (ret == -1)
{
setTimeout (10 * USEC_SEC); // this can be "overloaded" by a value in local endClose ();
endClose ();
infoAll ();
logStream (MESSAGE_CRITICAL | MESSAGE_REPORTIT) << "dome closing interrupted" << sendLog;
maskState (DOME_DOME_MASK | DEVICE_BLOCK_OPEN | DEVICE_BLOCK_CLOSE, DOME_CLOSED | DEVICE_BLOCK_OPEN, "closing finished with error");
}
if (ret == -2)
{
setTimeout (5 * USEC_SEC); // this can be "overloaded" by a value in local endClose ();
ret = endClose ();
infoAll ();
if (ret)
Expand All @@ -267,6 +297,9 @@ int Dome::checkOpening ()

int Dome::idle ()
{
if (getNow () < initialSettleTime) // give connections time to settle down
return Device::idle ();

checkOpening ();
if (isGoodWeather ())
{
Expand All @@ -286,7 +319,10 @@ int Dome::idle ()
}
// update our own weather state..
bool allCen = allCentraldRunning ();
if (allCen && getNextOpen () < getNow ())
if (allCen)
centraldLastContactTime = getNow ();

if ((allCen || centraldLastContactTime + DEF_CENTRALD_CONTACT_TIMEOUT > getNow ()) && getNextOpen () < getNow ())
{
valueGood (nextGoodWeather);
setWeatherState (true, "can open dome");
Expand All @@ -302,13 +338,28 @@ int Dome::idle ()
return Device::idle ();
}

void Dome::postEvent (rts2core::Event * event)
{
switch (event->getType ())
{
case EVENT_DOMECLOSE_RETRY:
logStream (MESSAGE_DEBUG) << "postEvent: EVENT_DOMECLOSE_RETRY" << sendLog;
domeCloseStart ();
break;
}
rts2core::Device::postEvent (event);
}

int Dome::closeDomeWeather ()
{
int ret = 0;
if (getIgnoreMeteo () == false)
{
if (domeAutoClose == NULL || domeAutoClose->getValueBool () == true)
{
logStream (MESSAGE_DEBUG) << "closeDomeWeather: domeCloseStart" << sendLog;
ret = domeCloseStart ();
}
setMasterStandby ();
return ret;
}
Expand All @@ -326,15 +377,21 @@ int Dome::standby ()
{
ignoreTimeout->setValueDouble (getNow () - 1);
if (domeAutoClose == NULL || domeAutoClose->getValueBool () == true)
{
logStream (MESSAGE_DEBUG) << "standby: domeCloseStart" << sendLog;
return domeCloseStart ();
}
return 0;
}

int Dome::off ()
{
ignoreTimeout->setValueDouble (getNow () - 1);
if (domeAutoClose == NULL || domeAutoClose->getValueBool () == true)
{
logStream (MESSAGE_DEBUG) << "off: domeCloseStart" << sendLog;
return domeCloseStart ();
}
return 0;
}

Expand Down Expand Up @@ -406,7 +463,7 @@ void Dome::setIgnoreTimeout (time_t _ignore_time)
{
time_t now;
time (&now);
now += _ignore_time;
ignoreTimeout->setValueDouble (getNow () + _ignore_time);
}

bool Dome::getIgnoreMeteo ()
Expand Down Expand Up @@ -436,6 +493,7 @@ int Dome::commandAuthorized (rts2core::Connection * conn)
}
else if (conn->isCommand (COMMAND_CLOSE))
{
logStream (MESSAGE_DEBUG) << "commandAuthorized: COMMAND_CLOSE" << sendLog;
return (domeCloseStart () == 0 ? 0 : -2);
}
else if (conn->isCommand (COMMAND_STOP))
Expand Down
6 changes: 4 additions & 2 deletions src/dome/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bin_PROGRAMS = rts2-dome-bart rts2-dome-apm rts2-dome-fram \
rts2-cupola-mark rts2-cupola-dummy rts2-dome-bootes1a \
rts2-dome-bootes1b rts2-dome-zelio rts2-dome-opentpl \
rts2-cupola-maxdomeii rts2-cupola-saao rts2-cupola-tcsng \
rts2-cupola-ddw
rts2-dome-d50 rts2-cupola-maxdomeii rts2-cupola-saao \
rts2-cupola-tcsng rts2-cupola-ddw

SUBDIRS = zelio

Expand Down Expand Up @@ -32,6 +32,8 @@ rts2_dome_zelio_SOURCES = zelio.cpp

rts2_dome_opentpl_SOURCES = opentpl.cpp

rts2_dome_d50_SOURCES = d50.cpp

rts2_dome_ahe_SOURCES = ahe.cpp

rts2_cupola_maxdomeii_SOURCES = maxdomeii.cpp
Expand Down
10 changes: 4 additions & 6 deletions src/dome/bart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ namespace rts2dome
class Bart:public Ford
{
private:
unsigned char spinac[2];

int handle_zasuvky (int zas);

time_t domeTimeout;
Expand Down Expand Up @@ -354,10 +352,10 @@ int Bart::info ()
ret = zjisti_stav_portu ();
if (ret)
return -1;
sw_state->setValueInteger (!getPortState (KONCAK_OTEVRENI_JIH));
sw_state->setValueInteger (sw_state->getValueInteger () | (!getPortState (SMER) << 1));
sw_state->setValueInteger (sw_state->getValueInteger () | (!getPortState (KONCAK_ZAVRENI_JIH) << 2));
sw_state->setValueInteger (sw_state->getValueInteger () | (!getPortState (MOTOR) << 3));
sw_state->setValueInteger ((!getPortState (KONCAK_OTEVRENI_JIH))
| (!getPortState (SMER) << 1)
| (!getPortState (KONCAK_ZAVRENI_JIH) << 2)
| (!getPortState (MOTOR) << 3));
domeMotorPower->setValueBool (getPortState (MOTOR));
domeMotorDirection->setValueInteger (getPortState (SMER));
domeSouthSwitchOpened->setValueInteger (getPortState (KONCAK_OTEVRENI_JIH));
Expand Down
Loading

0 comments on commit 7692edd

Please sign in to comment.