Skip to content

Commit

Permalink
Add status_code to TaskComposerNodeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed May 29, 2024
1 parent 769a287 commit a7371ce
Show file tree
Hide file tree
Showing 33 changed files with 358 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ class TaskComposerNodeInfo
/** @brief Value returned from the Task on completion */
int return_value{ -1 };

/** @brief Status code */
int status_code{ 0 };

/** @brief Status message */
std::string message;
std::string status_message;

/** @brief The start time */
std::chrono::system_clock::time_point start_time{ std::chrono::system_clock::now() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void runTaskComposerNodeInfoTest()
{ // Default
T node_info;
EXPECT_EQ(node_info.return_value, -1);
EXPECT_EQ(node_info.status_code, 0);
EXPECT_TRUE(tesseract_common::almostEqualRelativeAndAbs(node_info.elapsed_time, 0));
EXPECT_TRUE(node_info.uuid.is_nil());
EXPECT_TRUE(node_info.parent_uuid.is_nil());
Expand All @@ -59,6 +60,7 @@ void runTaskComposerNodeInfoTest()
TaskComposerNode node;
T node_info(node);
EXPECT_EQ(node_info.return_value, -1);
EXPECT_EQ(node_info.status_code, 0);
EXPECT_TRUE(tesseract_common::almostEqualRelativeAndAbs(node_info.elapsed_time, 0));
EXPECT_FALSE(node_info.uuid.is_nil());
EXPECT_EQ(node_info.uuid, node.getUUID());
Expand Down
5 changes: 3 additions & 2 deletions tesseract_task_composer/core/src/nodes/done_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ std::unique_ptr<TaskComposerNodeInfo> DoneTask::runImpl(TaskComposerContext& /*c
auto info = std::make_unique<TaskComposerNodeInfo>(*this);
info->color = "green";
info->return_value = 1;
info->message = "Successful";
CONSOLE_BRIDGE_logDebug("%s", info->message.c_str());
info->status_code = 1;
info->status_message = "Successful";
CONSOLE_BRIDGE_logDebug("%s", info->status_message.c_str());
return info;
}

Expand Down
5 changes: 3 additions & 2 deletions tesseract_task_composer/core/src/nodes/error_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ std::unique_ptr<TaskComposerNodeInfo> ErrorTask::runImpl(TaskComposerContext& /*
auto info = std::make_unique<TaskComposerNodeInfo>(*this);
info->color = "red";
info->return_value = 0;
info->message = "Error";
CONSOLE_BRIDGE_logDebug("%s", info->message.c_str());
info->status_code = 0;
info->status_message = "Error";
CONSOLE_BRIDGE_logDebug("%s", info->status_message.c_str());
return info;
}

Expand Down
6 changes: 4 additions & 2 deletions tesseract_task_composer/core/src/nodes/remap_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ std::unique_ptr<TaskComposerNodeInfo> RemapTask::runImpl(TaskComposerContext& co
{
info->color = "green";
info->return_value = 1;
info->message = "Successful";
info->status_code = 1;
info->status_message = "Successful";
}
else
{
info->color = "red";
info->return_value = 0;
info->message = "Failed to remap data.";
info->status_code = 0;
info->status_message = "Failed to remap data.";
}
return info;
}
Expand Down
3 changes: 2 additions & 1 deletion tesseract_task_composer/core/src/nodes/start_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ std::unique_ptr<TaskComposerNodeInfo> StartTask::runImpl(TaskComposerContext& /*
{
auto info = std::make_unique<TaskComposerNodeInfo>(*this);
info->color = "green";
info->message = "Successful";
info->return_value = 1;
info->status_code = 1;
info->status_message = "Successful";
return info;
}

Expand Down
3 changes: 2 additions & 1 deletion tesseract_task_composer/core/src/nodes/sync_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ std::unique_ptr<TaskComposerNodeInfo> SyncTask::runImpl(TaskComposerContext& /*c
{
auto info = std::make_unique<TaskComposerNodeInfo>(*this);
info->color = "green";
info->message = "Successful";
info->return_value = 1;
info->status_code = 1;
info->status_message = "Successful";
return info;
}

Expand Down
4 changes: 2 additions & 2 deletions tesseract_task_composer/core/src/task_composer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TaskComposerNode::dump(std::ostream& os,
if (it != results_map.end())
{
os << "\\nTime: " << std::fixed << std::setprecision(3) << it->second->elapsed_time << "s"
<< "\\n`" << it->second->message << "`";
<< "\\n`" << std::to_string(it->second->status_code) << "::" << it->second->status_message << "`";
}
os << "\", color=black, fillcolor=" << color << ", style=filled];\n";

Expand Down Expand Up @@ -205,7 +205,7 @@ TaskComposerNode::dump(std::ostream& os,
if (it != results_map.end())
{
os << "\\nTime: " << std::fixed << std::setprecision(3) << it->second->elapsed_time << "s"
<< "\\n'" << it->second->message << "'";
<< "\\n'" << std::to_string(it->second->status_code) << "::" << it->second->status_message << "'";
}
os << "\", color=black, fillcolor=" << color << ", style=filled];\n";

Expand Down
6 changes: 4 additions & 2 deletions tesseract_task_composer/core/src/task_composer_node_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ bool TaskComposerNodeInfo::operator==(const TaskComposerNodeInfo& rhs) const
equal &= uuid == rhs.uuid;
equal &= parent_uuid == rhs.parent_uuid;
equal &= return_value == rhs.return_value;
equal &= message == rhs.message;
equal &= status_code == rhs.status_code;
equal &= status_message == rhs.status_message;
equal &= start_time == rhs.start_time;
equal &= tesseract_common::almostEqualRelativeAndAbs(elapsed_time, rhs.elapsed_time, max_diff);
equal &= tesseract_common::isIdentical(inbound_edges, rhs.inbound_edges, false);
Expand All @@ -90,7 +91,8 @@ void TaskComposerNodeInfo::serialize(Archive& ar, const unsigned int /*version*/
ar& boost::serialization::make_nvp("uuid", uuid);
ar& boost::serialization::make_nvp("parent_uuid", parent_uuid);
ar& boost::serialization::make_nvp("return_value", return_value);
ar& boost::serialization::make_nvp("message", message);
ar& boost::serialization::make_nvp("status_code", status_code);
ar& boost::serialization::make_nvp("status_message", status_message);
ar& boost::serialization::make_nvp("start_time",
boost::serialization::make_binary_object(&start_time, sizeof(start_time)));
ar& boost::serialization::make_nvp("elapsed_time", elapsed_time);
Expand Down
9 changes: 6 additions & 3 deletions tesseract_task_composer/core/src/task_composer_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ int TaskComposerPipeline::run(TaskComposerContext& context, OptionalTaskComposer
info->input_keys = input_keys_;
info->output_keys = output_keys_;
info->return_value = 0;
info->status_code = 0;
info->status_message = "Aborted";
info->color = "white";
info->message = "Aborted";
info->aborted_ = true;
context.task_infos.addInfo(std::move(info));
return 0;
Expand All @@ -78,7 +79,8 @@ int TaskComposerPipeline::run(TaskComposerContext& context, OptionalTaskComposer
{
results = std::make_unique<TaskComposerNodeInfo>(*this);
results->color = "red";
results->message = "Exception thrown: " + std::string(e.what());
results->status_code = -1;
results->status_message = "Exception thrown: " + std::string(e.what());
results->return_value = 0;
}
timer.stop();
Expand Down Expand Up @@ -127,7 +129,8 @@ std::unique_ptr<TaskComposerNodeInfo> TaskComposerPipeline::runImpl(TaskComposer
info->output_keys = output_keys_;
info->return_value = static_cast<int>(i);
info->color = node_info->color;
info->message = node_info->message;
info->status_code = node_info->status_code;
info->status_message = node_info->status_message;
info->elapsed_time = timer.elapsedSeconds();
return info;
}
Expand Down
8 changes: 5 additions & 3 deletions tesseract_task_composer/core/src/task_composer_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ int TaskComposerTask::run(TaskComposerContext& context, OptionalTaskComposerExec
info->output_keys = output_keys_;
info->return_value = 0;
info->color = "white";
info->message = "Aborted";
info->status_code = 0;
info->status_message = "Aborted";
info->aborted_ = true;
context.task_infos.addInfo(std::move(info));
return 0;
Expand All @@ -89,7 +90,8 @@ int TaskComposerTask::run(TaskComposerContext& context, OptionalTaskComposerExec
{
results = std::make_unique<TaskComposerNodeInfo>(*this);
results->color = "red";
results->message = "Exception thrown: " + std::string(e.what());
results->status_code = -1;
results->status_message = "Exception thrown: " + std::string(e.what());
results->return_value = 0;
}
timer.stop();
Expand All @@ -104,7 +106,7 @@ int TaskComposerTask::run(TaskComposerContext& context, OptionalTaskComposerExec
// Call abort if required
if (trigger_abort_ && !context.isAborted())
{
results->message += " (Abort Triggered)";
results->status_message += " (Abort Triggered)";
context.abort(uuid_);
}

Expand Down
1 change: 1 addition & 0 deletions tesseract_task_composer/core/src/test_suite/test_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::unique_ptr<TaskComposerNodeInfo> TestTask::runImpl(TaskComposerContext& con
else
node_info->color = "green";
node_info->return_value = return_value;
node_info->status_code = return_value;

if (set_abort)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MotionPlannerTask : public TaskComposerTask

auto info = std::make_unique<MotionPlannerTaskInfo>(*this);
info->return_value = 0;
info->status_code = 0;
info->env = problem.env;

// --------------------
Expand All @@ -136,8 +137,8 @@ class MotionPlannerTask : public TaskComposerTask
auto input_data_poly = context.data_storage->getData(input_keys_[0]);
if (input_data_poly.isNull() || input_data_poly.getType() != std::type_index(typeid(CompositeInstruction)))
{
info->message = "Input instructions to MotionPlannerTask: " + name_ + " must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->message.c_str());
info->status_message = "Input instructions to MotionPlannerTask: " + name_ + " must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->status_message.c_str());
return info;
}

Expand Down Expand Up @@ -174,7 +175,8 @@ class MotionPlannerTask : public TaskComposerTask
{
info->return_value = 1;
info->color = "green";
info->message = response.message;
info->status_code = 1;
info->status_message = response.message;
CONSOLE_BRIDGE_logDebug("Motion Planner process succeeded");
return info;
}
Expand All @@ -189,7 +191,7 @@ class MotionPlannerTask : public TaskComposerTask
if (output_keys_[0] != input_keys_[0])
context.data_storage->setData(output_keys_[0], context.data_storage->getData(input_keys_[0]));

info->message = response.message;
info->status_message = response.message;
return info;
}
};
Expand Down
12 changes: 7 additions & 5 deletions tesseract_task_composer/planning/src/nodes/check_input_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ std::unique_ptr<TaskComposerNodeInfo> CheckInputTask::runImpl(TaskComposerContex
OptionalTaskComposerExecutor /*executor*/) const
{
auto info = std::make_unique<TaskComposerNodeInfo>(*this);
info->return_value = 0;
info->status_code = 0;

// Get the problem
auto& problem = dynamic_cast<PlanningTaskComposerProblem&>(*context.problem);

// Get Composite Profile
info->return_value = 0;
for (const auto& key : input_keys_)
{
auto input_data_poly = context.data_storage->getData(key);
if (input_data_poly.isNull() || input_data_poly.getType() != std::type_index(typeid(CompositeInstruction)))
{
info->message = "Input key '" + key + "' is missing";
CONSOLE_BRIDGE_logError("%s", info->message.c_str());
info->status_message = "Input key '" + key + "' is missing";
CONSOLE_BRIDGE_logError("%s", info->status_message.c_str());
return info;
}

Expand All @@ -95,13 +96,14 @@ std::unique_ptr<TaskComposerNodeInfo> CheckInputTask::runImpl(TaskComposerContex

if (!cur_composite_profile->isValid(context))
{
info->message = "Validator failed";
info->status_message = "Validator failed";
return info;
}
}

info->color = "green";
info->message = "Successful";
info->status_code = 1;
info->status_message = "Successful";
info->return_value = 1;
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ ContinuousContactCheckTask::runImpl(TaskComposerContext& context, OptionalTaskCo

auto info = std::make_unique<ContinuousContactCheckTaskInfo>(*this);
info->return_value = 0;
info->status_code = 0;
info->env = problem.env;

// --------------------
Expand All @@ -94,8 +95,9 @@ ContinuousContactCheckTask::runImpl(TaskComposerContext& context, OptionalTaskCo
auto input_data_poly = context.data_storage->getData(input_keys_[0]);
if (input_data_poly.isNull() || input_data_poly.getType() != std::type_index(typeid(CompositeInstruction)))
{
info->message = "Input seed to ContinuousContactCheckTask must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->message.c_str());
info->status_code = 0;
info->status_message = "Input seed to ContinuousContactCheckTask must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->status_message.c_str());
info->return_value = 0;
return info;
}
Expand All @@ -121,8 +123,9 @@ ContinuousContactCheckTask::runImpl(TaskComposerContext& context, OptionalTaskCo
std::vector<tesseract_collision::ContactResultMap> contacts;
if (contactCheckProgram(contacts, *manager, *state_solver, ci, cur_composite_profile->config))
{
info->message = "Results are not contact free for process input: " + ci.getDescription();
CONSOLE_BRIDGE_logInform("%s", info->message.c_str());
info->status_code = 0;
info->status_message = "Results are not contact free for process input: " + ci.getDescription();
CONSOLE_BRIDGE_logInform("%s", info->status_message.c_str());

// Save space
for (auto& contact_map : contacts)
Expand All @@ -134,8 +137,9 @@ ContinuousContactCheckTask::runImpl(TaskComposerContext& context, OptionalTaskCo
}

info->color = "green";
info->message = "Continuous contact check succeeded";
CONSOLE_BRIDGE_logDebug("%s", info->message.c_str());
info->status_code = 1;
info->status_message = "Continuous contact check succeeded";
CONSOLE_BRIDGE_logDebug("%s", info->status_message.c_str());
info->return_value = 1;
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ std::unique_ptr<TaskComposerNodeInfo> DiscreteContactCheckTask::runImpl(TaskComp

auto info = std::make_unique<DiscreteContactCheckTaskInfo>(*this);
info->return_value = 0;
info->status_code = 0;
info->env = problem.env;

// --------------------
Expand All @@ -95,8 +96,8 @@ std::unique_ptr<TaskComposerNodeInfo> DiscreteContactCheckTask::runImpl(TaskComp
auto input_data_poly = context.data_storage->getData(input_keys_[0]);
if (input_data_poly.isNull() || input_data_poly.getType() != std::type_index(typeid(CompositeInstruction)))
{
info->message = "Input to DiscreteContactCheckTask must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->message.c_str());
info->status_message = "Input to DiscreteContactCheckTask must be a composite instruction";
CONSOLE_BRIDGE_logError("%s", info->status_message.c_str());
return info;
}

Expand All @@ -120,8 +121,8 @@ std::unique_ptr<TaskComposerNodeInfo> DiscreteContactCheckTask::runImpl(TaskComp
std::vector<tesseract_collision::ContactResultMap> contacts;
if (contactCheckProgram(contacts, *manager, *state_solver, ci, cur_composite_profile->config))
{
info->message = "Results are not contact free for process input: " + ci.getDescription();
CONSOLE_BRIDGE_logInform("%s", info->message.c_str());
info->status_message = "Results are not contact free for process input: " + ci.getDescription();
CONSOLE_BRIDGE_logInform("%s", info->status_message.c_str());

// Save space
for (auto& contact_map : contacts)
Expand All @@ -132,9 +133,10 @@ std::unique_ptr<TaskComposerNodeInfo> DiscreteContactCheckTask::runImpl(TaskComp
}

info->color = "green";
info->message = "Discrete contact check succeeded";
info->status_code = 1;
info->status_message = "Discrete contact check succeeded";
info->return_value = 1;
CONSOLE_BRIDGE_logDebug("%s", info->message.c_str());
CONSOLE_BRIDGE_logDebug("%s", info->status_message.c_str());
return info;
}

Expand Down
Loading

0 comments on commit a7371ce

Please sign in to comment.