示例#1
0
/************************************************************************************
 *
* ***********************************************************************************/
IPState ScopeDome::UnPark()
{
    if (ParkShutterS[0].s == ISS_ON)
    {
        return ControlShutter(SHUTTER_OPEN);
    }
    return IPS_OK;
}
示例#2
0
/************************************************************************************
 *
* ***********************************************************************************/
IPState ScopeDome::Park()
{
    // First move to park position and then optionally close shutter
    targetAz  = GetAxis1Park();
    IPState s = MoveAbs(targetAz);
    if (s == IPS_OK && ParkShutterS[0].s == ISS_ON)
    {
        // Already at home, just close if needed
        return ControlShutter(SHUTTER_CLOSE);
    }
    return s;
}
示例#3
0
文件: maxdomeii.cpp 项目: mp77/indi
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;
}
示例#4
0
/************************************************************************************
 *
* ***********************************************************************************/
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);
}