diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ebf1c8..a748de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) set(VIAM_TRAJEX_XTENSOR_VERSION_MINIMUM 0.24.3) set(VIAM_TRAJEX_XTL_VERSION_MINIMUM 0.7.2) @@ -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 diff --git a/bin/setup.sh b/bin/setup.sh index 909c951..613c4fb 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -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 . diff --git a/conanfile.py b/conanfile.py index 79ba0a9..5407ba9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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]") diff --git a/src/viam/trajex/service/mlmodel.cpp b/src/viam/trajex/service/mlmodel.cpp index e877e12..1cf44c6 100644 --- a/src/viam/trajex/service/mlmodel.cpp +++ b/src/viam/trajex/service/mlmodel.cpp @@ -120,12 +120,11 @@ std::vector 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"); @@ -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(); if (!str) { @@ -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); } } @@ -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::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) { @@ -211,7 +202,7 @@ std::shared_ptr 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 @@ -227,7 +218,7 @@ std::shared_ptr 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; @@ -339,7 +330,6 @@ std::shared_ptr 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", diff --git a/src/viam/trajex/service/mlmodel.hpp b/src/viam/trajex/service/mlmodel.hpp index 6a35b93..992d561 100644 --- a/src/viam/trajex/service/mlmodel.hpp +++ b/src/viam/trajex/service/mlmodel.hpp @@ -2,26 +2,26 @@ #include #include -#include #include #include #include -#include #include 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 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 { + return {}; + } + static std::vector validate(const ::viam::sdk::ResourceConfig& cfg); private: @@ -32,10 +32,11 @@ class mlmodel final : public ::viam::sdk::MLModelService, public ::viam::sdk::Re std::vector 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