Пример #1
0
bool QHYCCD::StartExposure(float duration)
{
    unsigned int ret = QHYCCD_ERROR;

    if (Streamer->isBusy())
    {
        DEBUG(INDI::Logger::DBG_ERROR, "Cannot take exposure while streaming/recording is active.");
        return false;
    }
    //AbortPrimaryFrame = false;

    /*
    if (duration < MINIMUM_CCD_EXPOSURE)
    {
        DEBUGF(INDI::Logger::DBG_WARNING,
               "Exposure shorter than minimum duration %g s requested. Setting exposure time to %g s.", duration,
               MINIMUM_CCD_EXPOSURE);
        duration = MINIMUM_CCD_EXPOSURE;
    }*/

    imageFrameType = PrimaryCCD.getFrameType();

    /*if (imageFrameType == CCDChip::BIAS_FRAME)
    {
        duration = MINIMUM_CCD_EXPOSURE;
        DEBUGF(INDI::Logger::DBG_SESSION, "Bias Frame (s) : %g", duration);
    }
    else*/
    if (GetCCDCapability() & CCD_HAS_SHUTTER)
    {
        if (imageFrameType == INDI::CCDChip::DARK_FRAME || imageFrameType == INDI::CCDChip::BIAS_FRAME)
            ControlQHYCCDShutter(camhandle, MACHANICALSHUTTER_CLOSE);
        else
            ControlQHYCCDShutter(camhandle, MACHANICALSHUTTER_FREE);
    }

    DEBUGF(INDI::Logger::DBG_DEBUG, "Current exposure time is %f us", duration * 1000 * 1000);
    ExposureRequest = duration;
    PrimaryCCD.setExposureDuration(duration);

    if (sim)
        ret = QHYCCD_SUCCESS;
    else
    {
        if (LastExposureRequest != ExposureRequest)
        {
            ret = SetQHYCCDParam(camhandle, CONTROL_EXPOSURE, ExposureRequest * 1000 * 1000);

            if (ret != QHYCCD_SUCCESS)
            {
                DEBUGF(INDI::Logger::DBG_ERROR, "Set expose time failed (%d).", ret);
                return false;
            }

            LastExposureRequest = ExposureRequest;
        }
    }

    if (sim)
        ret = QHYCCD_SUCCESS;
    else
        ret = SetQHYCCDBinMode(camhandle, camxbin, camybin);
    if (ret != QHYCCD_SUCCESS)
    {
        DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD Bin mode failed (%d)", ret);
        return false;
    }

    DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDBinMode (%dx%d).", camxbin, camybin);

    if (sim)
        ret = QHYCCD_SUCCESS;
    else
        ret = SetQHYCCDResolution(camhandle, camroix, camroiy, camroiwidth, camroiheight);
    if (ret != QHYCCD_SUCCESS)
    {
        DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD ROI resolution (%d,%d) (%d,%d) failed (%d)", camroix, camroiy,
               camroiwidth, camroiheight, ret);
        return false;
    }

    DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDResolution camroix %d camroiy %d camroiwidth %d camroiheight %d", camroix,
           camroiy, camroiwidth, camroiheight);

    if (sim)
        ret = QHYCCD_SUCCESS;
    else
        ret = ExpQHYCCDSingleFrame(camhandle);
    if (ret == QHYCCD_ERROR)
    {
        DEBUGF(INDI::Logger::DBG_SESSION, "Begin QHYCCD expose failed (%d)", ret);
        return false;
    }

    gettimeofday(&ExpStart, NULL);
    DEBUGF(INDI::Logger::DBG_DEBUG, "Taking a %g seconds frame...", ExposureRequest);

    InExposure = true;

    // if (ExposureRequest*1000 < POLLMS)
    //     SetTimer(ExposureRequest*1000);
    // else
    SetTimer(POLLMS);

    return true;
}
Пример #2
0
bool QHYCCD::StartExposure(float duration)
{
  int ret = QHYCCD_ERROR;

#ifndef OSX_EMBEDED_MODE
  if (streamer->isBusy())
  {
      DEBUG(INDI::Logger::DBG_ERROR, "Cannot take exposure while streaming/recording is active.");
      return false;
  }
#endif
  //AbortPrimaryFrame = false;

  if (duration < MINIMUM_CCD_EXPOSURE)
  {
    DEBUGF(INDI::Logger::DBG_WARNING, "Exposure shorter than minimum duration %g s requested. Setting exposure time to %g s.", duration, MINIMUM_CCD_EXPOSURE);
    duration = MINIMUM_CCD_EXPOSURE;
  }

  imageFrameType = PrimaryCCD.getFrameType();

  if (imageFrameType == CCDChip::BIAS_FRAME)
  {
    duration = MINIMUM_CCD_EXPOSURE;
    DEBUGF(INDI::Logger::DBG_SESSION, "Bias Frame (s) : %g", duration);
  }
  else if(imageFrameType == CCDChip::DARK_FRAME)
  {
      ControlQHYCCDShutter(camhandle,MACHANICALSHUTTER_CLOSE);
  }
  else
  {
      ControlQHYCCDShutter(camhandle,MACHANICALSHUTTER_FREE);
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "Current exposure time is %f us",duration * 1000 * 1000);
  ExposureRequest = duration;
  PrimaryCCD.setExposureDuration(duration);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = SetQHYCCDParam(camhandle,CONTROL_EXPOSURE,ExposureRequest * 1000 * 1000);

  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_ERROR, "Set expose time failed (%d).", ret);
      return false;
  }

  // lzr: we need to call the following apis every single exposure,the usleep(200000) is important
  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = SetQHYCCDBinMode(camhandle,camxbin,camybin);
  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD Bin mode failed (%d)", ret);
      return false;
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDBinMode %dx%d", camxbin, camybin);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
     ret = SetQHYCCDResolution(camhandle,camroix,camroiy,camroiwidth,camroiheight);
  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD ROI resolution failed (%d)", ret);
      return false;
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDResolution camroix %d camroiy %d camroiwidth %d camroiheight %d", camroix,camroiy,camroiwidth,camroiheight);
  
  // JM 2016-05-08: Some QHY cameras needs 200ms before you can exposure a frame. Asked QHY to try to minimize this!
  //usleep(200000);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = ExpQHYCCDSingleFrame(camhandle);
  if(ret == QHYCCD_ERROR)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Begin QHYCCD expose failed (%d)", ret);
      return false;
  }

  gettimeofday(&ExpStart, NULL);
  DEBUGF(INDI::Logger::DBG_DEBUG, "Taking a %g seconds frame...", ExposureRequest);

  InExposure = true;

 // if (ExposureRequest*1000 < POLLMS)
 //     SetTimer(ExposureRequest*1000);
 // else
      SetTimer(POLLMS);

  return true;
}
Пример #3
0
bool Camera_QHY::Capture(int duration, usImage& img, int options, const wxRect& subframe)
{
    bool useSubframe = UseSubframes && !subframe.IsEmpty();

    if (Binning != m_curBin)
    {
        FullSize = wxSize(m_maxSize.GetX() / Binning, m_maxSize.GetY() / Binning);
        m_curBin = Binning;
        useSubframe = false; // subframe may be out of bounds now
    }

    if (img.Init(FullSize))
    {
        DisconnectWithAlert(CAPT_FAIL_MEMORY);
        return true;
    }

    wxRect frame = useSubframe ? subframe : wxRect(FullSize);
    if (useSubframe)
        img.Clear();

    wxRect roi;

    if (useSubframe)
    {
        // Use a larger ROI around the subframe to avoid changing the ROI as the centroid
        // wobbles around. Changing the ROI introduces a lag of several seconds.
        // This also satifies the constraint that ROI width and height must be multiples of 4.
        enum { PAD = 1 << 5 };
        roi.SetLeft(round_down(subframe.GetLeft(), PAD));
        roi.SetRight(round_up(subframe.GetRight() + 1, PAD) - 1);
        roi.SetTop(round_down(subframe.GetTop(), PAD));
        roi.SetBottom(round_up(subframe.GetBottom() + 1, PAD) - 1);
    }
    else
    {
        roi = frame;
    }

    uint32_t ret = QHYCCD_ERROR;
    // lzr from QHY says this needs to be set for every exposure
    ret = SetQHYCCDBinMode(m_camhandle, Binning, Binning);
    if (ret != QHYCCD_SUCCESS)
    {
        Debug.Write(wxString::Format("SetQHYCCDBinMode failed! ret = %d\n", (int)ret));
    }

    if (m_roi != roi)
    {
        // when roi changes, must call this
        ret = CancelQHYCCDExposingAndReadout(m_camhandle);
        if (ret == QHYCCD_SUCCESS)
        {
            Debug.Write("CancelQHYCCDExposingAndReadout success\n");
        }
        else
        {
            Debug.Write("CancelQHYCCDExposingAndReadout failed\n");
        }

        ret = SetQHYCCDResolution(m_camhandle, roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight());
        if (ret == QHYCCD_SUCCESS)
        {
            m_roi = roi;
        }
        else
        {
            Debug.Write(wxString::Format("SetQHYCCDResolution(%d,%d,%d,%d) failed! ret = %d\n",
                roi.GetLeft(), roi.GetTop(), roi.GetWidth(), roi.GetHeight(), (int)ret));
        }
    }

    if (duration != m_curExposure)
    {
        ret = SetQHYCCDParam(m_camhandle, CONTROL_EXPOSURE, duration * 1000.0); // QHY duration is usec
        if (ret == QHYCCD_SUCCESS)
        {
            m_curExposure = duration;
        } 
        else
        {
            Debug.Write(wxString::Format("QHY set exposure ret %d\n", (int)ret));
            pFrame->Alert(_("Failed to set camera exposure"));
        }
    }

    if (GuideCameraGain != m_curGain)
    {
        double gain = m_gainMin + GuideCameraGain * (m_gainMax - m_gainMin) / 100.0;
        gain = floor(gain / m_gainStep) * m_gainStep;
        Debug.Write(wxString::Format("QHY set gain %g (%g..%g incr %g)\n", gain, m_gainMin, m_gainMax, m_gainStep));
        ret = SetQHYCCDParam(m_camhandle, CONTROL_GAIN, gain);
        if (ret == QHYCCD_SUCCESS)
        {
            m_curGain = GuideCameraGain;
        }
        else
        {
            Debug.Write(wxString::Format("QHY set gain ret %d\n", (int)ret));
            pFrame->Alert(_("Failed to set camera gain"));
        }
    }

    ret = ExpQHYCCDSingleFrame(m_camhandle);
    if (ret == QHYCCD_ERROR)
    {
        Debug.Write(wxString::Format("QHY exp single frame ret %d\n", (int)ret));
        DisconnectWithAlert(_("QHY exposure failed"), NO_RECONNECT);
        return true;
    }
    if (ret == QHYCCD_SUCCESS)
    {
        Debug.Write(wxString::Format("QHY: 200ms delay needed\n"));
        WorkerThread::MilliSleep(200);
    }
    if (ret == QHYCCD_READ_DIRECTLY)
    {
        //Debug.Write("QHYCCD_READ_DIRECTLY\n");
    }

    uint32_t w, h, bpp, channels;
    ret = GetQHYCCDSingleFrame(m_camhandle, &w, &h, &bpp, &channels, RawBuffer);
    if (ret != QHYCCD_SUCCESS || (bpp != 8 && bpp != 16))
    {
        Debug.Write(wxString::Format("QHY get single frame ret %d bpp %u\n", ret, bpp));
        // users report that reconnecting the camera after this failure allows
        // them to resume guiding so we'll try to reconnect automatically
        DisconnectWithAlert(_("QHY get frame failed"), RECONNECT);
        return true;
    }

    if (useSubframe)
    {
        img.Subframe = frame;

        int xofs = subframe.GetLeft() - roi.GetLeft();
        int yofs = subframe.GetTop() - roi.GetTop();

        int dxr = w - frame.width - xofs;
        if (bpp == 8)
        {
            const unsigned char *src = RawBuffer + yofs * w;
            unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft();
            for (int y = 0; y < frame.height; y++)
            {
                unsigned short *d = dst;
                src += xofs;
                for (int x = 0; x < frame.width; x++)
                    *d++ = (unsigned short) *src++;
                src += dxr;
                dst += FullSize.GetWidth();
            }
        }
        else // bpp == 16
        {
            const unsigned short *src = (const unsigned short *) RawBuffer + yofs * w;
            unsigned short *dst = img.ImageData + frame.GetTop() * FullSize.GetWidth() + frame.GetLeft();
            for (int y = 0; y < frame.height; y++)
            {
                src += xofs;
                memcpy(dst, src, frame.width * sizeof(unsigned short));
                src += frame.width + dxr;
                dst += FullSize.GetWidth();
            }
        }
    }
    else
    {
        if (bpp == 8)
        {
            const unsigned char *src = RawBuffer;
            unsigned short *dst = img.ImageData;
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    *dst++ = (unsigned short) *src++;
                }
            }
        }
        else // bpp == 16
        {
            memcpy(img.ImageData, RawBuffer, w * h * sizeof(unsigned short));
        }
    }

    if (options & CAPTURE_SUBTRACT_DARK)
        SubtractDark(img);
    if (Color && Binning == 1 && (options & CAPTURE_RECON))
        QuickLRecon(img);

    return false;
}
Пример #4
0
bool QHYCCD::StartExposure(float duration)
{
  int ret = QHYCCD_ERROR;

  if (streamer->isBusy())
  {
      DEBUG(INDI::Logger::DBG_ERROR, "Cannot take exposure while streaming/recording is active.");
      return false;
  }

  //AbortPrimaryFrame = false;

  if (duration < MINIMUM_CCD_EXPOSURE)
  {
    DEBUGF(INDI::Logger::DBG_WARNING, "Exposure shorter than minimum duration %g s requested. Setting exposure time to %g s.", duration, MINIMUM_CCD_EXPOSURE);
    duration = MINIMUM_CCD_EXPOSURE;
  }

  imageFrameType = PrimaryCCD.getFrameType();

  if (imageFrameType == CCDChip::BIAS_FRAME)
  {
    duration = MINIMUM_CCD_EXPOSURE;
    DEBUGF(INDI::Logger::DBG_SESSION, "Bias Frame (s) : %g", duration);
  }
  else if(imageFrameType == CCDChip::DARK_FRAME)
  {
      ControlQHYCCDShutter(camhandle,MACHANICALSHUTTER_CLOSE);
  }
  else
  {
      ControlQHYCCDShutter(camhandle,MACHANICALSHUTTER_FREE);
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "Current exposure time is %f us",duration * 1000 * 1000);
  ExposureRequest = duration;
  PrimaryCCD.setExposureDuration(duration);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = SetQHYCCDParam(camhandle,CONTROL_EXPOSURE,ExposureRequest * 1000 * 1000);

  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_ERROR, "Set expose time failed (%d).", ret);
      return false;
  }

  // lzr: we need to call the following apis every single exposure,the usleep(200000) is important
  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = SetQHYCCDBinMode(camhandle,camxbin,camybin);
  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD Bin mode failed (%d)", ret);
      return false;
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDBinMode %dx%d", camxbin, camybin);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
     ret = SetQHYCCDResolution(camhandle,camroix,camroiy,camroiwidth,camroiheight);
  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Set QHYCCD ROI resolution failed (%d)", ret);
      return false;
  }

  DEBUGF(INDI::Logger::DBG_DEBUG, "SetQHYCCDResolution camroix %d camroiy %d camroiwidth %d camroiheight %d", camroix,camroiy,camroiwidth,camroiheight);
  
  // Jasem: Removed QHY 300ms delay that was added without specifying the reason. It seems any delay less than 100ms results in QHY Frame error. Again no reason. This renders
  // exposures less than 100ms useless, but there is nothing I can do about that.
  usleep(100000);

  if (sim)
      ret = QHYCCD_SUCCESS;
  else
      ret = ExpQHYCCDSingleFrame(camhandle);
  if(ret != QHYCCD_SUCCESS)
  {
      DEBUGF(INDI::Logger::DBG_SESSION, "Begin QHYCCD expose failed (%d)", ret);
      return false;
  }

  gettimeofday(&ExpStart, NULL);
  DEBUGF(INDI::Logger::DBG_DEBUG, "Taking a %g seconds frame...", ExposureRequest);

  InExposure = true;

 // if (ExposureRequest*1000 < POLLMS)
 //     SetTimer(ExposureRequest*1000);
 // else
      SetTimer(POLLMS);

  return true;
}