2021-10-31 16:07:22 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/foc/foc_motor_b16.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_MOTOR_B16_H
|
|
|
|
#define __APPS_EXAMPLES_FOC_FOC_MOTOR_B16_H
|
2021-10-31 16:07:22 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include "foc_mq.h"
|
|
|
|
#include "foc_thr.h"
|
|
|
|
|
|
|
|
#include "industry/foc/fixed16/foc_handler.h"
|
|
|
|
#include "industry/foc/fixed16/foc_ramp.h"
|
|
|
|
#include "industry/foc/fixed16/foc_angle.h"
|
|
|
|
#include "industry/foc/fixed16/foc_velocity.h"
|
2021-10-31 22:09:21 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
|
|
|
|
# include "industry/foc/fixed16/foc_align.h"
|
|
|
|
#endif
|
2022-08-15 14:36:04 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
# include "industry/foc/fixed16/foc_ident.h"
|
|
|
|
#endif
|
2021-10-31 16:07:22 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
|
|
|
# include "industry/foc/fixed16/foc_model.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definition
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
/* FOC setpoint (fixed16) */
|
|
|
|
|
|
|
|
struct foc_setpoint_b16_s
|
|
|
|
{
|
|
|
|
b16_t set;
|
|
|
|
b16_t now;
|
|
|
|
b16_t des;
|
|
|
|
};
|
|
|
|
|
2021-10-31 16:07:22 +01:00
|
|
|
/* FOC motor data (fixed16) */
|
|
|
|
|
|
|
|
struct foc_motor_b16_s
|
|
|
|
{
|
2023-05-16 12:49:30 +02:00
|
|
|
/* App data ***************************************************************/
|
|
|
|
|
2021-10-31 16:07:22 +01:00
|
|
|
FAR struct foc_ctrl_env_s *envp; /* Thread env */
|
2023-05-16 12:49:30 +02:00
|
|
|
struct foc_mq_s mq; /* MQ data */
|
2021-10-31 16:07:22 +01:00
|
|
|
bool fault; /* Fault flag */
|
|
|
|
bool startstop; /* Start/stop request */
|
2023-05-16 12:49:30 +02:00
|
|
|
int ctrl_state; /* Controller state */
|
2022-02-16 17:43:58 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN
|
|
|
|
int foc_mode_run; /* FOC mode for run state */
|
|
|
|
#endif
|
2023-05-16 12:49:30 +02:00
|
|
|
|
|
|
|
/* FOC data ***************************************************************/
|
|
|
|
|
|
|
|
struct foc_state_b16_s foc_state; /* FOC controller sate */
|
2023-10-04 11:50:02 +02:00
|
|
|
#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3
|
|
|
|
struct svm3_state_b16_s mod_state; /* Modulation state */
|
|
|
|
#endif
|
2023-05-16 12:49:30 +02:00
|
|
|
foc_handler_b16_t handler; /* FOC controller */
|
|
|
|
dq_frame_b16_t dq_ref; /* DQ reference */
|
|
|
|
dq_frame_b16_t vdq_comp; /* DQ voltage compensation */
|
|
|
|
int foc_mode; /* FOC mode */
|
2021-10-31 16:07:22 +01:00
|
|
|
b16_t vbus; /* Power bus voltage */
|
2023-05-16 12:49:30 +02:00
|
|
|
b16_t per; /* Controller period in seconds */
|
|
|
|
b16_t iphase_adc; /* Iphase ADC scaling factor */
|
|
|
|
b16_t pwm_duty_max; /* PWM duty max */
|
|
|
|
|
|
|
|
/* Velocity controller data ***********************************************/
|
|
|
|
|
|
|
|
struct foc_ramp_b16_s ramp; /* Velocity ramp data */
|
|
|
|
|
|
|
|
/* Motor state ************************************************************/
|
|
|
|
|
2021-10-31 16:07:22 +01:00
|
|
|
b16_t angle_now; /* Phase angle now */
|
2021-10-31 22:09:21 +01:00
|
|
|
b16_t angle_m; /* Motor mechanical angle */
|
|
|
|
b16_t angle_el; /* Motor electrical angle */
|
2023-05-16 12:49:30 +02:00
|
|
|
|
|
|
|
/* Motor setpoints ********************************************************/
|
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
|
|
|
|
struct foc_setpoint_b16_s torq; /* Torque setpoint */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
|
|
|
struct foc_setpoint_b16_s vel; /* Velocity setpoint */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
|
|
|
|
struct foc_setpoint_b16_s pos; /* Position setpoint */
|
|
|
|
#endif
|
2021-10-31 16:07:22 +01:00
|
|
|
b16_t dir; /* Motor's direction */
|
2023-05-16 12:49:30 +02:00
|
|
|
|
|
|
|
/* Motor routines *********************************************************/
|
|
|
|
|
2021-10-31 22:09:21 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
|
|
|
|
struct foc_routine_b16_s align; /* Alignment routine */
|
2022-08-15 14:36:04 +02:00
|
|
|
bool align_done; /* Alignment done */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
struct foc_routine_b16_s ident; /* Motor ident routine */
|
|
|
|
struct motor_phy_params_b16_s phy_ident; /* Motor phy from ident */
|
|
|
|
bool ident_done; /* Motor ident done */
|
2021-10-31 22:09:21 +01:00
|
|
|
#endif
|
2023-05-16 12:49:30 +02:00
|
|
|
|
|
|
|
/* Motor data *************************************************************/
|
|
|
|
|
2021-10-31 16:07:22 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
|
2023-05-16 12:49:30 +02:00
|
|
|
struct foc_model_b16_s model; /* Model handler */
|
|
|
|
struct foc_model_state_b16_s model_state; /* PMSM model state */
|
|
|
|
#endif
|
2022-11-04 19:08:27 +01:00
|
|
|
struct motor_phy_params_b16_s phy; /* Motor phy */
|
2023-05-16 12:49:30 +02:00
|
|
|
|
|
|
|
/* Motor velocity and angle handlers **************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
|
|
|
foc_angle_b16_t openloop; /* Open-loop angle handler */
|
|
|
|
bool openloop_now; /* Open-loop now */
|
|
|
|
b16_t angle_ol; /* Phase angle open-loop */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL
|
|
|
|
foc_angle_b16_t hall; /* Hall angle handler */
|
|
|
|
char hldpath[32]; /* Hall devpath */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO
|
|
|
|
foc_angle_b16_t qenco; /* Qenco angle handler */
|
|
|
|
char qedpath[32]; /* Qenco devpath */
|
2021-10-31 16:07:22 +01:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
|
|
|
FAR struct foc_ctrl_env_s *envp);
|
|
|
|
int foc_motor_deinit(FAR struct foc_motor_b16_s *motor);
|
|
|
|
int foc_motor_get(FAR struct foc_motor_b16_s *motor);
|
|
|
|
int foc_motor_control(FAR struct foc_motor_b16_s *motor);
|
|
|
|
int foc_motor_handle(FAR struct foc_motor_b16_s *motor,
|
|
|
|
FAR struct foc_mq_s *handle);
|
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#endif /* __APPS_EXAMPLES_FOC_FOC_MOTOR_B16_H */
|