* 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.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_FOC_FOC_CFG_H
#define __APPS_EXAMPLES_FOC_FOC_CFG_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_EXAMPLES_FOC_SENSORLESS) && \
defined(CONFIG_EXAMPLES_FOC_SENSORED)
# error Simultaneous support for sensorless and sensored mode not supported
#endif
#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS
# ifndef CONFIG_EXAMPLES_FOC_HAVE_VEL
# error
# endif
#endif
#if defined(CONFIG_EXAMPLES_FOC_HAVE_POS) && \
!defined(CONFIG_EXAMPLES_FOC_HAVE_VEL)
# error Position controller needs velocity controller
#endif
#if defined(CONFIG_EXAMPLES_FOC_HAVE_VEL) && \
!defined(CONFIG_EXAMPLES_FOC_HAVE_TORQ)
# error Velocity controller needs torque controller
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
# ifndef CONFIG_EXAMPLES_FOC_HAVE_VEL
# error open-loop needs CONFIG_EXAMPLES_FOC_HAVE_VEL set
# endif
# ifndef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
# error open-loop needs CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
# endif
#endif
#ifndef CONFIG_EXAMPLES_FOC_CONTROL_PI
# error For now only the FOC PI current controller supported
#endif
#if (CONFIG_EXAMPLES_FOC_RAMP_THR == 0)
# error CONFIG_EXAMPLES_FOC_RAMP_THR not configured
#endif
#if (CONFIG_EXAMPLES_FOC_RAMP_ACC == 0)
# error CONFIG_EXAMPLES_FOC_RAMP_ACC not configured
#endif
#if (CONFIG_EXAMPLES_FOC_RAMP_DEC == 0)
# error CONFIG_EXAMPLES_FOC_RAMP_DEC not configured
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT == 0)
# error CONFIG_EXAMPLES_FOC_IDENT_RES_CURRENT not configured
# endif
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_KI == 0)
# error CONFIG_EXAMPLES_FOC_IDENT_RES_KI not configured
# endif
# if (CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE == 0)
# error CONFIG_EXAMPLES_FOC_IDENT_IND_VOLTAGE not configured
# endif
# if (CONFIG_EXAMPLES_FOC_IDENT_RES_SEC == 0)
# error CONFIG_EXAMPLES_FOC_IDENT_RES_SEC not configured
# endif
# if (CONFIG_EXAMPLES_FOC_IDENT_IND_SEC == 0)
# error CONFIG_EXAMPLES_FOC_IDENT_IND_SEC not configured
# endif
#endif
#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
#define RAMP_CFG_THR (CONFIG_EXAMPLES_FOC_RAMP_THR / 1.0f)
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
# 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
#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO
# if CONFIG_EXAMPLES_FOC_MOTOR_POLES == 0
# error CONFIG_EXAMPLES_FOC_MOTOR_POLES must be defined
# endif
# if CONFIG_EXAMPLES_FOC_QENCO_POSMAX == 0
# error CONFIG_EXAMPLES_FOC_QENCO_POSMAX must be defined
# endif
#endif
#if !defined(CONFIG_EXAMPLES_FOC_SETPOINT_CONST) && \
!defined(CONFIG_EXAMPLES_FOC_SETPOINT_ADC) && \
!defined(CONFIG_EXAMPLES_FOC_SETPOINT_CHAR)
# error setpoint source not selected
#endif
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_ADC
# define SETPOINT_INTF_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX)
#endif
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST
# define SETPOINT_INTF_SCALE (1)
# if CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE == 0
# error CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE not configured
# endif
#endif
#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CHAR
# define SETPOINT_INTF_SCALE (1.0f / (CONFIG_EXAMPLES_FOC_SETPOINT_MAX / 1000.0f))
#endif
#if !defined(CONFIG_EXAMPLES_FOC_VBUS_CONST) && \
!defined(CONFIG_EXAMPLES_FOC_VBUS_ADC)
# error no VBUS source selected !
#endif
#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
#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 CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE not configured
# endif
#endif
#define VEL_CONTROL_PRESCALER (CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ / \
CONFIG_EXAMPLES_FOC_VELCTRL_FREQ)
#ifdef CONFIG_EXAMPLES_FOC_SENSORLESS
# if CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO > 0
# define ANGLE_MERGE_FACTOR (CONFIG_EXAMPLES_FOC_ANGOBS_MERGE_RATIO / 100.0f)
# endif
#endif
* Public Type Definition
****************************************************************************/
struct foc_thr_cfg_s
{
int fmode;
int mmode;
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
uint32_t qparam;
bool ol_force;
# ifdef CONFIG_EXAMPLES_FOC_ANGOBS
uint32_t ol_thr;
uint32_t ol_hys;
# endif
#endif
#ifdef CONFIG_EXAMPLES_FOC_CONTROL_PI
uint32_t foc_pi_kp;
uint32_t foc_pi_ki;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
uint32_t torqmax;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
uint32_t velmax;
uint32_t acc;
uint32_t dec;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
uint32_t posmax;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
uint32_t ident_res_ki;
uint32_t ident_res_curr;
uint32_t ident_res_sec;
uint32_t ident_ind_volt;
uint32_t ident_ind_sec;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
uint32_t vel_filter;
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
uint32_t vel_pll_kp;
uint32_t vel_pll_ki;
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
uint32_t vel_div_samples;
uint32_t vel_div_filter;
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI
uint32_t vel_pi_kp;
uint32_t vel_pi_ki;
#endif
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO
uint32_t ang_nfo_slow;
uint32_t ang_nfo_gain;
#endif
};
#endif