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>
|
|
|
|
|
2023-05-05 13:15:36 +02:00
|
|
|
#include <stdint.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"
|
|
|
|
|
2023-05-17 12:31:25 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE
|
|
|
|
# include "foc_nxscope.h"
|
|
|
|
#endif
|
|
|
|
|
2021-03-03 19:48:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
2023-04-21 12:10:10 +02:00
|
|
|
FOC_MMODE_IDLE = 6, /* IDLE state */
|
2021-03-03 19:48:19 +01:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
{
|
2023-05-17 12:31:25 +02:00
|
|
|
mqd_t mqd; /* Control msg queue */
|
|
|
|
int id; /* FOC device id */
|
|
|
|
int inst; /* Type specific instance counter */
|
|
|
|
int type; /* Controller type */
|
|
|
|
FAR struct foc_thr_cfg_s *cfg; /* Control thread configuration */
|
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_NXSCOPE
|
|
|
|
FAR struct foc_nxscope_s *nxs; /* nxscope handler */
|
|
|
|
#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);
|
2023-05-05 13:15:36 +02:00
|
|
|
uint32_t foc_threads_get(void);
|
2023-05-17 12:31:07 +02:00
|
|
|
int foc_thread_type(int id);
|
2021-12-05 15:57:42 +01:00
|
|
|
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 */
|