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");
155 fprintf(stderr,
" --ping Ping RS485 chained devices.\n");
168 if (param_names[i][0] ==
'_')
170 fprintf(stderr,
" %20s: %s\n", param_names[i], param_comments[i]);
188 for (i = 1; i < argc; i++)
190 if (!strcmp(argv[i],
"--help") || !strcmp(argv[i],
"-h"))
194 else if (!strcmp(argv[i],
"--long-help"))
198 else if (!strcmp(argv[i],
"--daemon"))
202 else if (!strcmp(argv[i],
"--ping"))
206 else if (!strcmp(argv[i],
"--param-help"))
210 else if (!strcmp(argv[i],
"--show-odometry") || !strcmp(argv[i],
"-o"))
214 else if (!strcmp(argv[i],
"--show-timestamp") || !strcmp(argv[i],
"-t"))
218 else if (!strcmp(argv[i],
"--param") || !strcmp(argv[i],
"-p"))
229 else if (!strcmp(argv[i],
"--socket"))
234 g_param.
port = atoi(argv[i]);
240 else if (!strcmp(argv[i],
"--admask"))
248 for (pos = argv[i]; *pos != 0; pos++)
258 else if (!strcmp(argv[i],
"--device") || !strcmp(argv[i],
"-d"))
268 else if (!strcmp(argv[i],
"--without-control") || !strcmp(argv[i],
"-c"))
276 else if (!strcmp(argv[i],
"--without-device"))
286 else if (!strcmp(argv[i],
"--high-resolution") ||
287 !strcmp(argv[i],
"--high-resolution=yes"))
291 else if (!strcmp(argv[i],
"--high-resolution=no"))
295 else if (!strcmp(argv[i],
"--version") || !strcmp(argv[i],
"-v"))
299 else if (!strcmp(argv[i],
"--verbose"))
303 else if (!strcmp(argv[i],
"--quiet"))
307 else if (!strcmp(argv[i],
"--reconnect"))
311 else if (!strcmp(argv[i],
"--enable-set-bs"))
315 else if (!strcmp(argv[i],
"--enable-get-digital-io"))
319 else if (!strcmp(argv[i],
"--no-yp-protocol"))
323 else if (!strcmp(argv[i],
"--without-ssm"))
327 else if (!strcmp(argv[i],
"--msq-key") || !strcmp(argv[i],
"-q"))
332 g_param.
msq_key = atoi(argv[i]);
337 else if (!strcmp(argv[i],
"--speed") || !strcmp(argv[i],
"-s"))
342 g_param.
speed = atoi(argv[i]);
347 else if (!strcmp(argv[i],
"--passive"))
351 else if (!strcmp(argv[i],
"--update-param"))
355 else if (!strcmp(argv[i],
"--ssm-id"))
360 g_param.
ssm_id = atoi(argv[i]);
389 if (value64 > 0x7FFFFFFF || value64 < -0x7FFFFFFE)
414 if (c >=
'A' && c <=
'Z')
416 if (c >=
'a' && c <=
'z')
425 if (c >=
'0' && c <=
'9')
460 #define VARIABLE_NUM 37 463 "X",
"Y",
"THETA",
"V",
"W",
464 "WHEEL_VEL[0]",
"WHEEL_VEL[1]",
465 "WHEEL_VEL[2]",
"WHEEL_VEL[3]",
466 "WHEEL_VEL[4]",
"WHEEL_VEL[5]",
467 "WHEEL_VEL[6]",
"WHEEL_VEL[7]",
468 "WHEEL_VEL[8]",
"WHEEL_VEL[9]",
469 "WHEEL_VEL[10]",
"WHEEL_VEL[11]",
470 "WHEEL_VEL[12]",
"WHEEL_VEL[13]",
471 "WHEEL_VEL[14]",
"WHEEL_VEL[15]",
472 "WHEEL_ANGLE[0]",
"WHEEL_ANGLE[1]",
473 "WHEEL_ANGLE[2]",
"WHEEL_ANGLE[3]",
474 "WHEEL_ANGLE[4]",
"WHEEL_ANGLE[5]",
475 "WHEEL_ANGLE[6]",
"WHEEL_ANGLE[7]",
476 "WHEEL_ANGLE[8]",
"WHEEL_ANGLE[9]",
477 "WHEEL_ANGLE[10]",
"WHEEL_ANGLE[11]",
478 "WHEEL_ANGLE[12]",
"WHEEL_ANGLE[13]",
479 "WHEEL_ANGLE[14]",
"WHEEL_ANGLE[15]",
488 char name[32], value_str[100];
492 int param_num, motor_num;
498 strcat(param_names0[i],
"[0]");
499 strcat(param_names1[i],
"[1]");
500 variables[i * 3 + 0].
name = param_names[i];
502 variables[i * 3 + 1].
name = param_names0[i];
504 variables[i * 3 + 2].
name = param_names1[i];
510 variables[i + j].
name = variable_names[j];
518 for (j = 0; j < 16; j++)
520 for (j = 0; j < 16; j++)
522 variables[i].
name = NULL;
607 value_str[str_wp] = c;
613 strcpy(value_str, name);
614 strcat(value_str,
"=");
615 str_wp = strlen(value_str);
621 char *num_end = NULL;
627 num_start = strchr(name,
'[');
631 num_end = strchr(name,
']');
639 *(num_start - 1) = 0;
641 num = atoi(num_start);
646 if (!strcmp(name, param_names[i]))
651 if (i == param_alias[j].alias)
654 param_names[i], param_names[param_alias[j].param], param_alias[j].motor);
655 i = param_alias[j].param;
656 motor_num = param_alias[j].motor;
666 *(num_start - 1) =
'[';
674 value_str[str_wp] = 0;
676 if (param_num == YP_PARAM_NUM)
681 else if (motor_num == -1)
686 g_P[param_num][j] = strtod(value_str, 0);
689 if (g_Pf[param_num][j])
692 g_Pf[param_num][j] = NULL;
699 g_P[param_num][motor_num] = strtod(value_str, 0);
700 g_P_set[param_num][motor_num] = 1;
703 if (g_Pf[param_num][motor_num])
706 g_Pf[param_num][motor_num] = NULL;
709 g_P[param_num][motor_num]);
718 value_str[str_wp] = c;
723 if (c ==
'#' || c ==
'\n')
725 value_str[str_wp] = 0;
727 if (param_num == YP_PARAM_NUM)
732 else if (motor_num == -1)
737 g_P[param_num][j] = 0;
739 if (g_Pf[param_num][j])
741 formula(value_str, &g_Pf[param_num][j], variables);
743 if (g_Pf[param_num][0] == NULL)
762 g_P[param_num][motor_num] = 0;
763 g_P_set[param_num][motor_num] = 1;
764 if (g_Pf[param_num][motor_num])
766 formula(value_str, &g_Pf[param_num][motor_num], variables);
767 if (g_Pf[param_num][motor_num] == NULL)
788 value_str[str_wp] = c;
818 if (param_necessary[i] && !
g_P_set[i][j])
857 "ERROR: Using ENCODER_DENOMINATOR requires parameter version >= 5.0.\n" 858 " Please make sure that all other motor parameters are based on mechanical motor revolution instead of electrical.\n");
863 "Warn: ENCODER_DENOMINATOR parameter support is experimental.\n" 864 " The behavior of this parameter may be changed in the future update.\n");
877 double default_value;
936 paramfile = fopen(filename,
"r");
945 #endif // HAVE_PKG_CONFIG 950 if (!strchr(filename,
'/'))
954 fd = popen(
"pkg-config --variable=YP_PARAMS_DIR yp-robot-params",
"r");
958 "Error: Cannot open pipe 'pkg-config --variable=YP_PARAMS_DIR yp-robot-params'.\n");
961 pret = fgets(dir_name,
sizeof(dir_name), fd);
963 if ((pclose(fd) == 0) && (pret != 0))
965 dir_name[strlen(dir_name) - 1] =
'\0';
967 snprintf(file_name,
sizeof(file_name),
"%s/%s", dir_name, filename);
969 paramfile = fopen(file_name,
"r");
980 "Error: Cannot read pipe 'pkg-config --variable=YP_PARAMS_DIR yp-robot-params'.\n");
985 strcpy(concrete_path, file_name);
986 strcpy(file_name, filename);
989 #endif // HAVE_PKG_CONFIG 997 strcpy(concrete_path, filename);
1006 if (pthread_create(thread, NULL, (
void *)
param_update, filename) != 0)
1019 struct stat prev_status;
1024 stat(filename, &prev_status);
1032 for (i = 0; i < 3; i++)
1035 pthread_testcancel();
1038 stat(filename, &status);
1040 if (difftime(status.st_mtime, prev_status.st_mtime) != 0.0)
1051 prev_status = status;
1053 pthread_cleanup_pop(1);
1082 sscanf(YP_PROTOCOL_NAME,
"YPP:%d:%d", &version, &age);
1120 Gl = fabs(
g_P[YP_PARAM_GEAR][1]);
1130 A = (Gr * Gr * Jmr + Jtr + Rr * Rr / 2.0 * (M / 2.0 + J / (T * T))) / Gr;
1131 B = (Gl * Gl * Jml + Jtl + Rl * Rl / 2.0 * (M / 2.0 + J / (T * T))) / Gl;
1132 C = (Rr * Rl / 2.0 * (M / 2.0 - J / (T * T))) / Gr;
1133 D = (Rr * Rl / 2.0 * (M / 2.0 - J / (T * T))) / Gl;
1389 const float cutoff_vel =
1409 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)