EN RU CN
CMD_READ_PARAMS_EXT and offset values using v2.55b api?
  • I am using v2.55b version of the firmware and testing api.

    I'm probably doing something wrong here, but my data returned from a call to CMD_READ_PARAMS_EXT seems to be off..
    for example in my resulting CMD_PARAMS_EXT struct the Mag_Declination and Mag_trust are the same as well as the OUTER_P and OUTER_I are all zero, I know I have set values in those fields via the ui.
    Mag_trust should be 50 (32) and Declination should be 12(C) I see those values in the raw hex (see below) but they dont seem to line up with the documentation for the api...

    am I doing something wrong here? anyone see any reason this may happen?

    char GimbalResponseBuffer[128] = { 0 };
    char GimbalCommandBuffer[128] = { 0 };
    int GimbalResponseFilled = 0;

    typedef struct {
    uint8_t NOTCH_FREQ;
    uint8_t NOTCH_WIDTH;
    }NOTCH_FILTER;

    typedef struct {
    uint8_t PROFILE_ID;
    NOTCH_FILTER NOTCH_FREQ3[3];
    uint16_t LPF_FREQ[3];
    uint8_t FILTERS_EN[3];
    int16_t ENCODER_OFFSET[3];
    int16_t ENCODER_FLD_OFFSET[3];
    uint8_t ENCODER_MANUAL_SET_TIME[3];
    uint8_t MOTOR_HEATING_FACTOR[3];
    uint8_t MOTOR_COOLING_FACTOR[3];
    byte RESERVED[3];
    uint8_t MOTOR_MAG_LINK[3];
    uint16_t MOTOR_GEARING[3];
    int8_t ENCODER_LIMIT_MIN[3];
    int8_t ENCODER_LIMIT_MAX[3];
    uint8_t NOTCH1_GAIN[3];
    uint8_t NOTCH2_GAIN[3];
    uint8_t NOTCH3_GAIN[3];
    uint8_t BEEPER_VOLUME;
    uint16_t ENCODER_GEAR_RATIO[3];
    uint8_t ENCODER_TYPE[3];
    uint8_t ENCODER_CFG[3];
    uint8_t OUTER_P[3];
    uint8_t OUTER_I[3];
    int8_t MAG_AXIS_TOP;
    int8_t MAG_AXIS_RIGHT;
    uint8_t MAG_TRUST;
    int8_t MAG_DECLINATION;
    byte RESERVED2[5];
    } CMD_PARAMS_EXT;

    int Gimbal_ProcessCommand(int Timeout, byte WaitForResponse, byte Command, void *Data, int DataSize)
    {
    WaitForResponse = true;
    int i;
    int StartTime;
    int CurrentTime;
    int ResponseSize = 4;
    int InMessage = FALSE;
    char NewChar;

    if (WaitForResponse == TRUE) /* Make sure anything that might be waiting is cleared */
    {
    while (Serial3.available())
    {
    Serial3.read();
    }
    }

    if (Command != 0)
    Gimbal_SendCommand(Command, (byte*)Data, DataSize);

    Serial1.println(Command);

    GimbalResponseFilled = 0;
    if (WaitForResponse == FALSE)
    return TRUE;

    StartTime = millis();
    while (GimbalResponseFilled < ResponseSize)
    {

    CurrentTime = millis();
    if ((CurrentTime - StartTime) > Timeout)
    {
    #ifdef DEBUG_MODE
    Serial.println("Timeout");
    #endif // DEBUG_MODE
    return FALSE;
    }

    if (Serial3.available())
    {
    while (Serial1.available())
    {
    Serial1.read();
    }

    GimbalLastMessage = millis();
    NewChar = Serial3.read();
    if ((NewChar == '>') && (InMessage == FALSE))
    {
    GimbalResponseFilled = 0;
    InMessage = TRUE;
    }
    if (InMessage == TRUE)
    {
    GimbalResponseBuffer[GimbalResponseFilled++] = NewChar;
    if (GimbalResponseFilled > (GIMBAL_MAXRESPONSE - 2))
    {
    #ifdef DEBUG_MODE
    Serial.print("Overrun: ");
    Serial.println(ResponseSize);
    #endif // DEBUG_MODE

    return FALSE;
    }
    if (GimbalResponseFilled == 2 && GimbalResponseBuffer[1] != Command)
    {
    GimbalResponseFilled = 0;
    InMessage = false;
    }
    if (GimbalResponseFilled == 3)
    {
    ResponseSize = (GimbalResponseBuffer[2] + 4 + 1);
    }
    }
    }
    }

    GimbalResponseBuffer[GimbalResponseFilled] = '\0';
    if ((GimbalResponseFilled == 0) && (ResponseSize > 0))
    {
    #ifdef DEBUG_MODE
    Serial.print("No response: ");
    Serial.println(ResponseSize);
    #endif
    return FALSE;
    }

    #ifdef DEBUG_MODE
    Serial.print("Response ");
    Serial.print(GimbalResponseFilled, DEC);
    Serial.print(": ");

    for (i = 0; i < GimbalResponseFilled; i++)
    {
    Serial.print(GimbalResponseBuffer[i], HEX);
    Serial.print(" ");
    }
    Serial.println("");
    #endif

    if ((Command != 0) &&
    (GimbalResponseBuffer[1] != Command))
    {
    #ifdef DEBUG_MODE
    Serial.print("Mismatched: ");
    Serial.println(Command, HEX);
    #endif
    return FALSE;
    }
    return TRUE;
    }

    CMD_PARAMS_EXT Gimbal_CommandReadExtParams(byte Mode)
    {
    CMD_PARAMS_EXT cmd_params;
    byte DataBuffer[2];
    DataBuffer[0] = Mode;
    Gimbal_ProcessCommand(GIMBAL_COMMANDTIMEOUT, true, 33, DataBuffer, 1); /* CMD_READ_PARAMS_EXT */

    memcpy(&cmd_params, GimbalResponseBuffer + 4, sizeof(cmd_params));
    return cmd_params;
    }

    loop()
    {
    //this is an example of calling the method to get the data.
    CMD_PARAMS_EXT = Gimbal_CommandReadExtParams(0); //get ext params for profile 1
    delay(2000);
    }

    command buffered response looks like this:
    3E,21,68,FFFFFF89,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,64,64,64,64,64,64,64,64,64,FFFFFFFF,0,0,0,0,0,0,F,F,F,0,0,0,14,14,14,14,14,14,1,FFFFFFFD,32,C,0,0,0,0,0,67

    something looks offset, near the end is my mag trust(32) and declination value(C), but not sure about some of the values.

    anyone have any ideas?

    thanks
  • this is the discrepancy I see in the returned data.
    below I have mapped (based on documented data types) of returned values.
    there is a gap in the middle of the returned values that contains undefined bytes of data... any insight would be helpful.
    thanks

    header 3E 21 68 FFFFFF89
    profile 0
    notch freq1 0
    notch width1 0
    notch freq2 0
    notch width2 0
    notch freq3 0
    notch width3 0
    lpf freqs 0 0 0 0 0 0
    filter en 0 0 0
    enc offset 0 0 0 0 0 0
    enc fld offset 0 0 0 0 0 0
    enc man set tim 0 0 0
    mot heat fac 0 0 0
    mot cool fac 0 0 0
    reserved 0 0 0
    mot mag lnk 0 0 0
    mot gearing 0 0 0 0 0 0
    enc limit min 0 0 0
    enc limit max 0 0 0
    ----------------------------------------------
    not sure what these bytes are but they are throwing my data off????? 0 1 0 1 0 1 0 0 0 0 0 0

    notch gain1? 64 64 64
    notch gain2? 64 64 64
    notch gain3? 64 64 64
    ----------------------------------------------
    beeper vol FFFFFFFF
    enc gear ratio 0 0 0 0 0 0
    enc typ F F F
    enc cfg 0 0 0
    outer p 19 19 19
    outer I 19 19 19
    mag axis top 1
    mag axis right FFFFFFFD
    mag trust 32
    mag declination C
    reserved2 0 0 0 0 0
    checksum????? FFFFFF85
  • Alex or Garug?
  • I have not been using Serial Api for long time, but will again soon. However this sounds like it could be a bug, anyway something that Aleksey hopefully takes a look at.