Skip to content

Commit

Permalink
Improved diagnostics for AksIM2 encoder (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiraz authored Feb 22, 2023
1 parent ddf8021 commit 530a4d5
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ extern "C" {
#define EOMTHEEMSAPPLCFG_VERSION_MAJOR (VERSION_MAJOR_OFFSET+3)
// <o> minor <0-255>
// <o> minor <0-255>
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 60
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 61

// </h>version

// <h> build date
// <o> year <2010-2030>
#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023
// <o> month <1-12>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 2
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 25
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 21
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 12
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 14
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 11
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 30
// </h>build date
// </h>Info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ typedef enum
encreader_err_NOTCONNECTED = 15, /* this error happens when the encoder type is none or encoder is not local, for example it is connected to 2foc board */
encreader_err_AKSIM2_INVALID_DATA = 16,
encreader_err_AKSIM2_CLOSE_TO_LIMITS= 17,
encreader_err_AKSIM2_CRC_ERROR = 18
encreader_err_AKSIM2_CRC_ERROR = 18,
encreader_err_AKSIM2_GENERIC = 19

} eOencoderreader_errortype_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ extern "C" {
#define EOMTHEEMSAPPLCFG_VERSION_MAJOR 3
// <o> minor <0-255>
// <o> minor <0-255>
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 42
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 43
// </h>version

// <h> build date
// <o> year <2010-2030>
#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023
// <o> month <1-12>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 2
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 25
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 21
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 12
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 14
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 12
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 30
// </h>build date

// </h>Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extern "C" {
// <o> minor <0-255>


#define EOMTHEEMSAPPLCFG_VERSION_MINOR 61
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 62


// </h>version
Expand All @@ -96,13 +96,13 @@ extern "C" {
// <o> year <2010-2030>
#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023
// <o> month <1-12>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1
#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 2
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 27
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 21
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 13
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 14
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 28
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 30

// </h>build date

Expand Down
93 changes: 64 additions & 29 deletions emBODY/eBcode/arch-arm/embobj/plus/board/EOappEncodersReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,18 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen
}
}
else
{ // we dont even have a valid reading from hal
prop.valueinfo->errortype = encreader_err_AEA_READING;
errorparam = 0xffff;
{ // we dont even have a valid reading from hal or the encoder is not properly connected to the board
prop.valueinfo->errortype = encreader_err_AKSIM2_GENERIC ;
errorparam = 0;

// notify the error (check and re-check)
eOerrmanDescriptor_t errdes = {0};
errdes.sourcedevice = eo_errman_sourcedevice_localboard;
errdes.sourceaddress = 0;
errdes.par16 = 0;
errdes.par64 = (uint64_t) (diagn.info.aksim2_status_crc) << 32;
errdes.code = eoerror_code_get(eoerror_category_HardWare, eoerror_value_HW_encoder_not_connected);
eo_errman_Error(eo_errman_GetHandle(), eo_errortype_error, NULL, NULL, &errdes);
}
} break;

Expand Down Expand Up @@ -869,7 +878,7 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen
// in par16[1] and par64[1] we put info of the 4 secondary encoders.
// so far we use prop.valueinfo->errortype but we may use also diagn for the amo

eObool_t filldiagnostics = eo_common_byte_bitcheck(p->diagnostics.config.jomomask, jomo);
eObool_t filldiagnostics = eo_common_byte_bitcheck(p->diagnostics.config.jomomask, jomo);
if(eobool_true == filldiagnostics)
{
if(eomc_enc_amo == prop.descriptor->type)
Expand All @@ -882,11 +891,11 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen
// select only 2 bytes: 1 from from diagn.type and one from diagn.info.value
uint64_t word = (0x0ff & diagn.type) | ((0xff & diagn.info.value) << 8);
// copy the word in correct position so that we have [word-enc3 | word-enc2 | word-enc1 | word-enc0]
p->diagnostics.par64[i] |= (word << (16*jomo));
p->diagnostics.par64[i] |= (word << (16*jomo));
}
}
else
{
{
switch(prop.valueinfo->errortype)
{
case encreader_err_NONE:
Expand All @@ -897,10 +906,14 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen
default:
case encreader_err_GENERIC:
{ // we dont know what is happening ... we just set the flag in par16[i].
p->diagnostics.par16[i] |= (encreader_err_GENERIC<<(4*jomo)); // shift by nibbles ..
p->diagnostics.par16[i] |= (encreader_err_GENERIC<<(4*jomo)); // shift by nibbles ..
} break;

case encreader_err_AEA_READING:
case encreader_err_AKSIM2_CLOSE_TO_LIMITS:
case encreader_err_AKSIM2_CRC_ERROR:
case encreader_err_AKSIM2_INVALID_DATA:
case encreader_err_AKSIM2_GENERIC:
case encreader_err_AEA_READING:
case encreader_err_AEA_PARITY:
case encreader_err_AEA_CHIP:
case encreader_err_QENC_GENERIC:
Expand All @@ -909,25 +922,22 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen
case encreader_err_PSC_GENERIC:
case encreader_err_POS_GENERIC:
case encreader_err_AMO_GENERIC:
case encreader_err_AKSIM2_CLOSE_TO_LIMITS:
case encreader_err_AKSIM2_CRC_ERROR:
case encreader_err_AKSIM2_INVALID_DATA:
case encreader_err_SPICHAINOF2_GENERIC:
case encreader_err_SPICHAINOF3_GENERIC:
{ // in such cases, we report the errortype and the errorparam that someone has prepared
p->diagnostics.par16[i] |= (prop.valueinfo->errortype<<(4*jomo)); // shift by nibbles ..
p->diagnostics.par64[i] &= (errorparam<<(16*jomo)); // shift by two bytes
} break;
p->diagnostics.par64[i] &= (errorparam<<(16*jomo)); // shift by two bytes
} break;
}
}
}
}

// ok, we now go to next encoder or ... we terminate the for() loop

} // for()


// now the return value. we return always OK
// now the return value. we return always OK
return eores_OK;
}

Expand Down Expand Up @@ -1332,7 +1342,7 @@ static eObool_t s_eo_appEncReader_IsValidValue_AEA(uint32_t *valueraw, eOencoder

static eObool_t s_eo_appEncReader_IsValidValue_AEA3(uint32_t *valueraw, eOencoderreader_errortype_t *error)
{
// TODO: there are no way to check the validity when using the AEA3 in SSI mode
// TODO: there is no way to check the validity when using the AEA3 in SSI mode
// if((*valueraw & 0x01) != 0x00)
// {
// *error = encreader_err_AEA_CHIP;
Expand All @@ -1343,19 +1353,44 @@ static eObool_t s_eo_appEncReader_IsValidValue_AEA3(uint32_t *valueraw, eOencode

static eObool_t s_eo_appEncReader_IsValidValue_AKSIM2(hal_spiencoder_diagnostic_t* diag, eOencoderreader_errortype_t *error)
{
switch(diag->type)
{
case hal_spiencoder_diagnostic_type_aksim2_invalid_data:
*error = encreader_err_AKSIM2_INVALID_DATA;
return eobool_false;
case hal_spiencoder_diagnostic_type_aksim2_crc_error:
*error = encreader_err_AKSIM2_CRC_ERROR;
return eobool_false;
case hal_spiencoder_diagnostic_type_aksim2_close_to_limits:
*error = encreader_err_AKSIM2_CLOSE_TO_LIMITS;
break;
default:
*error = encreader_err_NONE;
// switch(diag->type)
// {
// case hal_spiencoder_diagnostic_type_aksim2_invalid_data:
// *error = encreader_err_AKSIM2_INVALID_DATA;
// return eobool_false;
// case hal_spiencoder_diagnostic_type_aksim2_crc_error:
// *error = encreader_err_AKSIM2_CRC_ERROR;
// return eobool_false;
// case hal_spiencoder_diagnostic_type_aksim2_close_to_limits:
// *error = encreader_err_AKSIM2_CLOSE_TO_LIMITS;
// break;
// default:
// *error = encreader_err_NONE;
// }
//
// TODO: check and re-check
eOerrmanDescriptor_t errdes = {0};
errdes.sourcedevice = eo_errman_sourcedevice_localboard;
errdes.sourceaddress = 0;
errdes.par16 = 0;
errdes.par64 = (uint64_t) (diag->info.aksim2_status_crc) << 32;

if(0x04 == (0x04 & diag->info.aksim2_status_crc))
{
errdes.code = eoerror_code_get(eoerror_category_HardWare, eoerror_value_HW_encoder_invalid_value);
eo_errman_Error(eo_errman_GetHandle(), eo_errortype_error, NULL, NULL, &errdes);
}

if(0x02 == (0x02 & diag->info.aksim2_status_crc))
{
errdes.code = eoerror_code_get(eoerror_category_HardWare, eoerror_value_HW_encoder_close_to_limits);
eo_errman_Error(eo_errman_GetHandle(), eo_errortype_error, NULL, NULL, &errdes);
}

if(0x01 == (0x01 & diag->info.aksim2_status_crc))
{
errdes.code = eoerror_code_get(eoerror_category_HardWare, eoerror_value_HW_encoder_crc);
eo_errman_Error(eo_errman_GetHandle(), eo_errortype_error, NULL, NULL, &errdes);
}

return eobool_true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ typedef enum
hal_spiencoder_diagnostic_type_aksim2_invalid_data = 5,
hal_spiencoder_diagnostic_type_aksim2_close_to_limits = 6,
hal_spiencoder_diagnostic_type_aksim2_crc_error = 7,
hal_spiencoder_diagnostic_type_aksim2_not_connected = 8,
} hal_spiencoder_diagnostic_type_t;

typedef struct
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,16 @@ extern hal_result_t hal_spiencoder_get_value2(hal_spiencoder_t id, hal_spiencode
diagn->info.aksim2_status_crc |= 0x01;
}


// Check for SPI reading errors: if all data are FF then the encoder is not connected or the SPI is not working.
if (intitem->multiturncounter == 0xFFFF && intitem->position == 0x7FFFF && intitem->status_bits == 0x03 && intitem->crc == 0xFF)
{
// TODO: check if it can be manage it, or remove everything berfore the return because these diagnostic is not currently used.
diagn->type = hal_spiencoder_diagnostic_type_aksim2_not_connected;
diagn->info.value = 0;
return hal_res_NOK_generic;
}

*pos = intitem->position;
}
else if (intitem->config.type == hal_spiencoder_typeAMO)
Expand Down

0 comments on commit 530a4d5

Please sign in to comment.