void RollOff::TimerHit() { if(isConnected() == false) return; // No need to reset timer if we are not connected anymore if (DomeMotionSP.s == IPS_BUSY) { // Abort called if (MotionRequest < 0) { DEBUG(INDI::Logger::DBG_SESSION, "Roof motion is stopped."); setDomeState(DOME_IDLE); SetTimer(1000); return; } // Roll off is opening if (DomeMotionS[DOME_CW].s == ISS_ON) { if (getFullOpenedLimitSwitch()) { DEBUG(INDI::Logger::DBG_SESSION, "Roof is open."); SetParked(false); return; } } // Roll Off is closing else if (DomeMotionS[DOME_CCW].s == ISS_ON) { if (getFullClosedLimitSwitch()) { DEBUG(INDI::Logger::DBG_SESSION, "Roof is closed."); SetParked(true); return; } } SetTimer(1000); } //SetTimer(1000); }
void MaxDomeII::TimerHit() { SH_Status nShutterStatus; AZ_Status nAzimuthStatus; unsigned nHomePosition; float nAz; int nError; int nRetry = 1; if(isConnected() == false) return; // No need to reset timer if we are not connected anymore nError = Status_MaxDomeII(PortFD, &nShutterStatus, &nAzimuthStatus, &nCurrentTicks, &nHomePosition); handle_driver_error(&nError, &nRetry); // This is a timer, we will not repeat in order to not delay the execution. // Increment movment time counter if (nTimeSinceShutterStart >= 0) nTimeSinceShutterStart++; if (nTimeSinceAzimuthStart >= 0) nTimeSinceAzimuthStart++; // Watch dog nTimeSinceLastCommunication++; if (WatchDogNP.np[0].value > 0 && WatchDogNP.np[0].value <= nTimeSinceLastCommunication) { // Close Shutter if it is not if (nShutterStatus != Ss_CLOSED) { DomeShutterSP.s = ControlShutter(SHUTTER_CLOSE); IDSetSwitch(&DomeShutterSP, "Closing shutter due watch dog"); } } if (getWeatherState() == IPS_ALERT) { // Close Shutter if it is not if (nShutterStatus != Ss_CLOSED) { DomeShutterSP.s = ControlShutter(SHUTTER_CLOSE); IDSetSwitch(&DomeShutterSP, "Closing shutter due Weather conditions"); } } if (!nError) { // Shutter switch(nShutterStatus) { case Ss_CLOSED: if (DomeShutterS[1].s == ISS_ON) // Close Shutter { if (DomeShutterSP.s == IPS_BUSY || DomeShutterSP.s == IPS_ALERT) { DomeShutterSP.s = IPS_OK; // Shutter close movement ends. nTimeSinceShutterStart = -1; IDSetSwitch (&DomeShutterSP, "Shutter is closed"); } } else { if (nTimeSinceShutterStart >= 0) { // A movement has started. Warn but don't change if (nTimeSinceShutterStart >= 4) { DomeShutterSP.s = IPS_ALERT; // Shutter close movement ends. IDSetSwitch (&DomeShutterSP, "Shutter still closed"); } } else { // For some reason (manual operation?) the shutter has closed DomeShutterSP.s = IPS_IDLE; DomeShutterS[1].s = ISS_ON; DomeShutterS[0].s = ISS_OFF; IDSetSwitch (&DomeShutterSP, "Unexpected shutter closed"); } } break; case Ss_OPENING: if (DomeShutterS[0].s == ISS_OFF) // not opening Shutter { // For some reason the shutter is opening (manual operation?) DomeShutterSP.s = IPS_ALERT; DomeShutterS[1].s = ISS_OFF; DomeShutterS[0].s = ISS_OFF; IDSetSwitch (&DomeShutterSP, "Unexpected shutter opening"); } else if (nTimeSinceShutterStart < 0) { // For some reason the shutter is opening (manual operation?) DomeShutterSP.s = IPS_ALERT; nTimeSinceShutterStart = 0; IDSetSwitch (&DomeShutterSP, "Unexpected shutter opening"); } else if (DomeShutterSP.s == IPS_ALERT) { // The alert has corrected DomeShutterSP.s = IPS_BUSY; IDSetSwitch (&DomeShutterSP, "Shutter is opening"); } break; case Ss_OPEN: if (DomeShutterS[0].s == ISS_ON) // Open Shutter { if (DomeShutterSP.s == IPS_BUSY || DomeShutterSP.s == IPS_ALERT) { DomeShutterSP.s = IPS_OK; // Shutter open movement ends. nTimeSinceShutterStart = -1; IDSetSwitch (&DomeShutterSP, "Shutter is open"); } } else { if (nTimeSinceShutterStart >= 0) { // A movement has started. Warn but don't change if (nTimeSinceShutterStart >= 4) { DomeShutterSP.s = IPS_ALERT; // Shutter open movement alert. IDSetSwitch (&DomeShutterSP, "Shutter still open"); } } else { // For some reason (manual operation?) the shutter has open DomeShutterSP.s = IPS_IDLE; DomeShutterS[1].s = ISS_ON; DomeShutterS[0].s = ISS_OFF; IDSetSwitch (&DomeShutterSP, "Unexpected shutter open"); } } break; case Ss_CLOSING: if (DomeShutterS[1].s == ISS_OFF) // Not closing Shutter { // For some reason the shutter is closing (manual operation?) DomeShutterSP.s = IPS_ALERT; DomeShutterS[1].s = ISS_ON; DomeShutterS[0].s = ISS_OFF; IDSetSwitch (&DomeShutterSP, "Unexpected shutter closing"); } else if (nTimeSinceShutterStart < 0) { // For some reason the shutter is opening (manual operation?) DomeShutterSP.s = IPS_ALERT; nTimeSinceShutterStart = 0; IDSetSwitch (&DomeShutterSP, "Unexpected shutter closing"); } else if (DomeShutterSP.s == IPS_ALERT) { // The alert has corrected DomeShutterSP.s = IPS_BUSY; IDSetSwitch (&DomeShutterSP, "Shutter is closing"); } break; case Ss_ABORTED: case Ss_ERROR: default: if (nTimeSinceShutterStart >= 0) { DomeShutterSP.s = IPS_ALERT; // Shutter movement aborted. DomeShutterS[1].s = ISS_OFF; DomeShutterS[0].s = ISS_OFF; nTimeSinceShutterStart = -1; IDSetSwitch (&DomeShutterSP, "Unknown shutter status"); } break; } // Azimuth nAz = TicksToAzimuth(nCurrentTicks); if (DomeAbsPosN[0].value != nAz) { // Only refresh position if it changed DomeAbsPosN[0].value = nAz; //sprintf(buf,"%d", nCurrentTicks); IDSetNumber(&DomeAbsPosNP, NULL); } switch(nAzimuthStatus) { case As_IDLE: case As_IDEL2: if (nTimeSinceAzimuthStart > 3) { if (nTargetAzimuth >= 0 && AzimuthDistance(nTargetAzimuth,nCurrentTicks) > 3) // Maximum difference allowed: 3 ticks { DomeAbsPosNP.s = IPS_ALERT; nTimeSinceAzimuthStart = -1; IDSetNumber(&DomeAbsPosNP, "Could not position right"); } else { // Succesfull end of movement if (DomeAbsPosNP.s != IPS_OK) { setDomeState(DOME_SYNCED); nTimeSinceAzimuthStart = -1; DEBUG(INDI::Logger::DBG_SESSION, "Dome is on target position"); } if (HomeS[0].s == ISS_ON) { HomeS[0].s = ISS_OFF; HomeSP.s = IPS_OK; nTimeSinceAzimuthStart = -1; IDSetSwitch(&HomeSP, "Dome is homed"); } } } break; case As_MOVING_WE: case As_MOVING_EW: if (nTimeSinceAzimuthStart < 0) { nTimeSinceAzimuthStart = 0; nTargetAzimuth = -1; DomeAbsPosNP.s = IPS_ALERT; IDSetNumber(&DomeAbsPosNP, "Unexpected dome moving"); } break; case As_ERROR: if (nTimeSinceAzimuthStart >= 0) { DomeAbsPosNP.s = IPS_ALERT; nTimeSinceAzimuthStart = -1; nTargetAzimuth = -1; IDSetNumber(&DomeAbsPosNP, "Dome Error"); } default: break; } } else { DEBUGF(INDI::Logger::DBG_DEBUG, "Error: %s. Please reconnect and try again.",ErrorMessages[-nError]); return; } SetTimer(POLLMS); return; }
/************************************************************************************ * * ***********************************************************************************/ void ScopeDome::TimerHit() { if (!isConnected()) return; // No need to reset timer if we are not connected anymore readU16(GetStatus, currentStatus); // LOGF_INFO("Status: %x", currentStatus); UpdatePosition(); UpdateShutterStatus(); IDSetSwitch(&DomeShutterSP, nullptr); UpdateRelayStatus(); if (status == DOME_HOMING) { if ((currentStatus & 8) == 0 && getInputState(IN_HOME)) { // Found home status = DOME_READY; targetAz = DomeHomePositionN[0].value; // Reset counter writeCmd(ResetCounter); FindHomeSP.s = IPS_OK; DomeAbsPosNP.s = IPS_OK; IDSetSwitch(&FindHomeSP, nullptr); } IDSetNumber(&DomeAbsPosNP, nullptr); } else if (status == DOME_DEROTATING) { if ((currentStatus & 2) == 0) { readS32(GetCounterExt, currentRotation); LOGF_INFO("Current rotation is %d", currentRotation); if (abs(currentRotation) < 100) { // Close enough status = DOME_READY; DerotateSP.s = IPS_OK; DomeAbsPosNP.s = IPS_OK; IDSetSwitch(&DerotateSP, nullptr); } else { if (currentRotation < 0) { writeU16(CCWRotation, compensateInertia(-currentRotation)); } else { writeU16(CWRotation, compensateInertia(currentRotation)); } } } IDSetNumber(&DomeAbsPosNP, nullptr); } else if (DomeAbsPosNP.s == IPS_BUSY) { if ((currentStatus & 2) == 0) { // Rotation idle, are we close enough? double azDiff = targetAz - DomeAbsPosN[0].value; if (azDiff > 180) { azDiff -= 360; } if (azDiff < -180) { azDiff += 360; } if (fabs(azDiff) <= DomeParamN[0].value) { DomeAbsPosN[0].value = targetAz; DomeAbsPosNP.s = IPS_OK; LOG_INFO("Dome reached requested azimuth angle."); if (getDomeState() == DOME_PARKING) { if (ParkShutterS[0].s == ISS_ON && getInputState(IN_CLOSED1) == ISS_OFF) { ControlShutter(SHUTTER_CLOSE); } else { SetParked(true); } } else if (getDomeState() == DOME_UNPARKING) SetParked(false); else setDomeState(DOME_SYNCED); } else { // Refine azimuth MoveAbs(targetAz); } } IDSetNumber(&DomeAbsPosNP, nullptr); } else IDSetNumber(&DomeAbsPosNP, nullptr); // Read temperatures only every 10th time static int tmpCounter = 0; if (--tmpCounter <= 0) { UpdateSensorStatus(); tmpCounter = 10; } SetTimer(POLLMS); }
void DomeScript::TimerHit() { if (!isConnected()) return; char name[1024]={0}; // N.B. INDI_UNUSED to make it compile on MacOS // DO NOT CHANGE char *s = tmpnam(name); INDI_UNUSED(s); bool status = RunScript(SCRIPT_STATUS, name, nullptr); if (status) { int parked = 0, shutter = 0; float az = 0; FILE *file = fopen(name, "r"); int ret = 0; ret = fscanf(file, "%d %d %f", &parked, &shutter, &az); fclose(file); unlink(name); DomeAbsPosN[0].value = az = round(range360(az) * 10) / 10; if (parked != 0) { if (getDomeState() == DOME_PARKING || getDomeState() == DOME_UNPARKED) { SetParked(true); TargetAz = az; LOG_INFO("Park succesfully executed"); } } else { if (getDomeState() == DOME_UNPARKING || getDomeState() == DOME_PARKED) { SetParked(false); TargetAz = az; LOG_INFO("Unpark succesfully executed"); } } if (std::round(az * 10) != std::round(TargetAz * 10)) { LOGF_INFO("Moving %g -> %g %d", std::round(az * 10) / 10, std::round(TargetAz * 10) / 10, getDomeState()); IDSetNumber(&DomeAbsPosNP, nullptr); } else if (getDomeState() == DOME_MOVING) { setDomeState(DOME_SYNCED); IDSetNumber(&DomeAbsPosNP, nullptr); } if (shutterState == SHUTTER_OPENED) { if (shutter == 0) { shutterState = SHUTTER_CLOSED; DomeShutterSP.s = IPS_OK; IDSetSwitch(&DomeShutterSP, nullptr); LOG_INFO("Shutter was succesfully closed"); } } else { if (shutter == 1) { shutterState = SHUTTER_OPENED; DomeShutterSP.s = IPS_OK; IDSetSwitch(&DomeShutterSP, nullptr); LOG_INFO("Shutter was succesfully opened"); } } } else { LOG_ERROR("Failed to read status"); } SetTimer(POLLMS); if (!isParked() && TimeSinceUpdate++ > 4) { TimeSinceUpdate = 0; UpdateMountCoords(); } }
/************************************************************************************ * * ***********************************************************************************/ void BaaderDome::TimerHit() { if (!isConnected()) return; // No need to reset timer if we are not connected anymore UpdatePosition(); if (DomeAbsPosNP.s == IPS_BUSY) { if (sim) { double speed = 0; if (fabs(targetAz - DomeAbsPosN[0].value) > SIM_DOME_HI_SPEED) speed = SIM_DOME_HI_SPEED; else speed = SIM_DOME_LO_SPEED; if (DomeRelPosNP.s == IPS_BUSY) { // CW if (DomeMotionS[0].s == ISS_ON) DomeAbsPosN[0].value += speed; // CCW else DomeAbsPosN[0].value -= speed; } else { if (targetAz > DomeAbsPosN[0].value) { DomeAbsPosN[0].value += speed; } else if (targetAz < DomeAbsPosN[0].value) { DomeAbsPosN[0].value -= speed; } } if (DomeAbsPosN[0].value < DomeAbsPosN[0].min) DomeAbsPosN[0].value += DomeAbsPosN[0].max; if (DomeAbsPosN[0].value > DomeAbsPosN[0].max) DomeAbsPosN[0].value -= DomeAbsPosN[0].max; } if (fabs(targetAz - DomeAbsPosN[0].value) < DomeParamN[0].value) { DomeAbsPosN[0].value = targetAz; DEBUG(INDI::Logger::DBG_SESSION, "Dome reached requested azimuth angle."); if (status != DOME_CALIBRATING) { if (getDomeState() == DOME_PARKING) SetParked(true); else if (getDomeState() == DOME_UNPARKING) SetParked(false); else setDomeState(DOME_SYNCED); } if (status == DOME_CALIBRATING) { if (calibrationStage == CALIBRATION_STAGE1) { DEBUG(INDI::Logger::DBG_SESSION, "Calibration stage 1 complete. Starting stage 2..."); calibrationTarget2 = DomeAbsPosN[0].value + 2; calibrationStage = CALIBRATION_STAGE2; MoveAbs(calibrationTarget2); DomeAbsPosNP.s = IPS_BUSY; } else if (calibrationStage == CALIBRATION_STAGE2) { DEBUGF(INDI::Logger::DBG_SESSION, "Calibration stage 2 complete. Returning to initial position %g...", calibrationStart); calibrationStage = CALIBRATION_STAGE3; MoveAbs(calibrationStart); DomeAbsPosNP.s = IPS_BUSY; } else if (calibrationStage == CALIBRATION_STAGE3) { calibrationStage = CALIBRATION_COMPLETE; DEBUG(INDI::Logger::DBG_SESSION, "Dome reached initial position."); } } } IDSetNumber(&DomeAbsPosNP, nullptr); } else IDSetNumber(&DomeAbsPosNP, nullptr); UpdateShutterStatus(); if (sim && DomeShutterSP.s == IPS_BUSY) { if (simShutterTimer-- <= 0) { simShutterTimer = 0; simShutterStatus = (targetShutter == SHUTTER_OPEN) ? SHUTTER_OPENED : SHUTTER_CLOSED; } } else IDSetSwitch(&DomeShutterSP, nullptr); UpdateFlapStatus(); if (sim && DomeFlapSP.s == IPS_BUSY) { if (simFlapTimer-- <= 0) { simFlapTimer = 0; simFlapStatus = (targetFlap == FLAP_OPEN) ? FLAP_OPENED : FLAP_CLOSED; } } else IDSetSwitch(&DomeFlapSP, nullptr); SetTimer(POLLMS); }
void DomeSim::TimerHit() { int nexttimer=1000; if(isConnected() == false) return; // No need to reset timer if we are not connected anymore if (DomeAbsPosNP.s == IPS_BUSY) { if (targetAz > DomeAbsPosN[0].value) { DomeAbsPosN[0].value += DOME_SPEED; } else if (targetAz < DomeAbsPosN[0].value) { DomeAbsPosN[0].value -= DOME_SPEED; } DomeAbsPosN[0].value = range360(DomeAbsPosN[0].value); if (fabs(targetAz - DomeAbsPosN[0].value) <= DOME_SPEED) { DomeAbsPosN[0].value = targetAz; DEBUG(INDI::Logger::DBG_SESSION, "Dome reached requested azimuth angle."); if (getDomeState() == DOME_PARKING) SetParked(true); else if (getDomeState() == DOME_UNPARKING) SetParked(false); else setDomeState(DOME_SYNCED); } IDSetNumber(&DomeAbsPosNP, NULL); } if (DomeShutterSP.s == IPS_BUSY) { if (shutterTimer-- <= 0) { shutterTimer=0; DomeShutterSP.s = IPS_OK; DEBUGF(INDI::Logger::DBG_SESSION, "Shutter is %s.", (DomeShutterS[0].s == ISS_ON ? "open" : "closed")); IDSetSwitch(&DomeShutterSP, NULL); if (getDomeState() == DOME_UNPARKING) SetParked(false); } } SetTimer(nexttimer); // Not all mounts update ra/dec constantly if tracking co-ordinates // This is to ensure our alt/az gets updated even if ra/dec isn't being updated // Once every 10 seconds is more than sufficient // with this added, dome simulator will now correctly track telescope simulator // which does not emit new ra/dec co-ords if they are not changing if(isParked() == false && TimeSinceUpdate++ > 9) { TimeSinceUpdate=0; UpdateMountCoords(); } return; }