examples/foc: add option to disable open-loop operations
Initial step towards sensored control
This commit is contained in:
parent
cc4d817df4
commit
9c8e3cc46a
@ -75,6 +75,24 @@ config EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
|||||||
---help---
|
---help---
|
||||||
Use PMSM model instead of real hardware
|
Use PMSM model instead of real hardware
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "FOC sensored or sensorless configuration"
|
||||||
|
default EXAMPLES_FOC_SENSORLESS
|
||||||
|
|
||||||
|
config EXAMPLES_FOC_SENSORLESS
|
||||||
|
bool "FOC example sensorless configuration"
|
||||||
|
|
||||||
|
config EXAMPLES_FOC_SENSORED
|
||||||
|
bool "FOC example sensored configuration"
|
||||||
|
|
||||||
|
endchoice #
|
||||||
|
|
||||||
|
config EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
|
bool "FOC example have open-loop controller"
|
||||||
|
select INDUSTRY_FOC_ANGLE_OPENLOOP
|
||||||
|
default y if EXAMPLES_FOC_SENSORLESS
|
||||||
|
default n
|
||||||
|
|
||||||
menu "FOC user input"
|
menu "FOC user input"
|
||||||
|
|
||||||
config EXAMPLES_FOC_HAVE_ADC
|
config EXAMPLES_FOC_HAVE_ADC
|
||||||
@ -201,6 +219,7 @@ config EXAMPLES_FOC_OPMODE
|
|||||||
config EXAMPLES_FOC_OPENLOOP_Q
|
config EXAMPLES_FOC_OPENLOOP_Q
|
||||||
int "FOC open-loop Vq/Iq setting [x1000]"
|
int "FOC open-loop Vq/Iq setting [x1000]"
|
||||||
default 200
|
default 200
|
||||||
|
depends on EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
|
|
||||||
config EXAMPLES_FOC_IDQ_KP
|
config EXAMPLES_FOC_IDQ_KP
|
||||||
int "FOC PI controller Kp gain [x1000]"
|
int "FOC PI controller Kp gain [x1000]"
|
||||||
|
@ -31,6 +31,20 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* For now only open-loop supported */
|
||||||
|
|
||||||
|
#ifndef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
|
# error For now only open-loop supported
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Open-loop configuration */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
|
# ifndef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
||||||
|
# error
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Velocity ramp must be configured */
|
/* Velocity ramp must be configured */
|
||||||
|
|
||||||
#if (CONFIG_EXAMPLES_FOC_RAMP_THR == 0)
|
#if (CONFIG_EXAMPLES_FOC_RAMP_THR == 0)
|
||||||
|
@ -55,10 +55,6 @@
|
|||||||
# error
|
# error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
|
||||||
# error For now only open-loop supported
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Type Definition
|
* Private Type Definition
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -69,13 +65,14 @@ struct foc_motor_b16_s
|
|||||||
{
|
{
|
||||||
FAR struct foc_ctrl_env_s *envp; /* Thread env */
|
FAR struct foc_ctrl_env_s *envp; /* Thread env */
|
||||||
bool fault; /* Fault flag */
|
bool fault; /* Fault flag */
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
bool openloop_now; /* Open-loop now */
|
bool openloop_now; /* Open-loop now */
|
||||||
|
b16_t angle_ol; /* Phase angle open-loop */
|
||||||
|
foc_angle_b16_t openloop; /* Open-loop angle handler */
|
||||||
#endif
|
#endif
|
||||||
int foc_mode; /* FOC mode */
|
int foc_mode; /* FOC mode */
|
||||||
b16_t vbus; /* Power bus voltage */
|
b16_t vbus; /* Power bus voltage */
|
||||||
b16_t angle_now; /* Phase angle now */
|
b16_t angle_now; /* Phase angle now */
|
||||||
b16_t angle_ol; /* Phase angle open-loop */
|
|
||||||
b16_t vel_set; /* Velocity setting now */
|
b16_t vel_set; /* Velocity setting now */
|
||||||
b16_t vel_now; /* Velocity now */
|
b16_t vel_now; /* Velocity now */
|
||||||
b16_t vel_des; /* Velocity destination */
|
b16_t vel_des; /* Velocity destination */
|
||||||
@ -91,9 +88,6 @@ struct foc_motor_b16_s
|
|||||||
struct foc_state_s dev_state; /* FOC dev state */
|
struct foc_state_s dev_state; /* FOC dev state */
|
||||||
struct foc_params_s dev_params; /* FOC dev params */
|
struct foc_params_s dev_params; /* FOC dev params */
|
||||||
struct foc_ramp_b16_s ramp; /* Velocity ramp data */
|
struct foc_ramp_b16_s ramp; /* Velocity ramp data */
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
|
||||||
foc_angle_b16_t openloop; /* Open-loop angle handler */
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
||||||
struct foc_model_b16_s model; /* Model handler */
|
struct foc_model_b16_s model; /* Model handler */
|
||||||
struct foc_model_state_b16_s model_state; /* PMSM model state */
|
struct foc_model_state_b16_s model_state; /* PMSM model state */
|
||||||
@ -111,7 +105,7 @@ struct foc_motor_b16_s
|
|||||||
static int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
static int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
||||||
FAR struct foc_ctrl_env_s *envp)
|
FAR struct foc_ctrl_env_s *envp)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
struct foc_openloop_cfg_b16_s ol_cfg;
|
struct foc_openloop_cfg_b16_s ol_cfg;
|
||||||
#endif
|
#endif
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
@ -141,7 +135,7 @@ static int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
|||||||
motor->per = b16divi(b16ONE, CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
|
motor->per = b16divi(b16ONE, CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
|
||||||
motor->iphase_adc = ftob16((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
|
motor->iphase_adc = ftob16((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
/* Initialize open-loop angle handler */
|
/* Initialize open-loop angle handler */
|
||||||
|
|
||||||
foc_angle_init_b16(&motor->openloop,
|
foc_angle_init_b16(&motor->openloop,
|
||||||
@ -173,7 +167,7 @@ static int foc_mode_init(FAR struct foc_motor_b16_s *motor)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
case FOC_OPMODE_OL_V_VEL:
|
case FOC_OPMODE_OL_V_VEL:
|
||||||
{
|
{
|
||||||
motor->foc_mode = FOC_HANDLER_MODE_VOLTAGE;
|
motor->foc_mode = FOC_HANDLER_MODE_VOLTAGE;
|
||||||
@ -552,7 +546,7 @@ static int foc_motor_run(FAR struct foc_motor_b16_s *motor)
|
|||||||
ain.angle = motor->angle_now;
|
ain.angle = motor->angle_now;
|
||||||
ain.dir = motor->dir;
|
ain.dir = motor->dir;
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
foc_angle_run_b16(&motor->openloop, &ain, &aout);
|
foc_angle_run_b16(&motor->openloop, &ain, &aout);
|
||||||
|
|
||||||
/* Store open-loop angle */
|
/* Store open-loop angle */
|
||||||
|
@ -55,10 +55,6 @@
|
|||||||
# error
|
# error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
|
||||||
# error For now only open-loop supported
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Type Definition
|
* Private Type Definition
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -69,13 +65,14 @@ struct foc_motor_f32_s
|
|||||||
{
|
{
|
||||||
FAR struct foc_ctrl_env_s *envp; /* Thread env */
|
FAR struct foc_ctrl_env_s *envp; /* Thread env */
|
||||||
bool fault; /* Fault flag */
|
bool fault; /* Fault flag */
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
bool openloop_now; /* Open-loop now */
|
bool openloop_now; /* Open-loop now */
|
||||||
|
float angle_ol; /* Phase angle open-loop */
|
||||||
|
foc_angle_f32_t openloop; /* Open-loop angle handler */
|
||||||
#endif
|
#endif
|
||||||
int foc_mode; /* FOC mode */
|
int foc_mode; /* FOC mode */
|
||||||
float vbus; /* Power bus voltage */
|
float vbus; /* Power bus voltage */
|
||||||
float angle_now; /* Phase angle now */
|
float angle_now; /* Phase angle now */
|
||||||
float angle_ol; /* Phase angle open-loop */
|
|
||||||
float vel_set; /* Velocity setting now */
|
float vel_set; /* Velocity setting now */
|
||||||
float vel_now; /* Velocity now */
|
float vel_now; /* Velocity now */
|
||||||
float vel_des; /* Velocity destination */
|
float vel_des; /* Velocity destination */
|
||||||
@ -91,9 +88,6 @@ struct foc_motor_f32_s
|
|||||||
struct foc_state_s dev_state; /* FOC dev state */
|
struct foc_state_s dev_state; /* FOC dev state */
|
||||||
struct foc_params_s dev_params; /* FOC dev params */
|
struct foc_params_s dev_params; /* FOC dev params */
|
||||||
struct foc_ramp_f32_s ramp; /* Velocity ramp data */
|
struct foc_ramp_f32_s ramp; /* Velocity ramp data */
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
|
||||||
foc_angle_f32_t openloop; /* Open-loop angle handler */
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
||||||
struct foc_model_f32_s model; /* Model handler */
|
struct foc_model_f32_s model; /* Model handler */
|
||||||
struct foc_model_state_f32_s model_state; /* PMSM model state */
|
struct foc_model_state_f32_s model_state; /* PMSM model state */
|
||||||
@ -111,7 +105,7 @@ struct foc_motor_f32_s
|
|||||||
static int foc_motor_init(FAR struct foc_motor_f32_s *motor,
|
static int foc_motor_init(FAR struct foc_motor_f32_s *motor,
|
||||||
FAR struct foc_ctrl_env_s *envp)
|
FAR struct foc_ctrl_env_s *envp)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
struct foc_openloop_cfg_f32_s ol_cfg;
|
struct foc_openloop_cfg_f32_s ol_cfg;
|
||||||
#endif
|
#endif
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
@ -141,7 +135,7 @@ static int foc_motor_init(FAR struct foc_motor_f32_s *motor,
|
|||||||
motor->per = (float)(1.0f / CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
|
motor->per = (float)(1.0f / CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
|
||||||
motor->iphase_adc = ((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
|
motor->iphase_adc = ((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
/* Initialize open-loop angle handler */
|
/* Initialize open-loop angle handler */
|
||||||
|
|
||||||
foc_angle_init_f32(&motor->openloop,
|
foc_angle_init_f32(&motor->openloop,
|
||||||
@ -173,7 +167,7 @@ static int foc_mode_init(FAR struct foc_motor_f32_s *motor)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
case FOC_OPMODE_OL_V_VEL:
|
case FOC_OPMODE_OL_V_VEL:
|
||||||
{
|
{
|
||||||
motor->foc_mode = FOC_HANDLER_MODE_VOLTAGE;
|
motor->foc_mode = FOC_HANDLER_MODE_VOLTAGE;
|
||||||
@ -551,7 +545,7 @@ static int foc_motor_run(FAR struct foc_motor_f32_s *motor)
|
|||||||
ain.angle = motor->angle_now;
|
ain.angle = motor->angle_now;
|
||||||
ain.dir = motor->dir;
|
ain.dir = motor->dir;
|
||||||
|
|
||||||
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
foc_angle_run_f32(&motor->openloop, &ain, &aout);
|
foc_angle_run_f32(&motor->openloop, &ain, &aout);
|
||||||
|
|
||||||
/* Store open-loop angle */
|
/* Store open-loop angle */
|
||||||
|
@ -131,8 +131,10 @@ static void init_args(FAR struct args_s *args)
|
|||||||
(args->time == 0 ? CONFIG_EXAMPLES_FOC_TIME_DEFAULT : args->time);
|
(args->time == 0 ? CONFIG_EXAMPLES_FOC_TIME_DEFAULT : args->time);
|
||||||
args->mode =
|
args->mode =
|
||||||
(args->mode == 0 ? CONFIG_EXAMPLES_FOC_OPMODE : args->mode);
|
(args->mode == 0 ? CONFIG_EXAMPLES_FOC_OPMODE : args->mode);
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
args->qparam =
|
args->qparam =
|
||||||
(args->qparam == 0 ? CONFIG_EXAMPLES_FOC_OPENLOOP_Q : args->qparam);
|
(args->qparam == 0 ? CONFIG_EXAMPLES_FOC_OPENLOOP_Q : args->qparam);
|
||||||
|
#endif
|
||||||
args->pi_kp =
|
args->pi_kp =
|
||||||
(args->pi_kp == 0 ? CONFIG_EXAMPLES_FOC_IDQ_KP : args->pi_kp);
|
(args->pi_kp == 0 ? CONFIG_EXAMPLES_FOC_IDQ_KP : args->pi_kp);
|
||||||
args->pi_ki =
|
args->pi_ki =
|
||||||
@ -606,7 +608,9 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
/* Get configuration */
|
/* Get configuration */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
foc[i].qparam = args.qparam;
|
foc[i].qparam = args.qparam;
|
||||||
|
#endif
|
||||||
foc[i].mode = args.mode;
|
foc[i].mode = args.mode;
|
||||||
foc[i].pi_kp = args.pi_kp;
|
foc[i].pi_kp = args.pi_kp;
|
||||||
foc[i].pi_ki = args.pi_ki;
|
foc[i].pi_ki = args.pi_ki;
|
||||||
|
@ -80,7 +80,9 @@ static void foc_help(void)
|
|||||||
PRINTF(" 3 - motor CW\n");
|
PRINTF(" 3 - motor CW\n");
|
||||||
PRINTF(" 4 - motor CCW\n");
|
PRINTF(" 4 - motor CCW\n");
|
||||||
PRINTF(" [-j] enable specific instnaces\n");
|
PRINTF(" [-j] enable specific instnaces\n");
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
PRINTF(" [-o] openloop Vq/Iq setting [x1000]\n");
|
PRINTF(" [-o] openloop Vq/Iq setting [x1000]\n");
|
||||||
|
#endif
|
||||||
PRINTF(" [--fki] PI Kp coefficient [x1000]\n");
|
PRINTF(" [--fki] PI Kp coefficient [x1000]\n");
|
||||||
PRINTF(" [--fkp] PI Ki coefficient [x1000]\n");
|
PRINTF(" [--fkp] PI Ki coefficient [x1000]\n");
|
||||||
}
|
}
|
||||||
@ -158,11 +160,13 @@ void parse_args(FAR struct args_s *args, int argc, FAR char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
case 'o':
|
case 'o':
|
||||||
{
|
{
|
||||||
args->qparam = atoi(optarg);
|
args->qparam = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
|
@ -43,7 +43,9 @@ struct args_s
|
|||||||
{
|
{
|
||||||
int time; /* Run time limit in sec, -1 if forever */
|
int time; /* Run time limit in sec, -1 if forever */
|
||||||
int mode; /* Operation mode */
|
int mode; /* Operation mode */
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
int qparam; /* Open-loop Q setting (x1000) */
|
int qparam; /* Open-loop Q setting (x1000) */
|
||||||
|
#endif
|
||||||
uint32_t pi_kp; /* PI Kp (x1000) */
|
uint32_t pi_kp; /* PI Kp (x1000) */
|
||||||
uint32_t pi_ki; /* PI Ki (x1000) */
|
uint32_t pi_ki; /* PI Ki (x1000) */
|
||||||
uint32_t velmax; /* Velocity max (x1000) */
|
uint32_t velmax; /* Velocity max (x1000) */
|
||||||
|
@ -75,7 +75,9 @@ struct foc_ctrl_env_s
|
|||||||
int id; /* FOC device id */
|
int id; /* FOC device id */
|
||||||
int inst; /* Type specific instance counter */
|
int inst; /* Type specific instance counter */
|
||||||
int type; /* Controller type */
|
int type; /* Controller type */
|
||||||
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
||||||
int qparam; /* Open-loop Q setting (x1000) */
|
int qparam; /* Open-loop Q setting (x1000) */
|
||||||
|
#endif
|
||||||
int mode; /* Operation mode */
|
int mode; /* Operation mode */
|
||||||
uint32_t pi_kp; /* FOC PI Kp (x1000) */
|
uint32_t pi_kp; /* FOC PI Kp (x1000) */
|
||||||
uint32_t pi_ki; /* FOC PI Ki (x1000) */
|
uint32_t pi_ki; /* FOC PI Ki (x1000) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user