/************************************************************************************ * * ***********************************************************************************/ IPState ScopeDome::sendMove(double azDiff) { int rc; if (azDiff < 0) { uint16_t steps = (uint16_t)(-azDiff * stepsPerTurn / 360.0); LOGF_DEBUG("CCW (%d)", steps); steps = compensateInertia(steps); LOGF_DEBUG("CCW inertia (%d)", steps); if (steps == 0) return IPS_OK; rc = writeU16(CCWRotation, steps); } else { uint16_t steps = (uint16_t)(azDiff * stepsPerTurn / 360.0); LOGF_DEBUG("CW (%d)", steps); steps = compensateInertia(steps); LOGF_DEBUG("CW inertia (%d)", steps); if (steps == 0) return IPS_OK; rc = writeU16(CWRotation, steps); } if (rc != 0) { LOGF_ERROR("Error moving dome: %d", rc); } return IPS_BUSY; }
/************************************************************************************ * * ***********************************************************************************/ IPState ScopeDome::MoveAbs(double az) { LOGF_DEBUG("MoveAbs (%f)", az); targetAz = az; double azDiff = az - DomeAbsPosN[0].value; LOGF_DEBUG("azDiff = %f", azDiff); // Make relative (-180 - 180) regardless if it passes az 0 if (azDiff > 180) { azDiff -= 360; } if (azDiff < -180) { azDiff += 360; } LOGF_DEBUG("azDiff rel = %f", azDiff); int rc = 0; if (azDiff < 0) { uint16_t steps = (uint16_t)(-azDiff * stepsPerTurn / 360.0); LOGF_DEBUG("CCW (%d)", steps); steps = compensateInertia(steps); LOGF_DEBUG("CCW inertia (%d)", steps); if (steps == 0) return IPS_OK; rc = writeU16(CCWRotation, steps); } else { uint16_t steps = (uint16_t)(azDiff * stepsPerTurn / 360.0); LOGF_DEBUG("CW (%d)", steps); steps = compensateInertia(steps); LOGF_DEBUG("CW inertia (%d)", steps); if (steps == 0) return IPS_OK; rc = writeU16(CWRotation, steps); } if (rc != 0) { LOGF_ERROR("Error moving dome: %d", rc); } return IPS_BUSY; }
/************************************************************************************ * * ***********************************************************************************/ 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); }