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

Trad Heli: [GSoC] Autonomous Autorotation - SITL only #12108

Open
wants to merge 11 commits into
base: master
from

Conversation

@Gone4Dirt
Copy link
Contributor

commented Aug 21, 2019

This PR is to merge the work done so far on the autonomous autorotation controller. So far the Entry, Glide, and Bail Out phases have been developed to the point of being ready to incorporate into master. As it is incomplete, this flight mode has been made SITL only. Development is ongoing, however I would like for this to be merged into master at this stage to effectively act as a 'space saver' in the code and help me keep on top of maintaining the currency of the code with master.

Here is a demo of the functionality and brief explaination of how to use the flight mode using Real Flight 8.

https://youtu.be/rG3WAB25ctk

Switching into this flight mode is different to 'normal' flight modes. This diagram illustrates the switchology.

Switchology_Flow_Diagram_Mk2

Autorotation Library

This library holds all of the functions and parameters that are bespoke to the autorotation flight mode. Future autorotation functions will be stored here. The main two functions are update_hs_glide_controller() and get_rpm().

update_hs_glide_controller() is the head speed controller. This manipulates the collective position to achieve and maintain head speed. It utilises a simple P-term controller and a following trim. The following trim applys a LPF to the previous collective setting to control the rate at which the trim can change. During the entry phase the trim changes much quicker to achieve a sensible trim position. The trim is slowed down during the glide. This allows for fine tuning adjustments and reduces sensitivity to transient effects such as gusting winds.

get_rpm() interfaces with the RPM library, getting the correct RPM instance to be used for measuring the main rotor head speed. It also conducts sensor health monitoring and relays to the head speed controller if the sensor can be trusted or not. A demonstration of the sensor switching and the controller behaviour with poor RPM sensor health can be seen here:

https://youtu.be/6YBl-w4EowY

The parameters are as follows:

AROT_ENABLE - Enables the autorotation mode and displays the AROT parameters.

AROT_HS_P - P gain for the head speed controller. This parameter should need tuning. It should work for all helis.

AROT_HS_SP - Set Point for the head speed controller. This is the target RPM for the main rotor. Start by using the hover head speed
for your aircraft.

AROT_TARG_SP - Target forward speed (cm/s). This is the target speed passed to the speed height controller.

AROT_COL_FILT_E - The low pass filter cut off frequency (Hz), applied to the collective during the entry phase. This shouldn't need tuning.
However, if using a large heli with significant inertia in main rotor, and the head speed hughly over-shoots the target RPM (>450+ RPM) then
consider reducing this value a little. Conversly, very small helis with low inertia may need to increase the frequency. The default value
will work for all sizes though. This value should be greater than AROT_COL_FILT_G.

AROT_COL_FILT_G - The low pass filter cut off frequency (Hz), applied to the collective during the glide phase. This shouldn't need tuning.
However, if using a large heli with significant inertia in main rotor, and the head speed oscillates about target RPM (+/-50 RPM), whilst not
manouvering, then consider reducing this value a little. Conversly, very small helis with low inertia may need to increase the frequency.
The default value will work for all sizes though. This value should be smaller than AROT_COL_FILT_E.

AROT_AS_ACC_MAX - The maximum forward acceleration applied to the speed-height controller (cm/s/s).

AROT_BAIL_TIME - The time in seconds between initiating the bail out phase and hand over to the new flight mode.

AROT_HS_SENSOR - The RPM sensor instance to be used to measure main rotor head speed. 0 - RPM Sensor 1, 1 - RPM sensor 2. Must be 0 in SITL with real flight.

Speed Height Library

This library holds the functions for the forward speed/pitch control. This library was cherry-picked from @bnsgeyer 's L1-nav controller. I have modified it slightly. I moved the forward speed calculation into its own function, to allow it to be used by mode_autorotation.cpp. I removed the D-term as it is unnecessary/doesn't contribute must to this controller. The controller uses the PID library to convert the desired velocity into a desired acceleration. The acceleration is then limited to prevent over pitching and ensure smooth transitions. The acceleration is then converted into a pitch target using a little geometry. The pitch target is retrieved by mode_autorotation.cpp and passed to the attitude controller.

The parameters are as follows:

SPDHGT_VEL_P - P term gain

SPDHGT_VEL_I - I term gain

SPDHGT_VEL_D - D term gain. Not used but shows up as part of the PID library.

SPDHGT_VEL_FF - Feed forward term gain

SPDHGT_VEL_IMAX - I term limit.

SPDHGT_VEL_FLTT - Target filter

SPDHGT_VEL_FLTE - Error filter

SPDHGT_VEL_FLTD - D term filter. Not used but shows up as part of the PID library.

@OXINARF OXINARF requested review from bnsgeyer and ChristopherOlson Aug 21, 2019
@OXINARF OXINARF added the TradHeli label Aug 21, 2019
@bnsgeyer bnsgeyer force-pushed the Gone4Dirt:AROT-Master branch 2 times, most recently from fc84932 to b1fe8d8 Sep 14, 2019
@bnsgeyer

This comment has been minimized.

Copy link
Contributor

commented Sep 15, 2019

@Gone4Dirt I have completed the rebase on master. As discussed earlier today, please fix the metadata errors. I will start testing to make sure we haven't broken anything.

@Gone4Dirt Gone4Dirt force-pushed the Gone4Dirt:AROT-Master branch 3 times, most recently from f5150d3 to 86f2adf Sep 16, 2019
@Gone4Dirt

This comment has been minimized.

Copy link
Contributor Author

commented Sep 18, 2019

Thanks for pushing the meta data fix @bnsgeyer. I have fixed the last issues now and all of the checks pass. Do you think this is ready for merging? Anything else I need to do?

Copy link
Contributor

left a comment

@Gone4Dirt just a few nits on line spacing and notes on how to handle the spdhgt parameters

ArduCopter/Copter.h Outdated Show resolved Hide resolved
ArduCopter/Copter.h Outdated Show resolved Hide resolved
libraries/AP_SpdHgtControl/AP_SpdHgtControl_Heli.cpp Outdated Show resolved Hide resolved
ArduCopter/heli.cpp Show resolved Hide resolved
Copy link
Contributor

left a comment

Please move to mixed-case for your commit messages, so

COPTER: Added autorotation flight mode

becomes:

Copter: Added autorotation flight mode

ArduCopter/heli.cpp Outdated Show resolved Hide resolved
@Gone4Dirt Gone4Dirt force-pushed the Gone4Dirt:AROT-Master branch from 20a33c5 to ad9e34b Sep 21, 2019
ArduCopter/heli.cpp Outdated Show resolved Hide resolved
ArduCopter/heli.cpp Outdated Show resolved Hide resolved
@Gone4Dirt Gone4Dirt force-pushed the Gone4Dirt:AROT-Master branch from fbe686e to 8085441 Sep 21, 2019
@Gone4Dirt

This comment has been minimized.

Copy link
Contributor Author

commented Sep 21, 2019

I have now tidied up the commits and followed the convention that @peterbarker requested.

@rmackay9

This comment has been minimized.

Copy link
Contributor

commented Sep 24, 2019

The outcome of the dev call was that I will do a review and then merge.

// @Group: SPDHGT_
// @Path: ../libraries/AP_SpdHgtControl/AP_SpdHgtControl_Heli.cpp
GOBJECTPTR(helispdhgtctrl, "SPDHGT_", AP_SpdHgtControl_Heli),
#endif
#endif

This comment has been minimized.

Copy link
@bnsgeyer

bnsgeyer Sep 24, 2019

Contributor

Per last night's Dev call, these will need to be moved into the G2 parameter grouping below. Looks like the syntax is slightly different.

This comment has been minimized.

Copy link
@Gone4Dirt

Gone4Dirt Sep 25, 2019

Author Contributor

Having a spot of trouble with this. I have moved the parameters over to the G2 group and the code builds. However, I cant see the parameters in MP. I have pushed a commit with my changes. Would appreciate it anyone could have a look over it to see if they can spot what I am doing wrong.

@@ -373,6 +373,9 @@ class Parameters {

// 254,255: reserved

k_param_helispdhgtctrl = 256,
k_param_arot = 257, // Autorotation controller library

// the k_param_* space is 9-bits in size

This comment has been minimized.

Copy link
@bnsgeyer

bnsgeyer Sep 24, 2019

Contributor

Per last night's Dev call, these will need to be moved to the G2 parameter class below. Looks like the syntax is different for including the parameters in the group.

This comment has been minimized.

Copy link
@Gone4Dirt

Gone4Dirt Sep 25, 2019

Author Contributor

Having a spot of trouble with this. I have moved the parameters over to the G2 group and the code builds. However, I cant see the parameters in MP. I have pushed a commit with my changes. Would appreciate it anyone could have a look over it to see if they can spot what I am doing wrong.

Copy link
Contributor

left a comment

In general this looks pretty good. I've made a significant number of comments but most of them are non-functional formatting and style changes so hopefully they will be easy-ish to take care of. Some of my comments can be ignored of course if you and BillG don't agree. Txs!

ArduCopter/Parameters.cpp Outdated Show resolved Hide resolved
ArduCopter/Parameters.cpp Outdated Show resolved Hide resolved
ArduCopter/crash_check.cpp Outdated Show resolved Hide resolved
ArduCopter/defines.h Outdated Show resolved Hide resolved
ArduCopter/heli.cpp Show resolved Hide resolved
}

//Calculate glide slope
float windless_glide_slope = atanf(sink_velocity/ground_speed_forward);

This comment has been minimized.

Copy link
@rmackay9

rmackay9 Oct 4, 2019

Contributor

consider compressing this down into a single line, "return atanf(sink_velocity/ground_speed_forward);"

}


void ModeAutorotate::warning_message(uint8_t message_n)

This comment has been minimized.

Copy link
@rmackay9

rmackay9 Oct 4, 2019

Contributor

I guess it's to make things easier in the future but personally I'd remove this function and just add the send_texts in the single call to warning_message()

void AC_Autorotation::init_hs_controller()
{
//set initial collective position to be the collective position on initialisation
_collective_out = 0.4f;//_motors.get_throttle();

This comment has been minimized.

Copy link
@rmackay9

rmackay9 Oct 4, 2019

Contributor

let's remove the //_motors.get_throttle() part.

}

//Check that interlock is disengaged
if (motors->get_interlock()) {

This comment has been minimized.

Copy link
@rmackay9

rmackay9 Oct 4, 2019

Contributor

nitpick: slight indenting issue here...

#include <AP_Common/AP_Common.h>
#include <AP_Param/AP_Param.h>
#include <AP_Math/AP_Math.h>
#include <AP_Logger/AP_Logger.h>

This comment has been minimized.

Copy link
@rmackay9

rmackay9 Oct 4, 2019

Contributor

I think the include of AP_Logger and AP_RPM can be moved to the .cpp file. It's nice to reduce includes in the .h files because it reduces compile time.

@Gone4Dirt

This comment has been minimized.

Copy link
Contributor Author

commented Oct 4, 2019

Thank you for the review @rmackay9. There is a lot in there to help me learn, so I appricate you taking the time to explain things. I will get those changes implemented. I am also working on getting the parameters moved over to G2. Having a few difficulties with getting that working at the moment, but I am working through it.

@Gone4Dirt

This comment has been minimized.

Copy link
Contributor Author

commented Oct 7, 2019

I have been trying to move my parameters over to the G2 class as requested by @tridge . The parameters now show up but won't load defaults. I am completely stumped on this one, and have been working on it for ages. @rmackay9 @tridge @peterbarker would any of you have time to look over what I am doing and point me in the right direction please? Any advice is greatly received.

@peterbarker

This comment has been minimized.

Copy link
Contributor

commented Oct 7, 2019

IamPete1 and others added 3 commits Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.