-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
motor_ramp: set fmu in test mode and main cleanup #11249
Conversation
@RomanBapst FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Good to see this being simplified. I still would love to have motor test support via commands (already enabled in Auterion GS) in the UI. But that doesn't impact this PR. Please merge after on-HW test.
Motor test would be extremely helpful for new setups. It's a frequent request. Existing issue and related discussion. Safety concerns were one of the reasons I never got around to plumbing this together with the existing MAV_CMD_DO_MOTOR_TEST command. |
@LorenzMeier I tested it a bit and found out that the pwm min was not restored at the end of the test. I pushed a commit that fixes it. I think we can merge this. |
0d0aced
to
add7f05
Compare
@LorenzMeier @bkueng Rebased. I think we can merge this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup!
static Mode _mode; | ||
static char *_mode_c; | ||
static char *_pwm_output_dev = "/dev/pwm_output0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static char *_pwm_output_dev = "/dev/pwm_output0"; | |
static const char *_pwm_output_dev = "/dev/pwm_output0"; |
case 'r': | ||
_ramp_time = atof(myoptarg); | ||
|
||
if (!(_ramp_time > 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!(_ramp_time > 0)) { | |
if (_ramp_time <= 0) { |
} | ||
|
||
if (!(_ramp_time > 0)) { | ||
usage("ramp time must be greater than 0"); | ||
_mode_c = const_cast<char*>(myoptarg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change _mode_c
to const char*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the cast?
static char *_pwm_output_dev = "/dev/pwm_output0"; | ||
static struct pwm_output_values _last_spos; | ||
static struct pwm_output_values _last_min; | ||
static unsigned _servo_count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move all of these 3 into motor_ramp_thread_main
.
static int _min_pwm; | ||
static int _max_pwm; | ||
static int _max_pwm = 2000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reset these default values inside motor_ramp_main
, at the very top. Otherwise you get inconsistent results, e.g. with:
motor_ramp sine -a 1100 -r 0.5 -b 1800
motor_ramp sine <- will use 1800 as max pwm, not 2000.
add7f05
to
8aed261
Compare
@bkueng rebased and added a commit fixing stuff based on your review |
_mode = SQUARE; | ||
case 'd': | ||
if(!strcmp(myoptarg, "/dev/pwm_output0") || !strcmp(myoptarg, "/dev/pwm_output1")){ | ||
_pwm_output_dev = const_cast<char*>(myoptarg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast should not be required.
_pwm_output_dev = const_cast<char*>(myoptarg); | |
_pwm_output_dev = myoptarg; |
} | ||
|
||
if (!(_ramp_time > 0)) { | ||
usage("ramp time must be greater than 0"); | ||
_mode_c = const_cast<char*>(myoptarg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the cast?
8aed261
to
9dccb5a
Compare
… before returning
9dccb5a
to
c7bf569
Compare
@bkueng Are we good now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. Found some more things.
|
||
if(!set_pwm_min){ | ||
PX4_WARN("pwm_min not set. use -a flag"); | ||
error_flag = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error_flag = 1; | |
error_flag = true; |
|
||
if (fd < 0) { | ||
PX4_ERR("can't open %s", dev); | ||
PX4_ERR("can't open %s", _pwm_output_dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a return 1
Also _thread_running
needs to be set to false on each return.
@@ -413,8 +494,28 @@ int motor_ramp_thread_main(int argc, char *argv[]) | |||
} | |||
|
|||
if (fd >= 0) { | |||
/* disarm */ | |||
ioctl(fd, PWM_SERVO_DISARM, 0); | |||
/* get current pwm min */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* get current pwm min */ | |
/* set current pwm min */ |
ioctl(fd, PWM_SERVO_DISARM, 0); | ||
/* get current pwm min */ | ||
if (px4_ioctl(fd, PWM_SERVO_SET_MIN_PWM, (long unsigned int)&last_min) < 0) { | ||
PX4_ERR("failed getting pwm min values"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PX4_ERR("failed getting pwm min values"); | |
PX4_ERR("failed setting pwm min values"); |
@bkueng Done |
and restore pwm min after test
This application was broken because it created a conflict on the pwm outputs. Now before starting the test we put the outputs in TEST mode until the test is over. Moreover a cleanup of the main function was done. Now arguments are handled with the px4_getopt function and the usage function contains more information.
Before the test could be done only on pwm_output0, while now we can use the -d flag to choose output1.
Tested on a pixhawk 4 but without motors so I just need to do a test on a vehicle before it is ready to merge.