-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HasDataStorageEntryTask and FormatAsResultTask with unit tests (#462
- Loading branch information
1 parent
a1498ec
commit f095dd3
Showing
10 changed files
with
526 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...sk_composer/core/include/tesseract_task_composer/core/nodes/has_data_storage_entry_task.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef TESSERACT_TASK_COMPOSER_HAS_DATA_STORAGE_ENTRY_TASK_H | ||
#define TESSERACT_TASK_COMPOSER_HAS_DATA_STORAGE_ENTRY_TASK_H | ||
|
||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <boost/serialization/access.hpp> | ||
#include <boost/serialization/export.hpp> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/core/task_composer_task.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
class TaskComposerPluginFactory; | ||
class HasDataStorageEntryTask : public TaskComposerTask | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<HasDataStorageEntryTask>; | ||
using ConstPtr = std::shared_ptr<const HasDataStorageEntryTask>; | ||
using UPtr = std::unique_ptr<HasDataStorageEntryTask>; | ||
using ConstUPtr = std::unique_ptr<const HasDataStorageEntryTask>; | ||
|
||
HasDataStorageEntryTask(); | ||
explicit HasDataStorageEntryTask(std::string name, | ||
const std::vector<std::string>& input_keys, | ||
bool is_conditional = true); | ||
explicit HasDataStorageEntryTask(std::string name, | ||
const YAML::Node& config, | ||
const TaskComposerPluginFactory& plugin_factory); | ||
~HasDataStorageEntryTask() override = default; | ||
|
||
bool operator==(const HasDataStorageEntryTask& rhs) const; | ||
bool operator!=(const HasDataStorageEntryTask& rhs) const; | ||
|
||
protected: | ||
friend struct tesseract_common::Serialization; | ||
friend class boost::serialization::access; | ||
template <class Archive> | ||
void serialize(Archive& ar, const unsigned int version); // NOLINT | ||
|
||
std::unique_ptr<TaskComposerNodeInfo> | ||
runImpl(TaskComposerContext& context, OptionalTaskComposerExecutor executor = std::nullopt) const override final; | ||
}; | ||
|
||
} // namespace tesseract_planning | ||
|
||
BOOST_CLASS_EXPORT_KEY2(tesseract_planning::HasDataStorageEntryTask, "HasDataStorageEntryTask") | ||
|
||
#endif // TESSERACT_TASK_COMPOSER_HAS_DATA_STORAGE_ENTRY_TASK_H |
76 changes: 76 additions & 0 deletions
76
tesseract_task_composer/core/src/nodes/has_data_storage_entry_task.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <console_bridge/console.h> | ||
#include <boost/serialization/map.hpp> | ||
#include <yaml-cpp/yaml.h> | ||
#include <tesseract_common/serialization.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/core/nodes/has_data_storage_entry_task.h> | ||
#include <tesseract_task_composer/core/task_composer_context.h> | ||
#include <tesseract_task_composer/core/task_composer_data_storage.h> | ||
#include <tesseract_task_composer/core/task_composer_node_info.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
HasDataStorageEntryTask::HasDataStorageEntryTask() : TaskComposerTask("HasDataStorageEntryTask", true) {} | ||
HasDataStorageEntryTask::HasDataStorageEntryTask(std::string name, | ||
const std::vector<std::string>& input_keys, | ||
bool is_conditional) | ||
: TaskComposerTask(std::move(name), is_conditional) | ||
{ | ||
input_keys_ = input_keys; | ||
if (input_keys_.empty()) | ||
throw std::runtime_error("HasDataStorageEntryTask, input_keys should not be empty!"); | ||
} | ||
HasDataStorageEntryTask::HasDataStorageEntryTask(std::string name, | ||
const YAML::Node& config, | ||
const TaskComposerPluginFactory& /*plugin_factory*/) | ||
: TaskComposerTask(std::move(name), config) | ||
{ | ||
if (input_keys_.empty()) | ||
throw std::runtime_error("HasDataStorageEntryTask, input_keys should not be empty!"); | ||
|
||
if (!output_keys_.empty()) | ||
throw std::runtime_error("HasDataStorageEntryTask, output_keys should be empty!"); | ||
} | ||
|
||
std::unique_ptr<TaskComposerNodeInfo> HasDataStorageEntryTask::runImpl(TaskComposerContext& context, | ||
OptionalTaskComposerExecutor /*executor*/) const | ||
{ | ||
auto info = std::make_unique<TaskComposerNodeInfo>(*this); | ||
for (const auto& input_key : input_keys_) | ||
{ | ||
if (!context.data_storage->hasKey(input_key)) | ||
{ | ||
info->color = "red"; | ||
info->return_value = 0; | ||
info->status_code = 0; | ||
info->status_message = "Missing input key"; | ||
return info; | ||
} | ||
} | ||
|
||
info->color = "green"; | ||
info->return_value = 1; | ||
info->status_code = 1; | ||
info->status_message = "Successful"; | ||
return info; | ||
} | ||
|
||
bool HasDataStorageEntryTask::operator==(const HasDataStorageEntryTask& rhs) const | ||
{ | ||
return (TaskComposerNode::operator==(rhs)); | ||
} | ||
bool HasDataStorageEntryTask::operator!=(const HasDataStorageEntryTask& rhs) const { return !operator==(rhs); } | ||
|
||
template <class Archive> | ||
void HasDataStorageEntryTask::serialize(Archive& ar, const unsigned int /*version*/) | ||
{ | ||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(TaskComposerTask); | ||
} | ||
|
||
} // namespace tesseract_planning | ||
|
||
BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_planning::HasDataStorageEntryTask) | ||
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(tesseract_planning::HasDataStorageEntryTask) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
..._composer/planning/include/tesseract_task_composer/planning/nodes/format_as_result_task.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef TESSERACT_TASK_COMPOSER_FORMAT_AS_RESULT_TASK_H | ||
#define TESSERACT_TASK_COMPOSER_FORMAT_AS_RESULT_TASK_H | ||
|
||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <boost/serialization/access.hpp> | ||
#include <boost/serialization/export.hpp> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/core/task_composer_task.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
class TaskComposerPluginFactory; | ||
class FormatAsResultTask : public TaskComposerTask | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<FormatAsResultTask>; | ||
using ConstPtr = std::shared_ptr<const FormatAsResultTask>; | ||
using UPtr = std::unique_ptr<FormatAsResultTask>; | ||
using ConstUPtr = std::unique_ptr<const FormatAsResultTask>; | ||
|
||
FormatAsResultTask(); | ||
explicit FormatAsResultTask(std::string name, | ||
const std::vector<std::string>& input_keys, | ||
const std::vector<std::string>& output_keys, | ||
bool is_conditional = true); | ||
explicit FormatAsResultTask(std::string name, | ||
const YAML::Node& config, | ||
const TaskComposerPluginFactory& plugin_factory); | ||
~FormatAsResultTask() override = default; | ||
|
||
bool operator==(const FormatAsResultTask& rhs) const; | ||
bool operator!=(const FormatAsResultTask& rhs) const; | ||
|
||
protected: | ||
friend struct tesseract_common::Serialization; | ||
friend class boost::serialization::access; | ||
template <class Archive> | ||
void serialize(Archive& ar, const unsigned int version); // NOLINT | ||
|
||
std::unique_ptr<TaskComposerNodeInfo> | ||
runImpl(TaskComposerContext& context, OptionalTaskComposerExecutor executor = std::nullopt) const override final; | ||
}; | ||
|
||
} // namespace tesseract_planning | ||
|
||
BOOST_CLASS_EXPORT_KEY2(tesseract_planning::FormatAsResultTask, "FormatAsResultTask") | ||
|
||
#endif // TESSERACT_TASK_COMPOSER_FORMAT_AS_RESULT_TASK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tesseract_task_composer/planning/src/nodes/format_as_result_task.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <console_bridge/console.h> | ||
#include <boost/serialization/map.hpp> | ||
#include <yaml-cpp/yaml.h> | ||
#include <tesseract_common/serialization.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/planning/nodes/format_as_result_task.h> | ||
#include <tesseract_task_composer/core/task_composer_context.h> | ||
#include <tesseract_task_composer/core/task_composer_data_storage.h> | ||
#include <tesseract_task_composer/core/task_composer_node_info.h> | ||
#include <tesseract_command_language/composite_instruction.h> | ||
#include <tesseract_command_language/poly/move_instruction_poly.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
FormatAsResultTask::FormatAsResultTask() : TaskComposerTask("FormatAsResultTask", true) {} | ||
|
||
FormatAsResultTask::FormatAsResultTask(std::string name, | ||
const std::vector<std::string>& input_keys, | ||
const std::vector<std::string>& output_keys, | ||
bool is_conditional) | ||
: TaskComposerTask(std::move(name), is_conditional) | ||
{ | ||
input_keys_ = input_keys; | ||
output_keys_ = output_keys; | ||
|
||
if (input_keys_.empty()) | ||
throw std::runtime_error("FormatAsResultTask, input_keys should not be empty!"); | ||
|
||
if (output_keys_.empty()) | ||
throw std::runtime_error("FormatAsResultTask, output_keys should not be empty!"); | ||
|
||
if (input_keys_.size() != output_keys_.size()) | ||
throw std::runtime_error("FormatAsResultTask, input_keys and output_keys be the same size!"); | ||
} | ||
|
||
FormatAsResultTask::FormatAsResultTask(std::string name, | ||
const YAML::Node& config, | ||
const TaskComposerPluginFactory& /*plugin_factory*/) | ||
: TaskComposerTask(std::move(name), config) | ||
{ | ||
if (input_keys_.empty()) | ||
throw std::runtime_error("FormatAsResultTask, input_keys should not be empty!"); | ||
|
||
if (output_keys_.empty()) | ||
throw std::runtime_error("FormatAsResultTask, output_keys should not be empty!"); | ||
|
||
if (input_keys_.size() != output_keys_.size()) | ||
throw std::runtime_error("FormatAsResultTask, input_keys and output_keys be the same size!"); | ||
} | ||
|
||
std::unique_ptr<TaskComposerNodeInfo> FormatAsResultTask::runImpl(TaskComposerContext& context, | ||
OptionalTaskComposerExecutor /*executor*/) const | ||
{ | ||
for (std::size_t i = 0; i < input_keys_.size(); ++i) | ||
{ | ||
auto input_data = context.data_storage->getData(input_keys_[i]); | ||
auto& ci = input_data.as<CompositeInstruction>(); | ||
std::vector<std::reference_wrapper<InstructionPoly>> instructions = ci.flatten(&moveFilter); | ||
for (auto& instruction : instructions) | ||
{ | ||
auto& mi = instruction.get().as<MoveInstructionPoly>(); | ||
if (mi.getWaypoint().isStateWaypoint()) | ||
continue; | ||
|
||
if (!mi.getWaypoint().isJointWaypoint()) | ||
throw std::runtime_error("FormatAsResultTask, unsupported waypoint type!"); | ||
|
||
auto& jwp = mi.getWaypoint().as<JointWaypointPoly>(); | ||
|
||
// Convert to StateWaypoint | ||
StateWaypointPoly swp = mi.createStateWaypoint(); | ||
swp.setName(jwp.getName()); | ||
swp.setNames(jwp.getNames()); | ||
swp.setPosition(jwp.getPosition()); | ||
mi.assignStateWaypoint(swp); | ||
} | ||
|
||
context.data_storage->setData(output_keys_[i], ci); | ||
} | ||
|
||
auto info = std::make_unique<TaskComposerNodeInfo>(*this); | ||
info->color = "green"; | ||
info->return_value = 1; | ||
info->status_code = 1; | ||
info->status_message = "Successful"; | ||
return info; | ||
} | ||
|
||
bool FormatAsResultTask::operator==(const FormatAsResultTask& rhs) const { return (TaskComposerNode::operator==(rhs)); } | ||
bool FormatAsResultTask::operator!=(const FormatAsResultTask& rhs) const { return !operator==(rhs); } | ||
|
||
template <class Archive> | ||
void FormatAsResultTask::serialize(Archive& ar, const unsigned int /*version*/) | ||
{ | ||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(TaskComposerTask); | ||
} | ||
|
||
} // namespace tesseract_planning | ||
|
||
BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_planning::FormatAsResultTask) | ||
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(tesseract_planning::FormatAsResultTask) |
Oops, something went wrong.