Add FOC library

Supported features:
- float and fixed16 operations
- helper interface to interact with the kernel-side FOC device
- general interface for FOC controller
- PI current/voltage controller
- 3-phase space vector modulation
- general interface for FOC model
- PMSM model
- general interface for phase angle data
- open-loop handler
- general interface for phase velocity data
- general interface for ramp (eg. velocity ramp, torque ramp)
- (WIP) CORDIC interface for hardware acceleration
This commit is contained in:
raiden00pl 2021-03-20 21:06:54 +01:00 • committed by Xiang Xiao
parent a333a908a8
commit d75d6b7af0
39 changed files with 6744 additions and 0 deletions

View file

@ -0,0 +1,140 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_angle.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 __INDUSTRY_FOC_FIXED16_FOC_ANGLE_H
#define __INDUSTRY_FOC_FIXED16_FOC_ANGLE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
#include "industry/foc/fixed16/foc_handler.h"
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to angle handler */
struct foc_angle_in_b16_s
{
FAR struct foc_state_b16_s *state; /* FOC state */
b16_t angle; /* Last angle */
b16_t vel; /* Last velocity */
b16_t dir; /* Movement direction */
};
/* Output from angle handler */
struct foc_angle_out_b16_s
{
b16_t angle;
};
/* Forward declaration */
typedef struct foc_angle_b16_s foc_angle_b16_t;
/* Angle operations */
struct foc_angle_ops_b16_s
{
/* Initialize */
CODE int (*init)(FAR foc_angle_b16_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_angle_b16_t *h);
/* Configure */
CODE int (*cfg)(FAR foc_angle_b16_t *h, FAR void *cfg);
/* Run */
CODE void (*run)(FAR foc_angle_b16_t *h,
FAR struct foc_angle_in_b16_s *in,
FAR struct foc_angle_out_b16_s *out);
};
/* Angle handler - sensor or sensorless */
struct foc_angle_b16_s
{
FAR struct foc_angle_ops_b16_s *ops;
FAR void *data;
};
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
/* Open-loop configuration data */
struct foc_openloop_cfg_b16_s
{
b16_t per; /* Controller period */
};
#endif
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
/* Open-loop angle operations (fixed16) */
extern struct foc_angle_ops_b16_s g_foc_angle_ol_b16;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_angle_init_b16
****************************************************************************/
int foc_angle_init_b16(FAR foc_angle_b16_t *h,
FAR struct foc_angle_ops_b16_s *ops);
/****************************************************************************
* Name: foc_angle_deinit_b16
****************************************************************************/
int foc_angle_deinit_b16(FAR foc_angle_b16_t *h);
/****************************************************************************
* Name: foc_angle_cfg_b16
****************************************************************************/
int foc_angle_cfg_b16(FAR foc_angle_b16_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_angle_run_b16
****************************************************************************/
void foc_angle_run_b16(FAR foc_angle_b16_t *h,
FAR struct foc_angle_in_b16_s *in,
FAR struct foc_angle_out_b16_s *out);
#endif /* __INDUSTRY_FOC_FIXED16_FOC_ANGLE_H */

View file

@ -0,0 +1,48 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_cordic.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 __INDUSTRY_FOC_FIXED16_FOC_CORDIC_H
#define __INDUSTRY_FOC_FIXED16_FOC_CORDIC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_cordic_dqsat_b16
****************************************************************************/
int foc_cordic_dqsat_b16(int fd, FAR dq_frame_b16_t *dq_ref, b16_t mag_max);
/****************************************************************************
* Name: foc_cordic_angle_b16
****************************************************************************/
int foc_cordic_angle_b16(int fd, FAR phase_angle_b16_t *angle, b16_t a);
#endif /* __INDUSTRY_FOC_FIXED16_FOC_CORDIC_H */

View file

@ -0,0 +1,247 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_handler.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 __INDUSTRY_FOC_FIXED16_FOC_HANDLER_H
#define __INDUSTRY_FOC_FIXED16_FOC_HANDLER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
#ifdef CONFIG_INDUSTRY_FOC_CORDIC
# include "industry/foc/fixed16/foc_cordic.h"
#endif
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to FOC controller */
struct foc_handler_input_b16_s
{
FAR b16_t *current; /* Phase current samples */
FAR dq_frame_b16_t *dq_ref; /* DQ reference frame */
FAR dq_frame_b16_t *vdq_comp; /* DQ voltage compensation */
FAR b16_t angle; /* Phase angle */
FAR b16_t vbus; /* Bus voltage */
FAR int mode; /* Controller mode (enum foc_handler_mode_e) */
};
/* Output from FOC controller */
struct foc_handler_output_b16_s
{
b16_t duty[CONFIG_MOTOR_FOC_PHASES]; /* New duty cycle for PWM */
};
/* Controller state */
struct foc_state_b16_s
{
b16_t curr[CONFIG_MOTOR_FOC_PHASES];
b16_t volt[CONFIG_MOTOR_FOC_PHASES];
ab_frame_b16_t iab;
ab_frame_b16_t vab;
dq_frame_b16_t vdq;
dq_frame_b16_t idq;
};
/* Forward declaration */
typedef struct foc_handler_b16_s foc_handler_b16_t;
/* Modulation operations */
struct foc_modulation_ops_b16_s
{
/* Initialize */
CODE int (*init)(FAR foc_handler_b16_t *h);
/* Deinitialzie */
CODE void (*deinit)(FAR foc_handler_b16_t *h);
/* Configure modulation */
CODE void (*cfg)(FAR foc_handler_b16_t *h, FAR void *cfg);
/* Modulation specific current correction */
CODE void (*current)(FAR foc_handler_b16_t *h, FAR b16_t *curr);
/* Get the base voltage for a given modulation scheme */
CODE void (*vbase_get)(FAR foc_handler_b16_t *h,
b16_t vbus,
FAR b16_t *vbase);
/* Run modulation */
CODE void (*run)(FAR foc_handler_b16_t *h,
FAR ab_frame_b16_t *v_ab_mod,
FAR b16_t *duty);
};
/* Current/voltage controller operations */
struct foc_control_ops_b16_s
{
/* Initialize */
CODE int (*init)(FAR foc_handler_b16_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_handler_b16_t *h);
/* Configure controller */
CODE void (*cfg)(FAR foc_handler_b16_t *h, FAR void *cfg);
/* Feed controller with input data */
CODE void (*input_set)(FAR foc_handler_b16_t *h,
FAR b16_t *current,
b16_t vbase,
b16_t angle);
/* Run voltage controller */
CODE void (*voltage_run)(FAR foc_handler_b16_t *h,
FAR dq_frame_b16_t *dq_ref,
FAR ab_frame_b16_t *v_ab_mod);
/* Run current controller */
CODE void (*current_run)(FAR foc_handler_b16_t *h,
FAR dq_frame_b16_t *dq_ref,
FAR dq_frame_b16_t *vdq_comp,
FAR ab_frame_b16_t *v_ab_mod);
/* Get controller state data */
CODE void (*state_get)(FAR foc_handler_b16_t *h,
FAR struct foc_state_b16_s *state);
};
/* FOC handler operations */
struct foc_handler_ops_b16_s
{
/* Current/voltage controller interface */
struct foc_control_ops_b16_s *ctrl;
/* Modulation interface */
struct foc_modulation_ops_b16_s *mod;
};
/* FOC handler data */
struct foc_handler_b16_s
{
#ifdef CONFIG_INDUSTRY_FOC_CORDIC
int fd; /* CORDIC device */
#endif
struct foc_handler_ops_b16_s ops; /* Handler operations */
FAR void *modulation; /* Modulation data */
FAR void *control; /* Controller data */
};
/* Modulation configuration */
struct foc_mod_cfg_b16_s
{
b16_t pwm_duty_max; /* Maximum allowed PWM duty cycle */
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_CONTROL_PI
/* FOC PI controller (fixed16) */
extern struct foc_control_ops_b16_s g_foc_control_pi_b16;
#endif
#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3
/* 3-phase space vector modulation Modulation handler (fixed16) */
extern struct foc_modulation_ops_b16_s g_foc_mod_svm3_b16;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_handler_init_b16
****************************************************************************/
int foc_handler_init_b16(FAR foc_handler_b16_t *h,
FAR struct foc_control_ops_b16_s *ctrl,
FAR struct foc_modulation_ops_b16_s *mod);
/****************************************************************************
* Name: foc_handler_deinit_b16
****************************************************************************/
int foc_handler_deinit_b16(FAR foc_handler_b16_t *h);
/****************************************************************************
* Name: foc_handler_run_b16
****************************************************************************/
int foc_handler_run_b16(FAR foc_handler_b16_t *h,
FAR struct foc_handler_input_b16_s *in,
FAR struct foc_handler_output_b16_s *out);
/****************************************************************************
* Name: foc_handler_cfg_b16
****************************************************************************/
void foc_handler_cfg_b16(FAR foc_handler_b16_t *h,
FAR void *ctrl_cfg,
FAR void *mod_cfg);
/****************************************************************************
* Name: foc_handler_state_b16
****************************************************************************/
void foc_handler_state_b16(FAR foc_handler_b16_t *h,
FAR struct foc_state_b16_s *state);
#ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT
/****************************************************************************
* Name: foc_handler_state_print_b16
****************************************************************************/
void foc_handler_state_print_b16(FAR struct foc_state_b16_s *state);
#endif
#endif /* __INDUSTRY_FOC_FIXED16_FOC_HANDLER_H */

View file

@ -0,0 +1,160 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_model.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 __INDUSTRY_FOC_FIXED16_FOC_MODEL_H
#define __INDUSTRY_FOC_FIXED16_FOC_MODEL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
/****************************************************************************
* Public Type Definition
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_MODEL_PMSM
/* PMSM model configuration */
struct foc_model_pmsm_cfg_b16_s
{
uint8_t poles;
b16_t res;
b16_t ind;
b16_t iner;
b16_t flux_link;
b16_t ind_d;
b16_t ind_q;
b16_t per;
b16_t iphase_adc;
};
#endif /* CONFIG_INDUSTRY_FOC_MODEL_PMSM */
/* FOC model state */
struct foc_model_state_b16_s
{
int32_t curr_raw[CONFIG_MOTOR_FOC_PHASES];
b16_t curr[CONFIG_MOTOR_FOC_PHASES];
b16_t volt[CONFIG_MOTOR_FOC_PHASES];
ab_frame_b16_t iab;
ab_frame_b16_t vab;
dq_frame_b16_t vdq;
dq_frame_b16_t idq;
b16_t omega_e;
b16_t omega_m;
};
/* Forward declaration */
typedef struct foc_model_b16_s foc_model_b16_t;
/* FOC model operations */
struct foc_model_ops_b16_s
{
/* Initialize */
CODE int (*init)(FAR foc_model_b16_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_model_b16_t *h);
/* Configure model */
CODE int (*cfg)(FAR foc_model_b16_t *h, FAR void *cfg);
/* Run electrical model */
CODE void (*ele_run)(FAR foc_model_b16_t *h,
FAR ab_frame_b16_t *v_ab);
/* Run mechanical model */
CODE void (*mech_run)(FAR foc_model_b16_t *h,
b16_t load);
/* Get model state */
CODE void (*state)(FAR foc_model_b16_t *h,
FAR struct foc_model_state_b16_s *state);
};
/* FOC model handler */
struct foc_model_b16_s
{
FAR struct foc_model_ops_b16_s *ops;
FAR void *model;
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_MODEL_PMSM
/* PMSM model operations (fixed16) */
extern struct foc_model_ops_b16_s g_foc_model_pmsm_ops_b16;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_model_init_b16
****************************************************************************/
int foc_model_init_b16(FAR foc_model_b16_t *h,
FAR struct foc_model_ops_b16_s *ops);
/****************************************************************************
* Name: foc_model_deinit_b16
****************************************************************************/
int foc_model_deinit_b16(FAR foc_model_b16_t *h);
/****************************************************************************
* Name: foc_model_cfg_b16
****************************************************************************/
int foc_model_cfg_b16(FAR foc_model_b16_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_model_run_b16
****************************************************************************/
void foc_model_run_b16(FAR foc_model_b16_t *h,
b16_t load,
FAR ab_frame_b16_t *v_ab);
/****************************************************************************
* Name: foc_model_state_b16
****************************************************************************/
void foc_model_state_b16(FAR foc_model_b16_t *h,
FAR struct foc_model_state_b16_s *state);
#endif /* __INDUSTRY_FOC_FIXED16_FOC_MODEL_H */

View file

@ -0,0 +1,68 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_ramp.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 __INDUSTRY_FOC_FIXED16_FOC_RAMP_H
#define __INDUSTRY_FOC_FIXED16_FOC_RAMP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Ramp data */
struct foc_ramp_b16_s
{
uint8_t ramp_mode; /* Ramp mode */
b16_t per; /* Controller period */
b16_t ramp_thr; /* Ramp threshold */
b16_t ramp_acc; /* Ramp acceleration */
b16_t ramp_dec; /* Ramp deceleration */
b16_t ramp_dec_per; /* dec * per */
b16_t ramp_acc_per; /* acc * per */
b16_t diff; /* Difference now */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_ramp_init_b16
****************************************************************************/
int foc_ramp_init_b16(FAR struct foc_ramp_b16_s *ramp, b16_t per,
b16_t thr, b16_t acc, b16_t dec);
/****************************************************************************
* Name: foc_ramp_run_b16
****************************************************************************/
int foc_ramp_run_b16(FAR struct foc_ramp_b16_s *ramp, b16_t des,
b16_t now, FAR b16_t *set);
#endif /* __INDUSTRY_FOC_FIXED16_FOC_RAMP_H */

View file

@ -0,0 +1,121 @@
/****************************************************************************
* apps/include/industry/foc/fixed16/foc_velocity.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 __INDUSTRY_FOC_FIXED16_FOC_VELOCITY_H
#define __INDUSTRY_FOC_FIXED16_FOC_VELOCITY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dspb16.h>
#include "industry/foc/fixed16/foc_handler.h"
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to velocity handler */
struct foc_velocity_in_b16_s
{
FAR struct foc_state_b16_s *state; /* FOC state */
b16_t angle; /* Last angle */
b16_t vel; /* Last velocity */
b16_t dir; /* Movement direction */
};
/* Output from velocity handler */
struct foc_velocity_out_b16_s
{
b16_t velocity;
};
/* Forward declaration */
typedef struct foc_velocity_b16_s foc_velocity_b16_t;
/* Velocity operations */
struct foc_velocity_ops_b16_s
{
/* Initialize */
CODE int (*init)(FAR foc_velocity_b16_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_velocity_b16_t *h);
/* Configure */
CODE int (*cfg)(FAR foc_velocity_b16_t *h, FAR void *cfg);
/* Run */
CODE void (*run)(FAR foc_velocity_b16_t *h,
FAR struct foc_velocity_in_b16_s *in,
FAR struct foc_velocity_out_b16_s *out);
};
/* Velocity handler - sensor or sensorless */
struct foc_velocity_b16_s
{
FAR struct foc_velocity_ops_b16_s *ops;
FAR void *data;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_velocity_init_b16
****************************************************************************/
int foc_velocity_init_b16(FAR foc_velocity_b16_t *h,
FAR struct foc_velocity_ops_b16_s *ops);
/****************************************************************************
* Name: foc_velocity_deinit_b16
****************************************************************************/
int foc_velocity_deinit_b16(FAR foc_velocity_b16_t *h);
/****************************************************************************
* Name: foc_velocity_cfg_b16
****************************************************************************/
int foc_velocity_cfg_b16(FAR foc_velocity_b16_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_velocity_run_b16
****************************************************************************/
void foc_velocity_run_b16(FAR foc_velocity_b16_t *h,
FAR struct foc_velocity_in_b16_s *in,
FAR struct foc_velocity_out_b16_s *out);
#endif /* __INDUSTRY_FOC_FIXED16_FOC_VELOCITY_H */

View file

@ -0,0 +1,140 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_angle.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 __INDUSTRY_FOC_FLOAT_FOC_ANGLE_H
#define __INDUSTRY_FOC_FLOAT_FOC_ANGLE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
#include "industry/foc/float/foc_handler.h"
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to angle handler */
struct foc_angle_in_f32_s
{
FAR struct foc_state_f32_s *state; /* FOC state */
float angle; /* Last angle */
float vel; /* Last velocity */
float dir; /* Movement direction */
};
/* Output from angle handler */
struct foc_angle_out_f32_s
{
float angle;
};
/* Forward declaration */
typedef struct foc_angle_f32_s foc_angle_f32_t;
/* Angle operations */
struct foc_angle_ops_f32_s
{
/* Initialize */
CODE int (*init)(FAR foc_angle_f32_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_angle_f32_t *h);
/* Configure */
CODE int (*cfg)(FAR foc_angle_f32_t *h, FAR void *cfg);
/* Run angle handler */
CODE void (*run)(FAR foc_angle_f32_t *h,
FAR struct foc_angle_in_f32_s *in,
FAR struct foc_angle_out_f32_s *out);
};
/* Angle handler - sensor or sensorless */
struct foc_angle_f32_s
{
FAR struct foc_angle_ops_f32_s *ops;
FAR void *data;
};
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
/* Open-loop configuration data */
struct foc_openloop_cfg_f32_s
{
float per; /* Controller period */
};
#endif /* CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP */
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_ANGLE_OPENLOOP
/* Open-loop angle operations (float) */
extern struct foc_angle_ops_f32_s g_foc_angle_ol_f32;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_angle_init_f32
****************************************************************************/
int foc_angle_init_f32(FAR foc_angle_f32_t *h,
FAR struct foc_angle_ops_f32_s *ops);
/****************************************************************************
* Name: foc_angle_deinit_f32
****************************************************************************/
int foc_angle_deinit_f32(FAR foc_angle_f32_t *h);
/****************************************************************************
* Name: foc_angle_cfg_f32
****************************************************************************/
int foc_angle_cfg_f32(FAR foc_angle_f32_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_angle_run_f32
****************************************************************************/
void foc_angle_run_f32(FAR foc_angle_f32_t *h,
FAR struct foc_angle_in_f32_s *in,
FAR struct foc_angle_out_f32_s *out);
#endif /* __INDUSTRY_FOC_FLOAT_FOC_ANGLE_H */

View file

@ -0,0 +1,48 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_cordic.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 __INDUSTRY_FOC_FLOAT_FOC_CORDIC_H
#define __INDUSTRY_FOC_FLOAT_FOC_CORDIC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_cordic_dqsat_f32
****************************************************************************/
int foc_cordic_dqsat_f32(int fd, FAR dq_frame_f32_t *dq_ref, float mag_max);
/****************************************************************************
* Name: foc_cordic_angle_f32
****************************************************************************/
int foc_cordic_angle_f32(int fd, FAR phase_angle_f32_t *angle, float a);
#endif /* __INDUSTRY_FOC_FLOAT_FOC_CORDIC_H */

View file

@ -0,0 +1,248 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_handler.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 __INDUSTRY_FOC_FLOAT_FOC_HANDLER_H
#define __INDUSTRY_FOC_FLOAT_FOC_HANDLER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
#ifdef CONFIG_INDUSTRY_FOC_CORDIC
# include "industry/foc/float/foc_cordic.h"
#endif
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to FOC controller */
struct foc_handler_input_f32_s
{
FAR float *current; /* Phase current samples */
FAR dq_frame_f32_t *dq_ref; /* DQ reference frame */
FAR dq_frame_f32_t *vdq_comp; /* DQ voltage compensation */
FAR float angle; /* Phase angle */
FAR float vbus; /* Bus voltage */
FAR int mode; /* Controller mode (enum foc_handler_mode_e) */
};
/* Output from FOC controller */
struct foc_handler_output_f32_s
{
float duty[CONFIG_MOTOR_FOC_PHASES]; /* New duty cycle for PWM */
};
/* Controller state */
struct foc_state_f32_s
{
float curr[CONFIG_MOTOR_FOC_PHASES];
float volt[CONFIG_MOTOR_FOC_PHASES];
ab_frame_f32_t iab;
ab_frame_f32_t vab;
dq_frame_f32_t vdq;
dq_frame_f32_t idq;
};
/* Forward declaration */
typedef struct foc_handler_f32_s foc_handler_f32_t;
/* Modulation operations */
struct foc_modulation_ops_f32_s
{
/* Initialize */
CODE int (*init)(FAR foc_handler_f32_t *h);
/* Deinitialzie */
CODE void (*deinit)(FAR foc_handler_f32_t *h);
/* Configure modulation */
CODE void (*cfg)(FAR foc_handler_f32_t *h, FAR void *cfg);
/* Modulation specific current correction */
CODE void (*current)(FAR foc_handler_f32_t *h, FAR float *curr);
/* Get the base voltage for a given modulation scheme */
CODE void (*vbase_get)(FAR foc_handler_f32_t *h,
float vbus,
FAR float *vbase);
/* Run modulation */
CODE void (*run)(FAR foc_handler_f32_t *h,
FAR ab_frame_f32_t *v_ab_mod,
FAR float *duty);
};
/* Current/voltage controller operations */
struct foc_control_ops_f32_s
{
/* Initialize */
CODE int (*init)(FAR foc_handler_f32_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_handler_f32_t *h);
/* Configure controller */
CODE void (*cfg)(FAR foc_handler_f32_t *h,
FAR void *cfg);
/* Feed controller with input data */
CODE void (*input_set)(FAR foc_handler_f32_t *h,
FAR float *current,
float vbase,
float angle);
/* Run voltage controller */
CODE void (*voltage_run)(FAR foc_handler_f32_t *h,
FAR dq_frame_f32_t *dq_ref,
FAR ab_frame_f32_t *v_ab_mod);
/* Run current controller */
CODE void (*current_run)(FAR foc_handler_f32_t *h,
FAR dq_frame_f32_t *dq_ref,
FAR dq_frame_f32_t *vdq_comp,
FAR ab_frame_f32_t *v_ab_mod);
/* Get controller state data */
CODE void (*state_get)(FAR foc_handler_f32_t *h,
FAR struct foc_state_f32_s *state);
};
/* FOC handler operations */
struct foc_handler_ops_f32_s
{
/* Current/voltage controller interface */
struct foc_control_ops_f32_s *ctrl;
/* Modulation interface */
struct foc_modulation_ops_f32_s *mod;
};
/* FOC handler data */
struct foc_handler_f32_s
{
#ifdef CONFIG_INDUSTRY_FOC_CORDIC
int fd; /* CORDIC device */
#endif
struct foc_handler_ops_f32_s ops; /* Handler operations */
FAR void *modulation; /* Modulation data */
FAR void *control; /* Controller data */
};
/* Modulation configuration */
struct foc_mod_cfg_f32_s
{
float pwm_duty_max; /* Maximum allowed PWM duty cycle */
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_CONTROL_PI
/* FOC PI controller (float) */
extern struct foc_control_ops_f32_s g_foc_control_pi_f32;
#endif
#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3
/* 3-phase space vector modulation Modulation handler (float) */
extern struct foc_modulation_ops_f32_s g_foc_mod_svm3_f32;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_handler_init_f32
****************************************************************************/
int foc_handler_init_f32(FAR foc_handler_f32_t *h,
FAR struct foc_control_ops_f32_s *ctrl,
FAR struct foc_modulation_ops_f32_s *mod);
/****************************************************************************
* Name: foc_handler_deinit_f32
****************************************************************************/
int foc_handler_deinit_f32(FAR foc_handler_f32_t *h);
/****************************************************************************
* Name: foc_handler_run_f32
****************************************************************************/
int foc_handler_run_f32(FAR foc_handler_f32_t *h,
FAR struct foc_handler_input_f32_s *in,
FAR struct foc_handler_output_f32_s *out);
/****************************************************************************
* Name: foc_handler_cfg_f32
****************************************************************************/
void foc_handler_cfg_f32(FAR foc_handler_f32_t *h,
FAR void *ctrl_cfg,
FAR void *mod_cfg);
/****************************************************************************
* Name: foc_handler_state_f32
****************************************************************************/
void foc_handler_state_f32(FAR foc_handler_f32_t *h,
FAR struct foc_state_f32_s *state);
#ifdef CONFIG_INDUSTRY_FOC_HANDLER_PRINT
/****************************************************************************
* Name: foc_handler_state_print_f32
****************************************************************************/
void foc_handler_state_print_f32(FAR struct foc_state_f32_s *state);
#endif
#endif /* __INDUSTRY_FOC_FLOAT_FOC_HANDLER_H */

View file

@ -0,0 +1,160 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_model.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 __INDUSTRY_FOC_FLOAT_FOC_MODEL_H
#define __INDUSTRY_FOC_FLOAT_FOC_MODEL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
/****************************************************************************
* Public Type Definition
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_MODEL_PMSM
/* PMSM model configuration */
struct foc_model_pmsm_cfg_f32_s
{
uint8_t poles;
float res;
float ind;
float iner;
float flux_link;
float ind_d;
float ind_q;
float per;
float iphase_adc;
};
#endif /* CONFIG_INDUSTRY_FOC_MODEL_PMSM */
/* FOC model state */
struct foc_model_state_f32_s
{
int32_t curr_raw[CONFIG_MOTOR_FOC_PHASES];
float curr[CONFIG_MOTOR_FOC_PHASES];
float volt[CONFIG_MOTOR_FOC_PHASES];
ab_frame_f32_t iab;
ab_frame_f32_t vab;
dq_frame_f32_t vdq;
dq_frame_f32_t idq;
float omega_e;
float omega_m;
};
/* Forward declaration */
typedef struct foc_model_f32_s foc_model_f32_t;
/* FOC model operations */
struct foc_model_ops_f32_s
{
/* Initialize */
CODE int (*init)(FAR foc_model_f32_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_model_f32_t *h);
/* Configure model */
CODE int (*cfg)(FAR foc_model_f32_t *h, FAR void *cfg);
/* Run electrical model */
CODE void (*ele_run)(FAR foc_model_f32_t *h,
FAR ab_frame_f32_t *v_ab);
/* Run mechanical model */
CODE void (*mech_run)(FAR foc_model_f32_t *h,
float load);
/* Get model state */
CODE void (*state)(FAR foc_model_f32_t *h,
FAR struct foc_model_state_f32_s *state);
};
/* FOC model handler */
struct foc_model_f32_s
{
FAR struct foc_model_ops_f32_s *ops;
FAR void *model;
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_INDUSTRY_FOC_MODEL_PMSM
/* PMSM model operations (float) */
extern struct foc_model_ops_f32_s g_foc_model_pmsm_ops_f32;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_model_init_f32
****************************************************************************/
int foc_model_init_f32(FAR foc_model_f32_t *h,
FAR struct foc_model_ops_f32_s *ops);
/****************************************************************************
* Name: foc_model_deinit_f32
****************************************************************************/
int foc_model_deinit_f32(FAR foc_model_f32_t *h);
/****************************************************************************
* Name: foc_model_cfg_f32
****************************************************************************/
int foc_model_cfg_f32(FAR foc_model_f32_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_model_run_f32
****************************************************************************/
void foc_model_run_f32(FAR foc_model_f32_t *h,
float load,
FAR ab_frame_f32_t *v_ab);
/****************************************************************************
* Name: foc_model_state_f32
****************************************************************************/
void foc_model_state_f32(FAR foc_model_f32_t *h,
FAR struct foc_model_state_f32_s *state);
#endif /* __INDUSTRY_FOC_FLOAT_FOC_MODEL_H */

View file

@ -0,0 +1,68 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_ramp.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 __INDUSTRY_FOC_FLOAT_FOC_RAMP_H
#define __INDUSTRY_FOC_FLOAT_FOC_RAMP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Ramp data */
struct foc_ramp_f32_s
{
uint8_t ramp_mode; /* Ramp mode */
float per; /* Controller period */
float ramp_thr; /* Ramp threshold */
float ramp_acc; /* Ramp acceleration */
float ramp_dec; /* Ramp deceleration */
float ramp_dec_per; /* dec * per */
float ramp_acc_per; /* acc * per */
float diff; /* Difference now */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_ramp_init_f32
****************************************************************************/
int foc_ramp_init_f32(FAR struct foc_ramp_f32_s *ramp, float per,
float thr, float acc, float dec);
/****************************************************************************
* Name: foc_ramp_run_f32
****************************************************************************/
int foc_ramp_run_f32(FAR struct foc_ramp_f32_s *ramp, float des,
float now, FAR float *set);
#endif /* __INDUSTRY_FOC_FLOAT_FOC_RAMP_H */

View file

@ -0,0 +1,121 @@
/****************************************************************************
* apps/include/industry/foc/float/foc_velocity.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 __INDUSTRY_FOC_FLOAT_FOC_VELOCITY_H
#define __INDUSTRY_FOC_FLOAT_FOC_VELOCITY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dsp.h>
#include "industry/foc/float/foc_handler.h"
/****************************************************************************
* Public Type Definition
****************************************************************************/
/* Input to velocity handler */
struct foc_velocity_in_f32_s
{
FAR struct foc_state_f32_s *state; /* FOC state */
float angle; /* Last angle */
float vel; /* Last velocity */
float dir; /* Movement direction */
};
/* Output from velocity handler */
struct foc_velocity_out_f32_s
{
float velocity;
};
/* Forward declaration */
typedef struct foc_velocity_f32_s foc_velocity_f32_t;
/* Velocity operations */
struct foc_velocity_ops_f32_s
{
/* Initialize */
CODE int (*init)(FAR foc_velocity_f32_t *h);
/* Deinitialize */
CODE void (*deinit)(FAR foc_velocity_f32_t *h);
/* Configure */
CODE int (*cfg)(FAR foc_velocity_f32_t *h, FAR void *cfg);
/* Run velocity handler */
CODE void (*run)(FAR foc_velocity_f32_t *h,
FAR struct foc_velocity_in_f32_s *in,
FAR struct foc_velocity_out_f32_s *out);
};
/* Velocity handler - sensor or sensorless */
struct foc_velocity_f32_s
{
FAR struct foc_velocity_ops_f32_s *ops;
FAR void *data;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_velocity_init_f32
****************************************************************************/
int foc_velocity_init_f32(FAR foc_velocity_f32_t *h,
FAR struct foc_velocity_ops_f32_s *ops);
/****************************************************************************
* Name: foc_velocity_deinit_f32
****************************************************************************/
int foc_velocity_deinit_f32(FAR foc_velocity_f32_t *h);
/****************************************************************************
* Name: foc_velocity_cfg_f32
****************************************************************************/
int foc_velocity_cfg_f32(FAR foc_velocity_f32_t *h, FAR void *cfg);
/****************************************************************************
* Name: foc_velocity_run_f32
****************************************************************************/
void foc_velocity_run_f32(FAR foc_velocity_f32_t *h,
FAR struct foc_velocity_in_f32_s *in,
FAR struct foc_velocity_out_f32_s *out);
#endif /* __INDUSTRY_FOC_FLOAT_FOC_VELOCITY_H */

View file

@ -0,0 +1,78 @@
/****************************************************************************
* apps/include/industry/foc/foc_common.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_INCLUDE_INDUSTRY_FOC_FOC_COMMON_H
#define __APPS_INCLUDE_INDUSTRY_FOC_FOC_COMMON_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/* FOC controller mode */
enum foc_handler_mode_e
{
FOC_HANDLER_MODE_INIT = 0, /* Initial state */
FOC_HANDLER_MODE_IDLE, /* Idle */
FOC_HANDLER_MODE_VOLTAGE, /* Voltage mode - control DQ voltage */
FOC_HANDLER_MODE_CURRENT /* Current mode - control DQ current */
};
/* FOC number type identifiers */
enum foc_number_type_e
{
FOC_NUMBER_TYPE_INVALID = 0,
#ifdef CONFIG_INDUSTRY_FOC_FLOAT
FOC_NUMBER_TYPE_FLOAT = 1, /* float */
#endif
#ifdef CONFIG_INDUSTRY_FOC_FIXED16
FOC_NUMBER_TYPE_FIXED16 = 2, /* b16_t */
#endif
};
/* Speed ramp mode */
enum foc_ramp_mode_e
{
RAMP_MODE_INVALID = 0, /* Reserved */
RAMP_MODE_SOFTSTART = 1, /* Soft start */
RAMP_MODE_SOFTSTOP = 2, /* Soft stop */
RAMP_MODE_NORMAL = 3, /* Normal operation */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __APPS_INCLUDE_INDUSTRY_FOC_FOC_COMMON_H */

View file

@ -0,0 +1,42 @@
/****************************************************************************
* apps/include/industry/foc/foc_log.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_INCLUDE_INDUSTRY_FOC_FOC_LOG_H
#define __APPS_INCLUDE_INDUSTRY_FOC_FOC_LOG_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <inttypes.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define FOCLIBLOG(format, ...) printf(format, ##__VA_ARGS__)
#define FOCLIBERR(format, ...) printf(format, ##__VA_ARGS__)
#define FOCLIBWARN(format, ...) printf(format, ##__VA_ARGS__)
#endif /* __APPS_INCLUDE_INDUSTRY_FOC_FOC_LOG_H */

View file

@ -0,0 +1,92 @@
/****************************************************************************
* apps/include/industry/foc/foc_utils.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_INCLUDE_INDUSTRY_FOC_FOC_UTILS_H
#define __APPS_INCLUDE_INDUSTRY_FOC_FOC_UTILS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/motor/foc/foc.h>
#include <nuttx/motor/motor_ioctl.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foc_dev_stop
****************************************************************************/
int foc_dev_stop(int fd);
/****************************************************************************
* Name: foc_dev_start
****************************************************************************/
int foc_dev_start(int fd);
/****************************************************************************
* Name: foc_dev_clearfault
****************************************************************************/
int foc_dev_clearfault(int fd);
/****************************************************************************
* Name: foc_dev_getstate
****************************************************************************/
int foc_dev_getstate(int fd, FAR struct foc_state_s *state);
/****************************************************************************
* Name: foc_dev_setparams
****************************************************************************/
int foc_dev_setparams(int fd, FAR struct foc_params_s *params);
/****************************************************************************
* Name: foc_dev_setcfg
****************************************************************************/
int foc_dev_setcfg(int fd, FAR struct foc_cfg_s *cfg);
/****************************************************************************
* Name: foc_dev_getcfg
****************************************************************************/
int foc_dev_getcfg(int fd, FAR struct foc_cfg_s *cfg);
/****************************************************************************
* Name: foc_dev_getinfo
****************************************************************************/
int foc_dev_getinfo(int fd, FAR struct foc_info_s *info);
/****************************************************************************
* Name: foc_cfg_print
****************************************************************************/
void foc_cfg_print(FAR struct foc_cfg_s *cfg);
#endif /* __APPS_INCLUDE_INDUSTRY_FOC_FOC_UTILS_H */