examples/foc: terminate the control thread if no work to do

This commit is contained in:
raiden00pl 2022-08-18 11:17:07 +02:00 committed by Xiang Xiao
parent 420da4589e
commit 429f5a166f
5 changed files with 38 additions and 1 deletions

View File

@ -352,6 +352,14 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp)
PRINTF("ERROR: foc_dev_params_set failed %d!\n", ret);
goto errout;
}
/* Terminate control thread */
if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE)
{
PRINTF("TERMINATE CTRL THREAD\n");
goto errout;
}
}
else
{

View File

@ -353,6 +353,14 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp)
PRINTF("ERROR: foc_dev_prams_set failed %d!\n", ret);
goto errout;
}
/* Terminate control thread */
if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE)
{
PRINTF("TERMINATE CTRL THREAD\n");
goto errout;
}
}
else
{

View File

@ -1120,6 +1120,13 @@ int foc_motor_control(FAR struct foc_motor_b16_s *motor)
break;
}
case FOC_CTRL_STATE_TERMINATE:
{
/* Do nothing */
break;
}
default:
{
PRINTF("ERROR: invalid ctrl_state=%d\n", motor->ctrl_state);

View File

@ -1112,6 +1112,19 @@ 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;
}
case FOC_CTRL_STATE_TERMINATE:
{
/* Do nothing */
break;
}

View File

@ -88,7 +88,8 @@ enum foc_controller_state_e
FOC_CTRL_STATE_RUN_INIT,
FOC_CTRL_STATE_RUN,
#endif
FOC_CTRL_STATE_IDLE
FOC_CTRL_STATE_IDLE,
FOC_CTRL_STATE_TERMINATE
};
/* FOC thread data */