Skip to content
Snippets Groups Projects
Commit 6245a9b1 authored by Beat Küng's avatar Beat Küng Committed by Lorenz Meier
Browse files

motor_test: make -m & -p optional (select all motors/0 output if not given)

parent d660fb09
No related branches found
No related tags found
No related merge requests found
......@@ -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 <channel> Motor to test (0..7)\n"
" -p <power> Power (0..100)\n");
" -m <channel> Motor to test (0..7), all if -m not given\n"
" -p <power> 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;
}
if (channel == -1) {
for (int i = 0; i < 8; ++i) {
motor_test(i, value);
usleep(10000);
}
printf("motor %d set to %.2f\n", channel, (double)value);
} else {
motor_test(channel, value);
}
exit(0);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment