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 2023/10/17 14:42:48 UTC
[nuttx-apps] branch master updated (9ee4daea4 -> c8a4abfcb)
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/nuttx-apps.git
from 9ee4daea4 examples/foc: configure active breake current
new 9bcca6996 examples/foc: initialize motor phy
new 8e0819df0 examples/foc: add velocity observers
new fd0da7d4d examples/foc: open-loop needs initial phase alignment
new c8a4abfcb examples/foc: remove align configuration checks
The 4 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:
examples/foc/Kconfig | 90 +++++++++++++++-
examples/foc/foc_cfg.h | 24 +++--
examples/foc/foc_fixed16_thr.c | 8 +-
examples/foc/foc_float_thr.c | 12 ++-
examples/foc/foc_main.c | 11 ++
examples/foc/foc_motor_b16.c | 232 +++++++++++++++++++++++++++++++++++++---
examples/foc/foc_motor_b16.h | 19 +++-
examples/foc/foc_motor_f32.c | 237 ++++++++++++++++++++++++++++++++++++++---
examples/foc/foc_motor_f32.h | 19 +++-
examples/foc/foc_nxscope.c | 3 +
examples/foc/foc_nxscope.h | 1 +
examples/foc/foc_parseargs.c | 53 +++++++++
12 files changed, 656 insertions(+), 53 deletions(-)
[nuttx-apps] 01/04: examples/foc: initialize motor phy
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/nuttx-apps.git
commit 9bcca699673e02b2b905365cefb41303aa024817
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Nov 4 19:08:27 2022 +0100
examples/foc: initialize motor phy
---
examples/foc/Kconfig | 35 +++++++++++++++++++++++++++++++----
examples/foc/foc_motor_b16.c | 13 ++++++++-----
examples/foc/foc_motor_b16.h | 2 +-
examples/foc/foc_motor_f32.c | 12 +++++++-----
examples/foc/foc_motor_f32.h | 2 +-
5 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig
index 3c383464d..057dfbc3c 100644
--- a/examples/foc/Kconfig
+++ b/examples/foc/Kconfig
@@ -98,6 +98,37 @@ config EXAMPLES_FOC_SENSORED
endchoice #
+menu "Motor phy"
+
+config EXAMPLES_FOC_MOTOR_POLES
+ int "FOC example motor poles pairs"
+ default 0
+
+config EXAMPLES_FOC_MOTOR_RES
+ int "FOC example motor phase resistance (x1000000)"
+ default 0
+ ---help---
+ The unit is micro-ohm (1/1000000 ohm).
+
+config EXAMPLES_FOC_MOTOR_IND
+ int "FOC example motor phase inductance (x1000000)"
+ default 0
+ ---help---
+ The unit is micro micro-henry (1/1000000 henry).
+
+config EXAMPLES_FOC_MOTOR_FLUXLINK
+ int "FOC example motor flux linkage (x1000000)"
+ default 0
+ ---help---
+ The unit is micro-Vs (1/1000000 Vs).
+ Flux linkage can be obtained from the formula:
+ lambda_pm = (1 / sqrt(3)) * (60 / 2*PI) * (Ke / P) [Vs]
+ where:
+ Ke - motor voltage constant Ke [V/rpm]
+ P - motor pole pairs
+
+endmenu # Motor phy
+
if EXAMPLES_FOC_SENSORED
choice
@@ -115,10 +146,6 @@ endchoice # FOC sensored sensor selection
if EXAMPLES_FOC_HAVE_QENCO
-config EXAMPLES_FOC_MOTOR_POLES
- int "FOC example motor poles pairs"
- default 0
-
config EXAMPLES_FOC_QENCO_POSMAX
int "FOC example qencoder maximum position"
default 0
diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c
index 8791b4aca..f1b6be344 100644
--- a/examples/foc/foc_motor_b16.c
+++ b/examples/foc/foc_motor_b16.c
@@ -364,11 +364,13 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor)
foc_handler_cfg_b16(&motor->handler, &ctrl_cfg, &mod_cfg);
-#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES
- /* Configure motor poles */
+ /* Configure motor phy */
- motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES;
-#endif
+ motor_phy_params_init_b16(&motor->phy,
+ CONFIG_EXAMPLES_FOC_MOTOR_POLES,
+ ftob16(CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f),
+ ftob16(CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f),
+ ftob16(CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f));
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
/* Initialize PMSM model */
@@ -1200,7 +1202,8 @@ int foc_motor_get(FAR struct foc_motor_b16_s *motor)
/* Convert mechanical angle to electrical angle */
motor->angle_el = (b16muli(motor->angle_m,
- motor->poles) % MOTOR_ANGLE_E_MAX_B16);
+ motor->phy.poles) %
+ MOTOR_ANGLE_E_MAX_B16);
}
else
diff --git a/examples/foc/foc_motor_b16.h b/examples/foc/foc_motor_b16.h
index 0c3605389..8159cbb2d 100644
--- a/examples/foc/foc_motor_b16.h
+++ b/examples/foc/foc_motor_b16.h
@@ -133,7 +133,7 @@ struct foc_motor_b16_s
struct foc_model_b16_s model; /* Model handler */
struct foc_model_state_b16_s model_state; /* PMSM model state */
#endif
- uint8_t poles; /* Motor poles */
+ struct motor_phy_params_b16_s phy; /* Motor phy */
/* Motor velocity and angle handlers **************************************/
diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c
index 78eb0ea6a..fc4e7f9d2 100644
--- a/examples/foc/foc_motor_f32.c
+++ b/examples/foc/foc_motor_f32.c
@@ -362,11 +362,13 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor)
foc_handler_cfg_f32(&motor->handler, &ctrl_cfg, &mod_cfg);
-#ifdef CONFIG_EXAMPLES_FOC_MOTOR_POLES
- /* Configure motor poles */
+ /* Configure motor phy */
- motor->poles = CONFIG_EXAMPLES_FOC_MOTOR_POLES;
-#endif
+ motor_phy_params_init(&motor->phy,
+ CONFIG_EXAMPLES_FOC_MOTOR_POLES,
+ CONFIG_EXAMPLES_FOC_MOTOR_RES / 1000000.0f,
+ CONFIG_EXAMPLES_FOC_MOTOR_IND / 1000000.0f,
+ CONFIG_EXAMPLES_FOC_MOTOR_FLUXLINK / 1000000.0f);
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
/* Initialize PMSM model */
@@ -1185,7 +1187,7 @@ int foc_motor_get(FAR struct foc_motor_f32_s *motor)
/* Convert mechanical angle to electrical angle */
- motor->angle_el = fmodf(motor->angle_m * motor->poles,
+ motor->angle_el = fmodf(motor->angle_m * motor->phy.poles,
MOTOR_ANGLE_E_MAX);
}
diff --git a/examples/foc/foc_motor_f32.h b/examples/foc/foc_motor_f32.h
index fb4767885..7dac93ca8 100644
--- a/examples/foc/foc_motor_f32.h
+++ b/examples/foc/foc_motor_f32.h
@@ -133,7 +133,7 @@ struct foc_motor_f32_s
struct foc_model_f32_s model; /* Model handler */
struct foc_model_state_f32_s model_state; /* PMSM model state */
#endif
- uint8_t poles; /* Motor poles */
+ struct motor_phy_params_f32_s phy; /* Motor phy */
/* Motor velocity and angle handlers **************************************/
[nuttx-apps] 03/04: examples/foc: open-loop needs initial phase alignment
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/nuttx-apps.git
commit fd0da7d4df394484db3b012c3ace7a95a009c9ae
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Oct 13 20:42:41 2023 +0200
examples/foc: open-loop needs initial phase alignment
---
examples/foc/Kconfig | 1 +
examples/foc/foc_motor_b16.c | 78 ++++++++++++++++++++++++++++++++------------
examples/foc/foc_motor_f32.c | 78 ++++++++++++++++++++++++++++++++------------
3 files changed, 115 insertions(+), 42 deletions(-)
diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig
index 4b829ed84..35b88a589 100644
--- a/examples/foc/Kconfig
+++ b/examples/foc/Kconfig
@@ -175,6 +175,7 @@ endif # EXAMPLES_FOC_SENSORED
config EXAMPLES_FOC_HAVE_OPENLOOP
bool "FOC example have open-loop controller"
select INDUSTRY_FOC_ANGLE_OPENLOOP
+ select EXAMPLES_FOC_HAVE_ALIGN
default EXAMPLES_FOC_SENSORLESS
config EXAMPLES_FOC_HAVE_TORQ
diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c
index 06a7201d2..36c66ff21 100644
--- a/examples/foc/foc_motor_b16.c
+++ b/examples/foc/foc_motor_b16.c
@@ -577,6 +577,40 @@ errout:
return ret;
}
+/****************************************************************************
+ * Name: foc_motor_vel_reset
+ ****************************************************************************/
+
+static int foc_motor_vel_reset(FAR struct foc_motor_b16_s *motor)
+{
+ int ret = OK;
+
+ /* Reset velocity observer */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_zero_b16(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_zero_b16(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ errout:
+#endif
+ return ret;
+}
+
/****************************************************************************
* Name: foc_motor_state
****************************************************************************/
@@ -637,6 +671,27 @@ static int foc_motor_state(FAR struct foc_motor_b16_s *motor, int state)
}
}
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
+ /* Re-align motor if we change mode from FREE/STOP to CW/CCW otherwise,
+ * the open-loop may fail because the rotor position at the start is
+ * random.
+ */
+
+ if ((motor->mq.app_state == FOC_EXAMPLE_STATE_FREE ||
+ motor->mq.app_state == FOC_EXAMPLE_STATE_STOP) &&
+ (state == FOC_EXAMPLE_STATE_CW ||
+ state == FOC_EXAMPLE_STATE_CCW))
+ {
+ motor->ctrl_state = FOC_CTRL_STATE_ALIGN;
+ motor->align_done = false;
+ motor->angle_now = 0;
+
+ /* Reset velocity observer */
+
+ foc_motor_vel_reset(motor);
+ }
+#endif
+
/* Reset current setpoint */
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
@@ -706,29 +761,10 @@ static int foc_motor_run_init(FAR struct foc_motor_b16_s *motor)
{
int ret = OK;
- /* Reset velocity observer */
-
-#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
- ret = foc_velocity_zero_b16(&motor->vel_div);
- if (ret < 0)
- {
- PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
- goto errout;
- }
-#endif
-
-#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
- ret = foc_velocity_zero_b16(&motor->vel_pll);
- if (ret < 0)
- {
- PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
- goto errout;
- }
-#endif
-
#ifdef CONFIG_EXAMPLES_FOC_VELOBS
-errout:
+ ret = foc_motor_vel_reset(motor);
#endif
+
return ret;
}
diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c
index da6bdcab4..07cf16d9d 100644
--- a/examples/foc/foc_motor_f32.c
+++ b/examples/foc/foc_motor_f32.c
@@ -555,6 +555,40 @@ errout:
return ret;
}
+/****************************************************************************
+ * Name: foc_motor_vel_reset
+ ****************************************************************************/
+
+static int foc_motor_vel_reset(FAR struct foc_motor_f32_s *motor)
+{
+ int ret = OK;
+
+ /* Reset velocity observer */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_zero_f32(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_zero_f32(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ errout:
+#endif
+ return ret;
+}
+
/****************************************************************************
* Name: foc_motor_state
****************************************************************************/
@@ -614,6 +648,27 @@ static int foc_motor_state(FAR struct foc_motor_f32_s *motor, int state)
}
}
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
+ /* Re-align motor if we change mode from FREE/STOP to CW/CCW otherwise,
+ * the open-loop may fail because the rotor position at the start is
+ * random.
+ */
+
+ if ((motor->mq.app_state == FOC_EXAMPLE_STATE_FREE ||
+ motor->mq.app_state == FOC_EXAMPLE_STATE_STOP) &&
+ (state == FOC_EXAMPLE_STATE_CW ||
+ state == FOC_EXAMPLE_STATE_CCW))
+ {
+ motor->ctrl_state = FOC_CTRL_STATE_ALIGN;
+ motor->align_done = false;
+ motor->angle_now = 0.0f;
+
+ /* Reset velocity observer */
+
+ foc_motor_vel_reset(motor);
+ }
+#endif
+
/* Reset current setpoint */
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
@@ -690,29 +745,10 @@ static int foc_motor_run_init(FAR struct foc_motor_f32_s *motor)
{
int ret = OK;
- /* Reset velocity observer */
-
-#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
- ret = foc_velocity_zero_f32(&motor->vel_div);
- if (ret < 0)
- {
- PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
- goto errout;
- }
-#endif
-
-#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
- ret = foc_velocity_zero_f32(&motor->vel_pll);
- if (ret < 0)
- {
- PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
- goto errout;
- }
-#endif
-
#ifdef CONFIG_EXAMPLES_FOC_VELOBS
-errout:
+ ret = foc_motor_vel_reset(motor);
#endif
+
return ret;
}
[nuttx-apps] 02/04: examples/foc: add velocity observers
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/nuttx-apps.git
commit 8e0819df04a3f99eea3692c37446b2ed4b9608a8
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Nov 5 11:00:19 2022 +0100
examples/foc: add velocity observers
---
examples/foc/Kconfig | 54 ++++++++++++
examples/foc/foc_cfg.h | 13 +++
examples/foc/foc_fixed16_thr.c | 8 +-
examples/foc/foc_float_thr.c | 12 ++-
examples/foc/foc_main.c | 11 +++
examples/foc/foc_motor_b16.c | 185 ++++++++++++++++++++++++++++++++++++---
examples/foc/foc_motor_b16.h | 17 ++++
examples/foc/foc_motor_f32.c | 191 ++++++++++++++++++++++++++++++++++++++---
examples/foc/foc_motor_f32.h | 17 ++++
examples/foc/foc_nxscope.c | 3 +
examples/foc/foc_nxscope.h | 1 +
examples/foc/foc_parseargs.c | 53 ++++++++++++
12 files changed, 537 insertions(+), 28 deletions(-)
diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig
index 057dfbc3c..4b829ed84 100644
--- a/examples/foc/Kconfig
+++ b/examples/foc/Kconfig
@@ -189,6 +189,60 @@ config EXAMPLES_FOC_HAVE_POS
bool "FOC example position controller support"
default n
+config EXAMPLES_FOC_VELOBS
+ bool "FOC example velocity observer support"
+ default n
+
+if EXAMPLES_FOC_HAVE_VEL
+
+config EXAMPLES_FOC_VELNOW_FILTER
+ int "FOC example velocity controller (x1000)"
+ default 990
+
+endif # EXAMPLES_FOC_HAVE_VEL
+
+if EXAMPLES_FOC_VELOBS
+
+choice
+ prompt "FOC example velocity observer selection"
+ default EXAMPLES_FOC_VELOBS_DIV
+
+config EXAMPLES_FOC_VELOBS_DIV
+ bool "FOC velocity DIV observer"
+ select INDUSTRY_FOC_VELOCITY_ODIV
+
+config EXAMPLES_FOC_VELOBS_PLL
+ bool "FOC velocity PLL observer"
+ select INDUSTRY_FOC_VELOCITY_OPLL
+
+endchoice # FOC example velocity observer selection
+
+if EXAMPLES_FOC_VELOBS_DIV
+
+config EXAMPLES_FOC_VELOBS_DIV_SAMPLES
+ int "FOC velocity DIV observer samples"
+ default 10
+
+config EXAMPLES_FOC_VELOBS_DIV_FILTER
+ int "FOC velocity DIV observer filter (x1000)"
+ default 990
+
+endif # INDUSTRY_FOC_VELOCITY_ODIV
+
+if EXAMPLES_FOC_VELOBS_PLL
+
+config EXAMPLES_FOC_VELOBS_PLL_KP
+ int "FOC velocity PLL observer Kp (x1)"
+ default 0
+
+config EXAMPLES_FOC_VELOBS_PLL_KI
+ int "FOC velocity PLL observer Ki (x1)"
+ default 0
+
+endif # EXAMPLES_FOC_VELOBS_PLL
+
+endif # EXAMPLES_FOC_VELOBS
+
menu "FOC user input"
config EXAMPLES_FOC_HAVE_ADC
diff --git a/examples/foc/foc_cfg.h b/examples/foc/foc_cfg.h
index 14a1d1a47..ac2e6b3bc 100644
--- a/examples/foc/foc_cfg.h
+++ b/examples/foc/foc_cfg.h
@@ -244,6 +244,19 @@ struct foc_thr_cfg_s
uint32_t ident_ind_volt; /* Ident res voltage (x1000) */
uint32_t ident_ind_sec; /* Ident ind sec */
#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ uint32_t vel_filter; /* Velocity filter (x1000) */
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ uint32_t vel_pll_kp; /* Vel PLL observer Kp (x1000) */
+ uint32_t vel_pll_ki; /* Vel PLL observer Ki (x1000) */
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ uint32_t vel_div_samples; /* Vel DIV observer samples */
+ uint32_t vel_div_filter; /* Vel DIV observer filter (x1000) */
+#endif
};
#endif /* __APPS_EXAMPLES_FOC_FOC_CFG_H */
diff --git a/examples/foc/foc_fixed16_thr.c b/examples/foc/foc_fixed16_thr.c
index 66ce7feab..d3d7bbc5c 100644
--- a/examples/foc/foc_fixed16_thr.c
+++ b/examples/foc/foc_fixed16_thr.c
@@ -228,12 +228,12 @@ static void foc_fixed16_nxscope(FAR struct foc_nxscope_s *nxs,
nxscope_put_vb16(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VEL)
-# warning not supported yet
- i++;
+ ptr = (FAR b16_t *)&motor->vel_el;
+ nxscope_put_vb16(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VM)
-# warning not supported yet
- i++;
+ ptr = (FAR b16_t *)&motor->vel_mech;
+ nxscope_put_vb16(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VBUS)
ptr = (FAR b16_t *)&motor->vbus;
diff --git a/examples/foc/foc_float_thr.c b/examples/foc/foc_float_thr.c
index cc362a1da..94d8596be 100644
--- a/examples/foc/foc_float_thr.c
+++ b/examples/foc/foc_float_thr.c
@@ -229,12 +229,12 @@ static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs,
nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VEL)
-# warning not supported yet
- i++;
+ ptr = (FAR float *)&motor->vel_el;
+ nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VM)
-# warning not supported yet
- i++;
+ ptr = (FAR float *)&motor->vel_mech;
+ nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VBUS)
ptr = (FAR float *)&motor->vbus;
@@ -278,6 +278,10 @@ static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs,
ptr = svm3_tmp;
nxscope_put_vfloat(&nxs->nxs, i++, ptr, 4);
#endif
+#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VOBS)
+ ptr = (FAR float *)&motor->vel_obs;
+ nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1);
+#endif
nxscope_unlock(&nxs->nxs);
}
diff --git a/examples/foc/foc_main.c b/examples/foc/foc_main.c
index f4d8f95d2..9258a46f6 100644
--- a/examples/foc/foc_main.c
+++ b/examples/foc/foc_main.c
@@ -108,6 +108,17 @@ struct args_s g_args =
.ident_res_sec = CONFIG_EXAMPLES_FOC_IDENT_RES_SEC,
.ident_ind_volt = CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE,
.ident_ind_sec = CONFIG_EXAMPLES_FOC_IDENT_IND_SEC,
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ .vel_filter = CONFIG_EXAMPLES_FOC_VELNOW_FILTER,
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ .vel_pll_kp = CONFIG_EXAMPLES_FOC_VELOBS_PLL_KP,
+ .vel_pll_ki = CONFIG_EXAMPLES_FOC_VELOBS_PLL_KI,
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ .vel_div_samples = CONFIG_EXAMPLES_FOC_VELOBS_DIV_SAMPLES,
+ .vel_div_filter = CONFIG_EXAMPLES_FOC_VELOBS_DIV_FILTER,
#endif
}
};
diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c
index f1b6be344..06a7201d2 100644
--- a/examples/foc/foc_motor_b16.c
+++ b/examples/foc/foc_motor_b16.c
@@ -704,9 +704,32 @@ errout:
static int foc_motor_run_init(FAR struct foc_motor_b16_s *motor)
{
- /* Empty for now */
+ int ret = OK;
- return OK;
+ /* Reset velocity observer */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_zero_b16(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_zero_b16(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+errout:
+#endif
+ return ret;
}
/****************************************************************************
@@ -831,6 +854,12 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL
struct foc_hall_cfg_b16_s hl_cfg;
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ struct foc_vel_div_b16_cfg_s odiv_cfg;
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ struct foc_vel_pll_b16_cfg_s opll_cfg;
+#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
struct foc_routine_align_cfg_b16_s align_cfg;
#endif
@@ -944,6 +973,56 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ /* Initialize velocity observer */
+
+ ret = foc_velocity_init_b16(&motor->vel_div,
+ &g_foc_velocity_odiv_b16);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret);
+ goto errout;
+ }
+
+ /* Configure velocity observer */
+
+ odiv_cfg.samples = (motor->envp->cfg->vel_div_samples);
+ odiv_cfg.filter = ftob16(motor->envp->cfg->vel_div_samples / 1000.0f);
+ odiv_cfg.per = motor->per;
+
+ ret = foc_velocity_cfg_b16(&motor->vel_div, &odiv_cfg);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_cfg_b16 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ /* Initialize velocity observer */
+
+ ret = foc_velocity_init_b16(&motor->vel_pll,
+ &g_foc_velocity_opll_b16);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_angle_init_b16 failed %d!\n", ret);
+ goto errout;
+ }
+
+ /* Configure velocity observer */
+
+ opll_cfg.kp = ftob16(motor->envp->cfg->vel_pll_kp / 1.0f);
+ opll_cfg.ki = ftob16(motor->envp->cfg->vel_pll_ki / 1.0f);
+ opll_cfg.per = motor->per;
+
+ ret = foc_velocity_cfg_b16(&motor->vel_pll, &opll_cfg);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_cfg_b16 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
/* Initialize motor alignment routine */
@@ -1016,6 +1095,12 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ /* Store velocity filter value */
+
+ motor->vel_filter = ftob16(motor->envp->cfg->vel_filter / 1000.0f);
+#endif
+
/* Initialize controller state */
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
@@ -1087,6 +1172,28 @@ int foc_motor_deinit(FAR struct foc_motor_b16_s *motor)
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ /* Deinitialize DIV observer handler */
+
+ ret = foc_velocity_deinit_b16(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_deinit_b16 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ /* Deinitialize PLL observer handler */
+
+ ret = foc_velocity_deinit_b16(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_deinit_b16 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
/* Deinitialize motor alignment routine */
@@ -1143,9 +1250,13 @@ errout:
int foc_motor_get(FAR struct foc_motor_b16_s *motor)
{
- struct foc_angle_in_b16_s ain;
- struct foc_angle_out_b16_s aout;
- int ret = OK;
+ struct foc_angle_in_b16_s ain;
+ struct foc_angle_out_b16_s aout;
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ struct foc_velocity_in_b16_s vin;
+ struct foc_velocity_out_b16_s vout;
+#endif
+ int ret = OK;
DEBUGASSERT(motor);
@@ -1202,7 +1313,7 @@ int foc_motor_get(FAR struct foc_motor_b16_s *motor)
/* Convert mechanical angle to electrical angle */
motor->angle_el = (b16muli(motor->angle_m,
- motor->phy.poles) %
+ motor->phy.p) %
MOTOR_ANGLE_E_MAX_B16);
}
@@ -1227,20 +1338,74 @@ int foc_motor_get(FAR struct foc_motor_b16_s *motor)
motor->angle_now = motor->angle_el;
}
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ /* Update velocity handler input data */
+
+ vin.state = &motor->foc_state;
+ vin.angle = motor->angle_now;
+ vin.vel = motor->vel.now;
+ vin.dir = motor->dir;
+
+ /* Get velocity */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_run_b16(&motor->vel_div, &vin, &vout);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_run failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_run_b16(&motor->vel_pll, &vin, &vout);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_run failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+ /* Get motor electrical velocity now */
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
if (motor->openloop_now == true)
{
- /* No velocity feedback - assume that velocity now is velocity set */
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ /* Electrical velocity from observer */
- motor->vel.now = motor->vel.set;
+ motor->vel_el = motor->vel_obs;
+#else
+ UNUSED(vin);
+ UNUSED(vout);
+
+ /* No velocity feedback - assume that electical velocity is
+ * velocity set
+ */
+
+ motor->vel_el = motor->vel.set;
+#endif
}
else
#endif
{
- /* TODO: velocity observer or sensor */
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ /* Store electrical velocity */
+
+ motor->vel_el = motor->vel_obs;
+#else
+ ASSERT(0);
+#endif
}
-#ifdef CONFIG_EXAMPLES_FOC_SENSORED
+ LP_FILTER_B16(motor->vel.now, motor->vel_el, motor->vel_filter);
+
+ /* Get mechanical velocity */
+
+ motor->vel_mech = b16mulb16(motor->vel_el, motor->phy.one_by_p);
+#endif /* CONFIG_EXAMPLES_FOC_HAVE_VEL */
+
+#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_VELOBS)
errout:
#endif
return ret;
diff --git a/examples/foc/foc_motor_b16.h b/examples/foc/foc_motor_b16.h
index 8159cbb2d..843302da8 100644
--- a/examples/foc/foc_motor_b16.h
+++ b/examples/foc/foc_motor_b16.h
@@ -102,6 +102,17 @@ struct foc_motor_b16_s
b16_t angle_m; /* Motor mechanical angle */
b16_t angle_el; /* Motor electrical angle */
+ /* Velocity state *********************************************************/
+
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ b16_t vel_el; /* Velocity - electrical */
+ b16_t vel_mech; /* Velocity - mechanical */
+ b16_t vel_filter; /* Velocity low-pass filter */
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ b16_t vel_obs; /* Velocity observer output */
+#endif
+
/* Motor setpoints ********************************************************/
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
@@ -150,6 +161,12 @@ struct foc_motor_b16_s
foc_angle_b16_t qenco; /* Qenco angle handler */
char qedpath[32]; /* Qenco devpath */
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ foc_velocity_b16_t vel_div; /* DIV velocity observer */
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ foc_velocity_b16_t vel_pll; /* PLL velocity observer */
+#endif
};
/****************************************************************************
diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c
index fc4e7f9d2..da6bdcab4 100644
--- a/examples/foc/foc_motor_f32.c
+++ b/examples/foc/foc_motor_f32.c
@@ -688,9 +688,32 @@ errout:
static int foc_motor_run_init(FAR struct foc_motor_f32_s *motor)
{
- /* Empty for now */
+ int ret = OK;
- return OK;
+ /* Reset velocity observer */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_zero_f32(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_zero_f32(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_zero failed %d\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+errout:
+#endif
+ return ret;
}
/****************************************************************************
@@ -815,6 +838,12 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL
struct foc_hall_cfg_f32_s hl_cfg;
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ struct foc_vel_div_f32_cfg_s odiv_cfg;
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ struct foc_vel_pll_f32_cfg_s opll_cfg;
+#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
struct foc_routine_align_cfg_f32_s align_cfg;
#endif
@@ -928,6 +957,56 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ /* Initialize velocity observer */
+
+ ret = foc_velocity_init_f32(&motor->vel_div,
+ &g_foc_velocity_odiv_f32);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret);
+ goto errout;
+ }
+
+ /* Configure velocity observer */
+
+ odiv_cfg.samples = (motor->envp->cfg->vel_div_samples);
+ odiv_cfg.filter = (motor->envp->cfg->vel_div_samples / 1000.0f);
+ odiv_cfg.per = motor->per;
+
+ ret = foc_velocity_cfg_f32(&motor->vel_div, &odiv_cfg);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_cfg_f32 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ /* Initialize velocity observer */
+
+ ret = foc_velocity_init_f32(&motor->vel_pll,
+ &g_foc_velocity_opll_f32);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_angle_init_f32 failed %d!\n", ret);
+ goto errout;
+ }
+
+ /* Configure velocity observer */
+
+ opll_cfg.kp = (motor->envp->cfg->vel_pll_kp / 1.0f);
+ opll_cfg.ki = (motor->envp->cfg->vel_pll_ki / 1.0f);
+ opll_cfg.per = motor->per;
+
+ ret = foc_velocity_cfg_f32(&motor->vel_pll, &opll_cfg);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_cfg_f32 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
/* Initialize motor alignment routine */
@@ -997,6 +1076,12 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ /* Store velocity filter value */
+
+ motor->vel_filter = motor->envp->cfg->vel_filter / 1000.0f;
+#endif
+
/* Initialize controller state */
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
@@ -1073,6 +1158,28 @@ int foc_motor_deinit(FAR struct foc_motor_f32_s *motor)
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ /* Deinitialize DIV observer handler */
+
+ ret = foc_velocity_deinit_f32(&motor->vel_div);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_deinit_f32 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ /* Deinitialize PLL observer handler */
+
+ ret = foc_velocity_deinit_f32(&motor->vel_pll);
+ if (ret < 0)
+ {
+ PRINTFV("ERROR: foc_velocity_deinit_f32 failed %d!\n", ret);
+ goto errout;
+ }
+#endif
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
/* Deinitialize motor alignment routine */
@@ -1129,9 +1236,13 @@ errout:
int foc_motor_get(FAR struct foc_motor_f32_s *motor)
{
- struct foc_angle_in_f32_s ain;
- struct foc_angle_out_f32_s aout;
- int ret = OK;
+ struct foc_angle_in_f32_s ain;
+ struct foc_angle_out_f32_s aout;
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ struct foc_velocity_in_f32_s vin;
+ struct foc_velocity_out_f32_s vout;
+#endif
+ int ret = OK;
DEBUGASSERT(motor);
@@ -1187,7 +1298,7 @@ int foc_motor_get(FAR struct foc_motor_f32_s *motor)
/* Convert mechanical angle to electrical angle */
- motor->angle_el = fmodf(motor->angle_m * motor->phy.poles,
+ motor->angle_el = fmodf(motor->angle_m * motor->phy.p,
MOTOR_ANGLE_E_MAX);
}
@@ -1212,20 +1323,80 @@ int foc_motor_get(FAR struct foc_motor_f32_s *motor)
motor->angle_now = motor->angle_el;
}
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ /* Update velocity handler input data */
+
+ vin.state = &motor->foc_state;
+ vin.angle = motor->angle_now;
+ vin.vel = motor->vel.now;
+ vin.dir = motor->dir;
+
+ /* Get velocity */
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ ret = foc_velocity_run_f32(&motor->vel_div, &vin, &vout);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_run failed %d\n", ret);
+ goto errout;
+ }
+
+ motor->vel_obs = vout.velocity;
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ ret = foc_velocity_run_f32(&motor->vel_pll, &vin, &vout);
+ if (ret < 0)
+ {
+ PRINTF("ERROR: foc_velocity_run failed %d\n", ret);
+ goto errout;
+ }
+
+ motor->vel_obs = vout.velocity;
+#endif
+
+ /* Get motor electrical velocity now */
+
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
if (motor->openloop_now == true)
{
- /* No velocity feedback - assume that velocity now is velocity set */
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ /* Electrical velocity from observer */
+
+ motor->vel_el = motor->vel_obs;
+#else
+ UNUSED(vin);
+ UNUSED(vout);
- motor->vel.now = motor->vel.set;
+ /* No velocity feedback - assume that electical velocity is
+ * velocity set
+ */
+
+ motor->vel_el = motor->vel.set;
+#endif
}
else
#endif
{
- /* TODO: velocity observer or sensor */
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ /* Store electrical velocity */
+
+ motor->vel_el = motor->vel_obs;
+#else
+ ASSERT(0);
+#endif
}
-#ifdef CONFIG_EXAMPLES_FOC_SENSORED
+ /* Store filtered velocity */
+
+ LP_FILTER(motor->vel.now, motor->vel_el, motor->vel_filter);
+
+ /* Get mechanical velocity */
+
+ motor->vel_mech = motor->vel_el * motor->phy.one_by_p;
+#endif /* CONFIG_EXAMPLES_FOC_HAVE_VEL */
+
+#if defined(CONFIG_EXAMPLES_FOC_SENSORED) || defined(CONFIG_EXAMPLES_FOC_VELOBS)
errout:
#endif
return ret;
diff --git a/examples/foc/foc_motor_f32.h b/examples/foc/foc_motor_f32.h
index 7dac93ca8..84d8a3c7b 100644
--- a/examples/foc/foc_motor_f32.h
+++ b/examples/foc/foc_motor_f32.h
@@ -102,6 +102,17 @@ struct foc_motor_f32_s
float angle_m; /* Motor mechanical angle */
float angle_el; /* Motor electrical angle */
+ /* Velocity state *********************************************************/
+
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ float vel_el; /* Velocity - electrical */
+ float vel_mech; /* Velocity - mechanical */
+ float vel_filter; /* Velocity low-pass filter */
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS
+ float vel_obs; /* Velocity observer output */
+#endif
+
/* Motor setpoints ********************************************************/
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
@@ -150,6 +161,12 @@ struct foc_motor_f32_s
foc_angle_f32_t qenco; /* Qenco angle handler */
char qedpath[32]; /* Qenco devpath */
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ foc_velocity_f32_t vel_div; /* DIV velocity observer */
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ foc_velocity_f32_t vel_pll; /* PLL velocity observer */
+#endif
};
/****************************************************************************
diff --git a/examples/foc/foc_nxscope.c b/examples/foc/foc_nxscope.c
index a6fbde880..101a07ac7 100644
--- a/examples/foc/foc_nxscope.c
+++ b/examples/foc/foc_nxscope.c
@@ -239,6 +239,9 @@ int foc_nxscope_init(FAR struct foc_nxscope_s *nxs)
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3)
nxscope_chan_init(&nxs->nxs, i++, "svm3", u.u8, 4, 0);
#endif
+#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VOBS)
+ nxscope_chan_init(&nxs->nxs, i++, "vobs", u.u8, 1, 0);
+#endif
if (i > CONFIG_EXAMPLES_FOC_NXSCOPE_CHANNELS)
{
diff --git a/examples/foc/foc_nxscope.h b/examples/foc/foc_nxscope.h
index ef7a79a6d..38a998e2a 100644
--- a/examples/foc/foc_nxscope.h
+++ b/examples/foc/foc_nxscope.h
@@ -52,6 +52,7 @@
#define FOC_NXSCOPE_DQREF (1 << 14) /* DQ reference */
#define FOC_NXSCOPE_VDQCOMP (1 << 15) /* VDQ compensation */
#define FOC_NXSCOPE_SVM3 (1 << 16) /* Space-vector modulation sector */
+#define FOC_NXSCOPE_VOBS (1 << 17) /* Output from velocity observer */
/* Max 32-bit */
/****************************************************************************
diff --git a/examples/foc/foc_parseargs.c b/examples/foc/foc_parseargs.c
index fa4de580e..609500eac 100644
--- a/examples/foc/foc_parseargs.c
+++ b/examples/foc/foc_parseargs.c
@@ -45,6 +45,11 @@
#define OPT_IIV (SCHAR_MAX + 6)
#define OPT_IIS (SCHAR_MAX + 7)
+#define OPT_VOPLLKP (SCHAR_MAX + 7)
+#define OPT_VOPLLKI (SCHAR_MAX + 8)
+#define OPT_VODIVS (SCHAR_MAX + 9)
+#define OPT_VODIVF (SCHAR_MAX + 10)
+
/****************************************************************************
* Private Data
****************************************************************************/
@@ -79,6 +84,14 @@ static struct option g_long_options[] =
{ "irs", required_argument, 0, OPT_IRS },
{ "iiv", required_argument, 0, OPT_IIV },
{ "iis", required_argument, 0, OPT_IIS },
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ { "vopllkp", required_argument, 0, OPT_VOPLLKP },
+ { "vopllki", required_argument, 0, OPT_VOPLLKI },
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ { "vodivs", required_argument, 0, OPT_VODIVS },
+ { "vodivf", required_argument, 0, OPT_VODIVF },
#endif
{ 0, 0, 0, 0 }
};
@@ -153,6 +166,18 @@ static void foc_help(void)
PRINTF(" [--iis] ind sec (default: %d)\n",
CONFIG_EXAMPLES_FOC_IDENT_IND_SEC);
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ PRINTF(" [--vopllkp] velobs PLL Kp (default: %d)\n",
+ CONFIG_EXAMPLES_FOC_VELOBS_PLL_KP);
+ PRINTF(" [--vopllki] velobs PLL Ki (default: %d)\n",
+ CONFIG_EXAMPLES_FOC_VELOBS_PLL_KI);
+#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ PRINTF(" [--vodivs] velobs DIV samples (default: %d)\n",
+ CONFIG_EXAMPLES_FOC_VELOBS_DIV_SAMPLES);
+ PRINTF(" [--vodivf] velobs DIV filter (default: %d)\n",
+ CONFIG_EXAMPLES_FOC_VELOBS_DIV_FILTER);
+#endif
}
/****************************************************************************
@@ -226,6 +251,34 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv)
}
#endif
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
+ case OPT_VOPLLKP:
+ {
+ args->cfg.vel_pll_kp = atoi(optarg);
+ break;
+ }
+
+ case OPT_VOPLLKI:
+ {
+ args->cfg.vel_pll_ki = atoi(optarg);
+ break;
+ }
+#endif
+
+#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
+ case OPT_VODIVS:
+ {
+ args->cfg.vel_div_samples = atoi(optarg);
+ break;
+ }
+
+ case OPT_VODIVF:
+ {
+ args->cfg.vel_div_filter = atoi(optarg);
+ break;
+ }
+#endif
+
case 't':
{
args->time = atoi(optarg);
[nuttx-apps] 04/04: examples/foc: remove align configuration checks
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/nuttx-apps.git
commit c8a4abfcb2b463d93071cbd55717be88e1479769
Author: raiden00pl <ra...@railab.me>
AuthorDate: Mon Oct 16 19:19:18 2023 +0200
examples/foc: remove align configuration checks
these are already done when you configure the align routine
---
examples/foc/foc_cfg.h | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/examples/foc/foc_cfg.h b/examples/foc/foc_cfg.h
index ac2e6b3bc..7a59c7c9d 100644
--- a/examples/foc/foc_cfg.h
+++ b/examples/foc/foc_cfg.h
@@ -132,17 +132,6 @@
# define FOC_MODEL_INDQ (0.0002f)
#endif
-/* Motor alignment configuration */
-
-#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
-# if CONFIG_EXAMPLES_FOC_ALIGN_VOLT == 0
-# error
-# endif
-# if CONFIG_EXAMPLES_FOC_ALIGN_SEC == 0
-# error
-# endif
-#endif
-
/* Qenco configuration */
#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO