mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 00:03:33 +08:00
Handle the config command line arguments a bit more intuitive
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved.
|
||||||
* Author: Lorenz Meier <lm@inf.ethz.ch>
|
* Author: Lorenz Meier <lm@inf.ethz.ch>
|
||||||
|
* Author: Julian Oes <joes@student.ethz.ch>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file config.c
|
* @file config.c
|
||||||
* @author Lorenz Meier <lm@inf.ethz.ch>
|
* @author Lorenz Meier <lm@inf.ethz.ch>
|
||||||
|
* @author Julian Oes <joes@student.ethz.ch>
|
||||||
*
|
*
|
||||||
* config tool.
|
* config tool.
|
||||||
*/
|
*/
|
||||||
@@ -69,27 +71,15 @@ config_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
if (!strcmp(argv[1], "gyro")) {
|
if (!strcmp(argv[1], "gyro")) {
|
||||||
if (argc >= 3) {
|
do_gyro(argc - 2, argv + 2);
|
||||||
do_gyro(argc - 2, argv + 2);
|
|
||||||
} else {
|
|
||||||
errx(1, "not enough parameters.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "accel")) {
|
if (!strcmp(argv[1], "accel")) {
|
||||||
if (argc >= 3) {
|
do_accel(argc - 2, argv + 2);
|
||||||
do_accel(argc - 2, argv + 2);
|
|
||||||
} else {
|
|
||||||
errx(1, "not enough parameters.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "mag")) {
|
if (!strcmp(argv[1], "mag")) {
|
||||||
if (argc >= 3) {
|
do_mag(argc - 2, argv + 2);
|
||||||
do_mag(argc - 2, argv + 2);
|
|
||||||
} else {
|
|
||||||
errx(1, "not enough parameters.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,44 +99,36 @@ do_gyro(int argc, char *argv[])
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (argc >= 2) {
|
if (argc == 2 && !strcmp(argv[0], "sampling")) {
|
||||||
|
|
||||||
char* end;
|
/* set the gyro internal sampling rate up to at least i Hz */
|
||||||
int i = strtol(argv[1],&end,10);
|
ioctl(fd, GYROIOCSSAMPLERATE, strtoul(argv[1], NULL, 0));
|
||||||
|
|
||||||
if (!strcmp(argv[0], "sampling")) {
|
} else if (argc == 2 && !strcmp(argv[0], "rate")) {
|
||||||
|
|
||||||
/* set the accel internal sampling rate up to at leat i Hz */
|
/* set the driver to poll at i Hz */
|
||||||
ioctl(fd, GYROIOCSSAMPLERATE, i);
|
ioctl(fd, SENSORIOCSPOLLRATE, strtoul(argv[1], NULL, 0));
|
||||||
|
|
||||||
} else if (!strcmp(argv[0], "rate")) {
|
} else if (argc == 2 && !strcmp(argv[0], "range")) {
|
||||||
|
|
||||||
/* set the driver to poll at i Hz */
|
/* set the range to i dps */
|
||||||
ioctl(fd, SENSORIOCSPOLLRATE, i);
|
ioctl(fd, GYROIOCSRANGE, strtoul(argv[1], NULL, 0));
|
||||||
} else if (!strcmp(argv[0], "range")) {
|
|
||||||
|
|
||||||
/* set the range to i dps */
|
} else if(argc == 1 && !strcmp(argv[0], "check")) {
|
||||||
ioctl(fd, GYROIOCSRANGE, i);
|
int ret = ioctl(fd, GYROIOCSELFTEST, 0);
|
||||||
}
|
|
||||||
|
|
||||||
} else if (argc > 0) {
|
if (ret) {
|
||||||
|
warnx("gyro self test FAILED! Check calibration:");
|
||||||
if(!strcmp(argv[0], "check")) {
|
struct gyro_scale scale;
|
||||||
int ret = ioctl(fd, GYROIOCSELFTEST, 0);
|
ret = ioctl(fd, GYROIOCGSCALE, (long unsigned int)&scale);
|
||||||
|
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
||||||
if (ret) {
|
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
||||||
warnx("gyro self test FAILED! Check calibration:");
|
} else {
|
||||||
struct gyro_scale scale;
|
warnx("gyro calibration and self test OK");
|
||||||
ret = ioctl(fd, GYROIOCGSCALE, (long unsigned int)&scale);
|
|
||||||
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
|
||||||
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
|
||||||
} else {
|
|
||||||
warnx("gyro calibration and self test OK");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
warnx("no arguments given. Try: \n\n\t'sampling 500' to set sampling to 500 Hz\n\t'rate 500' to set publication rate to 500 Hz\n\t'range 2000' to set measurement range to 2000 dps\n\t");
|
errx(1, "wrong or no arguments given. Try: \n\n\t'check' for the self test\n\t'sampling 500' to set sampling to 500 Hz\n\t'rate 500' to set publication rate to 500 Hz\n\t'range 2000' to set measurement range to 2000 dps\n\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
int srate = ioctl(fd, GYROIOCGSAMPLERATE, 0);
|
int srate = ioctl(fd, GYROIOCGSAMPLERATE, 0);
|
||||||
@@ -174,29 +156,26 @@ do_mag(int argc, char *argv[])
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (argc > 0) {
|
if(argc == 1 && !strcmp(argv[0], "check")) {
|
||||||
|
int ret = ioctl(fd, MAGIOCSELFTEST, 0);
|
||||||
|
|
||||||
if (!strcmp(argv[0], "check")) {
|
if (ret) {
|
||||||
int ret = ioctl(fd, MAGIOCSELFTEST, 0);
|
warnx("mag self test FAILED! Check calibration:");
|
||||||
|
struct mag_scale scale;
|
||||||
if (ret) {
|
ret = ioctl(fd, MAGIOCGSCALE, (long unsigned int)&scale);
|
||||||
warnx("mag self test FAILED! Check calibration.");
|
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
||||||
struct mag_scale scale;
|
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
||||||
ret = ioctl(fd, MAGIOCGSCALE, (long unsigned int)&scale);
|
} else {
|
||||||
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
warnx("mag calibration and self test OK");
|
||||||
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
|
||||||
} else {
|
|
||||||
warnx("mag calibration and self test OK");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
warnx("no arguments given. Try: \n\n\t'check' or 'info'\n\t");
|
errx(1, "wrong or no arguments given. Try: \n\n\t'check' for the self test\n\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
int srate = -1;//ioctl(fd, MAGIOCGSAMPLERATE, 0);
|
int srate = -1; //ioctl(fd, MAGIOCGSAMPLERATE, 0);
|
||||||
int prate = ioctl(fd, SENSORIOCGPOLLRATE, 0);
|
int prate = ioctl(fd, SENSORIOCGPOLLRATE, 0);
|
||||||
int range = -1;//ioctl(fd, MAGIOCGRANGE, 0);
|
int range = -1; //ioctl(fd, MAGIOCGRANGE, 0);
|
||||||
|
|
||||||
warnx("mag: \n\tsample rate:\t%d Hz\n\tread rate:\t%d Hz\n\trange:\t%d gauss", srate, prate, range);
|
warnx("mag: \n\tsample rate:\t%d Hz\n\tread rate:\t%d Hz\n\trange:\t%d gauss", srate, prate, range);
|
||||||
|
|
||||||
@@ -219,43 +198,36 @@ do_accel(int argc, char *argv[])
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (argc >= 2) {
|
if (argc == 2 && !strcmp(argv[0], "sampling")) {
|
||||||
|
|
||||||
char* end;
|
/* set the accel internal sampling rate up to at least i Hz */
|
||||||
int i = strtol(argv[1],&end,10);
|
ioctl(fd, ACCELIOCSSAMPLERATE, strtoul(argv[1], NULL, 0));
|
||||||
|
|
||||||
if (!strcmp(argv[0], "sampling")) {
|
} else if (argc == 2 && !strcmp(argv[0], "rate")) {
|
||||||
|
|
||||||
/* set the accel internal sampling rate up to at leat i Hz */
|
/* set the driver to poll at i Hz */
|
||||||
ioctl(fd, ACCELIOCSSAMPLERATE, i);
|
ioctl(fd, SENSORIOCSPOLLRATE, strtoul(argv[1], NULL, 0));
|
||||||
|
|
||||||
} else if (!strcmp(argv[0], "rate")) {
|
} else if (argc == 2 && !strcmp(argv[0], "range")) {
|
||||||
|
|
||||||
/* set the driver to poll at i Hz */
|
/* set the range to i m/s^2 */
|
||||||
ioctl(fd, SENSORIOCSPOLLRATE, i);
|
ioctl(fd, ACCELIOCSRANGE, strtoul(argv[1], NULL, 0));
|
||||||
} else if (!strcmp(argv[0], "range")) {
|
|
||||||
|
|
||||||
/* set the range to i dps */
|
} else if(argc == 1 && !strcmp(argv[0], "check")) {
|
||||||
ioctl(fd, ACCELIOCSRANGE, i);
|
int ret = ioctl(fd, ACCELIOCSELFTEST, 0);
|
||||||
}
|
|
||||||
} else if (argc > 0) {
|
|
||||||
|
|
||||||
if (!strcmp(argv[0], "check")) {
|
if (ret) {
|
||||||
int ret = ioctl(fd, ACCELIOCSELFTEST, 0);
|
warnx("accel self test FAILED! Check calibration:");
|
||||||
|
struct accel_scale scale;
|
||||||
if (ret) {
|
ret = ioctl(fd, ACCELIOCGSCALE, (long unsigned int)&scale);
|
||||||
warnx("accel self test FAILED! Check calibration.");
|
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
||||||
struct accel_scale scale;
|
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
||||||
ret = ioctl(fd, ACCELIOCGSCALE, (long unsigned int)&scale);
|
} else {
|
||||||
warnx("offsets: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_offset, scale.y_offset, scale.z_offset);
|
warnx("accel calibration and self test OK");
|
||||||
warnx("scale: X: % 9.6f Y: % 9.6f Z: % 9.6f", scale.x_scale, scale.y_scale, scale.z_scale);
|
|
||||||
} else {
|
|
||||||
warnx("accel calibration and self test OK");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
warnx("no arguments given. Try: \n\n\t'sampling 500' to set sampling to 500 Hz\n\t'rate 500' to set publication rate to 500 Hz\n\t'range 2' to set measurement range to 2 G\n\t");
|
errx(1,"no arguments given. Try: \n\n\t'sampling 500' to set sampling to 500 Hz\n\t'rate 500' to set publication rate to 500 Hz\n\t'range 2' to set measurement range to 4 G\n\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
int srate = ioctl(fd, ACCELIOCGSAMPLERATE, 0);
|
int srate = ioctl(fd, ACCELIOCGSAMPLERATE, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user