Skip to content
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

Merged
merged 6 commits into from
Aug 15, 2019
Merged

Conversation

DanielePettenuzzo
Copy link
Contributor

@DanielePettenuzzo DanielePettenuzzo commented Jan 20, 2019

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.

@DanielePettenuzzo
Copy link
Contributor Author

@RomanBapst FYI

LorenzMeier
LorenzMeier previously approved these changes Jan 20, 2019
Copy link
Member

@LorenzMeier LorenzMeier left a 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.

@dagar
Copy link
Member

dagar commented Jan 21, 2019

Motor test would be extremely helpful for new setups. It's a frequent request.

Existing issue and related discussion.
#10782
#9544 (comment)

Safety concerns were one of the reasons I never got around to plumbing this together with the existing MAV_CMD_DO_MOTOR_TEST command.

@DanielePettenuzzo
Copy link
Contributor Author

@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.

@DanielePettenuzzo DanielePettenuzzo changed the title [WIP] motor_ramp: set fmu in test mode and main cleanup motor_ramp: set fmu in test mode and main cleanup Jan 21, 2019
@DanielePettenuzzo
Copy link
Contributor Author

@LorenzMeier @bkueng Rebased. I think we can merge this

Copy link
Member

@bkueng bkueng left a 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member

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*

Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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.

src/systemcmds/motor_ramp/motor_ramp.cpp Show resolved Hide resolved
@DanielePettenuzzo
Copy link
Contributor Author

@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);
Copy link
Member

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.

Suggested change
_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);
Copy link
Member

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?

src/systemcmds/motor_ramp/motor_ramp.cpp Show resolved Hide resolved
@bresch bresch force-pushed the pr-motor-ramp-fixes branch from 8aed261 to 9dccb5a Compare August 14, 2019 13:47
@bresch bresch force-pushed the pr-motor-ramp-fixes branch from 9dccb5a to c7bf569 Compare August 14, 2019 13:59
@bresch
Copy link
Member

bresch commented Aug 14, 2019

@bkueng Are we good now?

Copy link
Member

@bkueng bkueng left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member

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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* 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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PX4_ERR("failed getting pwm min values");
PX4_ERR("failed setting pwm min values");

@bresch
Copy link
Member

bresch commented Aug 14, 2019

@bkueng Done

@bkueng bkueng merged commit 82ecf4d into master Aug 15, 2019
@bkueng bkueng deleted the pr-motor-ramp-fixes branch August 15, 2019 07:42
bozkurthan pushed a commit to bozkurthan/Firmware that referenced this pull request Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants