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 103bf836081b43c22f78b684afe73cc4f5cf2f1e
Author: raiden00pl <raide...@railab.me>
AuthorDate: Mon Sep 30 12:30:17 2024 +0200

    examples/foc: fix option that disable motor controller
    
    fix some compiler error when EXAMPLES_FOC_RUN_DISABLE is enabled
---
 examples/foc/Kconfig         | 20 +++++++++++++-------
 examples/foc/foc_motor_b16.c | 15 ++++++++++++++-
 examples/foc/foc_motor_f32.c | 20 +++++++++++++-------
 3 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig
index 285870259..02a8188ec 100644
--- a/examples/foc/Kconfig
+++ b/examples/foc/Kconfig
@@ -112,19 +112,29 @@ config EXAMPLES_FOC_STATE_USE_MODEL_PMSM
                Use PMSM model instead of real hardware
 
 choice
-       prompt "FOC sensored or sensorless configuration"
+       prompt "FOC motor controller type"
        default EXAMPLES_FOC_SENSORLESS
 
 config EXAMPLES_FOC_SENSORLESS
-       bool "FOC example sensorless configuration"
+       bool "FOC example sensorless motor controller"
        select EXAMPLES_FOC_ANGOBS
+       ---help---
+               Use sensorless controller, no angle sensor required.
 
 config EXAMPLES_FOC_SENSORED
-       bool "FOC example sensored configuration"
+       bool "FOC example sensored motor controller"
        select EXAMPLES_FOC_HAVE_ALIGN
+       ---help---
+               Use sensored controller, angle sensor for motor required.
 
 endchoice #
 
+config EXAMPLES_FOC_RUN_DISABLE
+       bool "FOC Disable motor controller"
+       ---help---
+               Disable motor controller logic. Requested dq is always [0, 0].
+               Useful for testing and benchmarking.
+
 menu "Motor phy"
 
 config EXAMPLES_FOC_MOTOR_POLES
@@ -674,10 +684,6 @@ config EXAMPLES_FOC_HAVE_RUN
        bool
        default !EXAMPLES_FOC_RUN_DISABLE
 
-config EXAMPLES_FOC_RUN_DISABLE
-       bool "FOC Disable FOC motor controller"
-       default n
-
 config EXAMPLES_FOC_NXSCOPE
        bool "FOC nxscope support"
        depends on LOGGING_NXSCOPE
diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c
index aeee136a0..5cb25f610 100644
--- a/examples/foc/foc_motor_b16.c
+++ b/examples/foc/foc_motor_b16.c
@@ -581,6 +581,8 @@ errout:
   return ret;
 }
 
+#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) || \
+    defined(CONFIG_EXAMPLES_FOC_VELOBS)
 /****************************************************************************
  * Name: foc_motor_vel_reset
  ****************************************************************************/
@@ -614,6 +616,7 @@ static int foc_motor_vel_reset(FAR struct foc_motor_b16_s 
*motor)
 #endif
   return ret;
 }
+#endif
 
 /****************************************************************************
  * Name: foc_motor_state
@@ -1071,6 +1074,7 @@ static int foc_motor_ang_get(FAR struct foc_motor_b16_s 
*motor)
 #ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
   ain.vel   = motor->vel.set;
 #endif
+  ain.state = &motor->foc_state;
   ain.angle = motor->angle_now;
   ain.dir   = motor->dir;
 
@@ -1125,6 +1129,14 @@ static int foc_motor_ang_get(FAR struct foc_motor_b16_s 
*motor)
   motor->angle_obs = aout.angle;
 #endif
 
+#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN
+  /* Dummy value when motor controller disabled */
+
+  UNUSED(ain);
+  aout.type  = FOC_ANGLE_TYPE_ELE;
+  aout.angle = 0;
+#endif
+
   /* Store electrical angle from sensor or observer */
 
   if (aout.type == FOC_ANGLE_TYPE_ELE)
@@ -1247,7 +1259,8 @@ static int foc_motor_vel_get(FAR struct foc_motor_b16_s 
*motor)
   /* Get motor electrical velocity now */
 
 #if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) && \
-    !defined(CONFIG_EXAMPLES_FOC_VELOBS)
+    !defined(CONFIG_EXAMPLES_FOC_VELOBS) ||       \
+    !defined(CONFIG_EXAMPLES_FOC_HAVE_RUN)
   /* No velocity feedback - assume that electical velocity is velocity set
    * in a open-loop contorller.
    */
diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c
index be9abca0e..5ede5cb14 100644
--- a/examples/foc/foc_motor_f32.c
+++ b/examples/foc/foc_motor_f32.c
@@ -559,6 +559,8 @@ errout:
   return ret;
 }
 
+#if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) || \
+    defined(CONFIG_EXAMPLES_FOC_VELOBS)
 /****************************************************************************
  * Name: foc_motor_vel_reset
  ****************************************************************************/
@@ -592,6 +594,7 @@ static int foc_motor_vel_reset(FAR struct foc_motor_f32_s 
*motor)
 #endif
   return ret;
 }
+#endif
 
 /****************************************************************************
  * Name: foc_motor_state
@@ -1108,6 +1111,14 @@ static int foc_motor_ang_get(FAR struct foc_motor_f32_s 
*motor)
   motor->angle_obs = aout.angle;
 #endif
 
+#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN
+  /* Dummy value when motor controller disabled */
+
+  UNUSED(ain);
+  aout.type  = FOC_ANGLE_TYPE_ELE;
+  aout.angle = 0.0f;
+#endif
+
   /* Store electrical angle from sensor or observer */
 
   if (aout.type == FOC_ANGLE_TYPE_ELE)
@@ -1233,7 +1244,8 @@ static int foc_motor_vel_get(FAR struct foc_motor_f32_s 
*motor)
   /* Get motor electrical velocity now */
 
 #if defined(CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP) && \
-    !defined(CONFIG_EXAMPLES_FOC_VELOBS)
+    !defined(CONFIG_EXAMPLES_FOC_VELOBS) ||       \
+    !defined(CONFIG_EXAMPLES_FOC_HAVE_RUN)
   /* No velocity feedback - assume that electical velocity is
    * velocity set
    */
@@ -1958,12 +1970,6 @@ int foc_motor_control(FAR struct foc_motor_f32_s *motor)
         {
           motor->foc_mode = FOC_HANDLER_MODE_IDLE;
 
-#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN
-          /* Terminate */
-
-          motor->ctrl_state += 1;
-#endif
-
           break;
         }
 

Reply via email to