Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised Planner Profile Interfaces #156

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <any>
#include <boost/serialization/serialization.hpp>
#include <iostream>
#include <typeindex>
#include <unordered_map>
Expand All @@ -40,15 +41,107 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
%shared_ptr(tesseract_planning::ProfileDictionary)
#endif // SWIG

namespace tesseract_environment
{
class Environment;
}

namespace tesseract_planning
{
class Instruction;
class CompositeInstruction;

/**
* @brief Struct to produce a planner-specific planning profile to apply to a single waypoint.
* @details Examples of waypoint profiles might include costs/constraints for a waypoint or a waypoint sampler
*/
class WaypointProfile
{
public:
using Ptr = std::shared_ptr<WaypointProfile>;
using ConstPtr = std::shared_ptr<const WaypointProfile>;

WaypointProfile() = default;
WaypointProfile(const WaypointProfile&) = delete;
WaypointProfile& operator=(const WaypointProfile&) = delete;
WaypointProfile(WaypointProfile&&) = delete;
WaypointProfile&& operator=(WaypointProfile&&) = delete;

virtual ~WaypointProfile() = default;

virtual std::any create(const Instruction& instruction, const tesseract_environment::Environment& env) const = 0;

private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive&, const unsigned int) // NOLINT
{
}
};

/**
* @brief Struct to produce a planner-specific planning profile to apply to a collection of waypoints defined in a
* composite instruction.
* @details Examples of composite profiles include costs/constraints that apply collectively to a group of waypoints
*/
class CompositeProfile
{
public:
using Ptr = std::shared_ptr<CompositeProfile>;
using ConstPtr = std::shared_ptr<const CompositeProfile>;

CompositeProfile() = default;
CompositeProfile(const CompositeProfile&) = delete;
CompositeProfile& operator=(const CompositeProfile&) = delete;
CompositeProfile(CompositeProfile&&) = delete;
CompositeProfile&& operator=(CompositeProfile&&) = delete;

virtual ~CompositeProfile() = default;
virtual std::any create(const CompositeInstruction& instruction,
const tesseract_environment::Environment& env) const = 0;

private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive&, const unsigned int) // NOLINT
{
}
};

/**
* @brief Struct to produce configuration parameters for the motion planner
*/
struct PlannerProfile
{
public:
using Ptr = std::shared_ptr<PlannerProfile>;
using ConstPtr = std::shared_ptr<const PlannerProfile>;

PlannerProfile() = default;
PlannerProfile(const PlannerProfile&) = delete;
PlannerProfile& operator=(const PlannerProfile&) = delete;
PlannerProfile(PlannerProfile&&) = delete;
PlannerProfile&& operator=(PlannerProfile&&) = delete;

virtual ~PlannerProfile() = default;

virtual std::any create() const = 0;

private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive&, const unsigned int) // NOLINT
{
}
};

/**
* @brief This class is used to store profiles for motion planning and process planning
* @details This is a thread safe class
* A ProfileEntry<T> is a std::unordered_map<std::string, std::shared_ptr<const T>>
* - The key is the profile name
* - Where std::shared_ptr<const T> is the profile
* The ProfleEntry<T> is also stored in std::unordered_map where the key here is the std::type_index(typeid(T))
* The ProfileEntry<T> is also stored in std::unordered_map where the key here is the std::type_index(typeid(T))
* @note When adding a profile entry the T should be the base class type.
*/
class ProfileDictionary
Expand Down Expand Up @@ -210,10 +303,18 @@ class ProfileDictionary
.erase(profile_name);
}

std::unordered_map<std::string, std::unordered_map<std::string, WaypointProfile::ConstPtr>> waypoint_profiles;
std::unordered_map<std::string, std::unordered_map<std::string, CompositeProfile::ConstPtr>> composite_profiles;
std::unordered_map<std::string, std::unordered_map<std::string, PlannerProfile::ConstPtr>> planner_profiles;

protected:
std::unordered_map<std::string, std::unordered_map<std::type_index, std::any>> profiles_;
mutable std::shared_mutex mutex_;
};
} // namespace tesseract_planning

BOOST_SERIALIZATION_ASSUME_ABSTRACT(tesseract_planning::WaypointProfile);
BOOST_SERIALIZATION_ASSUME_ABSTRACT(tesseract_planning::CompositeProfile);
BOOST_SERIALIZATION_ASSUME_ABSTRACT(tesseract_planning::PlannerProfile);

#endif // TESSERACT_MOTION_PLANNERS_PROFILE_DICTIONARY_H
2 changes: 2 additions & 0 deletions tesseract_motion_planners/test/profile_dictionary_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <gtest/gtest.h>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_command_language/composite_instruction.h>
#include <tesseract_environment/environment.h>
#include <tesseract_command_language/profile_dictionary.h>

struct ProfileBase
Expand Down