Skip to content

Commit f749e33

Browse files
committed
feat: implement Get3DModels for arm
1 parent 04dc333 commit f749e33

File tree

10 files changed

+73
-1
lines changed

10 files changed

+73
-1
lines changed

src/viam/sdk/components/arm.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// @brief Defines an `Arm` component
44
#pragma once
55

6+
#include <common/v1/common.pb.h>
67
#include <string>
78

89
#include <boost/optional/optional.hpp>
@@ -142,6 +143,17 @@ class Arm : public Component, public Stoppable {
142143
return get_kinematics({});
143144
}
144145

146+
/// @brief Returns `3DModel`s associated with the calling arm
147+
/// @param extra Any additional arguments to the method
148+
/// @return A map of `3DModel`s associated with the calling arm
149+
virtual std::map<std::string, common::v1::Mesh> get_3d_models(const ProtoStruct& extra) = 0;
150+
151+
/// @brief Returns `3DModel`s associated with the calling arm
152+
/// @return A map of `3DModel`s associated with the calling arm
153+
inline std::map<std::string, common::v1::Mesh> get_3d_models() {
154+
return get_3d_models({});
155+
}
156+
145157
/// @brief Returns `GeometryConfig`s associated with the calling arm
146158
inline std::vector<GeometryConfig> get_geometries() {
147159
return get_geometries({});

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ Arm::KinematicsData ArmClient::get_kinematics(const ProtoStruct& extra) {
106106
});
107107
}
108108

109+
std::map<std::string, common::v1::Mesh> ArmClient::get_3d_models(const ProtoStruct& extra) {
110+
return make_client_helper(this, *stub_, &StubType::Get3DModels)
111+
.with(extra)
112+
.invoke([](auto& response) {
113+
return std::map<std::string, common::v1::Mesh>(response.models().begin(),
114+
response.models().end());
115+
});
116+
}
117+
109118
std::vector<GeometryConfig> ArmClient::get_geometries(const ProtoStruct& extra) {
110119
return make_client_helper(this, *stub_, &StubType::GetGeometries)
111120
.with(extra)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class ArmClient : public Arm {
3333
void stop(const ProtoStruct& extra) override;
3434
ProtoStruct do_command(const ProtoStruct& command) override;
3535
Arm::KinematicsData get_kinematics(const ProtoStruct& extra) override;
36+
std::map<std::string, common::v1::Mesh> get_3d_models(const ProtoStruct& extra) override;
3637
std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
3738

3839
// Using declarations to introduce convenience overloads of interface which do not need to be
3940
// passed the ProtoStruct parameter.
41+
using Arm::get_3d_models;
4042
using Arm::get_end_position;
4143
using Arm::get_geometries;
4244
using Arm::get_joint_positions;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ ::grpc::Status ArmServer::GetKinematics(
135135
});
136136
}
137137

138+
::grpc::Status ArmServer::Get3DModels(::grpc::ServerContext*,
139+
const ::viam::common::v1::Get3DModelsRequest* request,
140+
::viam::common::v1::Get3DModelsResponse* response) noexcept {
141+
return make_service_helper<Arm>(
142+
"ArmServer::Get3DModels", this, request)([&](auto& helper, auto& arm) {
143+
const std::map<std::string, common::v1::Mesh> models =
144+
arm->get_3d_models(helper.getExtra());
145+
146+
response->mutable_models()->insert(models.begin(), models.end());
147+
});
148+
}
149+
138150
::grpc::Status ArmServer::GetGeometries(
139151
::grpc::ServerContext*,
140152
const ::viam::common::v1::GetGeometriesRequest* request,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ArmServer : public ResourceServer, public viam::component::arm::v1::ArmSer
6767
const ::viam::common::v1::GetKinematicsRequest* request,
6868
::viam::common::v1::GetKinematicsResponse* response) noexcept override;
6969

70+
::grpc::Status Get3DModels(::grpc::ServerContext* context,
71+
const ::viam::common::v1::Get3DModelsRequest* request,
72+
::viam::common::v1::Get3DModelsResponse* response) noexcept override;
73+
7074
::grpc::Status GetGeometries(
7175
::grpc::ServerContext* context,
7276
const ::viam::common::v1::GetGeometriesRequest* request,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Start testing: Nov 18 09:37 EST
2+
----------------------------------------------------------
3+
End testing: Nov 18 09:37 EST

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace viam {
77
namespace sdktests {
88
namespace arm {
99

10+
std::map<std::string, common::v1::Mesh> fake_3d_models() {
11+
return {{"model1", common::v1::Mesh::default_instance()}};
12+
}
13+
1014
sdk::Arm::KinematicsData fake_kinematics() {
1115
return sdk::Arm::KinematicsDataSVA{{std::vector<unsigned char>{1, 2, 3, 4}}};
1216
}
@@ -59,6 +63,10 @@ std::vector<sdk::GeometryConfig> MockArm::get_geometries(const sdk::ProtoStruct&
5963
return fake_geometries();
6064
}
6165

66+
std::map<std::string, common::v1::Mesh> MockArm::get_3d_models(const sdk::ProtoStruct&) {
67+
return fake_3d_models();
68+
}
69+
6270
} // namespace arm
6371
} // namespace sdktests
6472
} // namespace viam

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace sdktests {
77
namespace arm {
88

99
sdk::Arm::KinematicsData fake_kinematics();
10+
std::map<std::string, common::v1::Mesh> fake_3d_models();
1011

1112
class MockArm : public sdk::Arm {
1213
public:
@@ -29,7 +30,7 @@ class MockArm : public sdk::Arm {
2930
sdk::ProtoStruct do_command(const sdk::ProtoStruct& command) override;
3031
sdk::Arm::KinematicsData get_kinematics(const sdk::ProtoStruct&) override;
3132
std::vector<sdk::GeometryConfig> get_geometries(const sdk::ProtoStruct&) override;
32-
33+
std::map<std::string, common::v1::Mesh> get_3d_models(const sdk::ProtoStruct&) override;
3334
sdk::pose current_location;
3435
std::vector<double> joint_positions;
3536
std::vector<std::vector<double>> move_thru_positions;

src/viam/sdk/tests/test_arm.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ BOOST_AUTO_TEST_CASE(test_do_command) {
104104
});
105105
}
106106

107+
BOOST_AUTO_TEST_CASE(test_get_3d_models) {
108+
std::shared_ptr<MockArm> mock = MockArm::get_mock_arm();
109+
client_to_mock_pipeline<Arm>(mock, [](Arm& client) {
110+
const auto& models = client.get_3d_models();
111+
const auto& expected = fake_3d_models();
112+
113+
// Compare keysets directly
114+
std::set<std::string> model_keys;
115+
std::set<std::string> expected_keys;
116+
for (const auto& [key, _] : models) {
117+
model_keys.insert(key);
118+
}
119+
for (const auto& [key, _] : expected) {
120+
expected_keys.insert(key);
121+
}
122+
BOOST_CHECK_EQUAL_COLLECTIONS(
123+
model_keys.begin(), model_keys.end(), expected_keys.begin(), expected_keys.end());
124+
});
125+
}
126+
107127
BOOST_AUTO_TEST_SUITE_END()
108128

109129
} // namespace sdktests

0 commit comments

Comments
 (0)