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/29 02:40:34 UTC
(nuttx-apps) 01/02: examples/foc: configure acceleration and deceleration from command line
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 8568439b8070057f26f937e54aa887d3d7754f0d
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Oct 13 21:12:44 2023 +0200
examples/foc: configure acceleration and deceleration from command line
---
examples/foc/foc_cfg.h | 4 ++--
examples/foc/foc_main.c | 4 ++++
examples/foc/foc_motor_b16.c | 4 ++--
examples/foc/foc_motor_f32.c | 4 ++--
examples/foc/foc_parseargs.c | 20 +++++++++++++++++++-
5 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/examples/foc/foc_cfg.h b/examples/foc/foc_cfg.h
index 9edb488ad..b8b0bad24 100644
--- a/examples/foc/foc_cfg.h
+++ b/examples/foc/foc_cfg.h
@@ -117,8 +117,6 @@
/* Velocity ramp configuration */
#define RAMP_CFG_THR (CONFIG_EXAMPLES_FOC_RAMP_THR / 1000.0f)
-#define RAMP_CFG_ACC (CONFIG_EXAMPLES_FOC_RAMP_ACC / 1000.0f)
-#define RAMP_CFG_DEC (CONFIG_EXAMPLES_FOC_RAMP_DEC / 1000.0f)
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
@@ -239,6 +237,8 @@ struct foc_thr_cfg_s
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
uint32_t velmax; /* Velocity max (x1000) */
+ uint32_t acc; /* Acceleration (x1000) */
+ uint32_t dec; /* Deceleration (x1000) */
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
uint32_t posmax; /* Position max (x1000) */
diff --git a/examples/foc/foc_main.c b/examples/foc/foc_main.c
index 071618a29..2d1c89cf2 100644
--- a/examples/foc/foc_main.c
+++ b/examples/foc/foc_main.c
@@ -107,6 +107,10 @@ struct args_s g_args =
.posmax = CONFIG_EXAMPLES_FOC_SETPOINT_MAX,
# endif
#endif
+#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
+ .acc = CONFIG_EXAMPLES_FOC_RAMP_ACC,
+ .dec = CONFIG_EXAMPLES_FOC_RAMP_DEC,
+#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
.ident_res_ki = CONFIG_EXAMPLES_FOC_IDENT_RES_KI,
.ident_res_curr = CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT,
diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c
index 1ceda71a3..06e79555f 100644
--- a/examples/foc/foc_motor_b16.c
+++ b/examples/foc/foc_motor_b16.c
@@ -307,8 +307,8 @@ static int foc_motor_configure(FAR struct foc_motor_b16_s *motor)
ret = foc_ramp_init_b16(&motor->ramp,
motor->per,
ftob16(RAMP_CFG_THR),
- ftob16(RAMP_CFG_ACC),
- ftob16(RAMP_CFG_ACC));
+ ftob16((motor->envp->cfg->acc / 1000.0f)),
+ ftob16((motor->envp->cfg->dec / 1000.0f)));
if (ret < 0)
{
PRINTF("ERROR: foc_ramp_init failed %d\n", ret);
diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c
index 3c7536345..795b5e82c 100644
--- a/examples/foc/foc_motor_f32.c
+++ b/examples/foc/foc_motor_f32.c
@@ -307,8 +307,8 @@ static int foc_motor_configure(FAR struct foc_motor_f32_s *motor)
ret = foc_ramp_init_f32(&motor->ramp,
motor->per,
RAMP_CFG_THR,
- RAMP_CFG_ACC,
- RAMP_CFG_ACC);
+ (motor->envp->cfg->acc / 1000.0f),
+ (motor->envp->cfg->dec / 1000.0f));
if (ret < 0)
{
PRINTF("ERROR: foc_ramp_init failed %d\n", ret);
diff --git a/examples/foc/foc_parseargs.c b/examples/foc/foc_parseargs.c
index 1c8c6adc4..1db84a928 100644
--- a/examples/foc/foc_parseargs.c
+++ b/examples/foc/foc_parseargs.c
@@ -76,6 +76,8 @@ static struct option g_long_options[] =
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
{ "vel", required_argument, 0, 'v' },
+ { "acc", required_argument, 0, 'a' },
+ { "dec", required_argument, 0, 'd' },
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
{ "pos", required_argument, 0, 'x' },
@@ -157,6 +159,10 @@ static void foc_help(FAR struct args_s *args)
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
PRINTF(" [-v] velocity [x1000]\n");
+ PRINTF(" [-a] acceleration [x1000] (default: %" PRId32 ")\n",
+ args->cfg.acc);
+ PRINTF(" [-d] deceleration [x1000] (default: %" PRId32 ")\n",
+ args->cfg.dec);
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
PRINTF(" [-x] position [x1000]\n");
@@ -238,7 +244,7 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv)
while (1)
{
- c = getopt_long(argc, argv, "ht:f:m:o:r:v:x:s:j:", g_long_options,
+ c = getopt_long(argc, argv, "ht:f:m:o:r:v:a:d:x:s:j:", g_long_options,
&option_index);
if (c == -1)
@@ -388,6 +394,18 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv)
args->cfg.velmax = atoi(optarg);
break;
}
+
+ case 'a':
+ {
+ args->cfg.acc = atoi(optarg);
+ break;
+ }
+
+ case 'd':
+ {
+ args->cfg.dec = atoi(optarg);
+ break;
+ }
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS