2021-03-03 19:48:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/foc/foc_thr.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_THR_H
|
|
|
|
#define __APPS_EXAMPLES_FOC_FOC_THR_H
|
2021-03-03 19:48:19 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-12-05 15:57:42 +01:00
|
|
|
#include <pthread.h>
|
2021-03-03 19:48:19 +01:00
|
|
|
#include <mqueue.h>
|
|
|
|
|
2021-12-05 15:57:42 +01:00
|
|
|
#include <nuttx/motor/foc/foc.h>
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
#include "foc_device.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Type Definition
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* FOC example state */
|
|
|
|
|
|
|
|
enum foc_example_state_e
|
|
|
|
{
|
|
|
|
FOC_EXAMPLE_STATE_INVALID = 0, /* Reserved */
|
|
|
|
FOC_EXAMPLE_STATE_FREE = 1, /* No current */
|
|
|
|
FOC_EXAMPLE_STATE_STOP = 2, /* Active break */
|
|
|
|
FOC_EXAMPLE_STATE_CW = 3, /* CW direction */
|
|
|
|
FOC_EXAMPLE_STATE_CCW = 4, /* CCW direction */
|
|
|
|
};
|
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
/* FOC control mode */
|
2021-03-03 19:48:19 +01:00
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
enum foc_foc_mode_e
|
2021-03-03 19:48:19 +01:00
|
|
|
{
|
2021-10-31 20:30:37 +01:00
|
|
|
FOC_FMODE_INVALID = 0, /* Reserved */
|
|
|
|
FOC_FMODE_IDLE = 1, /* IDLE */
|
|
|
|
FOC_FMODE_VOLTAGE = 2, /* Voltage mode */
|
|
|
|
FOC_FMODE_CURRENT = 3, /* Current mode */
|
|
|
|
};
|
2021-03-03 19:48:19 +01:00
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
/* Motor control mode */
|
2021-03-03 19:48:19 +01:00
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
enum foc_motor_mode_e
|
|
|
|
{
|
2022-08-27 12:38:18 +02:00
|
|
|
FOC_MMODE_INVALID = 0, /* Reserved */
|
2021-10-31 20:30:37 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
|
2022-08-27 12:38:18 +02:00
|
|
|
FOC_MMODE_TORQ = 1, /* Torque control */
|
2021-10-31 20:30:37 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
2022-08-27 12:38:18 +02:00
|
|
|
FOC_MMODE_VEL = 2, /* Velocity control */
|
2021-10-31 20:30:37 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
|
2022-08-27 12:38:18 +02:00
|
|
|
FOC_MMODE_POS = 3, /* Position control */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
|
|
|
|
FOC_MMODE_ALIGN_ONLY = 4, /* Sensor alignment only */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
FOC_MMODE_IDENT_ONLY = 5, /* Motor identification only */
|
2021-03-03 19:48:19 +01:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2021-10-31 18:40:34 +01:00
|
|
|
/* Controller state */
|
|
|
|
|
|
|
|
enum foc_controller_state_e
|
|
|
|
{
|
|
|
|
FOC_CTRL_STATE_INVALID = 0,
|
|
|
|
FOC_CTRL_STATE_INIT,
|
2021-10-31 22:09:21 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_ALIGN
|
|
|
|
FOC_CTRL_STATE_ALIGN,
|
|
|
|
#endif
|
2022-08-15 14:36:04 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_IDENT
|
|
|
|
FOC_CTRL_STATE_IDENT,
|
|
|
|
#endif
|
2022-02-16 13:32:30 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_RUN
|
2021-10-31 18:40:34 +01:00
|
|
|
FOC_CTRL_STATE_RUN_INIT,
|
|
|
|
FOC_CTRL_STATE_RUN,
|
2022-02-16 13:32:30 +01:00
|
|
|
#endif
|
2022-08-18 11:17:07 +02:00
|
|
|
FOC_CTRL_STATE_IDLE,
|
|
|
|
FOC_CTRL_STATE_TERMINATE
|
2021-10-31 18:40:34 +01:00
|
|
|
};
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
/* FOC thread data */
|
|
|
|
|
|
|
|
struct foc_ctrl_env_s
|
|
|
|
{
|
|
|
|
mqd_t mqd; /* Control msg queue */
|
|
|
|
int id; /* FOC device id */
|
|
|
|
int inst; /* Type specific instance counter */
|
|
|
|
int type; /* Controller type */
|
2021-10-31 20:30:37 +01:00
|
|
|
int fmode; /* FOC control mode */
|
|
|
|
int mmode; /* Motor control mode */
|
2021-10-30 14:27:32 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
2021-03-03 19:48:19 +01:00
|
|
|
int qparam; /* Open-loop Q setting (x1000) */
|
2021-10-30 14:27:32 +02:00
|
|
|
#endif
|
2022-02-16 14:03:16 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2021-10-31 20:30:37 +01:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
|
|
|
|
uint32_t torqmax; /* Torque max (x1000) */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_VEL
|
2021-03-03 19:48:19 +01:00
|
|
|
uint32_t velmax; /* Velocity max (x1000) */
|
2021-10-31 20:30:37 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_POS
|
|
|
|
uint32_t posmax; /* Position max (x1000) */
|
|
|
|
#endif
|
2021-03-03 19:48:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-12-05 15:57:42 +01:00
|
|
|
int foc_threads_init(void);
|
|
|
|
void foc_threads_deinit(void);
|
|
|
|
bool foc_threads_terminated(void);
|
|
|
|
int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd,
|
|
|
|
FAR pthread_t *thread);
|
2021-03-03 19:48:19 +01:00
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#endif /* __APPS_EXAMPLES_FOC_FOC_THR_H */
|