Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
507ab57
first commit of generic proto conversion machinery
lia-viam Nov 21, 2024
9ff1696
insulate pose and pose in frame
lia-viam Nov 21, 2024
5128069
add api fwd namespace macro
lia-viam Nov 22, 2024
cf35091
more general macro
lia-viam Nov 22, 2024
7a3376a
change translation
lia-viam Nov 22, 2024
a440614
refactor orientation and related code cleanup
lia-viam Nov 25, 2024
924b794
insult api vector3 and make sdk vector3 a struct
lia-viam Nov 25, 2024
c438580
remove duplicated pose interface
lia-viam Nov 25, 2024
4fbd8bf
use std::tie for equality operators
lia-viam Nov 25, 2024
4c258ac
remove pose_proto
lia-viam Nov 25, 2024
d520711
clean up geometry.hpp and add vector/ptr_field conversion
lia-viam Nov 26, 2024
74b9582
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into api-…
lia-viam Nov 26, 2024
c55948e
linter
lia-viam Nov 26, 2024
e2a5a3c
forgot to commit new file
lia-viam Nov 26, 2024
8479d34
add headers to file list
lia-viam Nov 26, 2024
27f147c
also do translation and linkconfig
lia-viam Nov 26, 2024
f69d797
linter semicolon
lia-viam Nov 26, 2024
42552ff
do worldstate
lia-viam Nov 26, 2024
34bfdd2
Merge branch 'main' into api-insulate
lia-viam Dec 2, 2024
8382629
remove proto_utils.hpp
lia-viam Dec 2, 2024
141487f
bring ProtoValue into the to_proto/from_proto fold
lia-viam Dec 3, 2024
7b7da5a
remove ctor semicolon
lia-viam Dec 3, 2024
cf7f60b
remove ctor semicolon
lia-viam Dec 3, 2024
9d876c5
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into api-…
lia-viam Dec 4, 2024
ba66ea6
Merge branch 'api-insulate' of github.com:lia-viam/viam-cpp-sdk into …
lia-viam Dec 4, 2024
8128398
Merge branch 'ptr-vec-conversions' into proto-value-unify
lia-viam Dec 4, 2024
02ce15f
remove geo geometry stuff i forgot to delete
lia-viam Dec 4, 2024
2ec0610
set const
lia-viam Dec 5, 2024
52590fa
Merge branch 'ptr-vec-conversions' into api-insulate
lia-viam Dec 5, 2024
0716a23
Merge branch 'proto-value-unify' into api-insulate
lia-viam Dec 5, 2024
369e321
add or relocate nolints
lia-viam Dec 5, 2024
97841a5
change include order and replace macro with explicit namespaces
lia-viam Dec 5, 2024
fbe2ea9
document args_t trick and set container to mp_list
lia-viam Dec 5, 2024
670d2ef
make to/from repeated field its own function object and a private detail
lia-viam Dec 5, 2024
96f2742
use static_const for callable objects
lia-viam Dec 5, 2024
40cf73b
include repeated ptr conversion
lia-viam Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/viam/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ target_sources(viamsdk
../../viam/sdk/common/exception.hpp
../../viam/sdk/common/linear_algebra.hpp
../../viam/sdk/common/pose.hpp
../../viam/sdk/common/proto_convert.hpp
../../viam/sdk/common/proto_value.hpp
../../viam/sdk/common/service_helper.hpp
../../viam/sdk/common/utils.hpp
Expand Down
2 changes: 1 addition & 1 deletion src/viam/sdk/common/client_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ClientHelper {
ProtoValue value = key->second;
debug_key_ = *value.get<std::string>();
}
*request_.mutable_extra() = map_to_struct(extra);
*request_.mutable_extra() = v2::to_proto(extra);
return with(std::forward<RequestSetupCallable>(rsc));
}

Expand Down
38 changes: 14 additions & 24 deletions src/viam/sdk/common/linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,45 @@
namespace viam {
namespace sdk {

Vector3::Vector3(scalar_type x, scalar_type y, scalar_type z) : data_{x, y, z} {};
Vector3::Vector3() : Vector3(0.0, 0.0, 0.0){};

double Vector3::x() const {
return this->data_[0];
return this->data[0];
}

double Vector3::y() const {
return this->data_[1];
return this->data[1];
}

double Vector3::z() const {
return this->data_[2];
return this->data[2];
}

Vector3& Vector3::set_x(double x) {
this->data_[0] = x;
this->data[0] = x;
return *this;
}

Vector3& Vector3::set_y(double y) {
this->data_[1] = y;
this->data[1] = y;
return *this;
}

Vector3& Vector3::set_z(double z) {
this->data_[2] = z;
this->data[2] = z;
return *this;
}

const std::array<double, 3>& Vector3::data() const {
return this->data_;
}
namespace proto_convert_details {

std::array<double, 3>& Vector3::data() {
return this->data_;
void to_proto<Vector3>::operator()(const Vector3& self, common::v1::Vector3* proto) const {
proto->set_x(self.x());
proto->set_y(self.y());
proto->set_z(self.z());
}

viam::common::v1::Vector3 Vector3::to_proto() const {
viam::common::v1::Vector3 result;
result.set_x(x());
result.set_y(y());
result.set_z(z());
return result;
};

Vector3 Vector3::from_proto(const viam::common::v1::Vector3& vec) {
return {vec.x(), vec.y(), vec.z()};
Vector3 from_proto<common::v1::Vector3>::operator()(const common::v1::Vector3* proto) const {
return {proto->x(), proto->y(), proto->z()};
}

} // namespace proto_convert_details
} // namespace sdk
} // namespace viam
44 changes: 29 additions & 15 deletions src/viam/sdk/common/linear_algebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
#include <boost/qvm/vec.hpp>
#include <boost/qvm/vec_traits.hpp>

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

namespace viam {
namespace common {
namespace v1 {

class Vector3;
}
} // namespace common
} // namespace viam

namespace viam {
namespace sdk {

// In the future, we may wish to inline this whole class
// for performance reasons.

class Vector3 {
public:
struct Vector3 {
using scalar_type = double;
Vector3(scalar_type x, scalar_type y, scalar_type z);
Vector3();

scalar_type x() const;
scalar_type y() const;
Expand All @@ -28,15 +35,22 @@ class Vector3 {
/// Set the z value of the vector (can be chained)
Vector3& set_z(scalar_type z);

const std::array<scalar_type, 3>& data() const;
std::array<scalar_type, 3>& data();
viam::common::v1::Vector3 to_proto() const;
static Vector3 from_proto(const viam::common::v1::Vector3& vec);
std::array<scalar_type, 3> data;
};

private:
std::array<scalar_type, 3> data_;
namespace proto_convert_details {

template <>
struct to_proto<Vector3> {
void operator()(const Vector3&, common::v1::Vector3*) const;
};

template <>
struct from_proto<common::v1::Vector3> {
Vector3 operator()(const common::v1::Vector3*) const;
};

} // namespace proto_convert_details
} // namespace sdk
} // namespace viam

Expand All @@ -51,20 +65,20 @@ struct vec_traits<viam::sdk::Vector3> {

template <int I>
static inline scalar_type& write_element(vec_type& v) {
return v.data()[I];
return v.data[I];
}

template <int I>
static inline scalar_type read_element(vec_type const& v) {
return v.data()[I];
return v.data[I];
}

static inline scalar_type& write_element_idx(int i, vec_type& v) {
return v.data()[i];
return v.data[i];
}

static inline scalar_type read_element_idx(int i, vec_type const& v) {
return v.data()[i];
return v.data[i];
}
};

Expand Down
73 changes: 43 additions & 30 deletions src/viam/sdk/common/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@
namespace viam {
namespace sdk {

common::v1::PoseInFrame pose_in_frame::to_proto() const {
common::v1::PoseInFrame pif;
*pif.mutable_reference_frame() = reference_frame;
common::v1::Pose proto_pose;
proto_pose.set_x(pose.coordinates.x);
proto_pose.set_y(pose.coordinates.y);
proto_pose.set_z(pose.coordinates.z);
proto_pose.set_o_x(pose.orientation.o_x);
proto_pose.set_o_y(pose.orientation.o_y);
proto_pose.set_o_z(pose.orientation.o_z);
proto_pose.set_theta(pose.theta);
*pif.mutable_pose() = std::move(proto_pose);
return pif;
};

pose_in_frame pose_in_frame::from_proto(const common::v1::PoseInFrame& proto) {
pose_in_frame pif;
pif.reference_frame = proto.reference_frame();
const auto& proto_pose = proto.pose();
pif.pose.orientation.o_x = proto_pose.o_x();
pif.pose.orientation.o_y = proto_pose.o_y();
pif.pose.orientation.o_z = proto_pose.o_z();
pif.pose.coordinates.x = proto_pose.x();
pif.pose.coordinates.y = proto_pose.y();
pif.pose.coordinates.z = proto_pose.z();
pif.pose.theta = proto_pose.theta();

return pif;
}

bool operator==(const pose_in_frame& lhs, const pose_in_frame& rhs) {
return lhs.pose == rhs.pose && lhs.reference_frame == rhs.reference_frame;
}
Expand All @@ -44,5 +14,48 @@ std::ostream& operator<<(std::ostream& os, const pose_in_frame& v) {
return os;
}

namespace proto_convert_details {

void to_proto<pose>::operator()(const pose& self, common::v1::Pose* proto) const {
proto->set_x(self.coordinates.x);
proto->set_y(self.coordinates.y);
proto->set_z(self.coordinates.z);
proto->set_o_x(self.orientation.o_x);
proto->set_o_y(self.orientation.o_y);
proto->set_o_z(self.orientation.o_z);
proto->set_theta(self.theta);
}

pose from_proto<common::v1::Pose>::operator()(const common::v1::Pose* proto) const {
pose pose;
pose.coordinates.x = proto->x();
pose.coordinates.y = proto->y();
pose.coordinates.z = proto->z();
pose.orientation.o_x = proto->o_x();
pose.orientation.o_y = proto->o_y();
pose.orientation.o_z = proto->o_z();
pose.theta = proto->theta();

return pose;
}

void to_proto<pose_in_frame>::operator()(const pose_in_frame& self,
common::v1::PoseInFrame* pif) const {
*(pif->mutable_reference_frame()) = self.reference_frame;
common::v1::Pose proto_pose;
to_proto<pose>{}(self.pose, &proto_pose);
*(pif->mutable_pose()) = std::move(proto_pose);
};

pose_in_frame from_proto<common::v1::PoseInFrame>::operator()(
const common::v1::PoseInFrame* proto) const {
pose_in_frame pif;
pif.reference_frame = proto->reference_frame();
pif.pose = from_proto<common::v1::Pose>{}(&(proto->pose()));

return pif;
}

} // namespace proto_convert_details
} // namespace sdk
} // namespace viam
43 changes: 37 additions & 6 deletions src/viam/sdk/common/pose.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#pragma once

#include <common/v1/common.pb.h>
#include <viam/sdk/common/proto_convert.hpp>

#include <ostream>

namespace viam {
namespace common {
namespace v1 {

class Pose;
class PoseInFrame;
} // namespace v1
} // namespace common
} // namespace viam

namespace viam {
namespace sdk {
Expand All @@ -20,16 +32,11 @@ struct pose {
pose_orientation orientation;
double theta;

static pose from_proto(const viam::common::v1::Pose& proto);
viam::common::v1::Pose to_proto() const;

friend bool operator==(const pose& lhs, const pose& rhs);
friend std::ostream& operator<<(std::ostream& os, const pose& v);
};

struct pose_in_frame {
viam::common::v1::PoseInFrame to_proto() const;
static pose_in_frame from_proto(const viam::common::v1::PoseInFrame& proto);
pose_in_frame(std::string reference_frame_, struct pose pose_)
: reference_frame(std::move(reference_frame_)), pose(std::move(pose_)) {}
pose_in_frame() {}
Expand All @@ -40,5 +47,29 @@ struct pose_in_frame {
friend std::ostream& operator<<(std::ostream& os, const pose_in_frame& v);
};

namespace proto_convert_details {

template <>
struct to_proto<pose> {
void operator()(const pose&, common::v1::Pose*) const;
};

template <>
struct from_proto<common::v1::Pose> {
pose operator()(const common::v1::Pose*) const;
};

template <>
struct to_proto<pose_in_frame> {
void operator()(const pose_in_frame&, common::v1::PoseInFrame*) const;
};

template <>
struct from_proto<common::v1::PoseInFrame> {
pose_in_frame operator()(const common::v1::PoseInFrame*) const;
};

} // namespace proto_convert_details

} // namespace sdk
} // namespace viam
63 changes: 0 additions & 63 deletions src/viam/sdk/common/private/proto_utils.hpp

This file was deleted.

Loading
Loading