Skip to content

Commit

Permalink
Update with refactored and cleaned IFreader interface in embot::app::…
Browse files Browse the repository at this point in the history
…eth::encoder::experimental and added comments to structs
  • Loading branch information
MSECode committed Oct 9, 2024
1 parent e7e282c commit 32cfe01
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern "C" {
#define EOMTHEEMSAPPLCFG_VERSION_MAJOR (VERSION_MAJOR_OFFSET+3)
// <o> minor <0-255>
// <o> minor <0-255>
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 94
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 194

// </h>version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
return eores_NOK_generic;
}

extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValue_t *rv1, eOencoderreader_RawValue_t *rv2, eOencoderreader_RawValue_t *rv3)
extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValuesOfJomo_t *rawValuesArray)
{
return eores_NOK_generic;
}
Expand Down Expand Up @@ -576,7 +576,7 @@ extern eOresult_t eo_encoderreader_Scale(EOtheEncoderReader* p, uint8_t jomo, eO
return r;
}

extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValue_t *rv1, eOencoderreader_RawValue_t *rv2, eOencoderreader_RawValue_t *rv3)
extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValuesOfJomo_t *rawValuesArray)
{
if(NULL == p)
{
Expand All @@ -593,7 +593,7 @@ extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, e
return(eores_NOK_generic);
}

eOresult_t res = eo_appEncReader_GetRawValue(s_eo_theencoderreader.reader, jomo, rv1, rv2, rv3);
eOresult_t res = eo_appEncReader_GetRawValue(s_eo_theencoderreader.reader, jomo, rawValuesArray);

return(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,26 @@ typedef enum
eo_encreader_pos_none = 15
} eOencoderreader_Position_t;


// The following enum and structs are the correspondent to the the ones in
// embot::app::eth::encoder::experimental in embot_app_eth_Encoder.h

// enum for the maximum number of jomo components
enum { eOencoderreader_maxnumberofencoderperjomo = 3 };

// raw data for single component, raw value and diagnostic
typedef struct
{
int32_t val;
int32_t diagnInfo;
} eOencoderreader_RawValue_t;
} eOencoderreader_RawValueEncoder_t;

// struct for raw data and validity flag for entire jomo
typedef struct
{
eOencoderreader_RawValueEncoder_t rawvalues[eOencoderreader_maxnumberofencoderperjomo];
bool areValidReadings[eOencoderreader_maxnumberofencoderperjomo];
} eOencoderreader_RawValuesOfJomo_t;

// - declaration of extern public variables, ...deprecated: better using use _get/_set instead ------------------------
// empty-section
Expand Down Expand Up @@ -149,7 +164,8 @@ extern eOmc_encoder_t eo_encoderreader_GetType(EOtheEncoderReader* p, uint8_t jo

extern eOresult_t eo_encoderreader_Scale(EOtheEncoderReader* p, uint8_t jomo, eOencoderreader_Position_t position, eOencoderreader_Scaler *scaler);

extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValue_t *rv1, eOencoderreader_RawValue_t *rv2, eOencoderreader_RawValue_t *rv3);
// Correlated to IFreader
extern eOresult_t eo_encoderreader_GetRaw(EOtheEncoderReader *p, uint8_t jomo, eOencoderreader_RawValuesOfJomo_t *rawValuesArray);

/** @}
end of group eo_EOtheEncoderReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1662,17 +1662,15 @@ static eOresult_t s_eo_motioncontrol_updatedPositionsFromEncoders(EOtheMotionCon
res = eores_NOK_generic;
}

embot::app::eth::encoder::experimental::RawValue valraw1 {};
embot::app::eth::encoder::experimental::RawValue valraw2 {};
embot::app::eth::encoder::experimental::RawValue valraw3 {};
embot::app::eth::encoder::experimental::RawValuesOfJomo rawValsArray = {};

embot::app::eth::theEncoderReader::getInstance().GetRaw(i, valraw1, valraw2, valraw3);
embot::app::eth::theEncoderReader::getInstance().GetRaw(i, rawValsArray);

if(NULL != (jstatus = eo_entities_GetJointStatus(eo_entities_GetHandle(), i)))
{
jstatus->addinfo.multienc[0] = valraw1.val;
jstatus->addinfo.multienc[1] = valraw2.val;
jstatus->addinfo.multienc[2] = valraw1.diagnInfo;
jstatus->addinfo.multienc[0] = rawValsArray.rawvalues[0].val;
jstatus->addinfo.multienc[1] = rawValsArray.rawvalues[1].val;
jstatus->addinfo.multienc[2] = rawValsArray.rawvalues[0].diagnInfo;

}
}
Expand Down
44 changes: 7 additions & 37 deletions emBODY/eBcode/arch-arm/embobj/plus/board/EOappEncodersReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,10 +970,9 @@ extern eOresult_t eo_appEncReader_GetValue(EOappEncReader *p, uint8_t jomo, eOen

}

//TODO: fill the array with spiRawValue --> first siolution use sawtooth values
p->genericEncoderRawData[jomo][i].val = (int32_t)rawValue;
p->genericEncoderRawData[jomo][i].diagnInfo = (int32_t)rawdiagn;
// p->genericEncoderRawData[jomo][i].diagnInfo = 3;
// here we are filling the struct that contains all the raw data (value and diagnostic) with what received from the sensor
p->genericEncoderRawData[jomo].rawvalues[i].val = (int32_t)rawValue;
p->genericEncoderRawData[jomo].rawvalues[i].diagnInfo = (int32_t)rawdiagn;


// now we see if there is any diagnostics to send up. we eval the errortype
Expand Down Expand Up @@ -1065,45 +1064,16 @@ extern eObool_t eo_appEncReader_isReady(EOappEncReader *p)
return(ready);
}

extern eOresult_t eo_appEncReader_GetRawValue(EOappEncReader *p, uint8_t jomo, eOencoderreader_RawValue_t *rv1, eOencoderreader_RawValue_t *rv2, eOencoderreader_RawValue_t *rv3)
extern eOresult_t eo_appEncReader_GetRawValue(EOappEncReader *p, uint8_t jomo, eOencoderreader_RawValuesOfJomo_t *rawValuesArray)
{
//static int debug_counter = 0;
if((NULL == p) || (NULL == rv1) || (NULL == rv2) || (NULL == rv3))
static int debug_counter = 0;
if((NULL == p) || (NULL == rawValuesArray))
{
return(eores_NOK_nullpointer);
}

eOencoderreader_RawValue_t *encRawValuesVec[3] = {rv1, rv2, rv3};
memcpy(rawValuesArray, &(p->genericEncoderRawData[jomo]), sizeof(eOencoderreader_RawValuesOfJomo_t));

for(uint8_t i=0; i<3; i++)
{ // for each of the two encoders --> value1: joint enc, value2: motor enc, value3: diagn

// so far we assume no errors and we assign 0 to all values
encRawValuesVec[i]->val = p->genericEncoderRawData[jomo][i].val;
encRawValuesVec[i]->diagnInfo = p->genericEncoderRawData[jomo][i].diagnInfo;
} // for()

// // Debug code
// if(++debug_counter > 1000)
// {
// char info[128];
// snprintf(info, sizeof(info), "Diagn values are d1:%d, d2:%d, d3:%d", p->genericEncoderRawData[jomo][0].diagnInfo,
// p->genericEncoderRawData[jomo][1].diagnInfo,
// p->genericEncoderRawData[jomo][2].diagnInfo
// );
// eOerrmanDescriptor_t errdes = {0};

// errdes.code = eoerror_code_get(eoerror_category_Debug, eoerror_value_DEB_tag02);
// errdes.sourcedevice = 0;
// errdes.sourceaddress = 0;
// errdes.par16 = jomo;
// errdes.par64 = 0;
// eo_errman_Error(eo_errman_GetHandle(), eo_errortype_debug, info, NULL, &errdes);
//
// debug_counter = 0;
// }
// // ends here

// now the return value. we return always OK
return eores_OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ extern eOresult_t eo_appEncReader_UpdatedMaisConversionFactors(EOappEncReader *p
extern eOresult_t eo_appEncReader_UpdatedHallAdcConversionFactors(EOappEncReader *p, uint8_t jomo, float convFactor);
extern eOresult_t eo_appEncReader_UpdatedHallAdcOffset(EOappEncReader *p, uint8_t jomo, int32_t offset);

extern eOresult_t eo_appEncReader_GetRawValue(EOappEncReader *p, uint8_t jomo, eOencoderreader_RawValue_t *rv1, eOencoderreader_RawValue_t *rv2, eOencoderreader_RawValue_t *rv3);
// IFreader
extern eOresult_t eo_appEncReader_GetRawValue(EOappEncReader *p, uint8_t jomo, eOencoderreader_RawValuesOfJomo_t *rawValuesArray);

/** @}
end of group eo_app_encodersReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ typedef struct

} eOappEncReader_Aksim2_DiagnosticError_Counters_t;

enum { rawValue_numOfEncoders = 3 };

struct EOappEncReader_hid
{
eObool_t initted;
Expand All @@ -141,9 +139,7 @@ struct EOappEncReader_hid
eOappEncReader_hallAdc_conversionData_t hallAdcConversionData;
eo_appEncReader_amodiag_t amodiag;
eOappEncReader_Aksim2_DiagnosticError_Counters_t aksim2DiagnerrorCounters;

//array for raw values[eOappEncReader_encoders_maxnumberof] to be filled at eo_appEncReader_GetValue() call and given when eo_appEncReader_GetValueRaw is requested
eOencoderreader_RawValue_t genericEncoderRawData[eOappEncReader_jomos_maxnumberof][rawValue_numOfEncoders];
eOencoderreader_RawValuesOfJomo_t genericEncoderRawData[eOappEncReader_jomos_maxnumberof];
};


Expand Down
61 changes: 25 additions & 36 deletions emBODY/eBcode/arch-arm/embot/app/eth/embot_app_eth_Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,55 +200,44 @@ namespace embot::app::eth::encoder::v1 {



// NOTE: Currently means 9th Oct 2024
// This is an experimental interface we are currently using for collecting the raw data from the joint encoder sensors
// Currently is used only for the joint encoder. It allows to stream to the higher sw level raw value (as ticks per revolution depending on the encoder resolution)
// and diagnostic raw value depending on what provided by the HAL of the sensor
namespace embot::app::eth::encoder::experimental {

// this is just an example of an experimental interface which can match the needs of the new sensors

enum class Error : uint8_t
{
NONE = 0,
SOME = 1,
OTHER = 2
};

// maybe in the future we want more than two encoders per joint-motor entity
enum class Position : uint8_t { one = 0, two = 1, three = 2, four = 3, every = 14, none = 15};
constexpr size_t maxPOSITIONs {4};

struct RawValueDiagnostic // do we need to use it in RawValue as datatype of diagnInfo
{
uint32_t info;
};
enum class Position : uint8_t { joint = 0, motor = 1, aux = 2}; // currently we are just looking at joint encoder
constexpr size_t maxPOSITIONs {3};

struct RawValue
// This struct defines a raw value and its raw diagnostic value for an encoder of any type
// It is totally generic, the only restriction is to cast eveything to int32_t values
struct RawValueEncoder
{ // the value w/ the diagnostic
int32_t val {0}; // i would set to uint32 since hal_spiencoder_position_t is uint32_t which is the datatype of the spi raw value coming from hal
int32_t val {0};
int32_t diagnInfo{0};
};

struct Value
{ // the value w/ a possible error
int64_t raw {0}; // to accomodate high resolution values
embot::app::eth::encoder::experimental::Error error {Error::NONE}; //
};

struct Target
// This struct defines the raw encoder data (raw value and diagnostic)
// and provides the possibility to add a validity flag to the readings
// for a jomo (which is thought as the combination of up to three encoders)
// idially joint and motor encoder and an auxiliary one if needed for a particulat setup
struct RawValuesOfJomo
{ // it tells which joint-motor pair + plus the posotion of the encoder
static constexpr size_t maxJOMOs {4};
uint8_t jomo {0};
Position pos {Position::one};

constexpr Target() = default;
constexpr Target(uint8_t j, Position p) : jomo(j), pos(p) {}

constexpr bool isvalid() { return (jomo < maxJOMOs) && (embot::core::tointegral(pos) < maxPOSITIONs); }
RawValueEncoder rawvalues[maxPOSITIONs];
bool areValidReadings[maxPOSITIONs];

constexpr RawValuesOfJomo() :
rawvalues{{0, 0}, {0, 0}, {0, 0}},
areValidReadings{false, false, false} {}
};

// Currently this struct provide the interface for reading the raw encoder data for a jomo
// or for a single component of the jomo. Only the first API is actually implemented in the code
struct IFreader
{
virtual bool read(const embot::app::eth::encoder::experimental::Target &target, embot::app::eth::encoder::experimental::Value &value) = 0;
//TBD: is it better define a vector of three???
virtual bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValue &value1, embot::app::eth::encoder::experimental::RawValue &value2, embot::app::eth::encoder::experimental::RawValue &value3) = 0;
virtual bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValuesOfJomo &rawValuesArray) = 0;
virtual bool GetRawSingle(uint8_t jomo, embot::app::eth::encoder::experimental::Position pos, embot::app::eth::encoder::experimental::RawValueEncoder &rawValue) = 0;

protected:
virtual ~IFreader() {}; // cannot delete from interface but only from derived object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ namespace embot { namespace app { namespace eth {
bool Scale(const embot::app::eth::encoder::v1::Target &target, const embot::app::eth::encoder::v1::Scaler &scaler) override;

// experimental::IFreader
bool read(const embot::app::eth::encoder::experimental::Target &target, embot::app::eth::encoder::experimental::Value &value) override;
bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValuesOfJomo &rawValuesArray) override;
bool GetRawSingle(uint8_t jomo, embot::app::eth::encoder::experimental::Position pos, embot::app::eth::encoder::experimental::RawValueEncoder &rawValue) override;

bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValue &value1, embot::app::eth::encoder::experimental::RawValue &value2, embot::app::eth::encoder::experimental::RawValue &value3) override;

bool raw(uint8_t jomo, embot::app::eth::encoder::v1::Position pos, embot::app::eth::encoder::experimental::Value &value);

void log();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct embot::app::eth::theEncoderReader::Impl
bool Scale(const embot::app::eth::encoder::v1::Target &target, const embot::app::eth::encoder::v1::Scaler &scaler);

// advanced
bool read(const embot::app::eth::encoder::experimental::Target &target, embot::app::eth::encoder::experimental::Value &value);
bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValuesOfJomo &rawValuesArray);
bool GetRawSingle(uint8_t jomo, embot::app::eth::encoder::experimental::Position pos, embot::app::eth::encoder::experimental::RawValueEncoder &rawValue);

bool GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValue &value1, embot::app::eth::encoder::experimental::RawValue &value2, embot::app::eth::encoder::experimental::RawValue &value3);
};


Expand Down Expand Up @@ -114,21 +114,16 @@ bool embot::app::eth::theEncoderReader::Impl::Scale(const embot::app::eth::encod
return eores_OK == eo_encoderreader_Scale(eo_encoderreader_GetHandle(), target.jomo, static_cast<eOencoderreader_Position_t>(embot::core::tointegral(target.pos)), &sca);
}

bool embot::app::eth::theEncoderReader::Impl::read(const embot::app::eth::encoder::experimental::Target &target, embot::app::eth::encoder::experimental::Value &value)
bool embot::app::eth::theEncoderReader::Impl::GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValuesOfJomo &rawValuesArray)
{
value.raw = 0x123456789A;
value.error = embot::app::eth::encoder::experimental::Error::NONE;
eOencoderreader_RawValuesOfJomo_t *rvja = reinterpret_cast<eOencoderreader_RawValuesOfJomo_t*>(&rawValuesArray);

return true;
return eores_OK == eo_encoderreader_GetRaw(eo_encoderreader_GetHandle(), jomo, rvja);
}

bool embot::app::eth::theEncoderReader::Impl::GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValue &value1, embot::app::eth::encoder::experimental::RawValue &value2, embot::app::eth::encoder::experimental::RawValue &value3)
bool embot::app::eth::theEncoderReader::Impl::GetRawSingle(uint8_t jomo, embot::app::eth::encoder::experimental::Position pos, embot::app::eth::encoder::experimental::RawValueEncoder &rawValue)
{
eOencoderreader_RawValue_t *rv1 = reinterpret_cast<eOencoderreader_RawValue_t*>(&value1);
eOencoderreader_RawValue_t *rv2 = reinterpret_cast<eOencoderreader_RawValue_t*>(&value2);
eOencoderreader_RawValue_t *rv3 = reinterpret_cast<eOencoderreader_RawValue_t*>(&value3);

return eores_OK == eo_encoderreader_GetRaw(eo_encoderreader_GetHandle(), jomo, rv1, rv2, rv3);
return eores_OK;
}


Expand Down Expand Up @@ -205,16 +200,15 @@ bool embot::app::eth::theEncoderReader::Scale(const embot::app::eth::encoder::v1
return pImpl->Scale(target, scaler);
}

bool embot::app::eth::theEncoderReader::read(const embot::app::eth::encoder::experimental::Target &target, embot::app::eth::encoder::experimental::Value &value)
bool embot::app::eth::theEncoderReader::GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValuesOfJomo &rawValuesArray)
{
return pImpl->read(target, value);
return pImpl->GetRaw(jomo, rawValuesArray);
}

bool embot::app::eth::theEncoderReader::GetRaw(uint8_t jomo, embot::app::eth::encoder::experimental::RawValue &value1, embot::app::eth::encoder::experimental::RawValue &value2, embot::app::eth::encoder::experimental::RawValue &value3)
bool embot::app::eth::theEncoderReader::GetRawSingle(uint8_t jomo, embot::app::eth::encoder::experimental::Position pos, embot::app::eth::encoder::experimental::RawValueEncoder &rawValue)
{
return pImpl->GetRaw(jomo, value1, value2, value3);
return pImpl->GetRawSingle(jomo, pos, rawValue);
}

// - end-of-file (leave a blank line after)----------------------------------------------------------------------------


0 comments on commit 32cfe01

Please sign in to comment.