Skip to content
Draft
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
11 changes: 10 additions & 1 deletion src/viam/sdk/components/gantry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ class Gantry : public Component, public Stoppable {
/// @param extra Any additional arguments to the method
virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;

/// @brief Returns the kinematics data of the component.
inline std::string get_kinematics() {
return get_kinematics({});
}

/// @brief Returns the kinematics data of the component.
/// @param extra Any additional arguments to the method
virtual std::string get_kinematics(const ProtoStruct& extra) = 0;

API api() const override;

protected:
Expand All @@ -107,4 +116,4 @@ struct API::traits<Gantry> {
};

} // namespace sdk
} // namespace viam
} // namespace viam
8 changes: 7 additions & 1 deletion src/viam/sdk/components/private/gantry_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ ProtoStruct GantryClient::do_command(const ProtoStruct& command) {
.invoke([](auto& response) { return from_proto(response.result()); });
}

std::string GantryClient::get_kinematics(const ProtoStruct& extra) {
return make_client_helper(this, *stub_, &StubType::GetKinematics)
.with(extra)
.invoke([](auto& response) { return response.kinematics_data(); });
}

std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extra) {
return make_client_helper(this, *stub_, &StubType::GetGeometries)
.with(extra)
Expand All @@ -77,4 +83,4 @@ std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extr

} // namespace impl
} // namespace sdk
} // namespace viam
} // namespace viam
4 changes: 3 additions & 1 deletion src/viam/sdk/components/private/gantry_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class GantryClient : public Gantry {
void stop(const ProtoStruct& extra) override;
ProtoStruct do_command(const ProtoStruct& command) override;
std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
std::string get_kinematics(const ProtoStruct& extra) override;

using Gantry::get_geometries;
using Gantry::get_kinematics;
using Gantry::get_lengths;
using Gantry::get_position;
using Gantry::home;
Expand All @@ -46,4 +48,4 @@ class GantryClient : public Gantry {

} // namespace impl
} // namespace sdk
} // namespace viam
} // namespace viam
13 changes: 12 additions & 1 deletion src/viam/sdk/components/private/gantry_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ ::grpc::Status GantryServer::DoCommand(::grpc::ServerContext*,
});
}

::grpc::Status GantryServer::GetKinematics(
::grpc::ServerContext*,
const ::viam::common::v1::GetKinematicsRequest* request,
::viam::common::v1::GetKinematicsResponse* response) noexcept {
return make_service_helper<Gantry>(
"GantryServer::GetKinematics", this, request)([&](auto& helper, auto& gantry) {
const std::string kinematics_data = gantry->get_kinematics(helper.getExtra());
response->set_kinematics_data(kinematics_data);
});
}

::grpc::Status GantryServer::GetGeometries(
::grpc::ServerContext*,
const ::viam::common::v1::GetGeometriesRequest* request,
Expand All @@ -95,4 +106,4 @@ ::grpc::Status GantryServer::GetGeometries(

} // namespace impl
} // namespace sdk
} // namespace viam
} // namespace viam
7 changes: 6 additions & 1 deletion src/viam/sdk/components/private/gantry_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class GantryServer : public ResourceServer,
const ::viam::common::v1::DoCommandRequest* request,
::viam::common::v1::DoCommandResponse* response) noexcept;

virtual ::grpc::Status GetKinematics(
::grpc::ServerContext* context,
const ::viam::common::v1::GetKinematicsRequest* request,
::viam::common::v1::GetKinematicsResponse* response) noexcept;

virtual ::grpc::Status GetGeometries(
::grpc::ServerContext* context,
const ::viam::common::v1::GetGeometriesRequest* request,
Expand All @@ -65,4 +70,4 @@ class GantryServer : public ResourceServer,

} // namespace impl
} // namespace sdk
} // namespace viam
} // namespace viam
12 changes: 11 additions & 1 deletion src/viam/sdk/tests/mocks/mock_gantry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ namespace viam {
namespace sdktests {
namespace gantry {

std::string fake_kinematics_data() {
return "kinematics_data";
}

std::vector<double> fake_lengths() {
return {1.0, 2.0, 3.0, 4.0};
}

std::shared_ptr<MockGantry> MockGantry::get_mock_gantry() {
return std::make_shared<MockGantry>("mock_gantry");
auto mock = std::make_shared<MockGantry>("mock_gantry");
mock->peek_kinematics_data = fake_kinematics_data();
return mock;
}

std::vector<double> MockGantry::get_position(const sdk::ProtoStruct&) {
return peek_positions;
}

std::string MockGantry::get_kinematics(const sdk::ProtoStruct&) {
return peek_kinematics_data;
}

void MockGantry::move_to_position(const std::vector<sdk::Gantry::movement_coordinate>& coordinates,
const sdk::ProtoStruct&) {
peek_positions = {};
Expand Down
4 changes: 3 additions & 1 deletion src/viam/sdk/tests/mocks/mock_gantry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class MockGantry : public sdk::Gantry {
void stop(const sdk::ProtoStruct& extra) override;
sdk::ProtoStruct do_command(const sdk::ProtoStruct& command) override;
std::vector<sdk::GeometryConfig> get_geometries(const sdk::ProtoStruct& extra) override;
std::string get_kinematics(const sdk::ProtoStruct& extra) override;

std::vector<double> peek_positions;
bool peek_stop_called{false};
bool peek_home_called{false};
sdk::ProtoStruct peek_command;
std::string peek_kinematics_data;
};
} // namespace gantry
} // namespace sdktests
} // namespace viam
} // namespace viam
11 changes: 10 additions & 1 deletion src/viam/sdk/tests/test_gantry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<viam::sdk::GeometryConfig>)
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<double>)
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::string)

namespace viam {
namespace sdktests {
Expand Down Expand Up @@ -83,7 +84,15 @@ BOOST_AUTO_TEST_CASE(test_do_command) {
});
}

BOOST_AUTO_TEST_CASE(test_get_kinematics) {
std::shared_ptr<MockGantry> mock = MockGantry::get_mock_gantry();
client_to_mock_pipeline<Gantry>(mock, [](Gantry& client) {
const auto& kinematics_data = client.get_kinematics();
BOOST_CHECK_EQUAL(kinematics_data, fake_kinematics_data());
});
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace sdktests
} // namespace viam
} // namespace viam
Loading