2021-03-03 19:48:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/foc/foc_cfg.h
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#ifndef __APPS_EXAMPLES_FOC_FOC_CFG_H
|
|
|
|
#define __APPS_EXAMPLES_FOC_FOC_CFG_H
|
2021-03-03 19:48:19 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2023-08-15 14:38:02 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-31 22:25:11 +01:00
|
|
|
/* For now only torque mode supported for sensored */
|
2021-10-30 14:27:32 +02:00
|
|
|
|
2021-10-31 22:25:11 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_SENSORED
|
|
|
|
# ifndef CONFIG_EXAMPLES_FOC_HAVE_TORQ
|
|
|
|
# error
|
|
|
|
# endif
|
2021-10-30 14:27:32 +02:00
|
|
|
#endif
|
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
/* For now only sensorless velocity control supported */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS
|
|
|
|
# ifndef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2021-10-30 14:27:32 +02:00
|
|
|
/* Open-loop configuration */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
2021-10-31 20:30:37 +01:00
|
|
|
# ifndef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
|
|
|
# error
|
|
|
|
# endif
|
2021-10-30 14:27:32 +02:00
|
|
|
# ifndef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2022-02-16 14:03:16 +01:00
|
|
|
/* For now only the FOC PI current controller supported */
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_FOC_CONTROL_PI
|
|
|
|
# error For now only the FOC PI current controller supported
|
|
|
|
#endif
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
/* Velocity ramp must be configured */
|
|
|
|
|
|
|
|
#if (CONFIG_EXAMPLES_FOC_RAMP_THR == 0)
|
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
#if (CONFIG_EXAMPLES_FOC_RAMP_ACC == 0)
|
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
#if (CONFIG_EXAMPLES_FOC_RAMP_DEC == 0)
|
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ADC Iphase ratio must be provided */
|
|
|
|
|
|
|
|
#if (CONFIG_EXAMPLES_FOC_IPHASE_ADC == 0)
|
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
|
2022-08-15 14:36:04 +02:00
|
|
|
/* Motor identification support */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT == 0)
|
2022-08-18 11:38:32 +02:00
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_KI == 0)
|
2022-08-15 14:36:04 +02:00
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
# if (CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE == 0)
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_SEC == 0)
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
# if (CONFIG_EXAMPLES_FOC_IDENT_IND_SEC == 0)
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
/* Printer prescaler */
|
|
|
|
|
|
|
|
#if defined(CONFIG_INDUSTRY_FOC_HANDLER_PRINT) && \
|
|
|
|
(CONFIG_EXAMPLES_FOC_STATE_PRINT_FREQ > 0)
|
|
|
|
# define FOC_STATE_PRINT_PRE (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ / \
|
|
|
|
CONFIG_EXAMPLES_FOC_STATE_PRINT_FREQ)
|
|
|
|
#else
|
|
|
|
# undef FOC_STATE_PRINT_PRE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Velocity ramp configuration */
|
|
|
|
|
|
|
|
#define RAMP_CFG_THR (CONFIG_EXAMPLES_FOC_RAMP_THR / 1000.0f)
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
|
|
|
|
|
|
|
/* PMSM model parameters */
|
|
|
|
|
|
|
|
# define FOC_MODEL_POLES 7
|
|
|
|
# define FOC_MODEL_LOAD (1.0f)
|
|
|
|
# define FOC_MODEL_RES (0.11f)
|
|
|
|
# define FOC_MODEL_IND (0.0002f)
|
|
|
|
# define FOC_MODEL_INER (0.1f)
|
|
|
|
# define FOC_MODEL_FLUX (0.001f)
|
|
|
|
# define FOC_MODEL_INDD (0.0002f)
|
|
|
|
# define FOC_MODEL_INDQ (0.0002f)
|
|
|
|
#endif
|
|
|
|
|
2021-11-06 18:44:30 +01:00
|
|
|
/* Qenco configuration */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO
|
|
|
|
# if CONFIG_EXAMPLES_FOC_MOTOR_POLES == 0
|
|
|
|
# error
|
|
|
|
# endif
|
2021-12-05 12:20:05 +01:00
|
|
|
# if CONFIG_EXAMPLES_FOC_QENCO_POSMAX == 0
|
2021-11-06 18:44:30 +01:00
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2021-12-04 17:34:58 +01:00
|
|
|
/* Setpoint source must be specified */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_EXAMPLES_FOC_SETPOINT_CONST) && \
|
2021-12-07 17:12:58 +01:00
|
|
|
!defined(CONFIG_EXAMPLES_FOC_SETPOINT_ADC) && \
|
|
|
|
!defined(CONFIG_EXAMPLES_FOC_SETPOINT_CHAR)
|
2021-12-04 17:34:58 +01:00
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Setpoint ADC scale factor */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_ADC
|
2023-10-17 18:39:42 +02:00
|
|
|
# define SETPOINT_INTF_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX)
|
2021-12-04 17:34:58 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If constant setpoint is selected, setpoint value must be provided */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST
|
2023-10-17 18:39:42 +02:00
|
|
|
# define SETPOINT_INTF_SCALE (1)
|
2021-12-04 17:34:58 +01:00
|
|
|
# if CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE == 0
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2021-12-07 17:12:58 +01:00
|
|
|
/* CHARCTRL setpoint control */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CHAR
|
2023-10-17 18:39:42 +02:00
|
|
|
# define SETPOINT_INTF_SCALE (1.0f / (CONFIG_EXAMPLES_FOC_SETPOINT_MAX / 1000.0f))
|
2021-12-07 17:12:58 +01:00
|
|
|
#endif
|
|
|
|
|
2021-12-04 17:34:58 +01:00
|
|
|
/* VBUS source must be specified */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_EXAMPLES_FOC_VBUS_CONST) && \
|
|
|
|
!defined(CONFIG_EXAMPLES_FOC_VBUS_ADC)
|
|
|
|
# error
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* VBUS ADC scale factor */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_VBUS_ADC
|
|
|
|
# define VBUS_ADC_SCALE (CONFIG_EXAMPLES_FOC_ADC_VREF * \
|
|
|
|
CONFIG_EXAMPLES_FOC_VBUS_SCALE / \
|
|
|
|
CONFIG_EXAMPLES_FOC_ADC_MAX / \
|
|
|
|
1000.0f / \
|
|
|
|
1000.0f)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If constant VBUS is selected, VBUS value must be provided */
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_VBUS_CONST
|
|
|
|
# define VBUS_ADC_SCALE (1)
|
|
|
|
# define VBUS_CONST_VALUE (CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE / 1000.0f)
|
|
|
|
# if CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE == 0
|
|
|
|
# error
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2023-05-16 14:10:18 +02:00
|
|
|
/* Velocity controller prescaler */
|
|
|
|
|
|
|
|
#define VEL_CONTROL_PRESCALER (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ / \
|
|
|
|
CONFIG_EXAMPLES_FOC_VELCTRL_FREQ)
|
|
|
|
|
2023-08-15 14:38:02 +02:00
|
|
|
/* Open-loop to observer angle merge factor */
|
|
|
|
|
|
|
|
#if CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO > 0
|
|
|
|
# define ANGLE_MERGE_FACTOR (CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO / 100.0f)
|
|
|
|
#endif
|
|
|
|
|
2022-10-22 18:06:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definition
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct foc_thr_cfg_s
|
|
|
|
{
|
|
|
|
int fmode; /* FOC control mode */
|
|
|
|
int mmode; /* Motor control mode */
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
2023-08-15 14:38:02 +02:00
|
|
|
uint32_t qparam; /* Open-loop Q setting (x1000) */
|
|
|
|
bool ol_force; /* Force open-loop */
|
|
|
|
# ifdef CONFIG_EXAMPLES_FOC_ANGOBS
|
|
|
|
uint32_t ol_thr; /* Observer vel threshold [x1] */
|
|
|
|
uint32_t ol_hys; /* Observer vel hysteresys [x1] */
|
|
|
|
# endif
|
2022-10-22 18:06:06 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI
|
|
|
|
uint32_t foc_pi_kp; /* FOC PI Kp (x1000) */
|
|
|
|
uint32_t foc_pi_ki; /* FOC PI Ki (x1000) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
|
|
|
|
uint32_t torqmax; /* Torque max (x1000) */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
|
|
|
uint32_t velmax; /* Velocity max (x1000) */
|
2023-10-13 21:12:44 +02:00
|
|
|
uint32_t acc; /* Acceleration (x1000) */
|
|
|
|
uint32_t dec; /* Deceleration (x1000) */
|
2022-10-22 18:06:06 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
|
|
|
|
uint32_t posmax; /* Position max (x1000) */
|
|
|
|
#endif
|
2022-10-22 19:41:34 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
uint32_t ident_res_ki; /* Ident res Ki (x1000) */
|
|
|
|
uint32_t ident_res_curr; /* Ident res current (x1000) */
|
|
|
|
uint32_t ident_res_sec; /* Ident res sec */
|
|
|
|
uint32_t ident_ind_volt; /* Ident res voltage (x1000) */
|
|
|
|
uint32_t ident_ind_sec; /* Ident ind sec */
|
|
|
|
#endif
|
2022-11-05 11:00:19 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
|
|
|
uint32_t vel_filter; /* Velocity filter (x1000) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
|
|
|
|
uint32_t vel_pll_kp; /* Vel PLL observer Kp (x1000) */
|
|
|
|
uint32_t vel_pll_ki; /* Vel PLL observer Ki (x1000) */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
|
|
|
|
uint32_t vel_div_samples; /* Vel DIV observer samples */
|
|
|
|
uint32_t vel_div_filter; /* Vel DIV observer filter (x1000) */
|
|
|
|
#endif
|
2023-05-16 14:10:18 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI
|
|
|
|
uint32_t vel_pi_kp; /* Vel controller PI Kp (x1000000) */
|
|
|
|
uint32_t vel_pi_ki; /* Vel controller PI Ki (x1000000) */
|
|
|
|
#endif
|
2023-08-15 14:38:02 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_ONFO
|
|
|
|
uint32_t ang_nfo_slow; /* Ang NFO slow gain (x1) */
|
|
|
|
uint32_t ang_nfo_gain; /* Ang NFO gain (x1) */
|
|
|
|
#endif
|
2022-10-22 18:06:06 +02:00
|
|
|
};
|
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#endif /* __APPS_EXAMPLES_FOC_FOC_CFG_H */
|