2021-10-30 11:18:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/foc/foc_parseargs.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 <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2021-10-30 11:42:14 +02:00
|
|
|
#include <getopt.h>
|
2021-10-30 11:18:00 +02:00
|
|
|
|
|
|
|
#include "foc_debug.h"
|
|
|
|
#include "foc_parseargs.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
#define OPT_FKI (SCHAR_MAX + 1)
|
|
|
|
#define OPT_FKP (SCHAR_MAX + 2)
|
|
|
|
|
2021-10-30 11:18:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
static struct option g_long_options[] =
|
|
|
|
{
|
|
|
|
{ "time", required_argument, 0, 't' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ "mode", required_argument, 0, 'm' },
|
|
|
|
{ "vel", required_argument, 0, 'v' },
|
|
|
|
{ "state", required_argument, 0, 's' },
|
|
|
|
{ "en", required_argument, 0, 'j' },
|
|
|
|
{ "oqset", required_argument, 0, 'o' },
|
|
|
|
{ "fkp", required_argument, 0, OPT_FKP },
|
|
|
|
{ "fki", required_argument, 0, OPT_FKI },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2021-10-30 11:18:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: foc_help
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void foc_help(void)
|
|
|
|
{
|
|
|
|
PRINTF("Usage: foc [OPTIONS]\n");
|
|
|
|
PRINTF(" [-t] run time\n");
|
|
|
|
PRINTF(" [-h] shows this message and exits\n");
|
|
|
|
PRINTF(" [-m] controller mode\n");
|
|
|
|
PRINTF(" 1 - IDLE mode\n");
|
|
|
|
PRINTF(" 2 - voltage open-loop velocity \n");
|
|
|
|
PRINTF(" 3 - current open-loop velocity \n");
|
|
|
|
PRINTF(" [-v] velocity [x1000]\n");
|
|
|
|
PRINTF(" [-s] motor state\n");
|
|
|
|
PRINTF(" 1 - motor free\n");
|
|
|
|
PRINTF(" 2 - motor stop\n");
|
|
|
|
PRINTF(" 3 - motor CW\n");
|
|
|
|
PRINTF(" 4 - motor CCW\n");
|
|
|
|
PRINTF(" [-j] enable specific instnaces\n");
|
2021-10-30 14:27:32 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
2021-10-30 11:42:14 +02:00
|
|
|
PRINTF(" [-o] openloop Vq/Iq setting [x1000]\n");
|
2021-10-30 14:27:32 +02:00
|
|
|
#endif
|
2021-10-30 11:42:14 +02:00
|
|
|
PRINTF(" [--fki] PI Kp coefficient [x1000]\n");
|
|
|
|
PRINTF(" [--fkp] PI Ki coefficient [x1000]\n");
|
2021-10-30 11:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: parse_args
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void parse_args(FAR struct args_s *args, int argc, FAR char **argv)
|
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
int option_index = 0;
|
|
|
|
int c = 0;
|
2021-10-30 11:18:00 +02:00
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
while (1)
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
c = getopt_long(argc, argv, "ht:m:o:v:s:j:", g_long_options,
|
|
|
|
&option_index);
|
|
|
|
|
|
|
|
if (c == -1)
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
break;
|
2021-10-30 11:18:00 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
switch (c)
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
case OPT_FKP:
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->pi_kp = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
case OPT_FKI:
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->pi_ki = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
case 't':
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->time = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
case 'h':
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
foc_help();
|
|
|
|
exit(0);
|
2021-10-30 11:18:00 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
case 'm':
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->mode = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->velmax = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->state = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'j':
|
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->en = atoi(optarg);
|
2021-10-30 11:18:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-30 14:27:32 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_FOC_HAVE_OPENLOOP
|
2021-10-30 11:42:14 +02:00
|
|
|
case 'o':
|
2021-10-30 11:18:00 +02:00
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
args->qparam = atoi(optarg);
|
|
|
|
break;
|
2021-10-30 11:18:00 +02:00
|
|
|
}
|
2021-10-30 14:27:32 +02:00
|
|
|
#endif
|
2021-10-30 11:18:00 +02:00
|
|
|
|
2021-10-30 11:42:14 +02:00
|
|
|
case '?':
|
2021-10-30 11:18:00 +02:00
|
|
|
default:
|
|
|
|
{
|
2021-10-30 11:42:14 +02:00
|
|
|
if (argv[optind - 1] == NULL)
|
|
|
|
{
|
|
|
|
PRINTF("ERROR: invalid option argument for %s\n",
|
|
|
|
argv[optind - 2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PRINTF("ERROR: invalid option %s\n", argv[optind - 1]);
|
|
|
|
}
|
|
|
|
|
2021-10-30 11:18:00 +02:00
|
|
|
foc_help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|