indilib / indi-3rdparty

INDI 3rd Party drivers repository
https://www.indilib.org/devices.html
GNU Lesser General Public License v2.1
124 stars 208 forks source link

Posible error Driver mi_ccd.cpp set temperature Moravian Gx-xxxx? #949

Open aeskartin opened 1 month ago

aeskartin commented 1 month ago

HI

Could this be the issue that several Moravian camera users are experiencing when we turn off the camera's cooling from EKOS and it activates at 100% instead? At least 4 users have had this problem for a long time, and we cannot use the CCD warming function at the end of the session.


Issue with INDIlib Driver Handling Moravian Camera Cooling

We are experiencing an issue with the INDIlib driver for Moravian cameras where the cooling does not turn off properly. Instead of shutting down, the cooling is activated at maximum power. To help diagnose and resolve this issue, we have reviewed and modified the driver files mi_ccd.cpp, mi_ccd.h, and the Moravian library gxccd.h.

Analysis of the Code

Header File: mi_ccd.h

In the header file, we have the declarations related to the cooling system:

ISwitch CoolerS[2];
ISwitchVectorProperty CoolerSP;
INumber CoolerN[1];
INumberVectorProperty CoolerNP;

Implementation File: mi_ccd.cpp

In the initProperties function, the cooler properties are defined:

IUFillSwitch(&CoolerS[0], "COOLER_ON", "ON", ISS_ON);
IUFillSwitch(&CoolerS[1], "COOLER_OFF", "OFF", ISS_OFF);
IUFillSwitchVector(&CoolerSP, CoolerS, 2, getDeviceName(), "CCD_COOLER", "Cooler", MAIN_CONTROL_TAB, IP_WO, ISR_1OFMANY, 0, IPS_IDLE);

// CCD Regulation power
IUFillNumber(&CoolerN[0], "CCD_COOLER_VALUE", "Cooling Power (%)", "%+6.2f", 0.0, 1.0, 0.01, 0.0);
IUFillNumberVector(&CoolerNP, CoolerN, 1, getDeviceName(), "CCD_COOLER_POWER", "Cooling Power", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE);

The SetTemperature function seems to set the desired temperature correctly:

int MICCD::SetTemperature(double temperature)
{
    TemperatureRequest = temperature;
    if (gxccd_set_temperature(cameraHandle, temperature) != 0)
    {
        LOGF_ERROR("Error setting temperature to %.2f", temperature);
        return -1;
    }
    LOGF_INFO("Temperature set to %.2f", temperature);
    return 0;
}

Handling Cooler Switch

The ISNewSwitch function handles the switch states, including those for cooling:

bool MICCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (!strcmp(name, "CCD_COOLER"))
    {
        if (states[0] == ISS_ON)
        {
            if (gxccd_set_temperature(cameraHandle, TemperatureRequest) != 0)
            {
                LOGF_ERROR("Error turning on cooler.");
                return false;
            }
        }
        else
        {
            if (gxccd_set_temperature(cameraHandle, TEMP_COOLER_OFF) != 0)
            {
                LOGF_ERROR("Error turning off cooler.");
                return false;
            }
        }
        LOGF_INFO("Cooler %s", states[0] == ISS_ON ? "ON" : "OFF");
        return true;
    }
    // Handle other switches...
    return INDI::CCD::ISNewSwitch(dev, name, states, names, n);
}

Possible Problem

The issue could be related to the TEMP_COOLER_OFF value set to 100 degrees Celsius. This high value might be causing the cooler to activate at maximum power instead of turning off.?

Solution

We propose adjusting the TEMP_COOLER_OFF value to a more appropriate setting, such as -1 degrees Celsius, to ensure the cooler turns off correctly:

#define TEMP_THRESHOLD  0.2  /* Differential temperature threshold (°C) */
#define TEMP_COOLER_OFF -1   /* Temperature to turn off the cooler (°C) */

This change should help in correctly turning off the cooler when needed.

Alex Josep Lluis Eduardo Ramon

knro commented 1 month ago

@sWski Can you please take a look?

sWski commented 1 month ago

Hello guys,

I have investigated this problem again, because it seemed to me that we have already fixed this bug... I found that this was the case in the firmware of the new Cx series cameras, but the bug still exists in the old Gx series cameras.

Basically the camera has some temp. offset in EEPROM, which is set by calibration, but if this offset is negative, then when calculating the value in FW it can overflow the maximum value and the camera starts cooling.

Solutions are two:

  1. Set TEMP_COOLER_OFF to some reasonable temperature, like 50, but we don't know what kind of offsets the cameras have in them, so some of them may still overflow
  2. gxccd library will read the offset from EEPROM and compensate this bug in FW, so it will not overflow

Option 2. seems more reasonable to me, I already have this compensation programmed and I think it works as it should. Next week I would just test it more and release a new version of the library.

aeskartin commented 1 month ago

Hi Jakub,

Thank you for your message and for investigating this problem again. If you consider it necessary and don't have the means to test it yourself, I would like to offer to perform a test on one of our Gx series cameras using a remote setup. For this, I would need detailed instructions to compile the code with the solution and a straightforward way to revert the changes if necessary.

Here’s what I need:

  1. Instructions to compile the solution code: Please provide the necessary steps to download, compile, and implement the updated version of the gxccd library with the programmed compensation. Include any specific dependencies or configurations needed.

  2. Procedure to revert to the previous version: In case the solution does not work as expected, it would be helpful to have clear instructions on how to revert the changes and restore the previous version of the firmware and library. This could include specific commands or detailed steps to undo the update.

Once I have these instructions, I can perform the test and provide you with detailed feedback on the camera's behavior with the new compensation.

Thank you for your help, and I look forward to your instructions.

Best regards,

Alex

aeskartin commented 1 week ago

Here is the translation of the text you provided:


Hello everyone,
I assume that this correction is implemented in the latest version of KStars 3.7.2.

I want to share the tests I have conducted with my Moravian G2-8300, using KStars version 3.7.2 and INDI 2.0.9. Some other colleagues are also experiencing similar issues where it doesn't work correctly.

I am using KStars 3.7.2 and INDI/EKOS 2.0.9 on a Raspberry Pi 4 with Ubuntu 22.04.4 LTS aarch64, with MATE 1.26.

Here are the tests I've done with the Moravian G2-8300: By default, when everything is connected and the cooling is on in EKOS, the CCD remains at ambient temperature and the cooling power is at 0%. imagen

If I turn off the cooling in EKOS, the CCD temperature drops to the minimum, the cooling power remains at 100%, and it goes down to -30ºC. imagen

If I turn the cooling back on in EKOS, the temperature now stays at 0ºC, and the cooling power at 20%. To bring it back to ambient temperature and the cooling power to 0%, I have to set the target temperature to +30ºC. imagen


Let me know if you need any further adjustments or assistance!

Alex