Skip to content
Snippets Groups Projects
Commit 0ce854ad authored by David Sidrane's avatar David Sidrane Committed by Lorenz Meier
Browse files

Support onshot command

parent 6bc04201
No related branches found
No related tags found
No related merge requests found
...@@ -83,6 +83,12 @@ usage(const char *reason) ...@@ -83,6 +83,12 @@ usage(const char *reason)
"arm\t\t\t\tArm output\n" "arm\t\t\t\tArm output\n"
"disarm\t\t\t\tDisarm output\n" "disarm\t\t\t\tDisarm output\n"
"\n" "\n"
"oneshot ...\t\t\tConfigure Onshot\n"
"\t[-g <channel group>]\t(e.g. 0,1,2)\n"
"\t[-m <channel mask> ]\t(e.g. 0xF)\n"
"\t[-a]\t\t\tConfigure all outputs\n"
"\t-t <pulse>\t\tOneshot duration (1 to 65535 125nS)\n"
"\n"
"rate ...\t\t\tConfigure PWM rates\n" "rate ...\t\t\tConfigure PWM rates\n"
"\t[-g <channel group>]\t(e.g. 0,1,2)\n" "\t[-g <channel group>]\t(e.g. 0,1,2)\n"
"\t[-m <channel mask> ]\t(e.g. 0xF)\n" "\t[-m <channel mask> ]\t(e.g. 0xF)\n"
...@@ -169,6 +175,7 @@ pwm_main(int argc, char *argv[]) ...@@ -169,6 +175,7 @@ pwm_main(int argc, char *argv[])
bool alt_channels_set = false; bool alt_channels_set = false;
bool print_verbose = false; bool print_verbose = false;
bool error_on_warn = false; bool error_on_warn = false;
bool oneshot = false;
int ch; int ch;
int ret; int ret;
char *ep; char *ep;
...@@ -302,6 +309,8 @@ pwm_main(int argc, char *argv[]) ...@@ -302,6 +309,8 @@ pwm_main(int argc, char *argv[])
return error_on_warn; return error_on_warn;
} }
oneshot = !strcmp(command, "oneshot");
if (!strcmp(command, "arm")) { if (!strcmp(command, "arm")) {
/* tell safety that its ok to disable it with the switch */ /* tell safety that its ok to disable it with the switch */
ret = px4_ioctl(fd, PWM_SERVO_SET_ARM_OK, 0); ret = px4_ioctl(fd, PWM_SERVO_SET_ARM_OK, 0);
...@@ -337,19 +346,18 @@ pwm_main(int argc, char *argv[]) ...@@ -337,19 +346,18 @@ pwm_main(int argc, char *argv[])
return 0; return 0;
} else if (!strcmp(command, "rate")) { } else if (oneshot || !strcmp(command, "rate")) {
/* change alternate PWM rate */ /* change alternate PWM rate or set oneshot */
// if (alt_rate > 0) { if (oneshot || alt_rate > 0) {
ret = px4_ioctl(fd, PWM_SERVO_SET_UPDATE_RATE, alt_rate); ret = px4_ioctl(fd, PWM_SERVO_SET_UPDATE_RATE, alt_rate);
if (ret != OK) { if (ret != OK) {
PX4_ERR("PWM_SERVO_SET_UPDATE_RATE (check rate for sanity)"); PX4_ERR("PWM_SERVO_SET_UPDATE_RATE (check rate for sanity)");
return error_on_warn; return error_on_warn;
}
} }
// }
/* directly supplied channel mask */ /* directly supplied channel mask */
if (set_mask > 0) { if (set_mask > 0) {
ret = px4_ioctl(fd, PWM_SERVO_SET_SELECT_UPDATE_RATE, set_mask); ret = px4_ioctl(fd, PWM_SERVO_SET_SELECT_UPDATE_RATE, set_mask);
...@@ -632,7 +640,6 @@ pwm_main(int argc, char *argv[]) ...@@ -632,7 +640,6 @@ pwm_main(int argc, char *argv[])
PX4_INFO("Press CTRL-C or 'c' to abort."); PX4_INFO("Press CTRL-C or 'c' to abort.");
while (1) { while (1) {
for (unsigned i = 0; i < servo_count; i++) { for (unsigned i = 0; i < servo_count; i++) {
if (set_mask & 1 << i) { if (set_mask & 1 << i) {
ret = px4_ioctl(fd, PWM_SERVO_SET(i), pwm_value); ret = px4_ioctl(fd, PWM_SERVO_SET(i), pwm_value);
...@@ -670,7 +677,15 @@ pwm_main(int argc, char *argv[]) ...@@ -670,7 +677,15 @@ pwm_main(int argc, char *argv[])
} }
} }
usleep(2500); /* Delay longer than the max Oneshot duration */
usleep(2542);
/* Trigger all timer's channels in Oneshot mode to fire
* the oneshots with updated values.
*/
up_pwm_update();
} }
return 0; return 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