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

AP_ESC_Telem: Improve handling of time wrap with RPM data #23896

Merged

Conversation

WickedShell
Copy link
Contributor

The primary target here is to close a window where after time wraps we would ignore the last reported RPM data even if it was valid (such as in the are_motors_running function). The secondary thing this helps us with is that by zeroing out the time we can ensure that if we lose telemetry after wrapping around we don't have a window of time where we consider it to be valid again.

This PR is worth reviewing in separate commits. The second commit is a combination of me kibitzing, and attempting some drive by improvements. They're detailed in the commit message and should be reviewed carefully.

Thus far this has been run through the autotest sequence, but needs to be tested on real hardware still. I'm hoping to get back to that shortly, and do some explicit testing of the behavior on wraps.

@WickedShell WickedShell requested a review from andyp1per May 25, 2023 23:17
@WickedShell WickedShell force-pushed the wickedshell/esc-rpm-wrap-handling branch from 1cdd69f to 953a658 Compare May 26, 2023 18:57
@WickedShell
Copy link
Contributor Author

Initial bench testing shows RPM data is still working, disconnecting/connecting the telemetry lines leads to it coming back and I used the set start time code to ensure that nothing unexpected happened when wrapping 32 microseconds.

libraries/AP_ESC_Telem/AP_ESC_Telem.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem.cpp Outdated Show resolved Hide resolved
@WickedShell WickedShell force-pushed the wickedshell/esc-rpm-wrap-handling branch from 953a658 to 86f54db Compare July 21, 2023 17:03
@WickedShell
Copy link
Contributor Author

@andyp1per I've significantly reworked this to add a flag as requested. I found that it made the various if statements doing the actual work really complicated though, so I inserted some helpers that force everything to have the same view.

@WickedShell WickedShell force-pushed the wickedshell/esc-rpm-wrap-handling branch from 86f54db to a35966d Compare July 21, 2023 17:07
Copy link
Collaborator

@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.

I like the helpers!

@@ -529,9 +528,32 @@ void AP_ESC_Telem::update()
_last_rpm_log_us[i] = _rpm_data[i].last_update_us;
}
}

if ((now_us - _rpm_data[i].last_update_us) > ESC_RPM_DATA_TIMEOUT_US) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this rpm_data_within_timeout()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what's actually setting the flag for us, the helper checks the data valid flag, which seemed kinda confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I came back to this, it does work just fine, but it makes it 24 bytes larger. In practice you will still bail out at the same time in general, but it has to run 2 more checks then it otherwise would have if that's not the case. I'm inclined to leave it as I presented since this is the explicit wrap protection.

libraries/AP_ESC_Telem/AP_ESC_Telem.h Outdated Show resolved Hide resolved
return instance.data_valid;
}

bool AP_ESC_Telem::was_rpm_data_evers_reported (const volatile AP_ESC_Telem_Backend::RpmData &instance) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

was_rpm_data_ever_reported()?

not a great fan of passing in the backend. Since it can be static you could make it a member of the backend or just pass in last_update_us

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the backend doesn't actually have the RpmData struct. It's declared back there, but it actually lives and exists in the frontend, which is why I stuck the helper there. I thought about passing the instance flag, but found that half the places were iterating over a reference anyways. I can stick it in the RpmData struct, but wasn't sure that actually seemed easier.

}
}

bool AP_ESC_Telem::rpm_data_within_timeout (const volatile AP_ESC_Telem_Backend::RpmData &instance, const uint32_t now_us, const uint32_t timeout_us) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

could just pass in last_update_us and data_valid or make it a member of the backend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but at a certain point it gets a lot larger of a function call, and makes the calling sites a lot less clear. I'm inclined to not pass everything...

@WickedShell WickedShell force-pushed the wickedshell/esc-rpm-wrap-handling branch 3 times, most recently from b0da5de to cb06bb0 Compare July 24, 2023 22:00
@WickedShell
Copy link
Contributor Author

Flown on a copter, with harmonic notch from ESC telemetry, no issues.

Copy link
Collaborator

@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.

LGTM

@tridge tridge merged commit 935fad5 into ArduPilot:master Aug 7, 2023
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.

4 participants