Skip to content
Open
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 @@ -73,7 +73,8 @@ class TaskComposerNode
TaskComposerNode(std::string name = "TaskComposerNode",
TaskComposerNodeType type = TaskComposerNodeType::NODE,
TaskComposerNodePorts ports = TaskComposerNodePorts(),
bool conditional = false);
bool conditional = false,
int return_value_override = -1);
explicit TaskComposerNode(std::string name,
TaskComposerNodeType type,
TaskComposerNodePorts ports,
Expand Down Expand Up @@ -220,6 +221,13 @@ class TaskComposerNode
/** @brief The nodes ports definition */
TaskComposerNodePorts ports_;

/**
* @brief Value with which to override the return value nominally provided by runImpl() in the TaskComposerNodeInfo.
* @details The return value provided by runImpl() will be overriden with this value when it is >= 0.
* This value can be set to force a task to behave in a specific way (e.g., for debugging or unit tests).
*/
int return_value_override_{ -1 };

/** @brief Indicate if task triggers abort */
bool trigger_abort_{ false };

Expand Down
13 changes: 12 additions & 1 deletion tesseract_task_composer/core/src/task_composer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@
TaskComposerNode::TaskComposerNode(std::string name,
TaskComposerNodeType type,
TaskComposerNodePorts ports,
bool conditional)
bool conditional,
int return_value_override)
: name_(std::move(name))
, ns_(name_)
, type_(type)
, uuid_(boost::uuids::random_generator()())
, uuid_str_(boost::uuids::to_string(uuid_))
, conditional_(conditional)
, ports_(std::move(ports))
, return_value_override_(return_value_override)
{
}

Expand Down Expand Up @@ -126,6 +128,9 @@

output_keys_ = n.as<TaskComposerKeys>();
}

if (YAML::Node n = config["return_value_override"])
return_value_override_ = n.as<int>();
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -158,6 +163,12 @@
try
{
results = runImpl(context, executor);
if (return_value_override_ >= 0)
{
results.return_value = return_value_override_;
results.status_message += " (Return value overridden to " + std::to_string(return_value_override_) + ")";
results.color = "yellow";

Check warning on line 170 in tesseract_task_composer/core/src/task_composer_node.cpp

View check run for this annotation

Codecov / codecov/patch

tesseract_task_composer/core/src/task_composer_node.cpp#L168-L170

Added lines #L168 - L170 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would vote for a color other than yellow as that is already used elsewhere. Maybe a blue or cyan? I was going to say gray, but that appears to already be used to represent "abort"

}
}
catch (const std::exception& e)
{
Expand Down
Loading