boards/sim: add support for FOC example

This commit is contained in:
raiden00pl 2021-03-01 21:17:05 +01:00 committed by Xiang Xiao
parent 08612337f6
commit 8da07e853e
5 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,92 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_DATE is not set
CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_CHIP="sim"
CONFIG_ARCH_SIM=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
CONFIG_BUILTIN=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_ERROR=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEBUG_WARN=y
CONFIG_DEV_LOOP=y
CONFIG_DEV_ZERO=y
CONFIG_EXAMPLES_FOC=y
CONFIG_EXAMPLES_FOC_FIXED16_INST=2
CONFIG_EXAMPLES_FOC_FLOAT_INST=2
CONFIG_EXAMPLES_FOC_IDQ_KI=10
CONFIG_EXAMPLES_FOC_IDQ_KP=10
CONFIG_EXAMPLES_FOC_IPHASE_ADC=100
CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ=5000
CONFIG_EXAMPLES_FOC_OPENLOOP_Q=2000
CONFIG_EXAMPLES_FOC_PWM_FREQ=15000
CONFIG_EXAMPLES_FOC_RAMP_ACC=10000000
CONFIG_EXAMPLES_FOC_RAMP_DEC=10000000
CONFIG_EXAMPLES_FOC_RAMP_THR=10000
CONFIG_EXAMPLES_FOC_STATE_INIT=3
CONFIG_EXAMPLES_FOC_STATE_PRINT_FREQ=1000
CONFIG_EXAMPLES_FOC_STATE_USE_MODEL_PMSM=y
CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE=24000
CONFIG_EXAMPLES_FOC_VERBOSE=2
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FSUTILS_PASSWD=y
CONFIG_FSUTILS_PASSWD_READONLY=y
CONFIG_FS_BINFS=y
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_INDUSTRY_FOC=y
CONFIG_INDUSTRY_FOC_FIXED16=y
CONFIG_INDUSTRY_FOC_FLOAT=y
CONFIG_INDUSTRY_FOC_HANDLER_PRINT=y
CONFIG_INDUSTRY_FOC_MODEL_PMSM=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_FLOATINGPOINT=y
CONFIG_LIBM=y
CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_MOTOR=y
CONFIG_MOTOR_FOC=y
CONFIG_MOTOR_FOC_INST=4
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_ARCHROMFS=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FATDEVNO=2
CONFIG_NSH_FILE_APPS=y
CONFIG_NSH_MOTD=y
CONFIG_NSH_MOTD_STRING="MOTD: username=admin password=Administrator"
CONFIG_NSH_READLINE=y
CONFIG_NSH_ROMFSDEVNO=1
CONFIG_NSH_ROMFSETC=y
CONFIG_PATH_INITIAL="/bin"
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIM_M32=y
CONFIG_SIM_MOTOR_FOC=y
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2008
CONFIG_SYSLOG_CONSOLE=y
CONFIG_SYSTEM_NSH=y
CONFIG_USERMAIN_STACKSIZE=4096
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -69,4 +69,8 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sim_buttons.c
endif
ifeq ($(CONFIG_SIM_MOTOR_FOC),y)
CSRCS += sim_foc.c
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -130,4 +130,19 @@ int sim_gpio_initialize(void);
int sim_tsc_setup(int minor);
#endif
/****************************************************************************
* Name: sim_foc_setup
*
* Description:
* Initialize the FOC controller driver.
*
* Returned Value:
* 0 on success, a negated errno value on failure
*
****************************************************************************/
#ifdef CONFIG_SIM_MOTOR_FOC
int sim_foc_setup(void);
#endif
#endif /* __BOARDS_SIM_SIM_SIM_SRC_SIM_H */

View File

@ -410,5 +410,15 @@ int sim_bringup(void)
}
#endif
#ifdef CONFIG_SIM_MOTOR_FOC
/* Setup FOC device */
ret = sim_foc_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sim_foc_setup() failed: %d\n", ret);
}
#endif
return ret;
}

View File

@ -0,0 +1,108 @@
/****************************************************************************
* boards/sim/sim/sim/src/sim_foc.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#include <arch/board/board.h>
#include <nuttx/motor/foc/foc_lower.h>
#include "up_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sim_foc_setup
*
* Description:
* Initialize the FOC device.
*
* This function should be call by board_app_initialize().
*
* Returned Value:
* 0 on success, a negated errno value on failure
*
****************************************************************************/
int sim_foc_setup(void)
{
FAR struct foc_dev_s *foc[CONFIG_MOTOR_FOC_INST];
static bool initialized = false;
int ret = OK;
int i = 0;
char devpath[20];
mtrinfo("sim_foc_setup\n");
/* Initialize only once */
if (!initialized)
{
/* Register devices */
for (i = 0; i < CONFIG_MOTOR_FOC_INST; i += 1)
{
/* Initialize arch specific FOC lower-half */
foc[i] = sim_foc_initialize(i);
if (foc[i] == NULL)
{
ret = -errno;
mtrerr("Failed to initialize sim FOC%d: %d\n", i, ret);
goto errout;
}
DEBUGASSERT(foc[i]->lower);
/* Get devpath for FOC */
sprintf(devpath, "/dev/foc%d", i);
/* Register FOC device */
ret = foc_register(devpath, foc[i]);
if (ret < 0)
{
mtrerr("Failed to register FOC device %s: %d\n",
devpath, ret);
goto errout;
}
}
initialized = true;
}
errout:
return ret;
}