Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(VIAM_TRAJEX_BOOST_VERSION_MINIMUM "") # TODO: Decide this
set(VIAM_TRAJEX_EIGEN3_VERSION_MINIMUM "") # TODO: Decide this
set(VIAM_TRAJEX_JSONCPP_VERSION_MINIMUM "") # TODO: Decide this
set(VIAM_TRAJEX_VIAMCPPSDK_VERSION_MINIMUM 0.31.0)
set(VIAM_TRAJEX_VIAMCPPSDK_VERSION_MINIMUM 0.37.0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a careful look for where else this is specified. I think at least the conan file. Dockerfile?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've updated the conan file, but there is no Dockerfile in this repo.

set(VIAM_TRAJEX_XTENSOR_VERSION_MINIMUM 0.24.3)
set(VIAM_TRAJEX_XTL_VERSION_MINIMUM 0.7.2)

Expand Down Expand Up @@ -166,7 +166,7 @@ if (VIAM_TRAJEX_ENABLE_SERVICE)
FetchContent_Declare(
viam-cpp-sdk
GIT_REPOSITORY https://github.com/viamrobotics/viam-cpp-sdk
GIT_TAG releases/v0.31.0
GIT_TAG releases/v0.37.0
GIT_SHALLOW TRUE
SYSTEM
# Delete conflicting protobuf headers
Expand Down
2 changes: 1 addition & 1 deletion bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

# NOTE: If you change this version, also change it in the `conanfile.py` requirements
# and in the Dockerfile and CMakeLists.txt
git checkout releases/v0.31.0
git checkout releases/v0.37.0

# Export the recipe to the cache so we can skip rebuilds gracefully
conan export .
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_version(self):
def requirements(self):
# NOTE: If you update the `viam-cpp-sdk` dependency here, it
# should also be updated in `bin/setup.sh`.
self.requires("viam-cpp-sdk/[>=0.31.0]")
self.requires("viam-cpp-sdk/[>=0.37.0]")
self.requires("eigen/[>=3.4 <5.0]")
self.requires("boost/[>=1.74.0]")
self.requires("jsoncpp/[>=1.9.5]")
Expand Down
30 changes: 10 additions & 20 deletions src/viam/trajex/service/mlmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ std::vector<std::string> mlmodel::validate(const vsdk::ResourceConfig& cfg) {
}

// NOLINTNEXTLINE(performance-unnecessary-value-param): Signature fixed by ModelRegistration factory.
mlmodel::mlmodel(vsdk::Dependencies deps, vsdk::ResourceConfig config) : MLModelService(config.name()) {
reconfigure(deps, config);
}
mlmodel::mlmodel(vsdk::Dependencies, vsdk::ResourceConfig config)
: MLModelService(config.name()), config_(mlmodel::config::from_resource_config(config)) {}

void mlmodel::reconfigure(const vsdk::Dependencies&, const vsdk::ResourceConfig& cfg) {
config new_config;
mlmodel::config mlmodel::config::from_resource_config(const vsdk::ResourceConfig& cfg) {
config out;

// Parse generator_sequence
auto seq_attr = cfg.attributes().find("generator_sequence");
Expand All @@ -134,7 +133,7 @@ void mlmodel::reconfigure(const vsdk::Dependencies&, const vsdk::ResourceConfig&
if (!arr || arr->empty()) {
throw std::invalid_argument("generator_sequence must be a non-empty array of strings");
}
new_config.generator_sequence.clear();
out.generator_sequence.clear();
for (const auto& elem : *arr) {
const auto* str = elem.get<std::string>();
if (!str) {
Expand All @@ -143,7 +142,7 @@ void mlmodel::reconfigure(const vsdk::Dependencies&, const vsdk::ResourceConfig&
if (*str != "totg" && *str != "legacy") {
throw std::invalid_argument("generator_sequence: unknown algorithm '" + *str + "' (expected 'totg' or 'legacy')");
}
new_config.generator_sequence.push_back(*str);
out.generator_sequence.push_back(*str);
}
}

Expand All @@ -154,21 +153,13 @@ void mlmodel::reconfigure(const vsdk::Dependencies&, const vsdk::ResourceConfig&
if (!val) {
throw std::invalid_argument("segment_for_trajex must be a boolean");
}
new_config.segment_for_trajex = *val;
out.segment_for_trajex = *val;
}

const std::unique_lock lock{config_mutex_};
config_ = std::move(new_config);
return out;
}

std::shared_ptr<mlmodel::named_tensor_views> mlmodel::infer(const named_tensor_views& inputs, const vsdk::ProtoStruct&) {
// Snapshot config under the read lock, then release
config local_config;
{
const std::shared_lock lock{config_mutex_};
local_config = config_;
}

// Parse inputs
const auto& waypoints_view = get_double_tensor(inputs, "waypoints_rads");
if (waypoints_view.dimension() != 2) {
Expand Down Expand Up @@ -211,7 +202,7 @@ std::shared_ptr<mlmodel::named_tensor_views> mlmodel::infer(const named_tensor_v
.acceleration_limits = std::move(acceleration_limits),
.path_blend_tolerance = path_tolerance,
.colinearization_ratio = colinearization_ratio,
.segment_totg = local_config.segment_for_trajex,
.segment_totg = config_.segment_for_trajex,
});

planner
Expand All @@ -227,7 +218,7 @@ std::shared_ptr<mlmodel::named_tensor_views> mlmodel::infer(const named_tensor_v
.with_segmenter([](auto&, totg::waypoint_accumulator accumulator) { return totg::segment_at_reversals(std::move(accumulator)); });

// Register algorithms based on configured sequence
for (const auto& algo : local_config.generator_sequence) {
for (const auto& algo : config_.generator_sequence) {
if (algo == "totg") {
planner.with_totg([&, dof](const auto&, service_result& acc, const totg::waypoint_accumulator&, totg::trajectory&& traj, auto) {
acc.dof = dof;
Expand Down Expand Up @@ -339,7 +330,6 @@ std::shared_ptr<mlmodel::named_tensor_views> mlmodel::infer(const named_tensor_v
}

struct mlmodel::metadata mlmodel::metadata(const vsdk::ProtoStruct&) {
const std::shared_lock lock{config_mutex_};
return {
.name = "trajex",
.type = "other",
Expand Down
15 changes: 8 additions & 7 deletions src/viam/trajex/service/mlmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

#include <memory>
#include <optional>
#include <shared_mutex>
#include <string>
#include <vector>

#include <viam/sdk/config/resource.hpp>
#include <viam/sdk/resource/reconfigurable.hpp>
#include <viam/sdk/services/mlmodel.hpp>

namespace viam::trajex::service {

class mlmodel final : public ::viam::sdk::MLModelService, public ::viam::sdk::Reconfigurable {
class mlmodel final : public ::viam::sdk::MLModelService {
public:
mlmodel(::viam::sdk::Dependencies deps, ::viam::sdk::ResourceConfig config);

void reconfigure(const ::viam::sdk::Dependencies&, const ::viam::sdk::ResourceConfig&) override;

std::shared_ptr<named_tensor_views> infer(const named_tensor_views& inputs, const ::viam::sdk::ProtoStruct& extra) override;

struct metadata metadata(const ::viam::sdk::ProtoStruct& extra) override;

::viam::sdk::ProtoStruct get_status() override {
Comment thread
acmorrow marked this conversation as resolved.
return {};
}

static std::vector<std::string> validate(const ::viam::sdk::ResourceConfig& cfg);

private:
Expand All @@ -32,10 +32,11 @@ class mlmodel final : public ::viam::sdk::MLModelService, public ::viam::sdk::Re
std::vector<std::string> generator_sequence = {"totg"};
#endif
bool segment_for_trajex = false;

static config from_resource_config(const ::viam::sdk::ResourceConfig& cfg);
};

mutable std::shared_mutex config_mutex_;
config config_;
const config config_;
};

} // namespace viam::trajex::service
Loading