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

RSDK-5770 - implement GetReadings API for all sensor types #126

Merged

Conversation

gvaradarajan
Copy link
Member

also includes improvement for DoCommand macro such that only the macro needs to be imported when someone needs to use it (you don't need to also import the DoCommand trait)

@gvaradarajan gvaradarajan requested a review from a team as a code owner November 30, 2023 19:02
@gvaradarajan gvaradarajan force-pushed the RSDK-5770-readings-api branch from ae5b6ec to 73d2f0c Compare November 30, 2023 20:14
Copy link
Member

@npmenard npmenard left a comment

Choose a reason for hiding this comment

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

Did you try to have the macro generate the body of the function instead of delegating to **_generic_readings ?

let micro_rdk_crate_name = if crate_name == "micro-rdk" {
"crate"
} else {
"micro_rdk"
Copy link
Member

Choose a reason for hiding this comment

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

Does this work even if the micro-rdk crate has been pulled in under a different name, per https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml.

Copy link
Member Author

Choose a reason for hiding this comment

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

it does not

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for checking. I was curious and I do wonder if we are missing something about how to stably name types from a "peer" crate within a proc macro. On the other hand, I don't think we need to address it right now: I think renaming dependencies is a pretty edge-case sort of thing. Maybe a comment is warranted for now, and should it ever cause problems in the wild we can revisit it.

Copy link
Member

Choose a reason for hiding this comment

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

i think the solution here rust-lang/rust#54363 (comment) might work even if the crate is renamed

Copy link
Member

Choose a reason for hiding this comment

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

if this doesn't work then we need to keep a ticket to track this. I agree it's not major but it can be a pain point in the future

let gen = quote! {
impl #impl_generics DoCommand for #name #ty_generics #where_clause {}
impl #impl_generics #crate_ident::common::generic::DoCommand for #name #ty_generics #where_clause {}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for doing this one too.

@@ -108,3 +126,19 @@ impl Status for FakeSensor {
}))
}
}

impl From<f64> for Value {
Copy link
Member

Choose a reason for hiding this comment

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

These seem more generic than simply being Sensor related. Is there a better home for them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually meant to remove these, sorry. I don't think it's saving that much effort

@gvaradarajan
Copy link
Member Author

Did you try to have the macro generate the body of the function instead of delegating to **_generic_readings ?

@npmenard I initially did this. However, I had the thought that the convenience function is useful to someone implementing a movement sensor or power sensor module who wanted to take the readings returned by the standard implementation and simply add to it in their get_generic_readings

Copy link
Member

@npmenard npmenard left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

LGTM. I'm happy with either implementing via proc-macro-crate in this review, or deferring any solution into a ticket with a TODO comment in this review.

@gvaradarajan gvaradarajan force-pushed the RSDK-5770-readings-api branch from 71bc07f to 6f86530 Compare December 4, 2023 18:43
@gvaradarajan gvaradarajan merged commit e88b6c7 into viamrobotics:main Dec 4, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants