Skip to content

Commit

Permalink
Make environment cache methods const (#124)
Browse files Browse the repository at this point in the history
* Make environment cache methods const

* Update docker version
  • Loading branch information
Levi-Armstrong authored Oct 30, 2021
1 parent 4528d59 commit d1d4997
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bionic_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
env:
OS_NAME: ubuntu
OS_CODE_NAME: bionic
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.2
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.4
CCACHE_DIR: ${{ github.workspace }}/${{ env.CI_NAME }}/.ccache
ROS_REPO: main
UNDERLAY: /root/ros-industrial/tesseract_target_ws/install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
env:
OS_NAME: ubuntu
OS_CODE_NAME: focal
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.2
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.4
CCACHE_DIR: ${{ github.workspace }}/${{ env.CI_NAME }}/.ccache
ROS_REPO: main
UNDERLAY: /root/ros-industrial/tesseract_target_ws/install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
env:
OS_NAME: ubuntu
OS_CODE_NAME: bionic
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.2
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.4
ROS_REPO: main
UNDERLAY: /root/ros-industrial/tesseract_target_ws/install
PREFIX: ${{ github.repository }}_
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependencies_windows_build.rosinstall
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- git:
local-name: tesseract
uri: https://github.com/ros-industrial-consortium/tesseract.git
version: 0.6.2
version: 0.6.4
- git:
local-name: trajopt
uri: https://github.com/ros-industrial-consortium/trajopt_ros.git
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/focal_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
env:
OS_NAME: ubuntu
OS_CODE_NAME: focal
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.2
DOCKER_IMAGE: ${{ env.REGISTRY }}/ros-industrial/tesseract:${{ env.ROS_DISTRO }}-0.6.4
CCACHE_DIR: ${{ github.workspace }}/${{ env.CI_NAME }}/.ccache
ROS_REPO: main
UNDERLAY: /root/ros-industrial/tesseract_target_ws/install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
- {CI_NAME: Bionic-Build-Nightly,
OS_CODE_NAME: bionic,
ROS_DISTRO: melodic,
DOCKER_IMAGE: "ghcr.io/ros-industrial/tesseract:melodic-0.6.1",
DOCKER_IMAGE: "ghcr.io/ros-industrial/tesseract:melodic-0.6.4",
CCACHE_DIR: "${{ github.workspace }}/Bionic-Build-Nightly/.ccache"}
- {CI_NAME: Focal-Build-Nightly,
OS_CODE_NAME: focal,
ROS_DISTRO: noetic,
DOCKER_IMAGE: "ghcr.io/ros-industrial/tesseract:noetic-0.6.1",
DOCKER_IMAGE: "ghcr.io/ros-industrial/tesseract:noetic-0.6.4",
CCACHE_DIR: "${{ github.workspace }}/Focal-Build-Nightly/.ccache"}

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class EnvironmentCache
public:
using Ptr = std::shared_ptr<EnvironmentCache>;
using ConstPtr = std::shared_ptr<const EnvironmentCache>;
using UPtr = std::unique_ptr<EnvironmentCache>;
using ConstUPtr = std::unique_ptr<const EnvironmentCache>;

EnvironmentCache() = default;
virtual ~EnvironmentCache() = default;
Expand All @@ -64,13 +66,13 @@ class EnvironmentCache
virtual long getCacheSize() const = 0;

/** @brief If the environment has changed it will rebuild the cache of tesseract objects */
virtual void refreshCache() = 0;
virtual void refreshCache() const = 0;

/**
* @brief This will pop an Environment object from the queue
* @details This will first call refreshCache to ensure it has an updated tesseract then proceed
*/
virtual tesseract_environment::Environment::Ptr getCachedEnvironment() = 0;
virtual tesseract_environment::Environment::UPtr getCachedEnvironment() const = 0;
};

class ProcessEnvironmentCache : public EnvironmentCache
Expand All @@ -85,35 +87,35 @@ class ProcessEnvironmentCache : public EnvironmentCache
* @brief Set the cache size used to hold tesseract objects for motion planning
* @param size The size of the cache.
*/
void setCacheSize(long size) override;
void setCacheSize(long size) override final;

/**
* @brief Get the cache size used to hold tesseract objects for motion planning
* @return The size of the cache.
*/
long getCacheSize() const override;
long getCacheSize() const override final;

/** @brief If the environment has changed it will rebuild the cache of tesseract objects */
void refreshCache() override;
void refreshCache() const override final;

/**
* @brief This will pop an Environment object from the queue
* @details This will first call refreshCache to ensure it has an updated tesseract then proceed
*/
tesseract_environment::Environment::Ptr getCachedEnvironment() override;
tesseract_environment::Environment::UPtr getCachedEnvironment() const override final;

protected:
/** @brief The tesseract_object used to create the cache */
tesseract_environment::Environment::ConstPtr env_;

/** @brief The environment revision number at the time the cache was populated */
int cache_env_revision_{ 0 };

/** @brief The assigned cache size */
std::size_t cache_size_{ 5 };

/** @brief A vector of cached Tesseact objects */
std::deque<tesseract_environment::Environment::Ptr> cache_;
/** @brief The environment revision number at the time the cache was populated */
mutable int cache_env_revision_{ 0 };

/** @brief A vector of cached Tesseract objects */
mutable std::deque<tesseract_environment::Environment::UPtr> cache_;

/** @brief The mutex used when reading and writing to cache_ */
mutable std::shared_mutex cache_mutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
namespace tesseract_planning
{
/**
* @brief A process planning server that support asynchronous exectuion of process planning requests
* @brief A process planning server that support asynchronous execution of process planning requests
* @details It allows the developer to register Process pipelines (aka. Taskflow Generators) so they may be request
*/
class ProcessPlanningServer
{
public:
using Ptr = std::shared_ptr<ProcessPlanningServer>;
using ConstPtr = std::shared_ptr<const ProcessPlanningServer>;
using UPtr = std::unique_ptr<ProcessPlanningServer>;
using ConstUPtr = std::unique_ptr<const ProcessPlanningServer>;

#ifndef SWIG
/**
* @brief Constructor
* @param cache The cache to use for getting Environment objects
* @param n The number of threads used by the planning server
*/
ProcessPlanningServer(EnvironmentCache::Ptr cache, size_t n = std::thread::hardware_concurrency());
ProcessPlanningServer(EnvironmentCache::ConstPtr cache, size_t n = std::thread::hardware_concurrency());
#endif // SWIG

/**
Expand Down Expand Up @@ -162,7 +164,7 @@ class ProcessPlanningServer
ProfileDictionary::ConstPtr getProfiles() const;

protected:
EnvironmentCache::Ptr cache_;
EnvironmentCache::ConstPtr cache_;
std::shared_ptr<tf::Executor> executor_;
std::shared_ptr<tf::TFProfObserver> profile_observer_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ void ProcessEnvironmentCache::setCacheSize(long size)

long ProcessEnvironmentCache::getCacheSize() const { return static_cast<long>(cache_size_); }

void ProcessEnvironmentCache::refreshCache()
void ProcessEnvironmentCache::refreshCache() const
{
std::unique_lock<std::shared_mutex> lock(cache_mutex_);
tesseract_environment::Environment::Ptr env;
tesseract_environment::Environment::UPtr env;

int rev = env_->getRevision();
if (rev != cache_env_revision_ || cache_.empty())
Expand All @@ -67,15 +67,15 @@ void ProcessEnvironmentCache::refreshCache()
}
}

tesseract_environment::Environment::Ptr ProcessEnvironmentCache::getCachedEnvironment()
tesseract_environment::Environment::UPtr ProcessEnvironmentCache::getCachedEnvironment() const
{
// This is to make sure the cached items are updated if needed
refreshCache();

tesseract_scene_graph::SceneState current_state = env_->getState();

std::unique_lock<std::shared_mutex> lock(cache_mutex_);
tesseract_environment::Environment::Ptr t = cache_.back();
tesseract_environment::Environment::UPtr t = std::move(cache_.back());

// Update to the current joint values
t->setState(current_state.joints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP

namespace tesseract_planning
{
ProcessPlanningServer::ProcessPlanningServer(EnvironmentCache::Ptr cache, size_t n)
ProcessPlanningServer::ProcessPlanningServer(EnvironmentCache::ConstPtr cache, size_t n)
: cache_(std::move(cache)), executor_(std::make_shared<tf::Executor>(n))
{
/** @todo Need to figure out if these can associated with an individual run versus global */
Expand Down

0 comments on commit d1d4997

Please sign in to comment.