-
Notifications
You must be signed in to change notification settings - Fork 16.9k
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
Copter: run rate loop at full filter rate in its own thread #27029
base: master
Are you sure you want to change the base?
Conversation
e67b845
to
679611b
Compare
Flow today on top of 4.5 - working well. |
2370654
to
6398bd3
Compare
@rmackay9 this is close to being ready and I could use your input on what the configuration should look like. The basic premise is that we run the rate controller at the same rate as the gyros which is controlled by Currently we have the following: I'm not currently convinced about the naming or the configuration. I think this is an important enough feature that it needs its own enable flag. I also think it would be worth having a rate parameter that allows you to fix the rate. I also think that ATT is a little bit misleading. Maybe FAST_RATE_ or RATET_ or something. So an alternative might be:
or something. It would also be possible to not use Hz at all but simply pick the divisor. So 2 would be gyro rate / 2 etc. |
conditionally compile rate thread pieces
log latest gyro in RATE messages
… through servos when outputting to motors
…hrough servos when outputting to motors
honour the requested dshot rate as near as possible
if target rate changes immediately jump to target rate recover quickly from rate changes ensure fixed rate always prints the rate on arming and is always up to date add support for fixed rate attitude that does not change when disarmed only push to subsystems at main loop rate add logging and motor timing debug correctly round gyro decimation rates set dshot rate when changing attitude rate fallback to higher dshot rates at lower loop rates re-factor rate loop rate updates
don't compile in support on tradheli
27113dd
to
45001c5
Compare
This is the rough cost for the refactoring required:
|
The reason why BinarySemaphore does not work in this case is two-fold:
|
223bbb7
to
5f1bc15
Compare
I hope I'm not just being thick here, but I think I really do need to understand what is going on here. Potentially dumb questions below.
first off, by "attitude thread" I assume you mean the rate thread? The attitude control is still in the main thread as far as I can see, only rate update in the rate thread. I know we discussed moving the attitude update into that thread but unless I've missed it that isn't being done in this PR, and it would be a tricky thing to do as you would need an attitude update (so would need to either run EKF propagation at high rate or do your own propagation using gyro/accel data)
the signal can come from any thread, the state is in the binary semaphore object itself, so I don't see how the first thread delaying makes a difference. I'd like to have this as an actual test to understand it |
I've updated the BinarySem test to do what you describe and it works and behaves exactly as I expected https://github.com/tridge/ardupilot/commits/pr-copter-rate-thread/ I used a blocking wait, which matches what you are doing in this PR, no timeouts (you can't timeout with a blocking wait, it blocks forever), and gets exactly the performance I expect:
|
I just noticed that the rate thread is being created with AP_HAL::Scheduler::PRIORITY_RCOUT+1, so it is priority 182, and SPI threads are priority 181, so there are different priorities, but the rate thread is the one waiting, and priority inheritance only ever boosts priority of the waiting thread. As the thread that is waiting (the rate thread) is at a higher priority than the thread sending the signal there can be no priority change, so I'm still puzzled as to how priority inheritance comes into the picture at all. |
tell the rate thread we have a new sample | ||
*/ | ||
if (++_imu.rate_decimation_count >= _imu.rate_decimation) { | ||
_imu._cmutex->lock_and_signal(); |
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.
why are you signalling before you push?? I think this may be why you are getting the odd binary sem behaviour. You have to signal after you have made the sample available or the rate thread will wake up pointlessly and you will always be one loop behind
@andyp1per we had a "climb away" event with this PR on Sunday with Michelle's quad, with FSTRATE_ENABLE=2. Looks like Z controller was not updating in ALT_HOLD mode. |
This is a redo of #26189
I have squashed the commits, rebased and started fixing the underlying problems. There were some fundamental problems with how the original PR was handling attitude control changes so I thought it was better to just open a new PR.
Support is enabled by setting:
which gives a variable attitude rate depending on load, and:
which gives an attitude rate locked to the gyro rate, but dynamic while disarmed. For testing there is also:
which is a locked rate at all times.
The output rate can be adjusted using
FSTRATE_DIV
which is a gyro divisor (default 1).Two different rates - and therefore tunes - can be compared by using the lua applet
switch_rates.lua
which will persistently switch the appropriate tune/rate parameters with ones saved in names beginning withX_