Skip to content

Commit 0f8a7a8

Browse files
committed
Merge branch 'main' of ssh://github.com/viamrobotics/viam-cpp-sdk into make-proto-conversions-private
2 parents 1af0f6f + 7c8487c commit 0f8a7a8

24 files changed

+989
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# constrained by the version of CMake available on target systems.
3535
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
3636

37-
set(CMAKE_PROJECT_VERSION 0.0.15)
37+
set(CMAKE_PROJECT_VERSION 0.0.16)
3838

3939
# Identify the project.
4040
project(viam-cpp-sdk

src/viam/api/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
225225
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.h
226226
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
227227
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.h
228+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
229+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.h
230+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
231+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.h
228232
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
229233
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.h
230234
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
@@ -328,6 +332,8 @@ target_sources(viamapi
328332
${PROTO_GEN_DIR}/service/mlmodel/v1/mlmodel.pb.cc
329333
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.cc
330334
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
335+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
336+
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
331337
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
332338
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
333339
PUBLIC FILE_SET viamapi_includes TYPE HEADERS
@@ -385,6 +391,8 @@ target_sources(viamapi
385391
${PROTO_GEN_DIR}/../../viam/api/service/mlmodel/v1/mlmodel.pb.h
386392
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.grpc.pb.h
387393
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.pb.h
394+
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.grpc.pb.h
395+
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.pb.h
388396
${PROTO_GEN_DIR}/../../viam/api/tagger/v1/tagger.pb.h
389397
)
390398

src/viam/sdk/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ target_sources(viamsdk
121121
services/generic.cpp
122122
services/mlmodel.cpp
123123
services/motion.cpp
124+
services/navigation.cpp
124125
services/private/generic_client.cpp
125126
services/private/generic_server.cpp
126127
services/private/mlmodel.cpp
127128
services/private/mlmodel_client.cpp
128129
services/private/mlmodel_server.cpp
129130
services/private/motion_client.cpp
130131
services/private/motion_server.cpp
132+
services/private/navigation_client.cpp
133+
services/private/navigation_server.cpp
131134
services/service.cpp
132135
spatialmath/geometry.cpp
133136
spatialmath/orientation.cpp
@@ -181,6 +184,7 @@ target_sources(viamsdk
181184
../../viam/sdk/services/generic.hpp
182185
../../viam/sdk/services/mlmodel.hpp
183186
../../viam/sdk/services/motion.hpp
187+
../../viam/sdk/services/navigation.hpp
184188
../../viam/sdk/services/service.hpp
185189
../../viam/sdk/spatialmath/geometry.hpp
186190
../../viam/sdk/spatialmath/orientation.hpp
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/// @file common/proto_utils.hpp
2+
///
3+
/// @brief Utils that require generated proto includes. These should be #included
4+
/// in cpp implementation files, but not in wrapper headers consumed by third party code.
5+
#pragma once
6+
7+
#include <viam/api/common/v1/common.pb.h>
8+
9+
namespace viam {
10+
namespace sdk {
11+
namespace impl {
12+
13+
/// @brief Copies elements from a protobuf repeated pointer array into a std::vector. Src type
14+
/// must have a `to_proto` method.
15+
template <typename Src, typename Dst>
16+
void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) {
17+
dest.Clear();
18+
dest.Reserve(vec.size());
19+
for (auto& x : vec) {
20+
*dest.Add() = x.to_proto();
21+
}
22+
}
23+
24+
/// @brief Non-member to_proto() version. (necessary for moving generated types out of wrapper
25+
/// headers). Takes explicit `to_proto`.
26+
template <typename Src, typename Dst>
27+
void vecToRepeatedPtr(const std::vector<Src>& vec,
28+
google::protobuf::RepeatedPtrField<Dst>& dest,
29+
Dst to_proto(const Src&)) {
30+
dest.Clear();
31+
dest.Reserve(vec.size());
32+
for (auto& x : vec) {
33+
*dest.Add() = to_proto(x);
34+
}
35+
}
36+
37+
/// @brief Copies elements from a std::vector into a protobuf repeated pointer array. Dst type
38+
/// must have a `from_proto` static method.
39+
template <typename Src, typename Dst>
40+
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) {
41+
vec.clear();
42+
vec.reserve(src.size());
43+
for (auto& x : src) {
44+
vec.push_back(Dst::from_proto(x));
45+
}
46+
}
47+
48+
/// @brief Non-member from_proto() version. (necessary for moving generated types out of wrapper
49+
/// headers). Takes explicit `from_proto`.
50+
template <typename Src, typename Dst>
51+
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src,
52+
std::vector<Dst>& vec,
53+
Dst from_proto(const Src&)) {
54+
vec.clear();
55+
vec.reserve(src.size());
56+
for (auto& x : src) {
57+
vec.push_back(from_proto(x));
58+
}
59+
}
60+
61+
} // namespace impl
62+
} // namespace sdk
63+
} // namespace viam

src/viam/sdk/components/arm.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <string>
77

8+
#include <boost/optional/optional.hpp>
89
#include <boost/variant/variant.hpp>
910

1011
#include <viam/sdk/common/pose.hpp>
@@ -58,6 +59,12 @@ class Arm : public Component, public Stoppable {
5859
using KinematicsData =
5960
boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;
6061

62+
/// @brief Movement specifications for move_through_join_positions.
63+
struct MoveOptions {
64+
boost::optional<double> max_vel_degs_per_sec;
65+
boost::optional<double> max_acc_degs_per_sec2;
66+
};
67+
6168
/// @brief Get the current position of the end of the arm.
6269
/// @return The `pose` representing the end position of the arm.
6370
inline pose get_end_position() {
@@ -98,6 +105,22 @@ class Arm : public Component, public Stoppable {
98105
virtual void move_to_joint_positions(const std::vector<double>& positions,
99106
const ProtoStruct& extra) = 0;
100107

108+
/// @brief Move each joint on the arm through the positions specified in @param positions
109+
/// @param options optional specifications to be obeyed during the motion.
110+
/// TODO consider replacing vector vector with xtensor array, and also if it may be
111+
/// possible to specify or constrain dimensionality of the array in advance.
112+
inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
113+
const MoveOptions& options) {
114+
return move_through_joint_positions(positions, options, {});
115+
}
116+
117+
/// @brief Move each joint on the arm through the positions specified in @param positions
118+
/// @param options optional specifications to be obeyed during the motion.
119+
/// @param extra Any additional arguments to the method.
120+
virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
121+
const MoveOptions& options,
122+
const ProtoStruct& extra) = 0;
123+
101124
/// @brief Reports if the arm is in motion.
102125
virtual bool is_moving() = 0;
103126

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ void ArmClient::move_to_joint_positions(const std::vector<double>& positions,
4747
.invoke();
4848
}
4949

50+
void ArmClient::move_through_joint_positions(const std::vector<std::vector<double>>& positions,
51+
const Arm::MoveOptions& options,
52+
const ProtoStruct& extra) {
53+
return make_client_helper(this, *stub_, &StubType::MoveThroughJointPositions)
54+
.with(extra,
55+
[&](viam::component::arm::v1::MoveThroughJointPositionsRequest& request) {
56+
if (options.max_vel_degs_per_sec) {
57+
request.mutable_options()->set_max_vel_degs_per_sec(
58+
*options.max_vel_degs_per_sec);
59+
}
60+
61+
if (options.max_acc_degs_per_sec2) {
62+
request.mutable_options()->set_max_acc_degs_per_sec2(
63+
*options.max_acc_degs_per_sec2);
64+
}
65+
66+
for (const auto& pos : positions) {
67+
viam::component::arm::v1::JointPositions jpos;
68+
jpos.mutable_values()->Add(pos.begin(), pos.end());
69+
request.mutable_positions()->Add(std::move(jpos));
70+
}
71+
})
72+
.invoke();
73+
}
74+
5075
bool ArmClient::is_moving() {
5176
return make_client_helper(this, *stub_, &StubType::IsMoving).invoke([](auto& response) {
5277
return response.is_moving();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ArmClient : public Arm {
2626
std::vector<double> get_joint_positions(const ProtoStruct& extra) override;
2727
void move_to_joint_positions(const std::vector<double>& positions,
2828
const ProtoStruct& extra) override;
29+
void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
30+
const Arm::MoveOptions& options,
31+
const ProtoStruct& extra) override;
2932
bool is_moving() override;
3033
void stop(const ProtoStruct& extra) override;
3134
ProtoStruct do_command(const ProtoStruct& command) override;
@@ -38,6 +41,7 @@ class ArmClient : public Arm {
3841
using Arm::get_geometries;
3942
using Arm::get_joint_positions;
4043
using Arm::get_kinematics;
44+
using Arm::move_through_joint_positions;
4145
using Arm::move_to_joint_positions;
4246
using Arm::move_to_position;
4347
using Arm::stop;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ ::grpc::Status ArmServer::MoveToJointPositions(
5454
});
5555
}
5656

57+
::grpc::Status ArmServer::MoveThroughJointPositions(
58+
::grpc::ServerContext*,
59+
const ::viam::component::arm::v1::MoveThroughJointPositionsRequest* request,
60+
::viam::component::arm::v1::MoveThroughJointPositionsResponse*) noexcept {
61+
return make_service_helper<Arm>(
62+
"ArmServer::MoveThroughJointPositions", this, request)([&](auto& helper, auto& arm) {
63+
std::vector<std::vector<double>> positions;
64+
65+
positions.reserve(request->positions_size());
66+
for (const auto& values : request->positions()) {
67+
positions.emplace_back(values.values().begin(), values.values().end());
68+
}
69+
70+
Arm::MoveOptions opts;
71+
if (request->options().has_max_vel_degs_per_sec()) {
72+
opts.max_vel_degs_per_sec = request->options().max_vel_degs_per_sec();
73+
}
74+
75+
if (request->options().has_max_acc_degs_per_sec2()) {
76+
opts.max_acc_degs_per_sec2 = request->options().max_acc_degs_per_sec2();
77+
}
78+
79+
arm->move_through_joint_positions(positions, opts, helper.getExtra());
80+
});
81+
}
82+
5783
::grpc::Status ArmServer::Stop(::grpc::ServerContext*,
5884
const ::viam::component::arm::v1::StopRequest* request,
5985
::viam::component::arm::v1::StopResponse*) noexcept {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class ArmServer : public ResourceServer, public viam::component::arm::v1::ArmSer
4444
const ::viam::component::arm::v1::MoveToJointPositionsRequest* request,
4545
::viam::component::arm::v1::MoveToJointPositionsResponse* response) noexcept override;
4646

47+
::grpc::Status MoveThroughJointPositions(
48+
::grpc::ServerContext* context,
49+
const ::viam::component::arm::v1::MoveThroughJointPositionsRequest* request,
50+
::viam::component::arm::v1::MoveThroughJointPositionsResponse* response) noexcept override;
51+
4752
::grpc::Status Stop(::grpc::ServerContext* context,
4853
const ::viam::component::arm::v1::StopRequest* request,
4954
::viam::component::arm::v1::StopResponse* response) noexcept override;

src/viam/sdk/registry/registry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <viam/sdk/services/private/mlmodel_server.hpp>
4848
#include <viam/sdk/services/private/motion_client.hpp>
4949
#include <viam/sdk/services/private/motion_server.hpp>
50+
#include <viam/sdk/services/private/navigation_client.hpp>
51+
#include <viam/sdk/services/private/navigation_server.hpp>
5052
#include <viam/sdk/services/service.hpp>
5153

5254
namespace viam {
@@ -179,6 +181,7 @@ void register_resources() {
179181
Registry::register_resource<impl::GenericServiceClient, impl::GenericServiceServer>();
180182
Registry::register_resource<impl::MLModelServiceClient, impl::MLModelServiceServer>();
181183
Registry::register_resource<impl::MotionClient, impl::MotionServer>();
184+
Registry::register_resource<impl::NavigationClient, impl::NavigationServer>();
182185
}
183186

184187
void Registry::initialize() {

0 commit comments

Comments
 (0)