* 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.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_FOC_FOC_MOTOR_B16_H
#define __APPS_EXAMPLES_FOC_FOC_MOTOR_B16_H
* 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"
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
# include "industry/foc/fixed16/foc_align.h"
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
# include "industry/foc/fixed16/foc_ident.h"
#endif
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
# include "industry/foc/fixed16/foc_model.h"
#endif
* Pre-processor Definitions
****************************************************************************/
* Public Type Definition
****************************************************************************/
struct foc_setpoint_b16_s
{
b16_t set;
b16_t now;
b16_t des;
};
struct foc_motor_b16_s
{
FAR struct foc_ctrl_env_s *envp;
struct foc_mq_s mq;
bool fault;
bool startstop;
int ctrl_state;
#ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN
int foc_mode_run;
#endif
struct foc_state_b16_s foc_state;
#ifdef CONFIG_EXAMPLES_FOC_MODULATION_SVM3
struct svm3_state_b16_s mod_state;
#endif
foc_handler_b16_t handler;
dq_frame_b16_t dq_ref;
dq_frame_b16_t vdq_comp;
int foc_mode;
int time;
b16_t vbus;
b16_t per;
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
b16_t ol_thr;
b16_t ol_hys;
b16_t angle_step;
#endif
b16_t iphase_adc;
b16_t pwm_duty_max;
struct foc_ramp_b16_s ramp;
#ifdef CONFIG_EXAMPLES_FOC_VELCTRL_PI
pid_controller_b16_t vel_pi;
#endif
b16_t angle_now;
b16_t angle_m;
b16_t angle_el;
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
b16_t angle_ol;
#endif
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
b16_t angle_obs;
b16_t angle_err;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
b16_t vel_el;
b16_t vel_mech;
b16_t vel_filter;
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELOBS
b16_t vel_obs;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
struct foc_setpoint_b16_s torq;
b16_t torq_sat;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
struct foc_setpoint_b16_s vel;
b16_t vel_sat;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
struct foc_setpoint_b16_s pos;
#endif
b16_t dir;
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
struct foc_routine_b16_s align;
bool align_done;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
struct foc_routine_b16_s ident;
struct motor_phy_params_b16_s phy_ident;
bool ident_done;
#endif
#ifdef CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM
struct foc_model_b16_s model;
struct foc_model_state_b16_s model_state;
#endif
struct motor_phy_params_b16_s phy;
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
foc_angle_b16_t openloop;
uint8_t openloop_now;
b16_t openloop_q;
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_HALL
foc_angle_b16_t hall;
char hldpath[32];
#endif
#ifdef CONFIG_EXAMPLES_FOC_HAVE_QENCO
foc_angle_b16_t qenco;
char qedpath[32];
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_DIV
foc_velocity_b16_t vel_div;
#endif
#ifdef CONFIG_EXAMPLES_FOC_VELOBS_PLL
foc_velocity_b16_t vel_pll;
#endif
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_SMO
foc_angle_b16_t ang_smo;
#endif
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS_NFO
foc_angle_b16_t ang_nfo;
#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);
#endif