Skip to content

Commit 596b90a

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit 90357e0
1 parent 8b4cfe3 commit 596b90a

File tree

10 files changed

+164
-8
lines changed

10 files changed

+164
-8
lines changed

src/viam/sdk/common/kinematics.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <viam/sdk/common/kinematics.hpp>
2+
3+
#include <ostream>
4+
5+
namespace viam {
6+
namespace sdk {
7+
8+
bool KinematicsFileConfig::operator==(const KinematicsFileConfig& other) const {
9+
return kinematics_type == other.kinematics_type && extra == other.extra;
10+
}
11+
12+
namespace proto_convert_details {
13+
14+
template <>
15+
struct to_proto_impl<KinematicsFileConfig> {
16+
void operator()(const KinematicsFileConfig& kinematics, viam::common::v1::KinematicsFileConfig* proto) const {
17+
proto->set_kinematics_type(static_cast<viam::common::v1::KinematicsType>(kinematics.kinematics_type));
18+
*proto->mutable_extra() = to_proto(kinematics.extra);
19+
}
20+
};
21+
22+
template <>
23+
struct from_proto_impl<viam::common::v1::KinematicsFileConfig> {
24+
KinematicsFileConfig operator()(const viam::common::v1::KinematicsFileConfig* proto) const {
25+
KinematicsFileConfig kinematics;
26+
kinematics.kinematics_type = static_cast<KinematicsType>(proto->kinematics_type());
27+
kinematics.extra = from_proto(proto->extra());
28+
return kinematics;
29+
}
30+
};
31+
32+
} // namespace proto_convert_details
33+
34+
// For Boost test logging
35+
std::ostream& operator<<(std::ostream& os, const KinematicsFileConfig& kinematics) {
36+
os << "{kinematics_type: " << static_cast<int>(kinematics.kinematics_type)
37+
<< ", extra: " << kinematics.extra.ShortDebugString() << "}";
38+
return os;
39+
}
40+
41+
} // namespace sdk
42+
} // namespace viam

src/viam/sdk/common/kinematics.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
#include <viam/api/common/v1/common.pb.h>
6+
#include <viam/sdk/common/proto_convert.hpp>
7+
#include <viam/sdk/common/proto_value.hpp>
8+
9+
namespace viam {
10+
namespace sdk {
11+
12+
/// @defgroup Kinematics Classes related to Kinematics configuration
13+
14+
/// @enum KinematicsType
15+
/// @brief Defines the type of kinematics configuration.
16+
/// @ingroup Kinematics
17+
enum class KinematicsType {
18+
KINEMATICS_TYPE_UNSPECIFIED = 0,
19+
KINEMATICS_TYPE_SIX_AXIS_ARM = 1,
20+
KINEMATICS_TYPE_GANTRY = 2,
21+
KINEMATICS_TYPE_CARTESIAN = 3,
22+
KINEMATICS_TYPE_CUSTOM = 4
23+
};
24+
25+
/// @struct KinematicsFileConfig
26+
/// @brief Defines the kinematics configuration of a component.
27+
/// @ingroup Kinematics
28+
struct KinematicsFileConfig {
29+
/// @brief The type of kinematics configuration.
30+
KinematicsType kinematics_type;
31+
/// @brief Additional arguments to the method.
32+
ProtoStruct extra;
33+
34+
/// @brief Equality operator for `KinematicsFileConfig`.
35+
bool operator==(const KinematicsFileConfig& other) const;
36+
};
37+
38+
/// @brief Convert an SDK `KinematicsFileConfig` to its corresponding API proto type.
39+
/// @param kinematics The SDK `KinematicsFileConfig` to convert.
40+
/// @return The API proto `viam::common::v1::KinematicsFileConfig`.
41+
viam::common::v1::KinematicsFileConfig to_proto(const KinematicsFileConfig& kinematics);
42+
43+
/// @brief Convert an API proto `viam::common::v1::KinematicsFileConfig` to its corresponding SDK type.
44+
/// @param proto The API proto `viam::common::v1::KinematicsFileConfig` to convert.
45+
/// @return The SDK `KinematicsFileConfig`.
46+
KinematicsFileConfig from_proto(const viam::common::v1::KinematicsFileConfig& proto);
47+
48+
} // namespace sdk
49+
} // namespace viam

src/viam/sdk/components/gantry.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <viam/sdk/resource/stoppable.hpp>
7+
#include <viam/sdk/common/kinematics.hpp>
78

89
namespace viam {
910
namespace sdk {
@@ -86,6 +87,15 @@ class Gantry : public Component, public Stoppable {
8687
/// @return The result of the executed command.
8788
virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
8889

90+
/// @brief Get the Kinematics configuration of the component.
91+
inline KinematicsFileConfig get_kinematics() {
92+
return get_kinematics({});
93+
}
94+
95+
/// @brief Get the Kinematics configuration of the component.
96+
/// @param extra Any additional arguments to the method
97+
virtual KinematicsFileConfig get_kinematics(const ProtoStruct& extra) = 0;
98+
8999
/// @brief Returns `GeometryConfig`s associated with the calling gantry
90100
inline std::vector<GeometryConfig> get_geometries() {
91101
return get_geometries({});
@@ -107,4 +117,4 @@ struct API::traits<Gantry> {
107117
};
108118

109119
} // namespace sdk
110-
} // namespace viam
120+
} // namespace viam

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

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

33
#include <viam/api/component/gantry/v1/gantry.grpc.pb.h>
44
#include <viam/api/component/gantry/v1/gantry.pb.h>
5+
#include <viam/sdk/common/kinematics.hpp>
56

67
#include <viam/sdk/common/client_helper.hpp>
78

@@ -69,6 +70,12 @@ ProtoStruct GantryClient::do_command(const ProtoStruct& command) {
6970
.invoke([](auto& response) { return from_proto(response.result()); });
7071
}
7172

73+
KinematicsFileConfig GantryClient::get_kinematics(const ProtoStruct& extra) {
74+
return make_client_helper(this, *stub_, &StubType::GetKinematics)
75+
.with(extra)
76+
.invoke([](auto& response) { return from_proto(response.kinematics()); });
77+
}
78+
7279
std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extra) {
7380
return make_client_helper(this, *stub_, &StubType::GetGeometries)
7481
.with(extra)
@@ -77,4 +84,4 @@ std::vector<GeometryConfig> GantryClient::get_geometries(const ProtoStruct& extr
7784

7885
} // namespace impl
7986
} // namespace sdk
80-
} // namespace viam
87+
} // namespace viam

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <viam/api/component/gantry/v1/gantry.grpc.pb.h>
99

1010
#include <viam/sdk/components/gantry.hpp>
11+
#include <viam/sdk/common/kinematics.hpp>
1112

1213
namespace viam {
1314
namespace sdk {
@@ -29,13 +30,15 @@ class GantryClient : public Gantry {
2930
bool is_moving() override;
3031
void stop(const ProtoStruct& extra) override;
3132
ProtoStruct do_command(const ProtoStruct& command) override;
33+
KinematicsFileConfig get_kinematics(const ProtoStruct& extra) override;
3234
std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
3335

3436
using Gantry::get_geometries;
3537
using Gantry::get_lengths;
3638
using Gantry::get_position;
3739
using Gantry::home;
3840
using Gantry::move_to_position;
41+
using Gantry::get_kinematics;
3942
using Gantry::stop;
4043

4144
private:
@@ -46,4 +49,4 @@ class GantryClient : public Gantry {
4649

4750
} // namespace impl
4851
} // namespace sdk
49-
} // namespace viam
52+
} // namespace viam

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <viam/sdk/components/private/gantry_server.hpp>
22

33
#include <viam/sdk/common/private/service_helper.hpp>
4+
#include <viam/api/common/v1/common.pb.h>
5+
#include <viam/sdk/common/kinematics.hpp>
46

57
namespace viam {
68
namespace sdk {
@@ -80,6 +82,17 @@ ::grpc::Status GantryServer::DoCommand(::grpc::ServerContext*,
8082
});
8183
}
8284

85+
::grpc::Status GantryServer::GetKinematics(
86+
::grpc::ServerContext*,
87+
const ::viam::common::v1::GetKinematicsRequest* request,
88+
::viam::common::v1::GetKinematicsResponse* response) noexcept {
89+
return make_service_helper<Gantry>(
90+
"GantryServer::GetKinematics", this, request)([&](auto& helper, auto& gantry) {
91+
const KinematicsFileConfig kinematics = gantry->get_kinematics(helper.getExtra());
92+
*response->mutable_kinematics() = to_proto(kinematics);
93+
});
94+
}
95+
8396
::grpc::Status GantryServer::GetGeometries(
8497
::grpc::ServerContext*,
8598
const ::viam::common::v1::GetGeometriesRequest* request,
@@ -95,4 +108,4 @@ ::grpc::Status GantryServer::GetGeometries(
95108

96109
} // namespace impl
97110
} // namespace sdk
98-
} // namespace viam
111+
} // namespace viam

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <viam/api/component/gantry/v1/gantry.grpc.pb.h>
77
#include <viam/api/component/gantry/v1/gantry.pb.h>
8+
#include <viam/api/common/v1/common.pb.h>
89

910
#include <viam/sdk/components/gantry.hpp>
1011
#include <viam/sdk/resource/resource_manager.hpp>
@@ -57,6 +58,11 @@ class GantryServer : public ResourceServer,
5758
const ::viam::common::v1::DoCommandRequest* request,
5859
::viam::common::v1::DoCommandResponse* response) noexcept;
5960

61+
virtual ::grpc::Status GetKinematics(
62+
::grpc::ServerContext* context,
63+
const ::viam::common::v1::GetKinematicsRequest* request,
64+
::viam::common::v1::GetKinematicsResponse* response) noexcept;
65+
6066
virtual ::grpc::Status GetGeometries(
6167
::grpc::ServerContext* context,
6268
const ::viam::common::v1::GetGeometriesRequest* request,
@@ -65,4 +71,4 @@ class GantryServer : public ResourceServer,
6571

6672
} // namespace impl
6773
} // namespace sdk
68-
} // namespace viam
74+
} // namespace viam

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <viam/sdk/tests/mocks/mock_gantry.hpp>
22

33
#include <viam/sdk/tests/test_utils.hpp>
4+
#include <viam/sdk/common/kinematics.hpp>
45

56
namespace viam {
67
namespace sdktests {
@@ -10,6 +11,13 @@ std::vector<double> fake_lengths() {
1011
return {1.0, 2.0, 3.0, 4.0};
1112
}
1213

14+
sdk::KinematicsFileConfig fake_kinematics() {
15+
sdk::KinematicsFileConfig k;
16+
k.kinematics_type = sdk::KinematicsType::KINEMATICS_TYPE_GANTRY;
17+
k.extra = fake_map();
18+
return k;
19+
}
20+
1321
std::shared_ptr<MockGantry> MockGantry::get_mock_gantry() {
1422
return std::make_shared<MockGantry>("mock_gantry");
1523
}
@@ -45,10 +53,14 @@ sdk::ProtoStruct MockGantry::do_command(const sdk::ProtoStruct& command) {
4553
return (peek_command = command);
4654
}
4755

56+
sdk::KinematicsFileConfig MockGantry::get_kinematics(const sdk::ProtoStruct&) {
57+
return peek_kinematics;
58+
}
59+
4860
std::vector<sdk::GeometryConfig> MockGantry::get_geometries(const sdk::ProtoStruct&) {
4961
return fake_geometries();
5062
}
5163

5264
} // namespace gantry
5365
} // namespace sdktests
54-
} // namespace viam
66+
} // namespace viam

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <viam/sdk/components/gantry.hpp>
4+
#include <viam/sdk/common/kinematics.hpp>
45

56
namespace viam {
67
namespace sdktests {
@@ -22,13 +23,15 @@ class MockGantry : public sdk::Gantry {
2223
bool is_moving() override;
2324
void stop(const sdk::ProtoStruct& extra) override;
2425
sdk::ProtoStruct do_command(const sdk::ProtoStruct& command) override;
26+
sdk::KinematicsFileConfig get_kinematics(const sdk::ProtoStruct& extra) override;
2527
std::vector<sdk::GeometryConfig> get_geometries(const sdk::ProtoStruct& extra) override;
2628

2729
std::vector<double> peek_positions;
2830
bool peek_stop_called{false};
2931
bool peek_home_called{false};
3032
sdk::ProtoStruct peek_command;
33+
sdk::KinematicsFileConfig peek_kinematics;
3134
};
3235
} // namespace gantry
3336
} // namespace sdktests
34-
} // namespace viam
37+
} // namespace viam

src/viam/sdk/tests/test_gantry.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
#include <viam/sdk/components/gantry.hpp>
66
#include <viam/sdk/tests/mocks/mock_gantry.hpp>
77
#include <viam/sdk/tests/test_utils.hpp>
8+
#include <viam/sdk/common/kinematics.hpp>
89

910
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<viam::sdk::GeometryConfig>)
1011
BOOST_TEST_DONT_PRINT_LOG_VALUE(std::vector<double>)
12+
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::KinematicsFileConfig)
1113

1214
namespace viam {
1315
namespace sdktests {
@@ -83,7 +85,16 @@ BOOST_AUTO_TEST_CASE(test_do_command) {
8385
});
8486
}
8587

88+
BOOST_AUTO_TEST_CASE(test_get_kinematics) {
89+
std::shared_ptr<MockGantry> mock = MockGantry::get_mock_gantry();
90+
client_to_mock_pipeline<Gantry>(mock, [&](Gantry& client) {
91+
mock->peek_kinematics = fake_kinematics();
92+
const auto& kinematics = client.get_kinematics();
93+
BOOST_CHECK_EQUAL(kinematics, fake_kinematics());
94+
});
95+
}
96+
8697
BOOST_AUTO_TEST_SUITE_END()
8798

8899
} // namespace sdktests
89-
} // namespace viam
100+
} // namespace viam

0 commit comments

Comments
 (0)