Skip to content

Commit

Permalink
Add integration for AEA3 encoder (#214)
Browse files Browse the repository at this point in the history
* added new aea projx files

* ems: added test project for the aea3

* added project for AEA3 test.

it uses macro TEST_AEA3 to shape used code.

* Added support for aea3. Code cleaup is work in progress (look at TODO marker)

* bug fix mentioned in: sgiraz@562eb54#r54428766

* mc4plus: moved the tests for aea3 into a dedicated project
and also added more heap

* Add new target hal-mc4plus-ethdbg-aea3 with AEA3 macros

* add missing code for aea3 in EOappEncodersReader.c and others. Edit the way to save the bits retrieved from the sensor in hal_spiencoder.c

* Bugfix: EOappEncodersReader now init correctly with AEA

* Add missing AEA3_SUPPORT macros

* Fix minor improvements to hal

* Update: disable TEST_AEA3 macro. Minor refactoring.

* Add: define AEA3_MIN_SPIKE for AbsEncoder

* Update the AEA3 reading compliant to the datasheet (1x16 consecutives clock cycles)

* Fix temporarily spike detection algorithm when zero-crossing has been detected. Now it will not rise a spike when the encoder complete a turn.

* Update zero-cross detection condition. Now it is more accurate

* Update: AbsEncoder spike detection performed using int16_t overflow as a feature

* Update: project settings

* Update comments in both AbsEncoder and hal2

* ems: added test project for the aea3

* added project for AEA3 test.

it uses macro TEST_AEA3 to shape used code.

* Added support for aea3. Code cleaup is work in progress (look at TODO marker)

* mc4plus: moved the tests for aea3 into a dedicated project
and also added more heap

* Add new target hal-mc4plus-ethdbg-aea3 with AEA3 macros

* add missing code for aea3 in EOappEncodersReader.c and others. Edit the way to save the bits retrieved from the sensor in hal_spiencoder.c

* Fix minor improvements to hal

* Update: disable TEST_AEA3 macro. Minor refactoring.

* Add: define AEA3_MIN_SPIKE for AbsEncoder

* Update the AEA3 reading compliant to the datasheet (1x16 consecutives clock cycles)

* Update: project settings

* Update comments in both AbsEncoder and hal2

* Update configuration sources and delete test.aea3 project folder

* adjusted merge conflicts of hal + appliciation after rebase vs robotology::devel

* Removed macro HAL_SYS_VERIFY_STACK_HEAP_SIZES, updated libraried and FW version

* Add test AEA2 and AEA3 in overridden_configurator under ifdef macros (disabled by default).

* ems, mc4plus, mc2plus: enabled the second RAM bank to be able to increase HEAP to 63K and STACK to 12K
increased application version to be one more than latest devel

* mc4plus: removed the second RAM bank

* ems, mc4plus, mc2plus: adjustment after the rebase vs latest robotology/devel

Co-authored-by: marco.accame <[email protected]>
  • Loading branch information
sgiraz and marcoaccame authored Nov 24, 2021
1 parent f0c76ab commit c9e9b37
Show file tree
Hide file tree
Showing 32 changed files with 447 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ extern "C" {
// <o> stack size <0x0-0xFFFFFFFF:8>
// <i> define how much stack you want.
#ifndef HAL_SYS_CFG_STACKSIZE
#define HAL_SYS_CFG_STACKSIZE 0x00002000
#define HAL_SYS_CFG_STACKSIZE 0x00003000
#endif

// <o> heap size <0x0-0xFFFFFFFF:8>
// <i> define how much heap you want.
#ifndef HAL_SYS_CFG_HEAPSIZE
#define HAL_SYS_CFG_HEAPSIZE 0x00018000
#define HAL_SYS_CFG_HEAPSIZE 0x0001FC00
#endif

// </h>SYS module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
;#include "hal_core_cfg.h"


Stack_Size EQU 0x00002000
Stack_Size EQU 0x00003000
;Stack_Size EQU HAL_SYS_CFG_STACKSIZE
EXPORT Stack_Size

Expand All @@ -74,7 +74,7 @@ __initial_sp
; o Heap Size (in Bytes) 0x0-0xFFFFFFFF:8
; </h>

Heap_Size EQU 0x00018000
Heap_Size EQU 0x0001FC00
;Heap_Size EQU HAL_SYS_CFG_HEAPSIZE
EXPORT Heap_Size

Expand Down
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 46
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 47

// </h>version

Expand All @@ -93,9 +93,9 @@ extern "C" {
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 23
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 11
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 16
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 32
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 34
// </h>build date
// </h>Info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,86 @@ extern void eom_emsconfigurator_hid_userdef_ProcessUserdef02Event(EOMtheEMSconfi
}


// simone.girardi on 8 Nov 2021: with the following macro enabled we can test the reading on aea3 encoder.
// with a minimum effort we can use it to test other similar encoders (e.g. aea1, aea2 ...) as well.
//#define TEST_AEA
//#define TEST_AEA3

#ifdef TEST_AEA

#include <hal_spiencoder.h>
#include <hal_trace.h>

void cbk(void *p)
{
static volatile uint32_t v = 0;
v++;
}

hal_spiencoder_cfg_t cfgaea = {0};
hal_spiencoder_diagnostic_t diag = {0};

hal_spiencoder_position_t raw_value = 0;

// This function is called every 10 ms (see eom_emsconfigurator_Initialise)
extern void eom_emsconfigurator_hid_userdef_ProcessTimeout(EOMtheEMSconfigurator* p)
{
static volatile uint32_t counter = 0;
static hal_result_t res;

if(0 == counter)
{
// init aea
memmove(&cfgaea, &hal_spiencoder_cfg_default, sizeof(hal_spiencoder_cfg_default));

cfgaea.callback_on_rx = cbk;
cfgaea.priority = hal_int_priority05;
cfgaea.arg = NULL;

#ifdef TEST_AEA3
cfgaea.type = hal_spiencoder_typeAEA3;
#else
cfgaea.type = hal_spiencoder_typeAEA;
#endif
cfgaea.sdata_precheck = hal_false;
cfgaea.reg_addresses[0] = 0;
cfgaea.reg_addresses[1] = 0;

hal_spiencoder_init(hal_spiencoder1, &cfgaea);

diag.type = hal_spiencoder_diagnostic_type_none;
}
else if(0 == (counter % 1))
{
// retrieve the reading
hal_result_t r = hal_spiencoder_get_value2(hal_spiencoder1, &raw_value, &diag);

// print value
char str[64] = {0};
if(hal_res_OK == r)
{
#ifdef TEST_AEA3
hal_spiencoder_position_t raw_value_shifted = raw_value >> 1; // sensor return 16 bits --> only 14 are valid
snprintf(str, sizeof(str), "%d, %d, %f", raw_value, raw_value_shifted, ((360.0 * raw_value_shifted) / (1024.0*16))); // (360*value)/(2^14)
#else
hal_spiencoder_position_t raw_value_shifted = (raw_value >> 6) & 0x0FFF; // sensor return 16 bits --> only 12 are valid
snprintf(str, sizeof(str), "%d, %d, %f", raw_value, raw_value_shifted, ((360.0 * raw_value_shifted) / (1024.0*4))); // (360*value)/(2^14)
#endif
}
else
{
snprintf(str, sizeof(str), "aea error during hal_spiencoder_get_value2");
}

hal_trace_puts(str);

// start reading
hal_spiencoder_read_start(hal_spiencoder1);
}
counter++;
}
#endif


#undef TEST_000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ LR_IROM1 0x08020000 0x60000 { ; load region size_region
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data - memory hole of 064B on top for ipc
.ANY (+RW +ZI)
}
; RW_IRAM2 0x10000000 0x10000 { ; RW data
; .ANY (+RW +ZI)
; }
RW_IRAM2 0x10000200 0xFE00 { ; RW data - memory hole of 512B at start for fatal error on restart
.ANY (+RW +ZI)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ extern "C" {
// <o> stack size <0x0-0xFFFFFFFF:8>
// <i> define how much stack you want.
#ifndef HAL_SYS_CFG_STACKSIZE
#define HAL_SYS_CFG_STACKSIZE 0x00002000
#define HAL_SYS_CFG_STACKSIZE 0x00003000
#endif

// <o> heap size <0x0-0xFFFFFFFF:8>
// <i> define how much heap you want.
#ifndef HAL_SYS_CFG_HEAPSIZE
#define HAL_SYS_CFG_HEAPSIZE 0x00018000
#define HAL_SYS_CFG_HEAPSIZE 0x0001FC00
#endif

// </h>SYS module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
;#include "hal_core_cfg.h"


Stack_Size EQU 0x00002000
Stack_Size EQU 0x00003000
;Stack_Size EQU HAL_SYS_CFG_STACKSIZE
EXPORT Stack_Size

Expand All @@ -74,7 +74,7 @@ __initial_sp
; o Heap Size (in Bytes) 0x0-0xFFFFFFFF:8
; </h>

Heap_Size EQU 0x00018000
Heap_Size EQU 0x0001FC00
;Heap_Size EQU HAL_SYS_CFG_HEAPSIZE
EXPORT Heap_Size

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

// <h> build date
Expand All @@ -86,9 +86,9 @@ extern "C" {
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 23
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 11
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 16
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 24
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 36
// </h>build date

// </h>Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ LR_IROM1 0x08020000 0x60000 { ; load region size_region
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data - memory hole of 064B on top for ipc
.ANY (+RW +ZI)
}
; RW_IRAM2 0x10000000 0x10000 { ; RW data
; .ANY (+RW +ZI)
; }
}
}
RW_IRAM2 0x10000200 0xFE00 { ; RW data - memory hole of 512B at start for fatal error on restart
.ANY (+RW +ZI)
}
}



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 43
#define EOMTHEEMSAPPLCFG_VERSION_MINOR 44


// </h>version
Expand All @@ -100,9 +100,9 @@ extern "C" {
// <o> day <1-31>
#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 23
// <o> hour <0-23>
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 11
#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 16
// <o> minute <0-59>
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 21
#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 35

// </h>build date

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,73 @@ extern void eom_emsconfigurator_hid_userdef_ProcessUserdef02Event(EOMtheEMSconfi
eo_ethmonitor_Tick(eo_ethmonitor_GetHandle());
}

// simone.girardi on 8 Nov 2021: with the following macro enabled we can test the reading on aea3 encoder.
// with a minimum effort we can use it to test other similar encoders (e.g. aea1, aea2 ...) as well.
#if defined(TEST_AEA3)

#include <hal_spiencoder.h>
#include <hal_trace.h>

void cbk(void *p)
{
static volatile uint32_t v = 0;
v++;
}

hal_spiencoder_cfg_t cfgaea = {0};
hal_spiencoder_diagnostic_t diag = {0};

hal_spiencoder_position_t raw_value = 0;

// This function is called every 10 ms (see eom_emsconfigurator_Initialise)
extern void eom_emsconfigurator_hid_userdef_ProcessTimeout(EOMtheEMSconfigurator* p)
{
static volatile uint32_t counter = 0;
static hal_result_t res;

if(0 == counter)
{
// init aea
memmove(&cfgaea, &hal_spiencoder_cfg_default, sizeof(hal_spiencoder_cfg_default));

cfgaea.callback_on_rx = cbk;
cfgaea.priority = hal_int_priority05;
cfgaea.arg = NULL;
cfgaea.type = hal_spiencoder_typeAEA3;
cfgaea.sdata_precheck = hal_false;
cfgaea.reg_addresses[0] = 0;
cfgaea.reg_addresses[1] = 0;

hal_spiencoder_init(hal_spiencoder1, &cfgaea);

diag.type = hal_spiencoder_diagnostic_type_none;
}
else if(0 == (counter % 1))
{
// retrieve the reading
hal_result_t r = hal_spiencoder_get_value2(hal_spiencoder1, &raw_value, &diag);

// print value
char str[64] = {0};
if(hal_res_OK == r)
{
hal_spiencoder_position_t raw_value_shifted = raw_value >> 1; // sensor return 16 bits --> only 14 are valid
snprintf(str, sizeof(str), "%d, %d, %f", raw_value, raw_value_shifted, ((360.0 * raw_value_shifted) / (1024.0*16))); // (360*value)/(2^14)
}
else
{
snprintf(str, sizeof(str), "aea error during hal_spiencoder_get_value2");
}

hal_trace_puts(str);

// start reading
hal_spiencoder_read_start(hal_spiencoder1);
}
counter++;
}
#endif

// marco.accame on 20 oct 2015: this function is triggered if function eom_emssocket_Transmit() inside the task
// of EOMtheEMSconfigurator it there is a failure to transmit a UDP packet.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extern void eom_emsrunner_hid_userdef_taskDO_activity(EOMtheEMSrunner *p)
// so far we tick only the motion control.
eo_motioncontrol_Tick(eo_motioncontrol_GetHandle());

eo_mais_Tick(eo_mais_GetHandle());
eo_mais_Tick(eo_mais_GetHandle());
eo_strain_Tick(eo_strain_GetHandle());
eo_psc_Tick(eo_psc_GetHandle());
eo_pos_Tick(eo_pos_GetHandle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ LR_IROM1 0x08020000 0x60000 { ; load region size_region
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data
RW_IRAM1 0x20000000 0x1FFC0 { ; RW data - memory hole of 064B on top for ipc
.ANY (+RW +ZI)
}
; RW_IRAM2 0x10000000 0x10000 { ; RW data
}
; RW_IRAM2 0x10000200 0xFE00 { ; RW data - memory hole of 512B at start for fatal error on restart
; .ANY (+RW +ZI)
; }
}
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
Expand Down Expand Up @@ -555,7 +555,7 @@
<OPTFL>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
<IsCurrentTarget>0</IsCurrentTarget>
</OPTFL>
<CpuCode>18</CpuCode>
<DebugOpt>
Expand Down Expand Up @@ -749,7 +749,7 @@

<Group>
<GroupName>abslayer-lib</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
Expand Down
Loading

0 comments on commit c9e9b37

Please sign in to comment.