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-7149 - implement resolution for analogs and remove get_board_status #207

Merged

Conversation

gvaradarajan
Copy link
Member

@gvaradarajan gvaradarajan commented May 16, 2024

When auto-generating the proto code, the removal of BoardStatus from the Board API also made its way in. Separating it out felt harder than simply removing the board status specific code on our side.

@gvaradarajan gvaradarajan requested a review from a team as a code owner May 16, 2024 20:19
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.

Seems like we need to update the board status function too since they have changed the layout of Board.Status proto

@@ -71,6 +71,11 @@ pub mod proto {
include!("gen/viam.app.datasync.v1.rs");
}
}
pub mod mltraining {
pub mod v1 {
include!("gen/viam.app.mltraining.v1.rs");
Copy link
Member

Choose a reason for hiding this comment

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

why do we pull this proto in?

Copy link
Member

Choose a reason for hiding this comment

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

I believe it effectively became mandatory to gen mltraining for anything consuming app as a consequence of viamrobotics/api@f02f6cc#diff-e842ca0f50219c67d40be90a2a1efd40ee1b6df19a254357ab177d631b3ea4b4R5

Copy link
Member Author

Choose a reason for hiding this comment

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

^ yep

Copy link
Member

Choose a reason for hiding this comment

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

annoying


#[derive(Debug, Default)]
pub struct AnalogResolution {
pub min_range: f64,
Copy link
Member

Choose a reason for hiding this comment

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

if the proto takes f32 let's leave it at f32

// all units are in mV
AnalogResolution {
min_range: 150.0,
max_range: 2450.0,
Copy link
Member

Choose a reason for hiding this comment

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

true for the linear range for the ADC can actually measure higher than 2.45mv might make more sense to use esp_adc_cal_raw_to_voltage to feed min max and resolution (0-4095) into this struct.

Copy link
Member

Choose a reason for hiding this comment

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

it's far from perfect since adc curve are not linear for error will accumulate especially outside the 150-2450 range

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I'm a little unclear here. That function seems to directly compute voltage, so do you mean I should replace the raw value with the value in mV? If so does it actually make sense to even return non-trivial values for the resolution?

Copy link
Member

Choose a reason for hiding this comment

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

The range in this struct is the suggested voltage range for esp32 for accurate voltage measurement where raw to volatge is mostly linear. That doesn't mean ADC is not able to measure voltage outside of this range. I don't know if the purpose of this api is to offload the conversion to SDKs but if it is the case then we should calcultage mon/max voltage by calling esp_adc_cal_raw_to_voltage(0,&chars) for min and esp_adc_cal_raw_to_voltage(4095,&chars) for min/max (can use the rust bindings for that too) and assume it's linear for the range (which is not) Would need to confirm the values are not too insane

Ideally we should return mV instead of raw

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 agree with the last sentence, maybe I return the mV value and make the step_size 1?

Copy link
Member

Choose a reason for hiding this comment

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

👌

Copy link
Member

Choose a reason for hiding this comment

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

if the returned value goes above 2450 what's happening on the SDK side?

Copy link
Member

@mattjperez mattjperez left a comment

Choose a reason for hiding this comment

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

Looks great! Just a question, but otherwise LGTM. Will let the others approve since there were pending modification requests.

Comment on lines +38 to +43
fn resolution(&self) -> AnalogResolution {
Default::default()
}
}

#[derive(Debug, Default)]
Copy link
Member

Choose a reason for hiding this comment

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

do we want to be returning derived Default values here? We'd always be returning a min_range, max_range, and step_size of 0.0.

Would it not be better to return some "realistic" defaults that we can test the FakeAnalogReader against later?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, sure I could throw in some numbers I guess

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 I am glad board status gets removed :P I see in the proto file there is still

message Status {
  map<string, int32> analogs = 1;
  map<string, int64> digital_interrupts = 2;
}

Do we know what's the purpose? Do we need to implement it

Lastly how do we validate behavior? IRC Board Status was just returning Analog readers and DigitalInterrupt status (which we didn't implement?)

@gvaradarajan
Copy link
Member Author

LGTM I am glad board status gets removed :P I see in the proto file there is still

message Status {
  map<string, int32> analogs = 1;
  map<string, int64> digital_interrupts = 2;
}

Do we know what's the purpose? Do we need to implement it

Lastly how do we validate behavior? IRC Board Status was just returning Analog readers and DigitalInterrupt status (which we didn't implement?)

I checked RDK and that message was being used only internally and gets turned into a generic struct field for RobotStatus. I figured we didn't need the extra step.

I figured asking for RobotStatus through an SDK and seeing that the analogs are returned without error and in mV would be sufficient

@gvaradarajan gvaradarajan force-pushed the RSDK-7149-breaking-proto-changes branch from f7cd5a3 to 2a60708 Compare May 24, 2024 18:12
@gvaradarajan
Copy link
Member Author

Tested on hardware

@gvaradarajan gvaradarajan merged commit afddb87 into viamrobotics:main May 24, 2024
5 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
4 participants