From 6245a9b1345187e71642df482e176559a1e86c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 25 Jul 2016 12:53:34 +0200 Subject: [PATCH] motor_test: make -m & -p optional (select all motors/0 output if not given) --- src/systemcmds/motor_test/motor_test.c | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/systemcmds/motor_test/motor_test.c b/src/systemcmds/motor_test/motor_test.c index a1175c289f..76ec68d0d4 100644 --- a/src/systemcmds/motor_test/motor_test.c +++ b/src/systemcmds/motor_test/motor_test.c @@ -77,6 +77,8 @@ void motor_test(unsigned channel, float value) /* advertise and publish */ _test_motor_pub = orb_advertise(ORB_ID(test_motor), &_test_motor); } + + printf("motor %d set to %.2f\n", channel, (double)value); } static void usage(const char *reason) @@ -88,27 +90,24 @@ static void usage(const char *reason) errx(1, "usage:\n" "motor_test\n" - " -m Motor to test (0..7)\n" - " -p Power (0..100)\n"); + " -m Motor to test (0..7), all if -m not given\n" + " -p Power (0..100), 0 if -p not given\n" + "motor_test stop Stop all motors\n"); } int motor_test_main(int argc, char *argv[]) { - unsigned long channel = 0; + int channel = -1; //default to all channels unsigned long lval; float value = 0.0f; int ch; - if (argc != 5) { - usage("please specify motor and power"); - } - while ((ch = getopt(argc, argv, "m:p:")) != EOF) { switch (ch) { case 'm': /* Read in motor number */ - channel = strtoul(optarg, NULL, 0); + channel = (int)strtoul(optarg, NULL, 0); break; case 'p': @@ -127,9 +126,20 @@ int motor_test_main(int argc, char *argv[]) } } - motor_test(channel, value); + if (argc > 1 && strcmp("stop", argv[1]) == 0) { + channel = -1; + value = 0.f; + } - printf("motor %d set to %.2f\n", channel, (double)value); + if (channel == -1) { + for (int i = 0; i < 8; ++i) { + motor_test(i, value); + usleep(10000); + } + + } else { + motor_test(channel, value); + } exit(0); }