Skip to content

Commit 2dad8ed

Browse files
authored
Merge branch 'main' into aw-docker-2
2 parents 589099b + c6ab72d commit 2dad8ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1726
-1046
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/examples/modules/complex/proto/buf.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ deps:
44
- remote: buf.build
55
owner: googleapis
66
repository: googleapis
7-
commit: e7f8d366f5264595bcc4cd4139af9973
8-
digest: shake256:e5e5f1c12f82e028ea696faa43b4f9dc6258a6d1226282962a8c8b282e10946281d815884f574bd279ebd9cd7588629beb3db17b892af6c33b56f92f8f67f509
7+
commit: c0913f24652a4cfc95f77d97443a5005
8+
digest: shake256:0ef3248c6235d420fe61f373154adcde6b94e3297f82472b1d8d8c3747240b61b4a10405e2a6f8ac1c98816ac6e690ea7871024aa5ae0e035cd540214667ceed

src/viam/sdk/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_sources(viamsdk
7676
components/private/board_server.cpp
7777
components/private/camera_client.cpp
7878
components/private/camera_server.cpp
79+
components/private/encoder.cpp
7980
components/private/encoder_client.cpp
8081
components/private/encoder_server.cpp
8182
components/private/gantry_client.cpp
@@ -119,13 +120,16 @@ target_sources(viamsdk
119120
services/generic.cpp
120121
services/mlmodel.cpp
121122
services/motion.cpp
123+
services/navigation.cpp
122124
services/private/generic_client.cpp
123125
services/private/generic_server.cpp
124126
services/private/mlmodel.cpp
125127
services/private/mlmodel_client.cpp
126128
services/private/mlmodel_server.cpp
127129
services/private/motion_client.cpp
128130
services/private/motion_server.cpp
131+
services/private/navigation_client.cpp
132+
services/private/navigation_server.cpp
129133
services/service.cpp
130134
spatialmath/geometry.cpp
131135
spatialmath/orientation.cpp
@@ -179,6 +183,7 @@ target_sources(viamsdk
179183
../../viam/sdk/services/generic.hpp
180184
../../viam/sdk/services/mlmodel.hpp
181185
../../viam/sdk/services/motion.hpp
186+
../../viam/sdk/services/navigation.hpp
182187
../../viam/sdk/services/service.hpp
183188
../../viam/sdk/spatialmath/geometry.hpp
184189
../../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.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ API API::traits<Arm>::api() {
1111
return {kRDK, kComponent, "arm"};
1212
}
1313

14-
Arm::KinematicsData Arm::from_proto(const viam::common::v1::GetKinematicsResponse& proto) {
15-
std::vector<unsigned char> bytes(proto.kinematics_data().begin(),
16-
proto.kinematics_data().end());
17-
switch (proto.format()) {
18-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_SVA:
19-
return Arm::KinematicsDataSVA(std::move(bytes));
20-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_URDF:
21-
return Arm::KinematicsDataURDF(std::move(bytes));
22-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_UNSPECIFIED: // fallthrough
23-
default:
24-
return Arm::KinematicsDataUnspecified{};
25-
}
26-
}
27-
2814
Arm::Arm(std::string name) : Component(std::move(name)) {}
2915

3016
} // namespace sdk

src/viam/sdk/components/arm.hpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
#include <string>
77

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

10-
#include <viam/api/common/v1/common.pb.h>
11-
#include <viam/api/component/arm/v1/arm.pb.h>
12-
1311
#include <viam/sdk/common/pose.hpp>
1412
#include <viam/sdk/resource/stoppable.hpp>
1513
#include <viam/sdk/spatialmath/geometry.hpp>
@@ -61,7 +59,11 @@ class Arm : public Component, public Stoppable {
6159
using KinematicsData =
6260
boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;
6361

64-
static KinematicsData from_proto(const viam::common::v1::GetKinematicsResponse& proto);
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+
};
6567

6668
/// @brief Get the current position of the end of the arm.
6769
/// @return The `pose` representing the end position of the arm.
@@ -103,6 +105,22 @@ class Arm : public Component, public Stoppable {
103105
virtual void move_to_joint_positions(const std::vector<double>& positions,
104106
const ProtoStruct& extra) = 0;
105107

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+
106124
/// @brief Reports if the arm is in motion.
107125
virtual bool is_moving() = 0;
108126

src/viam/sdk/components/base.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#include <viam/sdk/components/base.hpp>
22

3-
#include <google/protobuf/descriptor.h>
4-
5-
#include <viam/api/component/base/v1/base.grpc.pb.h>
6-
#include <viam/api/component/base/v1/base.pb.h>
7-
8-
#include <viam/sdk/common/utils.hpp>
9-
#include <viam/sdk/resource/resource.hpp>
10-
113
namespace viam {
124
namespace sdk {
135

@@ -19,12 +11,6 @@ API API::traits<Base>::api() {
1911
return {kRDK, kComponent, "base"};
2012
}
2113

22-
Base::properties Base::properties::from_proto(
23-
const component::base::v1::GetPropertiesResponse& proto) {
24-
return {
25-
proto.width_meters(), proto.turning_radius_meters(), proto.wheel_circumference_meters()};
26-
}
27-
2814
std::ostream& operator<<(std::ostream& os, const Base::properties& v) {
2915
os << "{ turning_radius_meters: " << v.turning_radius_meters
3016
<< ", wheel_circumference_meters: " << v.wheel_circumference_meters

src/viam/sdk/components/base.hpp

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

66
#include <string>
77

8-
#include <viam/api/component/base/v1/base.pb.h>
9-
108
#include <viam/sdk/common/linear_algebra.hpp>
119
#include <viam/sdk/common/proto_value.hpp>
1210
#include <viam/sdk/common/utils.hpp>
@@ -32,8 +30,6 @@ class Base : public Component, public Stoppable {
3230
double width_meters;
3331
double turning_radius_meters;
3432
double wheel_circumference_meters;
35-
36-
static properties from_proto(const component::base::v1::GetPropertiesResponse& proto);
3733
};
3834
friend std::ostream& operator<<(std::ostream& os, const properties& v);
3935
friend bool operator==(const properties& lhs, const properties& rhs);

src/viam/sdk/components/board.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
#include <google/protobuf/descriptor.h>
44

5-
#include <viam/api/component/board/v1/board.grpc.pb.h>
6-
#include <viam/api/component/board/v1/board.pb.h>
7-
8-
#include <viam/sdk/common/exception.hpp>
95
#include <viam/sdk/common/utils.hpp>
106
#include <viam/sdk/resource/resource.hpp>
117

@@ -20,59 +16,6 @@ API API::traits<Board>::api() {
2016
return {kRDK, kComponent, "board"};
2117
}
2218

23-
Board::status Board::from_proto(const viam::component::board::v1::Status& proto) {
24-
Board::status status;
25-
for (const auto& analog : proto.analogs()) {
26-
status.analog_reader_values.emplace(analog.first, analog.second);
27-
}
28-
for (const auto& digital : proto.digital_interrupts()) {
29-
status.digital_interrupt_values.emplace(digital.first, digital.second);
30-
}
31-
return status;
32-
}
33-
34-
Board::power_mode Board::from_proto(viam::component::board::v1::PowerMode proto) {
35-
switch (proto) {
36-
case viam::component::board::v1::POWER_MODE_NORMAL: {
37-
return Board::power_mode::normal;
38-
}
39-
case viam::component::board::v1::POWER_MODE_OFFLINE_DEEP: {
40-
return Board::power_mode::offline_deep;
41-
}
42-
case viam::component::board::v1::POWER_MODE_UNSPECIFIED:
43-
default: {
44-
throw Exception(ErrorCondition::k_not_supported,
45-
"Invalid proto board power_mode to decode");
46-
}
47-
}
48-
}
49-
50-
viam::component::board::v1::Status Board::to_proto(const status& status) {
51-
viam::component::board::v1::Status proto;
52-
for (const auto& analog : status.analog_reader_values) {
53-
proto.mutable_analogs()->insert({analog.first, analog.second});
54-
}
55-
56-
for (const auto& digital : status.digital_interrupt_values) {
57-
proto.mutable_digital_interrupts()->insert({digital.first, digital.second});
58-
}
59-
return proto;
60-
}
61-
62-
viam::component::board::v1::PowerMode Board::to_proto(Board::power_mode power_mode) {
63-
switch (power_mode) {
64-
case Board::power_mode::normal: {
65-
return viam::component::board::v1::POWER_MODE_NORMAL;
66-
}
67-
case Board::power_mode::offline_deep: {
68-
return viam::component::board::v1::POWER_MODE_OFFLINE_DEEP;
69-
}
70-
default: {
71-
throw Exception(ErrorCondition::k_not_supported, "Invalid board power_mode to encode");
72-
}
73-
}
74-
}
75-
7619
Board::Board(std::string name) : Component(std::move(name)){};
7720

7821
bool operator==(const Board::status& lhs, const Board::status& rhs) {

0 commit comments

Comments
 (0)