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

Merge vtol mc motor handling methods #9028

Merged
merged 9 commits into from
Apr 12, 2018
Merged

Conversation

dagar
Copy link
Member

@dagar dagar commented Mar 5, 2018

Currently vtol standard disables MC motors by setting the max to PWM 950us, then re-enables them by setting it to 2000 us. PWM min is also overrides the min set in the interface. This PR changes that behaviour to use the configured PWM disarm value to disable the motors, and the set PWM max when re-enabling.

This was tested in a private branch a long time ago, and I tried to get it in with #8040, but it was never merged. As a result this needs to be carefully reviewed and tested from scratch.

With this in place we should be able to get rid of VT_IDLE_PWM_MC.

@dagar
Copy link
Member Author

dagar commented Mar 5, 2018

Tiltrotor::set_rear_motor_state() needs review/rethinking.

@dagar
Copy link
Member Author

dagar commented Mar 5, 2018

After code review this needs bench testing checking pwm info for each vtol type at startup, after transition to FW, after transition back.

@dagar dagar force-pushed the pr-vtol_pwm_preserve branch from 84b39f6 to 7f20813 Compare March 6, 2018 00:41
@RomanBapst
Copy link
Contributor

@dagar I'll have a look at this today.

@RomanBapst
Copy link
Contributor

@dagar Looks good so far. One thing that you could add is to move the set_rear_motor_state() method from the tiltrotor class to the vtol_type class and give it a different name like, e.g. set_motor_state(). Actually now that I think of it we can probably merge all those methods which fiddle with the pwm state of the outputs and use a bitmask (we also already have that for the tiltrotor) to differentiate between the motors.
In the past I was working with a tailsitter which required switching off one motor during fixed wing flight and so I regretted not having the methods to do that in vtol_type.

Copy link
Contributor

@RomanBapst RomanBapst left a comment

Choose a reason for hiding this comment

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

Looks good, see comment in conservation about merging with tiltrotor specific motor disable methods.

@RomanBapst
Copy link
Contributor

@dagar If you rebase I can test it on the tiltrotor and we can get it in.

@RomanBapst
Copy link
Contributor

@dagar I'll take care of this tomorrow.

@dagar dagar force-pushed the pr-vtol_pwm_preserve branch from 7f20813 to 04c5ce7 Compare March 15, 2018 01:00
@dagar
Copy link
Member Author

dagar commented Mar 15, 2018

Rebased, but still need to think about how tiltrotor is even supposed to function. Might need to keep VT_IDLE_PWM_MC after all.

@dagar dagar added this to the Release v1.8.0 milestone Mar 15, 2018
@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 04c5ce7 to a1bdaed Compare March 15, 2018 14:52
@RomanBapst
Copy link
Contributor

@dagar I went through this and noticed that there was a fundamental problem. The motors for tiltrotors and tailsitters where shut off in fixed wing flight which is ok for standard vtol but not for the former ones.

I've reworked this according to the following requirements:

  1. We need to disable a selection of mc motors during the transition or in fixed wing mode. An example of this is the convergence vtol where the rear motor needs to be shut off in fixed wing flight.

Proposed solution:
I've added the function set_motor_state(const motor_state current_state, const motor_state next_state, const int value)

which allows to modify the state of a selection of motors (via the parameter VT_FW_MOT_OFFID).
This method was before only used for tiltrotors. However, the method is now implemented in VtolType and can be used to e.g. shut off the mc motors for a quad plane.
As suggested by your PR, this function preserves the maximum pwm value given by the system.

  1. Idle speed for mc vs fw
    While in mc mode you want the motors to spin you don't necessarily want this behavior in fw mode.

Solution:
As before we use set_idle_mc()/ set_idle_fw() to adjust the idle speed depending on which mode are in.
The following parameter consideration is important for the system to work:
PWM_MIN: defines the idle speed for fixed wing flight, so should be set such that motors stop when throttle is zero
VT_IDLE_PWM_MC: defnes the idle speed when in mc mode, so should be set such that motors spin when throttle is zero.

Important consideration:
Because the parameter VT_FW_MOT_OFFID was previously not used for standard vtol I added a check to the vtol module which hardcodes the parameter such that all motors will be disabled in fw mode. Otherwise we are going to break all existing setups which have this parameter set to a default value of zero.

@RomanBapst RomanBapst changed the title VTOL preserve PWM min and max when enabling/disabling actuators WIP: Merge vtol mc motor handling methods Mar 15, 2018
_flag_enable_mc_motors = false;
// in back transition we need to start the MC motors again
if (_motor_state != ENABLED) {
_motor_state = set_motor_state(_motor_state, ENABLED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about passing the VT_FW_MOT_OFFID parameter as another argument here so that it become more clear that this methods sets the state of a motors selection.

@dagar
Copy link
Member Author

dagar commented Mar 15, 2018

I need to go through in detail, but this makes sense for now. We should have some more interesting options to consider once thrust is split x,y,z.

@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 2920dcd to 5507d88 Compare March 23, 2018 08:45
@RomanBapst
Copy link
Contributor

RomanBapst commented Mar 23, 2018

@dagar Could you give this a review please? I tested the behavior with my tiltrotor and it seems to work fine.
It's important to test if the correct motors switch off during transition from mc to fw and back. Also the idle speed needs to work for both modes.
I tested the quadplane and the tailsitter in SITL which revealed some minor bugs I fixed.
As soon as you reviewed we should get real test flights in on all three platforms.

@dagar
Copy link
Member Author

dagar commented Mar 24, 2018

CI failure is real, but otherwise looks good so far.

This should work for now, but fundamentally it seems like at a lower level the system should already know which motors belong where.

For the shared FW/MC motors in tiltrotor and tailsitter do we need different PWM limits in each state?

@@ -337,18 +288,21 @@ void Tiltrotor::update_transition_state()
int rear_value = (1.0f - time_since_trans_start / _params_tiltrotor.front_trans_dur_p2) *
(PWM_DEFAULT_MAX - PWM_DEFAULT_MIN) + PWM_DEFAULT_MIN;

set_rear_motor_state(VALUE, rear_value);

_motor_state = set_motor_state(_motor_state, VALUE, rear_value);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kind of unfortunate, but I guess we should preserve the existing behaviour for now.

return ret == PX4_OK;
}

bool VtolType::set_idle_fw()
Copy link
Member Author

Choose a reason for hiding this comment

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

Why can't we do this with set_motor_state()?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dagar The problem is that these are two different states which need to be tracked separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mainly wanted to share as much of the code that calls that IOCTLS as we could. At a glance it looks like you've done that now.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dagar Yep, my last commit does that -only one method is used to do ioctl to the pwm output device.

@@ -263,5 +252,153 @@ void VtolType::check_quadchute_condition()
}
}
}
}

bool VtolType::set_idle_mc()
Copy link
Member Author

Choose a reason for hiding this comment

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

Why can't we do this with set_motor_state()?

@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch 2 times, most recently from 7d10266 to 936503e Compare March 26, 2018 12:50
@RomanBapst RomanBapst changed the title WIP: Merge vtol mc motor handling methods Merge vtol mc motor handling methods Mar 26, 2018
@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 936503e to 2613db5 Compare March 26, 2018 13:03
@RomanBapst
Copy link
Contributor

@dagar I totally agree with you that it's not the best solution when the vtol attitude controller directly alters the pwm limits in order to achieve the desired behavior.
The intent of this PR is not to fix this but rather make what we have usable for all three vtol types.

@RomanBapst
Copy link
Contributor

@PX4/testflights Could you please test this on a standard VTOL?

IMPORTANT Please first do a bench test as follows:

  • switch to stabilized mode and arm system in hover mode

  • increase throttle to > 30 %

  • flip transition switch

  • verify that during the transition the mc motors are still working

  • verify that after the transition the mc motors stop and do not respond to throttle
    (if you use an airspeed sensor then pinch the ram pressure tube to trigger the transition to fw mode)

  • flip the switch back to hover

  • verify that the mc motors come alive and control attitude

There should not be any difference in behavior compared to master. If you succeed with the bench tests I'd appreciate a test flight in which you transition from mc to fw a couple of times successively.

@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 2613db5 to 8022708 Compare March 27, 2018 15:38
@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 8022708 to 8b46978 Compare March 28, 2018 07:47
@RomanBapst
Copy link
Contributor

@dagar I tested this again on the tricopter including bailing out of transitions from both mc and fw.
I fixed up a missing px4_close on the file descriptor.
Could you please review, it would like to bring it in then?

@RomanBapst
Copy link
Contributor

@dagar Could you please give this a review if you have some time? I'd like to get it in and it avoids lots of code duplication.

@dagar
Copy link
Member Author

dagar commented Apr 4, 2018

Probably needs one more pass, but looks good.

@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from cb49650 to 939744c Compare April 10, 2018 12:44
@RomanBapst
Copy link
Contributor

Tested on the tiltrotor once more, no issues found
https://logs.px4.io/plot_app?log=ae2b19fb-a22d-47e6-96ad-1a0abf91b348

@RomanBapst RomanBapst force-pushed the pr-vtol_pwm_preserve branch from 939744c to f2da086 Compare April 11, 2018 07:34
@RomanBapst
Copy link
Contributor

@dagar Could you have a look why CI fails, I don't understand it.

dagar and others added 9 commits April 12, 2018 01:45
- moved methods used to modify channel maximum pwm value to VtolType
class so that the can be shared by the differnt vtol types

Signed-off-by: Roman <[email protected]>
- board config can define PX4_PWM_ALTERNATE_RANGES which needs to be known
by the compiler prior to processing this file

Signed-off-by: Roman <[email protected]>
- created one method which has access to the pwm output device

Signed-off-by: Roman <[email protected]>
@dagar dagar force-pushed the pr-vtol_pwm_preserve branch from f2da086 to cfa4d57 Compare April 12, 2018 05:45
@dagar
Copy link
Member Author

dagar commented Apr 12, 2018

Rebased, please check CI again.

@RomanBapst RomanBapst merged commit c206e0f into master Apr 12, 2018
@RomanBapst RomanBapst deleted the pr-vtol_pwm_preserve branch April 12, 2018 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants