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-794 Sensor wrapper #174

Merged
merged 8 commits into from
Nov 16, 2023
Merged

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Nov 6, 2023

RSDK-794

Implements wrappers for sensor API.

(cc @cheukt and @acmorrow).

@benjirewis benjirewis changed the title RSDK-795 Sensor wrapper RSDK-794 Sensor wrapper Nov 6, 2023
@benjirewis benjirewis requested a review from stuqdog November 6, 2023 20:21
@benjirewis benjirewis marked this pull request as ready for review November 6, 2023 20:21
@benjirewis benjirewis requested a review from a team as a code owner November 6, 2023 20:21
@benjirewis benjirewis requested review from njooma and removed request for a team November 6, 2023 20:21
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

Nice, a couple small things but otherwise looks great!

src/viam/sdk/components/sensor/client.hpp Show resolved Hide resolved
src/viam/sdk/tests/mocks/mock_sensor.cpp Show resolved Hide resolved
src/viam/sdk/tests/test_sensor.cpp Show resolved Hide resolved
Copy link
Member Author

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Also fixed some "typos" in movement sensor files.

src/viam/sdk/tests/test_sensor.cpp Show resolved Hide resolved
src/viam/sdk/tests/mocks/mock_sensor.cpp Show resolved Hide resolved
src/viam/sdk/components/sensor/client.hpp Show resolved Hide resolved
@benjirewis benjirewis requested a review from stuqdog November 7, 2023 19:20
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.

Overall, this looks fine to me, but I have reservations about the current design ofserver_wrapper and client_stub and I don't want to see them go viral by duplication. I'll follow up with some suggestions about how I think they could be improved such that they could be factored out in this review. I missed my chance on the prior review but I didn't mind much because they were just in one place.

src/viam/sdk/components/sensor/client.hpp Show resolved Hide resolved
src/viam/sdk/tests/test_sensor.cpp Outdated Show resolved Hide resolved
src/viam/sdk/components/sensor/server.hpp Outdated Show resolved Hide resolved
src/viam/sdk/registry/registry.hpp Show resolved Hide resolved
Copy link
Member Author

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Used @acmorrow's ServiceHelper class for both SensorServer and MovementSensorServer. Removed custom ServerWrapperResult structs and server_wrapper methods.


std::unordered_map<std::string, float> result =
status.movementsensor->get_accuracy(status.extra);
response->mutable_accuracy()->empty();
Copy link
Member Author

@benjirewis benjirewis Nov 14, 2023

Choose a reason for hiding this comment

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

I removed this line; I don't think it did anything (my guess is it was an attempt to "empty" the mutable_accuracy map, but empty just returns a boolean describing if the map is empty that we were ignoring).

return ::grpc::Status();
return make_service_helper<MovementSensor>("MovementSensorServer::GetAccuracy", this, request)(
[&](auto& helper, auto& movementsensor) {
const std::unordered_map<std::string, float> result =
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a fine place for auto.

return make_service_helper<MovementSensor>("MovementSensorServer::GetGeometries",
this,
request)([&](auto& helper, auto& movementsensor) {
const std::vector<GeometryConfig> geometries =
Copy link
Member

Choose a reason for hiding this comment

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

ditto auto

"SensorServer::GetReadings", this, request)([&](auto& helper, auto& sensor) {
const AttributeMap result = sensor->get_readings(helper.getExtra());
for (const auto& r : *result) {
response->mutable_readings()->insert({std::move(r.first), r.second->proto_value()});
Copy link
Member

Choose a reason for hiding this comment

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

r is const, so I suspect this move can't do anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.


::grpc::Status GetReadings(::grpc::ServerContext* context,
const GetReadingsRequest* request,
GetReadingsResponse* response) override;
Copy link
Member

Choose a reason for hiding this comment

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

These can and should now all be noexcept!

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! Thank you; done.

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 for my part (wrappers and such).

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

lgtm!

@benjirewis benjirewis merged commit 77c4d7b into viamrobotics:main Nov 16, 2023
2 checks passed
@benjirewis benjirewis deleted the sensor-wrappers branch November 16, 2023 17:24
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