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
The following commit(s) were added to refs/heads/master by this push: new 839829751 examples/foc: add an option to call nxscope work from control thread 839829751 is described below commit 83982975187bfb47ceddd2399078b7e5bf4a6c92 Author: raiden00pl <raide...@railab.me> AuthorDate: Thu Oct 5 19:18:04 2023 +0200 examples/foc: add an option to call nxscope work from control thread This alows nxscope data to be sent with every cycle of the control loop, which increases the execution time of the control loop, but allows data to be sent at a highier frequency using the small nxscope buffer. Useful when tuning and debuging using RTT transfer. --- examples/foc/Kconfig | 30 +++++++++++++++++++++++++++++- examples/foc/foc_fixed16_thr.c | 9 +++++++++ examples/foc/foc_float_thr.c | 31 ++++++++++++++++++++++--------- examples/foc/foc_main.c | 3 +-- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/examples/foc/Kconfig b/examples/foc/Kconfig index c3d03f9f8..8328d02f8 100644 --- a/examples/foc/Kconfig +++ b/examples/foc/Kconfig @@ -620,12 +620,40 @@ config EXAMPLES_FOC_NXSCOPE_START frame from a NxScope master device. This allows us to capture controller data from the very beginning of its operation. +choice + prompt "FOC nxscope work caller" + default EXAMPLES_FOC_NXSCOPE_MAIN + +config EXAMPLES_FOC_NXSCOPE_MAIN + bool "FOC nxscope uses foc_main()" + ---help--- + Use foc_main() for NxScope communication. + +config EXAMPLES_FOC_NXSCOPE_CONTROL + bool "FOC nxscope uses control thread" + ---help--- + Use control thread for NxScope communication. + With this option enabled you should limit the number of nxscope channels. + Otherwise, handling incoming nxscope data may significantly delay the control + loop, and consequently, the control cycle may be missed. + config EXAMPLES_FOC_NXSCOPE_THREAD bool "FOC nxscope uses separate thread" - default n ---help--- Use a separate thread for NxScope communication. +endchoice # FOC nxscope work caller + +if EXAMPLES_FOC_NXSCOPE_CONTROL + +config EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER + int "FOC nxscope work prescaler" + default 10 + ---help--- + This option allows you to reduce the frequency of calling nxscope worker. + +endif #EXAMPLES_FOC_NXSCOPE_CONTROL + if EXAMPLES_FOC_NXSCOPE_THREAD config EXAMPLES_FOC_NXSCOPE_PRIO diff --git a/examples/foc/foc_fixed16_thr.c b/examples/foc/foc_fixed16_thr.c index 1b0c89700..fec3837f6 100644 --- a/examples/foc/foc_fixed16_thr.c +++ b/examples/foc/foc_fixed16_thr.c @@ -471,6 +471,15 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp) } #endif +#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL + /* Handle nxscope work */ + + if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER == 0) + { + foc_nxscope_work(envp->nxs); + } +#endif + /* Terminate control thread */ if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE) diff --git a/examples/foc/foc_float_thr.c b/examples/foc/foc_float_thr.c index 0e2d89d62..8c5127cc7 100644 --- a/examples/foc/foc_float_thr.c +++ b/examples/foc/foc_float_thr.c @@ -194,7 +194,9 @@ static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs, int i = nxs->ch_per_inst * motor->envp->id; #endif +#ifndef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL nxscope_lock(&nxs->nxs); +#endif #if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_IABC) ptr = (FAR float *)&motor->foc_state.curr; @@ -283,7 +285,9 @@ static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs, nxscope_put_vfloat(&nxs->nxs, i++, ptr, 1); #endif +#ifndef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL nxscope_unlock(&nxs->nxs); +#endif } #endif @@ -450,15 +454,6 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) } #endif -#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE - /* Capture nxscope samples */ - - if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_PRESCALER == 0) - { - foc_float_nxscope(envp->nxs, &motor, &dev); - } -#endif - #ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM /* Feed FOC model with data */ @@ -476,6 +471,24 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp) goto errout; } +#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE + /* Capture nxscope samples */ + + if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_PRESCALER == 0) + { + foc_float_nxscope(envp->nxs, &motor, &dev); + } +#endif + +#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_CONTROL + /* Handle nxscope work */ + + if (motor.time % CONFIG_EXAMPLES_FOC_NXSCOPE_WORK_PRESCALER == 0) + { + foc_nxscope_work(envp->nxs); + } +#endif + /* Terminate control thread */ if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE) diff --git a/examples/foc/foc_main.c b/examples/foc/foc_main.c index 79107073f..e559f2539 100644 --- a/examples/foc/foc_main.c +++ b/examples/foc/foc_main.c @@ -383,8 +383,7 @@ int main(int argc, char *argv[]) { PRINTFV("foc_main loop %d\n", time); -#if defined(CONFIG_EXAMPLES_FOC_NXSCOPE) && \ - !defined(CONFIG_EXAMPLES_FOC_NXSCOPE_THREAD) +#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE_MAIN foc_nxscope_work(&nxs); #endif