-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Open
andyp1per
wants to merge
19
commits into
ArduPilot:master
Choose a base branch
from
andyp1per:pr-fast-rate-thread
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,052
−38
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
01d205d
Copter: run copter attitude control with separate rate thread
andyp1per 61c47c2
autotest: add rate thread autotest
andyp1per 482ba22
AP_Vehicle: use update_dynamic_notch() directly in rate loop
tridge 7bd1afc
AP_HAL: allow forcing of trigger_groups()
andyp1per cfff230
AP_HAL: set HAL_INS_RATE_LOOP in boards
andyp1per f4ce0aa
AP_HAL_ChibiOS: allow forcing of trigger_groups()
andyp1per e37a211
AP_HAL_ChibiOS: compile MambaH743v4 at -O2
andyp1per 61308dc
AP_HAL_ChibiOS: ensure dshot rate can be set dynamically
andyp1per 47328c6
scripts: add AP_INERTIALSENSOR_FAST_SAMPLE_WINDOW_ENABLED to build_op…
andyp1per 0d3e475
waf: add rate loop config abstraction that allows code to be elided o…
andyp1per e673b70
Copter: correctly set fast rate thread rates
andyp1per b961a48
AP_InertialSensor: keep a queue of gyro samples for use by the rate t…
andyp1per 353b289
Copter: ensure decimated rates are never 0 in rate thread
andyp1per 26d6de4
AP_InertialSensor: avoid multiple allocations of rate loop buffer
andyp1per b8d0a00
AP_HAL_ChibiOS: add comments to force_push on rcout
andyp1per 0d346b2
Copter: move RTDT logging to fast path
andyp1per c57c6d5
Copter: address review comments
andyp1per 90daff6
AP_InertialSensor: address review comments
andyp1per 89bc8ce
AP_HAL_ChibiOS: add cork()/push() check
andyp1per File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ | |
*/ | ||
|
||
#include "Copter.h" | ||
#include <AP_InertialSensor/AP_InertialSensor_rate_config.h> | ||
|
||
#define FORCE_VERSION_H_INCLUDE | ||
#include "version.h" | ||
|
@@ -113,15 +114,15 @@ const AP_Scheduler::Task Copter::scheduler_tasks[] = { | |
// update INS immediately to get current gyro data populated | ||
FAST_TASK_CLASS(AP_InertialSensor, &copter.ins, update), | ||
// run low level rate controllers that only require IMU data | ||
FAST_TASK(run_rate_controller), | ||
FAST_TASK(run_rate_controller_main), | ||
#if AC_CUSTOMCONTROL_MULTI_ENABLED | ||
FAST_TASK(run_custom_controller), | ||
#endif | ||
#if FRAME_CONFIG == HELI_FRAME | ||
FAST_TASK(heli_update_autorotation), | ||
#endif //HELI_FRAME | ||
// send outputs to the motors library immediately | ||
FAST_TASK(motors_output), | ||
FAST_TASK(motors_output_main), | ||
// run EKF state estimator (expensive) | ||
FAST_TASK(read_AHRS), | ||
#if FRAME_CONFIG == HELI_FRAME | ||
|
@@ -259,6 +260,10 @@ const AP_Scheduler::Task Copter::scheduler_tasks[] = { | |
#if HAL_BUTTON_ENABLED | ||
SCHED_TASK_CLASS(AP_Button, &copter.button, update, 5, 100, 168), | ||
#endif | ||
#if AP_INERTIALSENSOR_FAST_SAMPLE_WINDOW_ENABLED | ||
andyp1per marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// don't delete this, there is an equivalent (virtual) in AP_Vehicle for the non-rate loop case | ||
SCHED_TASK(update_dynamic_notch_at_specified_rate_main, LOOP_RATE, 200, 215), | ||
#endif | ||
}; | ||
|
||
void Copter::get_scheduler_tasks(const AP_Scheduler::Task *&tasks, | ||
|
@@ -570,12 +575,15 @@ void Copter::update_batt_compass(void) | |
// should be run at loop rate | ||
void Copter::loop_rate_logging() | ||
{ | ||
if (should_log(MASK_LOG_ATTITUDE_FAST) && !copter.flightmode->logs_attitude()) { | ||
if (should_log(MASK_LOG_ATTITUDE_FAST) && !copter.flightmode->logs_attitude()) { | ||
Log_Write_Attitude(); | ||
Log_Write_PIDS(); // only logs if PIDS bitmask is set | ||
if (!using_rate_thread) { | ||
Log_Write_Rate(); | ||
Log_Write_PIDS(); // only logs if PIDS bitmask is set | ||
} | ||
} | ||
#if AP_INERTIALSENSOR_HARMONICNOTCH_ENABLED | ||
if (should_log(MASK_LOG_FTN_FAST)) { | ||
if (should_log(MASK_LOG_FTN_FAST) && !using_rate_thread) { | ||
AP::ins().write_notch_log_messages(); | ||
} | ||
#endif | ||
|
@@ -593,10 +601,15 @@ void Copter::ten_hz_logging_loop() | |
// log attitude controller data if we're not already logging at the higher rate | ||
if (should_log(MASK_LOG_ATTITUDE_MED) && !should_log(MASK_LOG_ATTITUDE_FAST) && !copter.flightmode->logs_attitude()) { | ||
Log_Write_Attitude(); | ||
if (!using_rate_thread) { | ||
Log_Write_Rate(); | ||
} | ||
} | ||
if (!should_log(MASK_LOG_ATTITUDE_FAST) && !copter.flightmode->logs_attitude()) { | ||
// log at 10Hz if PIDS bitmask is selected, even if no ATT bitmask is selected; logs at looprate if ATT_FAST and PIDS bitmask set | ||
Log_Write_PIDS(); | ||
if (!using_rate_thread) { | ||
Log_Write_PIDS(); | ||
} | ||
} | ||
// log EKF attitude data always at 10Hz unless ATTITUDE_FAST, then do it in the 25Hz loop | ||
if (!should_log(MASK_LOG_ATTITUDE_FAST)) { | ||
|
@@ -741,11 +754,24 @@ void Copter::one_hz_loop() | |
AP_Notify::flags.flying = !ap.land_complete; | ||
|
||
// slowly update the PID notches with the average loop rate | ||
attitude_control->set_notch_sample_rate(AP::scheduler().get_filtered_loop_rate_hz()); | ||
if (!using_rate_thread) { | ||
attitude_control->set_notch_sample_rate(AP::scheduler().get_filtered_loop_rate_hz()); | ||
} | ||
pos_control->get_accel_z_pid().set_notch_sample_rate(AP::scheduler().get_filtered_loop_rate_hz()); | ||
#if AC_CUSTOMCONTROL_MULTI_ENABLED | ||
custom_control.set_notch_sample_rate(AP::scheduler().get_filtered_loop_rate_hz()); | ||
#endif | ||
|
||
#if AP_INERTIALSENSOR_FAST_SAMPLE_WINDOW_ENABLED | ||
// see if we should have a separate rate thread | ||
if (!started_rate_thread && get_fast_rate_type() != FastRateType::FAST_RATE_DISABLED) { | ||
if (hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&Copter::rate_controller_thread, void), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we throw a allocation error if this fails? |
||
"rate", | ||
1536, AP_HAL::Scheduler::PRIORITY_RCOUT, 1)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is 1536 from? Should we add some more headroom? |
||
started_rate_thread = true; | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
void Copter::init_simple_bearing() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 were not running the controller should we replace this with a "rate control save" that would save the current targets for use by the rate thread. It may not be a good assumption that the "input" methods are only called once each loop.