Skip to content

Prearm check to validate backend read rates against scheduler loop rate #28672

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

Merged
merged 3 commits into from
Apr 2, 2025

Conversation

bugobliterator
Copy link
Member

This PR adds a prearm check that ensures that we are reading gyro data atleast as fast as we are running our main loop, where all controllers run at. We do this for all the INS sensors that are enabled.

This avoids a situation where user might have set SCHED LOOP RATE faster than gyro poll rate or primary gyro with appropriate backend rate but forgot to do so for the rest.

@bugobliterator bugobliterator force-pushed the pr-sched-rate-prearm-check branch 3 times, most recently from fafeac5 to 6628454 Compare November 19, 2024 01:55
@amilcarlucas
Copy link
Contributor

Binary Name      Text [B]        Data [B]     BSS (B)        Total Flash Change [B] (%)      Flash Free After PR (B)
---------------  --------------  -----------  -------------  ----------------------------  -------------------------
arducopter-heli  316 (+0.0174%)  0 (0.0000%)  -4 (-0.0015%)  316 (+0.0174%)                                   144800
antennatracker   316 (+0.0234%)  0 (0.0000%)  -4 (-0.0015%)  316 (+0.0234%)                                   614640
arducopter       316 (+0.0174%)  0 (0.0000%)  -4 (-0.0015%)  316 (+0.0173%)                                   144344
ardurover        316 (+0.0190%)  0 (0.0000%)  4 (+0.0015%)   316 (+0.0190%)                                   298392
arduplane        316 (+0.0174%)  0 (0.0000%)  -4 (-0.0015%)  316 (+0.0174%)                                   146824
blimp            316 (+0.0231%)  0 (0.0000%)  4 (+0.0015%)   316 (+0.0230%)                                   592716
ardusub          316 (+0.0196%)  0 (0.0000%)  -4 (-0.0015%)  316 (+0.0196%)                                   354132

Copy link
Contributor

@andyp1per andyp1per left a comment

Choose a reason for hiding this comment

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

Getting there

}
// if gyro backend rate hz is 0, that means we are polling sensor at the sample rate or higher
if (_backends[i]->get_gyro_backend_rate_hz() == 0) {
if (_gyro_raw_sample_rates[i] < _loop_rate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you have to cater for oversampling here? See get_gyro_rate_hz()

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we agree that the rate needs to be at least 2x the loop rate?

Copy link
Member Author

@bugobliterator bugobliterator Nov 20, 2024

Choose a reason for hiding this comment

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

Don't you have to cater for oversampling here? See get_gyro_rate_hz()

No, oversampling is only set by drivers that use FIFO, and hence will be setting backend_rate_hz and we will be using that for comparision

Didn't we agree that the rate needs to be at least 2x the loop rate?

Done.

Copy link
Contributor

@rmackay9 rmackay9 left a comment

Choose a reason for hiding this comment

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

It looks good to me but I'll leave it to Andy and Sid to sort out naming

Copy link
Contributor

@tridge tridge 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 to me, thanks @bugobliterator !

@tridge
Copy link
Contributor

tridge commented Nov 20, 2024

@andyp1per I'd like to get your comments on this if possible

@peterbarker
Copy link
Contributor

@andyp1per looking for your approval on this one. Seems like a sensible sanity check.

Copy link
Contributor

@andyp1per andyp1per 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 now - thanks @bugobliterator !

@peterbarker peterbarker force-pushed the pr-sched-rate-prearm-check branch from ff88246 to 94c4ebc Compare November 25, 2024 22:44
@peterbarker
Copy link
Contributor

I've rebased this on top of CI fixes and marking it for MergeOnCIPass.

@peterbarker
Copy link
Contributor

.... has to pass CI:

2024-11-26T03:16:37.4288781Z AT-0007.5: Received TIMESYNC response after 0.000000s
2024-11-26T03:16:37.4289428Z AT-0008.8: AP: PreArm: Gyro 1 backend rate 760Hz < sched loop rat
2024-11-26T03:16:37.4289977Z AT-0008.8: AP: e 400Hz
2024-11-26T03:16:37.4290385Z AT-0010.3: AP: PreArm: Gyro 1 backend rate 760Hz < sched loop rat
2024-11-26T03:16:37.4290930Z AT-0010.3: AP: e 400Hz
2024-11-26T03:16:37.4291424Z AT-0011.8: AP: PreArm: Gyro 1 backend rate 760Hz < sched loop rat
2024-11-26T03:16:37.4291859Z AT-0011.8: AP: e 400Hz
2024-11-26T03:16:37.4292372Z AT-0013.3: AP: PreArm: Gyro 1 backend rate 760Hz < sched loop rat
2024-11-26T03:16:37.4292827Z AT-0013.3: AP: e 400Hz
2024-11-26T03:16:37.4293426Z AT-0013.4: Prearm bit never went true.  Attempting arm to elicit reason from autopilot
2024-11-26T03:16:37.4294321Z AT-0013.4: Arm motors with MAVLink cmd
2024-11-26T03:16:37.4296075Z AT-0013.4: Sending COMMAND_LONG to (1,1) (MAV_CMD_COMPONENT_ARM_DISARM=400) (p1=1.000000 p2=0.000000 p3=0.000000 p4=0.000000 p5=0.000000 p6=0.000000  p7=0.000000)
2024-11-26T03:16:37.4297415Z AT-0013.4: ACK received: COMMAND_ACK {command : 400, result : 4, progress : 0, result_param2 : 0, target_system : 250, target_component : 250} (0.000000s)

@tridge tridge force-pushed the pr-sched-rate-prearm-check branch from 94c4ebc to d30d6f7 Compare December 11, 2024 03:40
@bugobliterator bugobliterator force-pushed the pr-sched-rate-prearm-check branch from d30d6f7 to 70db719 Compare December 11, 2024 08:47
@bugobliterator
Copy link
Member Author

Seems like SITL was failing the prearm because the second IMU gyro rate is 760 < 2*400.

Pixhawk1 and other boards using LSM9DS0 will have the same issue. @tridge

tridge
tridge previously requested changes Dec 18, 2024
@tridge tridge removed the DevCallEU label Dec 18, 2024
@rmackay9
Copy link
Contributor

rmackay9 commented Feb 18, 2025

@bugobliterator,

This PR is linked from our 4.6.0 issues list so I wonder if we want to try again to get this in?

@bugobliterator bugobliterator force-pushed the pr-sched-rate-prearm-check branch from 5939782 to dd644b3 Compare March 4, 2025 03:13
@tridge tridge force-pushed the pr-sched-rate-prearm-check branch from dd644b3 to 7d16d55 Compare March 12, 2025 08:42
@tridge tridge force-pushed the pr-sched-rate-prearm-check branch from 7d16d55 to 75ca7e5 Compare March 12, 2025 08:43
@tridge tridge dismissed their stale review March 12, 2025 08:46

fixed

@tridge
Copy link
Contributor

tridge commented Mar 12, 2025

@bugobliterator I updated the fn to avoid the multiple fn calls, and shorted the msg so it fits in the message buffer, tested on a Pixhawk1, behaves as expected

@tridge
Copy link
Contributor

tridge commented Mar 14, 2025

@bugobliterator VectorNavEAHRS test is failing - it produces very low gyro rates. It is flyable on fixed wing but cannot be used for notch filtering. I think we will need an exception for external AHRS IMUs

@peterbarker
Copy link
Contributor

OK, new real failure on EAHRS systems; we can consume gyro data from these systems and we're failing the new test:

2025-03-14T20:38:45.0515324Z AT-0057.2: AP: EKF2 IMU1 is using GPS
2025-03-14T20:38:45.0515815Z AT-0057.7: AP: PreArm: Gyro 0 rate 48Hz < loop ratex1.8 90Hz
2025-03-14T20:38:45.0516412Z AT-0058.6: AP: PreArm: Gyro 0 rate 48Hz < loop ratex1.8 90Hz
2025-03-14T20:38:45.0517000Z AT-0059.4: AP: PreArm: Gyro 0 rate 48Hz < loop ratex1.8 90Hz
2025-03-14T20:38:45.0517717Z AT-0059.7: Prearm bit never went true.  Attempting arm to elicit reason from autopilot
2025-03-14T20:38:45.0518384Z AT-0059.7: Arm motors with MAVLink cmd
2025-03-14T20:38:45.0519301Z AT-0059.7: Sending COMMAND_LONG to (1,1) (MAV_CMD_COMPONENT_ARM_DISARM=400) (p1=1.000000 p2=0.000000 p3=0.000000 p4=0.000000 p5=0.000000 p6=0.000000  p7=0.000000)
2025-03-14T20:38:45.0520955Z AT-0059.7: ACK received: COMMAND_ACK {command : 400, result : 4, progress : 0, result_param2 : 0, target_system : 250, target_component : 250} (0.000000s)
2025-03-14T20:38:45.0521977Z AT-0059.7: AP: Arm: Gyro 0 rate 48Hz < loop ratex1.8 90Hz
2025-03-14T20:38:45.0522457Z AT-0059.7: Delaying 5.000000 seconds
2025-03-14T20:38:45.0522936Z AT-0059.9: Exception caught: Prearm bit never went true
2025-03-14T20:38:45.0523436Z Traceback (most recent call last):
2025-03-14T20:38:45.0524243Z   File "/__w/ardupilot/ardupilot/Tools/autotest/vehicle_test_suite.py", line 8915, in run_one_test_attempt
2025-03-14T20:38:45.0525067Z     test_function(**test_kwargs)
2025-03-14T20:38:45.0525748Z   File "/__w/ardupilot/ardupilot/Tools/autotest/arduplane.py", line 3074, in VectorNavEAHRS
2025-03-14T20:38:45.0526547Z     self.fly_external_AHRS("VectorNav", 1, "ap1.txt")
2025-03-14T20:38:45.0527335Z   File "/__w/ardupilot/ardupilot/Tools/autotest/arduplane.py", line 2984, in fly_external_AHRS
2025-03-14T20:38:45.0528319Z     self.wait_ready_to_arm()
2025-03-14T20:38:45.0529082Z   File "/__w/ardupilot/ardupilot/Tools/autotest/vehicle_test_suite.py", line 8454, in wait_ready_to_arm
2025-03-14T20:38:45.0530136Z     self.wait_prearm_sys_status_healthy(timeout=timeout)
2025-03-14T20:38:45.0531075Z   File "/__w/ardupilot/ardupilot/Tools/autotest/vehicle_test_suite.py", line 8336, in wait_prearm_sys_status_healthy
2025-03-14T20:38:45.0532084Z     raise AutoTestTimeoutException("Prearm bit never went true")
2025-03-14T20:38:45.0532684Z vehicle_test_suite.AutoTestTimeoutException: Prearm bit never went true

}
const auto rate_hz = _backends[i]->get_gyro_backend_rate_hz();
if (rate_hz < threshold) {
hal.util->snprintf(fail_msg, fail_msg_len, "Gyro %d rate %dHz < loop ratex1.8 %dHz",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hal.util->snprintf(fail_msg, fail_msg_len, "Gyro %d rate %dHz < loop ratex1.8 %dHz",
hal.util->snprintf(fail_msg, fail_msg_len, "Gyro%d-rate=%dHz < loop rate*1.8=%dHz",

@tridge
Copy link
Contributor

tridge commented Mar 24, 2025

@bugobliterator ping on the test fail with vectornav? see above comments

@bugobliterator bugobliterator force-pushed the pr-sched-rate-prearm-check branch from 3223ad4 to bec18df Compare April 2, 2025 00:22
@tridge tridge merged commit e0c3234 into ArduPilot:master Apr 2, 2025
102 checks passed
@github-project-automation github-project-automation bot moved this to Pending in 4.6 Backports Apr 2, 2025
@IamPete1 IamPete1 removed the DevCallEU label Apr 5, 2025
@rmackay9
Copy link
Contributor

this is included in 4.6.0-beta6

@rmackay9 rmackay9 moved this from Pending to 4.6.0-beta6 in 4.6 Backports Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WikiNeeded needs wiki update
Projects
Status: 4.6.0-beta6
Development

Successfully merging this pull request may close these issues.

8 participants