Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions src/viam/sdk/robot/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ namespace sdk {

using google::protobuf::RepeatedPtrField;
using viam::common::v1::Transform;
using viam::robot::v1::Discovery;
using viam::robot::v1::DiscoveryQuery;
using viam::robot::v1::FrameSystemConfig;
using viam::robot::v1::Operation;
using viam::robot::v1::RobotService;
Expand All @@ -49,28 +47,6 @@ using viam::robot::v1::RobotService;
const std::string kStreamRemoved("Stream removed");

namespace {
// TODO: add a traits class for proto to type and back conversion
DiscoveryQuery to_proto(const RobotClient::discovery_query& query) {
DiscoveryQuery proto;
*proto.mutable_subtype() = query.subtype;
*proto.mutable_model() = query.model;
return proto;
}

RobotClient::discovery_query from_proto(const DiscoveryQuery& proto) {
RobotClient::discovery_query query;
query.subtype = proto.subtype();
query.model = proto.model();
return query;
}

RobotClient::discovery from_proto(const Discovery& proto) {
RobotClient::discovery discovery;
discovery.query = from_proto(proto.query());
discovery.results = v2::from_proto(proto.results());
return discovery;
}

RobotClient::frame_system_config from_proto(const FrameSystemConfig& proto) {
RobotClient::frame_system_config fsconfig;
fsconfig.frame = v2::from_proto(proto.frame());
Expand All @@ -97,15 +73,6 @@ RobotClient::operation from_proto(const Operation& proto) {
}
} // namespace

bool operator==(const RobotClient::discovery_query& lhs, const RobotClient::discovery_query& rhs) {
return lhs.subtype == rhs.subtype && lhs.model == rhs.model;
}

bool operator==(const RobotClient::discovery& lhs, const RobotClient::discovery& rhs) {
return lhs.query == rhs.query && v2::to_proto(lhs.results).SerializeAsString() ==
v2::to_proto(rhs.results).SerializeAsString();
}

bool operator==(const RobotClient::frame_system_config& lhs,
const RobotClient::frame_system_config& rhs) {
return lhs.frame == rhs.frame && v2::to_proto(lhs.kinematics).SerializeAsString() ==
Expand Down Expand Up @@ -356,32 +323,6 @@ pose_in_frame RobotClient::transform_pose(
return v2::from_proto(resp.pose());
}

std::vector<RobotClient::discovery> RobotClient::discover_components(
const std::vector<discovery_query>& queries) {
viam::robot::v1::DiscoverComponentsRequest req;
viam::robot::v1::DiscoverComponentsResponse resp;
ClientContext ctx;

RepeatedPtrField<DiscoveryQuery>* req_queries = req.mutable_queries();

for (const discovery_query& query : queries) {
*req_queries->Add() = to_proto(query);
}

const grpc::Status response = impl_->stub_->DiscoverComponents(ctx, req, &resp);
if (is_error_response(response)) {
BOOST_LOG_TRIVIAL(error) << "Error discovering components: " << response.error_message();
}

std::vector<discovery> components = std::vector<discovery>();

for (const Discovery& d : resp.discovery()) {
components.push_back(from_proto(d));
}

return components;
}

std::shared_ptr<Resource> RobotClient::resource_by_name(const Name& name) {
return resource_manager_.resource(name.name());
}
Expand Down
14 changes: 0 additions & 14 deletions src/viam/sdk/robot/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ namespace sdk {
/// `with_channel` require a user call to `close()`.
class RobotClient {
public:
struct discovery_query {
std::string subtype;
std::string model;
friend bool operator==(const discovery_query& lhs, const discovery_query& rhs);
};

struct discovery {
discovery_query query;
ProtoStruct results;
friend bool operator==(const discovery& lhs, const discovery& rhs);
};

struct frame_system_config {
WorldState::transform frame;
ProtoStruct kinematics;
Expand Down Expand Up @@ -120,8 +108,6 @@ class RobotClient {
/// @return The list of operations currently running on the calling robot.
std::vector<operation> get_operations();

std::vector<discovery> discover_components(const std::vector<discovery_query>& queries);

/// @brief Transform a given `Pose` to a new specified destination which is a reference frame.
/// @param query The pose that should be transformed.
/// @param destination The name of the reference frame to transform the given pose to.
Expand Down
53 changes: 0 additions & 53 deletions src/viam/sdk/tests/mocks/mock_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ using namespace viam::sdk;
using common::v1::Pose;
using common::v1::PoseInFrame;
using common::v1::ResourceName;
using viam::robot::v1::Discovery;
using viam::robot::v1::DiscoveryQuery;
using viam::robot::v1::FrameSystemConfig;
using viam::robot::v1::Operation;

Expand Down Expand Up @@ -93,41 +91,6 @@ std::vector<Operation> mock_proto_operations_response() {
return resp;
}

std::vector<RobotClient::discovery> mock_discovery_response() {
RobotClient::discovery_query query;
query.subtype = "camera";
query.model = "webcam";
ProtoValue s("bar");
ProtoValue map(fake_map());

ProtoList inner{{map}};
ProtoList l{{s, ProtoValue{false}, ProtoValue{3.0}, ProtoValue{4.2}, map, std::move(inner)}};

ProtoStruct results{{"foo", l}};

RobotClient::discovery discovery;
discovery.query = std::move(query);
discovery.results = std::move(results);
return std::vector<RobotClient::discovery>{std::move(discovery)};
}

std::vector<Discovery> mock_proto_discovery_response() {
std::vector<viam::robot::v1::Discovery> v;
for (const auto& d : mock_discovery_response()) {
DiscoveryQuery query;
*query.mutable_subtype() = d.query.subtype;
*query.mutable_model() = d.query.model;

viam::robot::v1::Discovery discovery;
*discovery.mutable_query() = query;
*discovery.mutable_results() = v2::to_proto(d.results);

v.push_back(std::move(discovery));
}

return v;
}

pose_in_frame mock_transform_response() {
return {"arm", default_pose()};
}
Expand Down Expand Up @@ -347,22 +310,6 @@ ::grpc::Status MockRobotService::FrameSystemConfig(
return ::grpc::Status();
}

::grpc::Status MockRobotService::DiscoverComponents(
::grpc::ServerContext* context,
const ::viam::robot::v1::DiscoverComponentsRequest*,
::viam::robot::v1::DiscoverComponentsResponse* response) {
auto client_md = context->client_metadata();
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
"viam_client info not properly set in metadata");
}
auto* discovery = response->mutable_discovery();
for (auto& d : mock_proto_discovery_response()) {
*discovery->Add() = d;
}
return ::grpc::Status();
}

::grpc::Status MockRobotService::TransformPose(::grpc::ServerContext* context,
const ::viam::robot::v1::TransformPoseRequest*,
::viam::robot::v1::TransformPoseResponse* response) {
Expand Down
7 changes: 0 additions & 7 deletions src/viam/sdk/tests/mocks/mock_robot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ class MockRobotService : public ResourceServer, public viam::robot::v1::RobotSer
const ::viam::robot::v1::TransformPoseRequest* request,
::viam::robot::v1::TransformPoseResponse* response) override;

::grpc::Status DiscoverComponents(
::grpc::ServerContext* context,
const ::viam::robot::v1::DiscoverComponentsRequest* request,
::viam::robot::v1::DiscoverComponentsResponse* response) override;

::grpc::Status GetOperations(::grpc::ServerContext* context,
const ::viam::robot::v1::GetOperationsRequest* request,
::viam::robot::v1::GetOperationsResponse* response) override;
Expand All @@ -63,8 +58,6 @@ class MockRobotService : public ResourceServer, public viam::robot::v1::RobotSer
pose default_pose(int offset = 0);
std::vector<RobotClient::operation> mock_operations_response();
std::vector<viam::robot::v1::Operation> mock_proto_operations_response();
std::vector<RobotClient::discovery> mock_discovery_response();
std::vector<viam::robot::v1::Discovery> mock_proto_discovery_response();
std::vector<Name> mock_resource_names_response();
std::vector<common::v1::ResourceName> mock_proto_resource_names_response();
std::vector<RobotClient::frame_system_config> mock_config_response();
Expand Down
36 changes: 0 additions & 36 deletions src/viam/sdk/tests/test_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <viam/sdk/tests/mocks/mock_robot.hpp>
#include <viam/sdk/tests/test_utils.hpp>

BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::discovery_query)
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::discovery)
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::frame_system_config)
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::operation)

Expand Down Expand Up @@ -181,40 +179,6 @@ BOOST_AUTO_TEST_CASE(test_get_operations) {
});
}

// This test ensures that the functions in the `mock_robot` files have the same fields for both
// the proto and custom type versions.
BOOST_AUTO_TEST_CASE(test_discovery) {
robot_client_to_mocks_pipeline(
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
auto components = mock_discovery_response();
auto component = components[0];
auto results = component.results.begin();
auto protos = mock_proto_discovery_response();
auto proto = protos[0];
auto proto_results = proto.results().fields().begin();

BOOST_CHECK_EQUAL(component.query.subtype, proto.query().subtype());
BOOST_CHECK_EQUAL(component.query.model, proto.query().model());
BOOST_CHECK_EQUAL(results->first, proto_results->first);
// the `Value` type in our mock responses is a `list` type so we can comprehensively
// test `ProtoValue` conversions. Unfortunately the protobuf `ListValue` type doesn't
// seem to have `==` defined, so we convert to a `DebugString` here to verify
// comparison and to provide helpful printing of differences in case of an error.
BOOST_CHECK_EQUAL(v2::to_proto(results->second).DebugString(),
proto_results->second.DebugString());
});
}

BOOST_AUTO_TEST_CASE(test_discover_components) {
robot_client_to_mocks_pipeline(
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
auto components = client->discover_components({});
auto mock_components = mock_discovery_response();

BOOST_TEST(components == mock_components, boost::test_tools::per_element());
});
}

BOOST_AUTO_TEST_CASE(test_transform_pose) {
robot_client_to_mocks_pipeline(
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
Expand Down
Loading