31 #include <sys/types.h>    36 #endif  // HAVE_CONFIG_H    81   return g_P[id][motor];
    96   return &
g_P[id][motor];
   101   if (g_param.
option & option)
   122   fprintf(stderr, 
"USAGE: %s [OPTION]...\n\n", argv[0]);
   123   fprintf(stderr, 
"  -v, --version            Display version info and exit.\n");
   124   fprintf(stderr, 
"  -d, --device <device>    Specify a B-Loco device. e.g. /dev/ttyUSB0\n");
   125   fprintf(stderr, 
"  -p, --param <tile>       Specify a robot parameter file.\n");
   126   fprintf(stderr, 
"  --verbose                Display detail information.\n");
   127   fprintf(stderr, 
"  --quiet                  Display nothing.\n");
   128   fprintf(stderr, 
"  -h, --help               This help\n");
   129   fprintf(stderr, 
"  --long-help              Long help\n");
   130   fprintf(stderr, 
"  --param-help             Comments of parameters\n\n");
   137   fprintf(stderr, 
"  -o, --show-odometry      Display estimated robot position.\n");
   138   fprintf(stderr, 
"  -t, --show-timestamp     Display timestamp of serial communication \n"   139                   "                            with the B-Loco device.\n");
   140   fprintf(stderr, 
"  --reconnect              Try reconnect device when device was closed.\n");
   141   fprintf(stderr, 
"  --without-ssm            Run without ssm output.\n");
   142   fprintf(stderr, 
"  -q, --msq-key <MSQKEY>   Run with message que key MSQKEY (default = 28741).\n");
   143   fprintf(stderr, 
"  -s, --speed <BAUDRATE>   Set baudrate.\n");
   144   fprintf(stderr, 
"  --admask <ADMASK>        Get AD data of ADMASK from B-Loco device.\n");
   145   fprintf(stderr, 
"  --enable-get-digital-io  Enable digital IO port.\n");
   146   fprintf(stderr, 
"  -c, --without-control    Run without control.\n");
   147   fprintf(stderr, 
"  --without-device         Run without B-Loco device.\n");
   148   fprintf(stderr, 
"  --no-yp-protocol         Run without checking plotocol of B-Loco device.\n");
   149   fprintf(stderr, 
"  --passive                Passive run mode.\n");
   150   fprintf(stderr, 
"  --update-param           Automatically reload parameter file.\n");
   151   fprintf(stderr, 
"  --high-resolution[=ARG]  Use high resolution velocity control mode (default = yes).\n");
   152   fprintf(stderr, 
"  --ssm-id <SSMID>         Change ssm id (default = 0).\n");
   153   fprintf(stderr, 
"  --socket <port>          Use socket ipc.\n");
   154   fprintf(stderr, 
"  --daemon                 Run in daemon mode.\n");
   167     if (param_names[i][0] == 
'_')
   169     fprintf(stderr, 
"  %20s: %s\n", param_names[i], param_comments[i]);
   187   for (i = 1; i < argc; i++)
   189     if (!strcmp(argv[i], 
"--help") || !strcmp(argv[i], 
"-h"))
   193     else if (!strcmp(argv[i], 
"--long-help"))
   197     else if (!strcmp(argv[i], 
"--daemon"))
   201     else if (!strcmp(argv[i], 
"--param-help"))
   205     else if (!strcmp(argv[i], 
"--show-odometry") || !strcmp(argv[i], 
"-o"))
   209     else if (!strcmp(argv[i], 
"--show-timestamp") || !strcmp(argv[i], 
"-t"))
   213     else if (!strcmp(argv[i], 
"--param") || !strcmp(argv[i], 
"-p"))
   224     else if (!strcmp(argv[i], 
"--socket"))
   229         g_param.
port = atoi(argv[i]);
   235     else if (!strcmp(argv[i], 
"--admask"))
   243         for (pos = argv[i]; *pos != 0; pos++)
   253     else if (!strcmp(argv[i], 
"--device") || !strcmp(argv[i], 
"-d"))
   263     else if (!strcmp(argv[i], 
"--without-control") || !strcmp(argv[i], 
"-c"))
   271     else if (!strcmp(argv[i], 
"--without-device"))
   281     else if (!strcmp(argv[i], 
"--high-resolution") ||
   282              !strcmp(argv[i], 
"--high-resolution=yes"))
   286     else if (!strcmp(argv[i], 
"--high-resolution=no"))
   290     else if (!strcmp(argv[i], 
"--version") || !strcmp(argv[i], 
"-v"))
   294     else if (!strcmp(argv[i], 
"--verbose"))
   298     else if (!strcmp(argv[i], 
"--quiet"))
   302     else if (!strcmp(argv[i], 
"--reconnect"))
   306     else if (!strcmp(argv[i], 
"--enable-set-bs"))
   310     else if (!strcmp(argv[i], 
"--enable-get-digital-io"))
   314     else if (!strcmp(argv[i], 
"--no-yp-protocol"))
   318     else if (!strcmp(argv[i], 
"--without-ssm"))
   322     else if (!strcmp(argv[i], 
"--msq-key") || !strcmp(argv[i], 
"-q"))
   327         g_param.
msq_key = atoi(argv[i]);
   332     else if (!strcmp(argv[i], 
"--speed") || !strcmp(argv[i], 
"-s"))
   337         g_param.
speed = atoi(argv[i]);
   342     else if (!strcmp(argv[i], 
"--passive"))
   346     else if (!strcmp(argv[i], 
"--update-param"))
   350     else if (!strcmp(argv[i], 
"--ssm-id"))
   355         g_param.
ssm_id = atoi(argv[i]);
   384   if (value64 > 0x7FFFFFFF || value64 < -0x7FFFFFFE)
   409   if (c >= 
'A' && c <= 
'Z')
   411   if (c >= 
'a' && c <= 
'z')
   420   if (c >= 
'0' && c <= 
'9')
   455 #define VARIABLE_NUM 37   458         "X", 
"Y", 
"THETA", 
"V", 
"W",
   459         "WHEEL_VEL[0]", 
"WHEEL_VEL[1]",
   460         "WHEEL_VEL[2]", 
"WHEEL_VEL[3]",
   461         "WHEEL_VEL[4]", 
"WHEEL_VEL[5]",
   462         "WHEEL_VEL[6]", 
"WHEEL_VEL[7]",
   463         "WHEEL_VEL[8]", 
"WHEEL_VEL[9]",
   464         "WHEEL_VEL[10]", 
"WHEEL_VEL[11]",
   465         "WHEEL_VEL[12]", 
"WHEEL_VEL[13]",
   466         "WHEEL_VEL[14]", 
"WHEEL_VEL[15]",
   467         "WHEEL_ANGLE[0]", 
"WHEEL_ANGLE[1]",
   468         "WHEEL_ANGLE[2]", 
"WHEEL_ANGLE[3]",
   469         "WHEEL_ANGLE[4]", 
"WHEEL_ANGLE[5]",
   470         "WHEEL_ANGLE[6]", 
"WHEEL_ANGLE[7]",
   471         "WHEEL_ANGLE[8]", 
"WHEEL_ANGLE[9]",
   472         "WHEEL_ANGLE[10]", 
"WHEEL_ANGLE[11]",
   473         "WHEEL_ANGLE[12]", 
"WHEEL_ANGLE[13]",
   474         "WHEEL_ANGLE[14]", 
"WHEEL_ANGLE[15]",
   483   char name[32], value_str[100];
   487   int param_num, motor_num;
   493     strcat(param_names0[i], 
"[0]");
   494     strcat(param_names1[i], 
"[1]");
   495     variables[i * 3 + 0].
name = param_names[i];
   497     variables[i * 3 + 1].
name = param_names0[i];
   499     variables[i * 3 + 2].
name = param_names1[i];
   505     variables[i + j].
name = variable_names[j];
   513   for (j = 0; j < 16; j++)
   515   for (j = 0; j < 16; j++)
   517   variables[i].
name = NULL;
   602           value_str[str_wp] = c;
   608           strcpy(value_str, name);
   609           strcat(value_str, 
"=");
   610           str_wp = strlen(value_str);
   616           char *num_end = NULL;
   622           num_start = strchr(name, 
'[');
   626             num_end = strchr(name, 
']');
   634             *(num_start - 1) = 0;
   636             num = atoi(num_start);
   641             if (!strcmp(name, param_names[i]))
   646                 if (i == param_alias[j].alias)
   649                           param_names[i], param_names[param_alias[j].param], param_alias[j].motor);
   650                   i = param_alias[j].param;
   651                   motor_num = param_alias[j].motor;
   661             *(num_start - 1) = 
'[';
   669           value_str[str_wp] = 0;
   671           if (param_num == YP_PARAM_NUM)
   676           else if (motor_num == -1)
   681               g_P[param_num][j] = strtod(value_str, 0);
   684               if (g_Pf[param_num][j])
   687                 g_Pf[param_num][j] = NULL;
   694             g_P[param_num][motor_num] = strtod(value_str, 0);
   695             g_P_set[param_num][motor_num] = 1;
   698             if (g_Pf[param_num][motor_num])
   701               g_Pf[param_num][motor_num] = NULL;
   704                     g_P[param_num][motor_num]);
   713           value_str[str_wp] = c;
   718         if (c == 
'#' || c == 
'\n')
   720           value_str[str_wp] = 0;
   722           if (param_num == YP_PARAM_NUM)
   727           else if (motor_num == -1)
   732               g_P[param_num][j] = 0;
   734               if (g_Pf[param_num][j])
   736               formula(value_str, &g_Pf[param_num][j], variables);
   738             if (g_Pf[param_num][0] == NULL)
   757             g_P[param_num][motor_num] = 0;
   758             g_P_set[param_num][motor_num] = 1;
   759             if (g_Pf[param_num][motor_num])
   761             formula(value_str, &g_Pf[param_num][motor_num], variables);
   762             if (g_Pf[param_num][motor_num] == NULL)
   783           value_str[str_wp] = c;
   813       if (param_necessary[i] && !
g_P_set[i][j])
   852             "ERROR: Using ENCODER_DENOMINATOR requires parameter version >= 5.0.\n"   853             " Please make sure that all other motor parameters are based on mechanical motor revolution instead of electrical.\n");
   858           "Warn: ENCODER_DENOMINATOR parameter support is experimental.\n"   859           " The behavior of this parameter may be changed in the future update.\n");
   872       double default_value;
   925   paramfile = fopen(filename, 
"r");
   934 #endif  // HAVE_PKG_CONFIG   939     if (!strchr(filename, 
'/'))
   943       fd = popen(
"pkg-config --variable=YP_PARAMS_DIR yp-robot-params", 
"r");
   947                 "Error: Cannot open pipe 'pkg-config --variable=YP_PARAMS_DIR yp-robot-params'.\n");
   950       pret = fgets(dir_name, 
sizeof(dir_name), fd);
   952       if ((pclose(fd) == 0) && (pret != 0))
   954         dir_name[strlen(dir_name) - 1] = 
'\0';
   956         sprintf(file_name, 
"%s/%s", dir_name, filename);
   958         paramfile = fopen(file_name, 
"r");
   969                 "Error: Cannot read pipe 'pkg-config --variable=YP_PARAMS_DIR yp-robot-params'.\n");
   974         strcpy(concrete_path, file_name);
   975       strcpy(file_name, filename);
   978 #endif  // HAVE_PKG_CONFIG   986       strcpy(concrete_path, filename);
   995   if (pthread_create(thread, NULL, (
void *)
param_update, filename) != 0)
  1008   struct stat prev_status;
  1013   stat(filename, &prev_status);
  1021     for (i = 0; i < 3; i++)
  1024       pthread_testcancel();
  1027     stat(filename, &status);
  1029     if (difftime(status.st_mtime, prev_status.st_mtime) != 0.0)
  1040     prev_status = status;
  1042   pthread_cleanup_pop(1);
  1071     sscanf(YP_PROTOCOL_NAME, 
"YPP:%d:%d", &version, &age);
  1109   Gl = fabs(
g_P[YP_PARAM_GEAR][1]);
  1119   A = (Gr * Gr * Jmr + Jtr + Rr * Rr / 2.0 * (M / 2.0 + J / (T * T))) / Gr;
  1120   B = (Gl * Gl * Jml + Jtl + Rl * Rl / 2.0 * (M / 2.0 + J / (T * T))) / Gl;
  1121   C = (Rr * Rl / 2.0 * (M / 2.0 - J / (T * T))) / Gr;
  1122   D = (Rr * Rl / 2.0 * (M / 2.0 - J / (T * T))) / Gl;
  1362     int ffr_changed = 0, ffl_changed = 0;
 
char g_state[YP_STATE_NUM]
#define YP_PARAM_ALIAS_NUM
double * pp(YPSpur_param id, enum motor_id motor)
void init_param_update_thread(pthread_t *thread, char *filename)
struct rpf_t * g_Pf[YP_PARAM_NUM][YP_PARAM_MAX_MOTOR_NUM]
ParamOutputLv output_lv(void)
int encode_write(char *data, int len)
double wang[YP_PARAM_MAX_MOTOR_NUM]
ParametersPtr get_param_ptr()
int ischanged_p(YPSpur_param id, enum motor_id motor)
void arg_longhelp(int argc, char *argv[])
int state(YPSpur_state id)
#define YP_PARAM_SUPPORTED_VERSION
int set_paramptr(FILE *paramfile)
char parameter_filename[132]
void param_update_loop_cleanup(void *data)
int arg_analyze(int argc, char *argv[])
int g_P_set[YP_PARAM_NUM][YP_PARAM_MAX_MOTOR_NUM]
#define DEFAULT_PARAMETER_FILE
int set_param_motor(void)
#define DEFAULT_DEVICE_NAME
void calc_param_inertia2ff(void)
int parameter_set(char param, char id, long long int value64)
#define YP_PARAM_MAX_MOTOR_NUM
double wvel[YP_PARAM_MAX_MOTOR_NUM]
void yprintf(ParamOutputLv level, const char *format,...)
int motor_enable[YP_PARAM_MAX_MOTOR_NUM]
void param_update(void *filename)
int g_P_changed[YP_PARAM_NUM][YP_PARAM_MAX_MOTOR_NUM]
void disable_state(YPSpur_state id)
OdometryPtr get_odometry_ptr()
void enable_state(YPSpur_state id)
int isset_p(YPSpur_param id, enum motor_id motor)
double g_P[YP_PARAM_NUM][YP_PARAM_MAX_MOTOR_NUM]
double p(YPSpur_param id, enum motor_id motor)
#define YP_PARAM_REQUIRED_VERSION
#define YP_PARAM_NECESSARY
void arg_help(int argc, char *argv[])
int option(ParamOptions option)
int set_param_velocity(void)
int set_param(char *filename, char *concrete_path)