Skip to content

Commit

Permalink
Merge branch 'main' into aw-docker-2
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter authored Nov 19, 2024
2 parents 589099b + c6ab72d commit 2dad8ed
Show file tree
Hide file tree
Showing 81 changed files with 1,726 additions and 1,046 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# constrained by the version of CMake available on target systems.
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)

set(CMAKE_PROJECT_VERSION 0.0.15)
set(CMAKE_PROJECT_VERSION 0.0.16)

# Identify the project.
project(viam-cpp-sdk
Expand Down
8 changes: 8 additions & 0 deletions src/viam/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ if (VIAMCPPSDK_USE_DYNAMIC_PROTOS)
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.h
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.h
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.h
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.h
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.h
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
Expand Down Expand Up @@ -328,6 +332,8 @@ target_sources(viamapi
${PROTO_GEN_DIR}/service/mlmodel/v1/mlmodel.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.grpc.pb.cc
${PROTO_GEN_DIR}/service/motion/v1/motion.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.grpc.pb.cc
${PROTO_GEN_DIR}/service/navigation/v1/navigation.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.grpc.pb.cc
${PROTO_GEN_DIR}/tagger/v1/tagger.pb.cc
PUBLIC FILE_SET viamapi_includes TYPE HEADERS
Expand Down Expand Up @@ -385,6 +391,8 @@ target_sources(viamapi
${PROTO_GEN_DIR}/../../viam/api/service/mlmodel/v1/mlmodel.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/motion/v1/motion.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.grpc.pb.h
${PROTO_GEN_DIR}/../../viam/api/service/navigation/v1/navigation.pb.h
${PROTO_GEN_DIR}/../../viam/api/tagger/v1/tagger.pb.h
)

Expand Down
4 changes: 2 additions & 2 deletions src/viam/examples/modules/complex/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: e7f8d366f5264595bcc4cd4139af9973
digest: shake256:e5e5f1c12f82e028ea696faa43b4f9dc6258a6d1226282962a8c8b282e10946281d815884f574bd279ebd9cd7588629beb3db17b892af6c33b56f92f8f67f509
commit: c0913f24652a4cfc95f77d97443a5005
digest: shake256:0ef3248c6235d420fe61f373154adcde6b94e3297f82472b1d8d8c3747240b61b4a10405e2a6f8ac1c98816ac6e690ea7871024aa5ae0e035cd540214667ceed
5 changes: 5 additions & 0 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ target_sources(viamsdk
components/private/board_server.cpp
components/private/camera_client.cpp
components/private/camera_server.cpp
components/private/encoder.cpp
components/private/encoder_client.cpp
components/private/encoder_server.cpp
components/private/gantry_client.cpp
Expand Down Expand Up @@ -119,13 +120,16 @@ target_sources(viamsdk
services/generic.cpp
services/mlmodel.cpp
services/motion.cpp
services/navigation.cpp
services/private/generic_client.cpp
services/private/generic_server.cpp
services/private/mlmodel.cpp
services/private/mlmodel_client.cpp
services/private/mlmodel_server.cpp
services/private/motion_client.cpp
services/private/motion_server.cpp
services/private/navigation_client.cpp
services/private/navigation_server.cpp
services/service.cpp
spatialmath/geometry.cpp
spatialmath/orientation.cpp
Expand Down Expand Up @@ -179,6 +183,7 @@ target_sources(viamsdk
../../viam/sdk/services/generic.hpp
../../viam/sdk/services/mlmodel.hpp
../../viam/sdk/services/motion.hpp
../../viam/sdk/services/navigation.hpp
../../viam/sdk/services/service.hpp
../../viam/sdk/spatialmath/geometry.hpp
../../viam/sdk/spatialmath/orientation.hpp
Expand Down
63 changes: 63 additions & 0 deletions src/viam/sdk/common/private/proto_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// @file common/proto_utils.hpp
///
/// @brief Utils that require generated proto includes. These should be #included
/// in cpp implementation files, but not in wrapper headers consumed by third party code.
#pragma once

#include <viam/api/common/v1/common.pb.h>

namespace viam {
namespace sdk {
namespace impl {

/// @brief Copies elements from a protobuf repeated pointer array into a std::vector. Src type
/// must have a `to_proto` method.
template <typename Src, typename Dst>
void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) {
dest.Clear();
dest.Reserve(vec.size());
for (auto& x : vec) {
*dest.Add() = x.to_proto();
}
}

/// @brief Non-member to_proto() version. (necessary for moving generated types out of wrapper
/// headers). Takes explicit `to_proto`.
template <typename Src, typename Dst>
void vecToRepeatedPtr(const std::vector<Src>& vec,
google::protobuf::RepeatedPtrField<Dst>& dest,
Dst to_proto(const Src&)) {
dest.Clear();
dest.Reserve(vec.size());
for (auto& x : vec) {
*dest.Add() = to_proto(x);
}
}

/// @brief Copies elements from a std::vector into a protobuf repeated pointer array. Dst type
/// must have a `from_proto` static method.
template <typename Src, typename Dst>
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) {
vec.clear();
vec.reserve(src.size());
for (auto& x : src) {
vec.push_back(Dst::from_proto(x));
}
}

/// @brief Non-member from_proto() version. (necessary for moving generated types out of wrapper
/// headers). Takes explicit `from_proto`.
template <typename Src, typename Dst>
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src,
std::vector<Dst>& vec,
Dst from_proto(const Src&)) {
vec.clear();
vec.reserve(src.size());
for (auto& x : src) {
vec.push_back(from_proto(x));
}
}

} // namespace impl
} // namespace sdk
} // namespace viam
14 changes: 0 additions & 14 deletions src/viam/sdk/components/arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ API API::traits<Arm>::api() {
return {kRDK, kComponent, "arm"};
}

Arm::KinematicsData Arm::from_proto(const viam::common::v1::GetKinematicsResponse& proto) {
std::vector<unsigned char> bytes(proto.kinematics_data().begin(),
proto.kinematics_data().end());
switch (proto.format()) {
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_SVA:
return Arm::KinematicsDataSVA(std::move(bytes));
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_URDF:
return Arm::KinematicsDataURDF(std::move(bytes));
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_UNSPECIFIED: // fallthrough
default:
return Arm::KinematicsDataUnspecified{};
}
}

Arm::Arm(std::string name) : Component(std::move(name)) {}

} // namespace sdk
Expand Down
26 changes: 22 additions & 4 deletions src/viam/sdk/components/arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

#include <string>

#include <boost/optional/optional.hpp>
#include <boost/variant/variant.hpp>

#include <viam/api/common/v1/common.pb.h>
#include <viam/api/component/arm/v1/arm.pb.h>

#include <viam/sdk/common/pose.hpp>
#include <viam/sdk/resource/stoppable.hpp>
#include <viam/sdk/spatialmath/geometry.hpp>
Expand Down Expand Up @@ -61,7 +59,11 @@ class Arm : public Component, public Stoppable {
using KinematicsData =
boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;

static KinematicsData from_proto(const viam::common::v1::GetKinematicsResponse& proto);
/// @brief Movement specifications for move_through_join_positions.
struct MoveOptions {
boost::optional<double> max_vel_degs_per_sec;
boost::optional<double> max_acc_degs_per_sec2;
};

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

/// @brief Move each joint on the arm through the positions specified in @param positions
/// @param options optional specifications to be obeyed during the motion.
/// TODO consider replacing vector vector with xtensor array, and also if it may be
/// possible to specify or constrain dimensionality of the array in advance.
inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
const MoveOptions& options) {
return move_through_joint_positions(positions, options, {});
}

/// @brief Move each joint on the arm through the positions specified in @param positions
/// @param options optional specifications to be obeyed during the motion.
/// @param extra Any additional arguments to the method.
virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
const MoveOptions& options,
const ProtoStruct& extra) = 0;

/// @brief Reports if the arm is in motion.
virtual bool is_moving() = 0;

Expand Down
14 changes: 0 additions & 14 deletions src/viam/sdk/components/base.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#include <viam/sdk/components/base.hpp>

#include <google/protobuf/descriptor.h>

#include <viam/api/component/base/v1/base.grpc.pb.h>
#include <viam/api/component/base/v1/base.pb.h>

#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/resource/resource.hpp>

namespace viam {
namespace sdk {

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

Base::properties Base::properties::from_proto(
const component::base::v1::GetPropertiesResponse& proto) {
return {
proto.width_meters(), proto.turning_radius_meters(), proto.wheel_circumference_meters()};
}

std::ostream& operator<<(std::ostream& os, const Base::properties& v) {
os << "{ turning_radius_meters: " << v.turning_radius_meters
<< ", wheel_circumference_meters: " << v.wheel_circumference_meters
Expand Down
4 changes: 0 additions & 4 deletions src/viam/sdk/components/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <string>

#include <viam/api/component/base/v1/base.pb.h>

#include <viam/sdk/common/linear_algebra.hpp>
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
Expand All @@ -32,8 +30,6 @@ class Base : public Component, public Stoppable {
double width_meters;
double turning_radius_meters;
double wheel_circumference_meters;

static properties from_proto(const component::base::v1::GetPropertiesResponse& proto);
};
friend std::ostream& operator<<(std::ostream& os, const properties& v);
friend bool operator==(const properties& lhs, const properties& rhs);
Expand Down
57 changes: 0 additions & 57 deletions src/viam/sdk/components/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

#include <google/protobuf/descriptor.h>

#include <viam/api/component/board/v1/board.grpc.pb.h>
#include <viam/api/component/board/v1/board.pb.h>

#include <viam/sdk/common/exception.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/resource/resource.hpp>

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

Board::status Board::from_proto(const viam::component::board::v1::Status& proto) {
Board::status status;
for (const auto& analog : proto.analogs()) {
status.analog_reader_values.emplace(analog.first, analog.second);
}
for (const auto& digital : proto.digital_interrupts()) {
status.digital_interrupt_values.emplace(digital.first, digital.second);
}
return status;
}

Board::power_mode Board::from_proto(viam::component::board::v1::PowerMode proto) {
switch (proto) {
case viam::component::board::v1::POWER_MODE_NORMAL: {
return Board::power_mode::normal;
}
case viam::component::board::v1::POWER_MODE_OFFLINE_DEEP: {
return Board::power_mode::offline_deep;
}
case viam::component::board::v1::POWER_MODE_UNSPECIFIED:
default: {
throw Exception(ErrorCondition::k_not_supported,
"Invalid proto board power_mode to decode");
}
}
}

viam::component::board::v1::Status Board::to_proto(const status& status) {
viam::component::board::v1::Status proto;
for (const auto& analog : status.analog_reader_values) {
proto.mutable_analogs()->insert({analog.first, analog.second});
}

for (const auto& digital : status.digital_interrupt_values) {
proto.mutable_digital_interrupts()->insert({digital.first, digital.second});
}
return proto;
}

viam::component::board::v1::PowerMode Board::to_proto(Board::power_mode power_mode) {
switch (power_mode) {
case Board::power_mode::normal: {
return viam::component::board::v1::POWER_MODE_NORMAL;
}
case Board::power_mode::offline_deep: {
return viam::component::board::v1::POWER_MODE_OFFLINE_DEEP;
}
default: {
throw Exception(ErrorCondition::k_not_supported, "Invalid board power_mode to encode");
}
}
}

Board::Board(std::string name) : Component(std::move(name)){};

bool operator==(const Board::status& lhs, const Board::status& rhs) {
Expand Down
14 changes: 0 additions & 14 deletions src/viam/sdk/components/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <string>
#include <unordered_map>

#include <viam/api/component/board/v1/board.pb.h>

#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/config/resource.hpp>
Expand Down Expand Up @@ -76,18 +74,6 @@ class Board : public Component {

API api() const override;

/// @brief Creates a `status` struct from its proto representation.
static status from_proto(const viam::component::board::v1::Status& proto);

/// @brief Creates a `power_mode` enum from its proto representation.
static power_mode from_proto(viam::component::board::v1::PowerMode proto);

/// @brief Converts a `status` struct to its proto representation.
static viam::component::board::v1::Status to_proto(const status& status);

/// @brief Converts a `power_mode` enum to its proto representation.
static viam::component::board::v1::PowerMode to_proto(power_mode power_mode);

/// @brief Gets the high/low state of the given pin on a board.
/// @param pin board pin name
/// @return high/low state of the given pin. High = on, low = off
Expand Down
Loading

0 comments on commit 2dad8ed

Please sign in to comment.