-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30bdcbb
commit c7237cd
Showing
8 changed files
with
509 additions
and
2 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
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
76 changes: 76 additions & 0 deletions
76
tesseract_task_composer/core/include/tesseract_task_composer/core/nodes/remap_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,76 @@ | ||
/** | ||
* @file remap_task.h | ||
* | ||
* @author Levi Armstrong | ||
* @date July 13, 2023 | ||
* @version TODO | ||
* @bug No known bugs | ||
* | ||
* @copyright Copyright (c) 2023, Levi Armstrong | ||
* | ||
* @par License | ||
* Software License Agreement (Apache License) | ||
* @par | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* @par | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef TESSERACT_TASK_COMPOSER_REMAP_TASK_H | ||
#define TESSERACT_TASK_COMPOSER_REMAP_TASK_H | ||
|
||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <boost/serialization/access.hpp> | ||
#include <boost/serialization/map.hpp> | ||
#include <map> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/core/task_composer_task.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
class TaskComposerPluginFactory; | ||
class RemapTask : public TaskComposerTask | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<RemapTask>; | ||
using ConstPtr = std::shared_ptr<const RemapTask>; | ||
using UPtr = std::unique_ptr<RemapTask>; | ||
using ConstUPtr = std::unique_ptr<const RemapTask>; | ||
|
||
RemapTask(); | ||
explicit RemapTask(std::string name, | ||
std::map<std::string, std::string> remap, | ||
bool copy = false, | ||
bool is_conditional = false); | ||
explicit RemapTask(std::string name, const YAML::Node& config, const TaskComposerPluginFactory& plugin_factory); | ||
~RemapTask() override = default; | ||
|
||
bool operator==(const RemapTask& rhs) const; | ||
bool operator!=(const RemapTask& rhs) const; | ||
|
||
protected: | ||
std::map<std::string, std::string> remap_; | ||
bool copy_{ false }; | ||
|
||
friend struct tesseract_common::Serialization; | ||
friend class boost::serialization::access; | ||
template <class Archive> | ||
void serialize(Archive& ar, const unsigned int version); // NOLINT | ||
|
||
TaskComposerNodeInfo::UPtr runImpl(TaskComposerInput& input, | ||
OptionalTaskComposerExecutor executor = std::nullopt) const override final; | ||
}; | ||
|
||
} // namespace tesseract_planning | ||
|
||
#include <boost/serialization/export.hpp> | ||
BOOST_CLASS_EXPORT_KEY2(tesseract_planning::RemapTask, "RemapTask") | ||
#endif // TESSERACT_TASK_COMPOSER_REMAP_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
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,101 @@ | ||
/** | ||
* @file remap_task.h | ||
* | ||
* @author Levi Armstrong | ||
* @date July 13, 2023 | ||
* @version TODO | ||
* @bug No known bugs | ||
* | ||
* @copyright Copyright (c) 2023, Levi Armstrong | ||
* | ||
* @par License | ||
* Software License Agreement (Apache License) | ||
* @par | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* @par | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <console_bridge/console.h> | ||
#include <yaml-cpp/yaml.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
#include <tesseract_task_composer/core/nodes/remap_task.h> | ||
|
||
namespace tesseract_planning | ||
{ | ||
RemapTask::RemapTask() : TaskComposerTask("RemapTask", false) {} | ||
RemapTask::RemapTask(std::string name, std::map<std::string, std::string> remap, bool copy, bool is_conditional) | ||
: TaskComposerTask(std::move(name), is_conditional), remap_(std::move(remap)), copy_(copy) | ||
{ | ||
if (remap_.empty()) | ||
throw std::runtime_error("RemapTask, remap should not be empty!"); | ||
} | ||
RemapTask::RemapTask(std::string name, const YAML::Node& config, const TaskComposerPluginFactory& /*plugin_factory*/) | ||
: TaskComposerTask(std::move(name), config) | ||
{ | ||
if (!input_keys_.empty()) | ||
throw std::runtime_error("RemapTask, input_keys should be empty!"); | ||
|
||
if (!output_keys_.empty()) | ||
throw std::runtime_error("RemapTask, output_keys should be empty!"); | ||
|
||
if (YAML::Node n = config["remap"]) | ||
remap_ = n.as<std::map<std::string, std::string>>(); | ||
else | ||
throw std::runtime_error("RemapTask missing config key: 'remap'"); | ||
|
||
if (YAML::Node n = config["copy"]) | ||
copy_ = n.as<bool>(); | ||
} | ||
|
||
TaskComposerNodeInfo::UPtr RemapTask::runImpl(TaskComposerInput& input, OptionalTaskComposerExecutor /*executor*/) const | ||
{ | ||
auto info = std::make_unique<TaskComposerNodeInfo>(*this); | ||
if (input.data_storage.remapData(remap_, copy_)) | ||
{ | ||
info->color = "green"; | ||
info->return_value = 1; | ||
info->message = "Successful"; | ||
} | ||
else | ||
{ | ||
info->color = "red"; | ||
info->return_value = 0; | ||
info->message = "Failed to remap data."; | ||
} | ||
return info; | ||
} | ||
|
||
bool RemapTask::operator==(const RemapTask& rhs) const | ||
{ | ||
bool equal = true; | ||
equal &= (remap_ == rhs.remap_); | ||
equal &= (copy_ == rhs.copy_); | ||
equal &= TaskComposerNode::operator==(rhs); | ||
return equal; | ||
} | ||
bool RemapTask::operator!=(const RemapTask& rhs) const { return !operator==(rhs); } | ||
|
||
template <class Archive> | ||
void RemapTask::serialize(Archive& ar, const unsigned int /*version*/) | ||
{ | ||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(TaskComposerTask); | ||
ar& boost::serialization::make_nvp("remap_data", remap_); | ||
ar& boost::serialization::make_nvp("copy", copy_); | ||
} | ||
|
||
} // namespace tesseract_planning | ||
|
||
#include <tesseract_common/serialization.h> | ||
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(tesseract_planning::RemapTask) | ||
BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_planning::RemapTask) |
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
Oops, something went wrong.