Skip to content

Commit 697d5c8

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit 71399b6
1 parent 9427ed1 commit 697d5c8

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

src/viam/sdk/components/gantry.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ class Gantry : public Component, public Stoppable {
9595
/// @param extra Any additional arguments to the method
9696
virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
9797

98+
/// @brief Returns the kinematics data of the component.
99+
inline std::string get_kinematics() {
100+
return get_kinematics({});
101+
}
102+
103+
/// @brief Returns the kinematics data of the component.
104+
/// @param extra Any additional arguments to the method
105+
virtual std::string get_kinematics(const ProtoStruct& extra) = 0;
106+
98107
API api() const override;
99108

100109
protected:
@@ -107,4 +116,4 @@ struct API::traits<Gantry> {
107116
};
108117

109118
} // namespace sdk
110-
} // namespace viam
119+
} // namespace viam

src/viam/sdk/components/private/gantry_client.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ ProtoStruct GantryClient::do_command(const ProtoStruct& command) {
6969
.invoke([](auto& response) { return from_proto(response.result()); });
7070
}
7171

72+
std::string GantryClient::get_kinematics(const ProtoStruct& extra) {
73+
return make_client_helper(this, *stub_, &StubType::GetKinematics)
74+
.with(extra)
75+
.invoke([](auto& response) { return response.kinematics_data(); });
76+
}
77+
7278
std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extra) {
7379
return make_client_helper(this, *stub_, &StubType::GetGeometries)
7480
.with(extra)
@@ -77,4 +83,4 @@ std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extr
7783

7884
} // namespace impl
7985
} // namespace sdk
80-
} // namespace viam
86+
} // namespace viam

src/viam/sdk/components/private/gantry_client.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class GantryClient : public Gantry {
3030
void stop(const ProtoStruct& extra) override;
3131
ProtoStruct do_command(const ProtoStruct& command) override;
3232
std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
33+
std::string get_kinematics(const ProtoStruct& extra) override;
3334

3435
using Gantry::get_geometries;
36+
using Gantry::get_kinematics;
3537
using Gantry::get_lengths;
3638
using Gantry::get_position;
3739
using Gantry::home;
@@ -46,4 +48,4 @@ class GantryClient : public Gantry {
4648

4749
} // namespace impl
4850
} // namespace sdk
49-
} // namespace viam
51+
} // namespace viam

src/viam/sdk/components/private/gantry_server.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ ::grpc::Status GantryServer::DoCommand(::grpc::ServerContext*,
8080
});
8181
}
8282

83+
::grpc::Status GantryServer::GetKinematics(
84+
::grpc::ServerContext*,
85+
const ::viam::common::v1::GetKinematicsRequest* request,
86+
::viam::common::v1::GetKinematicsResponse* response) noexcept {
87+
return make_service_helper<Gantry>(
88+
"GantryServer::GetKinematics", this, request)([&](auto& helper, auto& gantry) {
89+
const std::string kinematics_data = gantry->get_kinematics(helper.getExtra());
90+
response->set_kinematics_data(kinematics_data);
91+
});
92+
}
93+
8394
::grpc::Status GantryServer::GetGeometries(
8495
::grpc::ServerContext*,
8596
const ::viam::common::v1::GetGeometriesRequest* request,
@@ -95,4 +106,4 @@ ::grpc::Status GantryServer::GetGeometries(
95106

96107
} // namespace impl
97108
} // namespace sdk
98-
} // namespace viam
109+
} // namespace viam

src/viam/sdk/components/private/gantry_server.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class GantryServer : public ResourceServer,
5757
const ::viam::common::v1::DoCommandRequest* request,
5858
::viam::common::v1::DoCommandResponse* response) noexcept;
5959

60+
virtual ::grpc::Status GetKinematics(
61+
::grpc::ServerContext* context,
62+
const ::viam::common::v1::GetKinematicsRequest* request,
63+
::viam::common::v1::GetKinematicsResponse* response) noexcept;
64+
6065
virtual ::grpc::Status GetGeometries(
6166
::grpc::ServerContext* context,
6267
const ::viam::common::v1::GetGeometriesRequest* request,
@@ -65,4 +70,4 @@ class GantryServer : public ResourceServer,
6570

6671
} // namespace impl
6772
} // namespace sdk
68-
} // namespace viam
73+
} // namespace viam

src/viam/sdk/tests/mocks/mock_gantry.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ namespace viam {
66
namespace sdktests {
77
namespace gantry {
88

9+
std::string fake_kinematics_data() {
10+
return "kinematics_data";
11+
}
12+
913
std::vector<double> fake_lengths() {
1014
return {1.0, 2.0, 3.0, 4.0};
1115
}
1216

1317
std::shared_ptr<MockGantry> MockGantry::get_mock_gantry() {
14-
return std::make_shared<MockGantry>("mock_gantry");
18+
auto mock = std::make_shared<MockGantry>("mock_gantry");
19+
mock->peek_kinematics_data = fake_kinematics_data();
20+
return mock;
1521
}
1622

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

27+
std::string MockGantry::get_kinematics(const sdk::ProtoStruct&) {
28+
return peek_kinematics_data;
29+
}
30+
2131
void MockGantry::move_to_position(const std::vector<sdk::Gantry::movement_coordinate>& coordinates,
2232
const sdk::ProtoStruct&) {
2333
peek_positions = {};

src/viam/sdk/tests/mocks/mock_gantry.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ class MockGantry : public sdk::Gantry {
2323
void stop(const sdk::ProtoStruct& extra) override;
2424
sdk::ProtoStruct do_command(const sdk::ProtoStruct& command) override;
2525
std::vector<sdk::GeometryConfig> get_geometries(const sdk::ProtoStruct& extra) override;
26+
std::string get_kinematics(const sdk::ProtoStruct& extra) override;
2627

2728
std::vector<double> peek_positions;
2829
bool peek_stop_called{false};
2930
bool peek_home_called{false};
3031
sdk::ProtoStruct peek_command;
32+
std::string peek_kinematics_data;
3133
};
3234
} // namespace gantry
3335
} // namespace sdktests
34-
} // namespace viam
36+
} // namespace viam

src/viam/sdk/tests/test_gantry.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<viam::sdk::GeometryConfig>)
1010
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<double>)
11+
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::string)
1112

1213
namespace viam {
1314
namespace sdktests {
@@ -83,7 +84,15 @@ BOOST_AUTO_TEST_CASE(test_do_command) {
8384
});
8485
}
8586

87+
BOOST_AUTO_TEST_CASE(test_get_kinematics) {
88+
std::shared_ptr<MockGantry> mock = MockGantry::get_mock_gantry();
89+
client_to_mock_pipeline<Gantry>(mock, [](Gantry& client) {
90+
const auto& kinematics_data = client.get_kinematics();
91+
BOOST_CHECK_EQUAL(kinematics_data, fake_kinematics_data());
92+
});
93+
}
94+
8695
BOOST_AUTO_TEST_SUITE_END()
8796

8897
} // namespace sdktests
89-
} // namespace viam
98+
} // namespace viam

0 commit comments

Comments
 (0)