You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/11/03 18:08:14 UTC
[incubator-nuttx-apps] branch master updated (13bfad105 -> 8609c9208)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
from 13bfad105 examples/foc: control motor identification parameters from cmd line
new 9517b4695 industry/foc/fixed16/foc_ident.c: port changes from float32 implementation
new 4beb63792 industry/foc/fixed16/foc_ident.c: fix div operation
new 8609c9208 industry/foc/fixed16/foc_ident.c: add b16_t overflow protection
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
industry/foc/fixed16/foc_ident.c | 79 ++++++++++++++++++++++++++++++++--------
industry/foc/float/foc_ident.c | 1 +
2 files changed, 64 insertions(+), 16 deletions(-)
[incubator-nuttx-apps] 02/03: industry/foc/fixed16/foc_ident.c: fix div operation
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 4beb6379251134249519abc8911729ae9ea51b2f
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Aug 27 17:58:54 2022 +0200
industry/foc/fixed16/foc_ident.c: fix div operation
---
industry/foc/fixed16/foc_ident.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/industry/foc/fixed16/foc_ident.c b/industry/foc/fixed16/foc_ident.c
index 28433e538..fbc8eab78 100644
--- a/industry/foc/fixed16/foc_ident.c
+++ b/industry/foc/fixed16/foc_ident.c
@@ -314,8 +314,8 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
tmp1 = b16muli(ident->curr1_sum, 2);
tmp2 = b16muli(ident->curr2_sum, 2);
- curr1_avg = b16divb16(tmp1, ident->cntr);
- curr2_avg = b16divb16(tmp2, ident->cntr);
+ curr1_avg = b16divi(tmp1, ident->cntr);
+ curr2_avg = b16divi(tmp2, ident->cntr);
/* Average delta current */
@@ -374,7 +374,7 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
int foc_routine_ident_init_b16(FAR foc_routine_b16_t *r)
{
FAR struct foc_ident_b16_s *i = NULL;
- int ret = OK;
+ int ret = OK;
DEBUGASSERT(r);
[incubator-nuttx-apps] 01/03: industry/foc/fixed16/foc_ident.c: port changes from float32 implementation
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 9517b46958b70a54c2497744538c87e6e39ef7b7
Author: raiden00pl <ra...@railab.me>
AuthorDate: Tue Aug 16 09:54:19 2022 +0200
industry/foc/fixed16/foc_ident.c: port changes from float32 implementation
---
industry/foc/fixed16/foc_ident.c | 59 +++++++++++++++++++++++++++++-----------
industry/foc/float/foc_ident.c | 1 +
2 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/industry/foc/fixed16/foc_ident.c b/industry/foc/fixed16/foc_ident.c
index be9d4eaef..28433e538 100644
--- a/industry/foc/fixed16/foc_ident.c
+++ b/industry/foc/fixed16/foc_ident.c
@@ -66,6 +66,17 @@ struct foc_ident_b16_s
pid_controller_b16_t pi; /* PI controller for res */
int cntr; /* Helper counter */
int stage; /* Ident stage */
+
+ /* global data in resistance identification */
+
+ b16_t curr_sum;
+ b16_t volt_sum;
+
+ /* global data in inductance identification */
+
+ b16_t sign;
+ b16_t curr1_sum;
+ b16_t curr2_sum;
};
/****************************************************************************
@@ -193,12 +204,21 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident,
/* Increase counter */
ident->cntr += 1;
-
+ if (ident->cntr > (ident->cfg.res_steps / 3))
+ {
+ ident->volt_sum += vector2d_mag_b16(in->foc_state->vdq.q,
+ in->foc_state->vdq.d);
+ ident->curr_sum += vector2d_mag_b16(in->foc_state->idq.q,
+ in->foc_state->idq.d);
+ }
if (ident->cntr > ident->cfg.res_steps)
{
/* Get resistance */
- ident->final.res = b16divb16(vref, ident->cfg.res_current);
+ ident->final.res = b16divb16(b16mulb16(
+ ftob16(2.0f / 3.0f),
+ ident->volt_sum),
+ ident->curr_sum);
/* Force IDLE state */
@@ -216,6 +236,11 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident,
/* Reset counter */
ident->cntr = 0;
+
+ /* Reset static curr_sum and volt_sum */
+
+ ident->curr_sum = 0;
+ ident->volt_sum = 0;
}
return ret;
@@ -243,9 +268,6 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
b16_t curr1_avg = 0;
b16_t curr2_avg = 0;
b16_t delta_curr = 0;
- static b16_t sign = b16ONE;
- static b16_t curr1_sum = 0;
- static b16_t curr2_sum = 0;
b16_t tmp1 = 0;
b16_t tmp2 = 0;
b16_t tmp3 = 0;
@@ -254,23 +276,23 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
* if previous sing was +1 then we have bottom current.
*/
- if (sign > 0)
+ if (ident->sign > 0)
{
/* Average bottm current */
- curr1_sum += in->foc_state->idq.d;
+ ident->curr1_sum += in->foc_state->idq.d;
}
else
{
/* Average top current */
- curr2_sum += in->foc_state->idq.d;
+ ident->curr2_sum += in->foc_state->idq.d;
}
/* Invert voltage to generate square wave D voltage */
- sign = -sign;
- vref = b16mulb16(sign, ident->cfg.ind_volt);
+ ident->sign = -ident->sign;
+ vref = b16mulb16(ident->sign, ident->cfg.ind_volt);
/* Force alpha voltage = vref */
@@ -289,8 +311,8 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
{
/* Half samples from curr1, other half from curr2 */
- tmp1 = b16muli(curr1_sum, 2);
- tmp2 = b16muli(curr2_sum, 2);
+ tmp1 = b16muli(ident->curr1_sum, 2);
+ tmp2 = b16muli(ident->curr2_sum, 2);
curr1_avg = b16divb16(tmp1, ident->cntr);
curr2_avg = b16divb16(tmp2, ident->cntr);
@@ -330,9 +352,9 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
/* Reset static data */
- sign = b16ONE;
- curr1_sum = 0;
- curr2_sum = 0;
+ ident->sign = b16ONE;
+ ident->curr1_sum = 0;
+ ident->curr2_sum = 0;
}
return ret;
@@ -351,7 +373,8 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
int foc_routine_ident_init_b16(FAR foc_routine_b16_t *r)
{
- int ret = OK;
+ FAR struct foc_ident_b16_s *i = NULL;
+ int ret = OK;
DEBUGASSERT(r);
@@ -364,6 +387,9 @@ int foc_routine_ident_init_b16(FAR foc_routine_b16_t *r)
goto errout;
}
+ i = r->data;
+ i->sign = b16ONE;
+
errout:
return ret;
}
@@ -566,6 +592,7 @@ int foc_routine_ident_run_b16(FAR foc_routine_b16_t *r,
case FOC_IDENT_RUN_DONE:
{
ret = FOC_ROUTINE_RUN_DONE;
+ i->stage = FOC_IDENT_RUN_INIT;
break;
}
diff --git a/industry/foc/float/foc_ident.c b/industry/foc/float/foc_ident.c
index 4a04c74d3..53f5b7b06 100644
--- a/industry/foc/float/foc_ident.c
+++ b/industry/foc/float/foc_ident.c
@@ -81,6 +81,7 @@ struct foc_ident_f32_s
float sign;
float curr1_sum;
float curr2_sum;
+
#ifdef CONFIG_INDUSTRY_FOC_IDENT_FLUX
/* global data in flux linkage identification */
[incubator-nuttx-apps] 03/03: industry/foc/fixed16/foc_ident.c: add b16_t overflow protection
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 8609c92081e4a3f0fad462000748f17ff1165f01
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Aug 27 17:59:12 2022 +0200
industry/foc/fixed16/foc_ident.c: add b16_t overflow protection
---
industry/foc/fixed16/foc_ident.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/industry/foc/fixed16/foc_ident.c b/industry/foc/fixed16/foc_ident.c
index fbc8eab78..0ac5bb26b 100644
--- a/industry/foc/fixed16/foc_ident.c
+++ b/industry/foc/fixed16/foc_ident.c
@@ -39,6 +39,7 @@
****************************************************************************/
#define IDENT_PI_KP (ftob16(0.0f))
+#define B16UPPERLIMIT (0x7e000000)
/****************************************************************************
* Private Data Types
@@ -211,6 +212,15 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident,
ident->curr_sum += vector2d_mag_b16(in->foc_state->idq.q,
in->foc_state->idq.d);
}
+
+ /* Overflow protection */
+
+ if (ident->volt_sum > B16UPPERLIMIT || ident->curr_sum > B16UPPERLIMIT)
+ {
+ ret = -EOVERFLOW;
+ goto errout;
+ }
+
if (ident->cntr > ident->cfg.res_steps)
{
/* Get resistance */
@@ -243,6 +253,7 @@ int foc_ident_res_run_b16(FAR struct foc_ident_b16_s *ident,
ident->volt_sum = 0;
}
+errout:
return ret;
}
@@ -289,6 +300,14 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
ident->curr2_sum += in->foc_state->idq.d;
}
+ /* Overflow protection */
+
+ if (ident->curr1_sum > B16UPPERLIMIT || ident->curr2_sum > B16UPPERLIMIT)
+ {
+ ret = -EOVERFLOW;
+ goto errout;
+ }
+
/* Invert voltage to generate square wave D voltage */
ident->sign = -ident->sign;
@@ -357,6 +376,7 @@ int foc_ident_ind_run_b16(FAR struct foc_ident_b16_s *ident,
ident->curr2_sum = 0;
}
+errout:
return ret;
}