Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 13, 2024
1 parent 3182ef5 commit ddfa930
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ namespace tesseract_planning
*/
struct TaskComposerNodePorts
{
std::unordered_map<std::string, bool> input_required;
std::unordered_map<std::string, bool> input_optional;
enum Type
{
SINGLE = 0,
MULTIPLE = 1
};

std::unordered_map<std::string, bool> output_required;
std::unordered_map<std::string, bool> output_optional;
std::unordered_map<std::string, Type> input_required;
std::unordered_map<std::string, Type> input_optional;

std::unordered_map<std::string, Type> output_required;
std::unordered_map<std::string, Type> output_optional;

std::string toString() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ HasDataStorageEntryTask::HasDataStorageEntryTask(std::string name,
TaskComposerNodePorts HasDataStorageEntryTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_KEYS_PORT] = true;
ports.input_required[INPUT_KEYS_PORT] = TaskComposerNodePorts::MULTIPLE;
return ports;
}

Expand Down
42 changes: 20 additions & 22 deletions tesseract_task_composer/core/src/task_composer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void TaskComposerNode::validatePorts() const
const auto& output_keys = output_keys_.data();

// Check for required ports
for (const auto& [port, container] : ports_.input_required)
for (const auto& [port, type] : ports_.input_required)
{
auto it = input_keys.find(port);
if (it == input_keys.end())
Expand All @@ -164,38 +164,38 @@ void TaskComposerNode::validatePorts() const
msg.append(", missing required input port '");
msg.append(port);
msg.append(":");
msg.append((container) ? "Multiple" : "Single");
msg.append((static_cast<bool>(type)) ? "Multiple" : "Single");
msg.append("'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}

if (static_cast<bool>(it->second.index()) != container)
if (it->second.index() != type)
{
std::string msg;
msg.append(name_);
msg.append(", required input port is wrong type'");
msg.append(port);
msg.append(":");
msg.append((container) ? "Multiple" : "Single");
msg.append((static_cast<bool>(type)) ? "Multiple" : "Single");
msg.append("'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}

if (container && std::get<std::vector<std::string>>(it->second).empty())
if (static_cast<bool>(type) && std::get<std::vector<std::string>>(it->second).empty())
{
std::string msg;
msg.append(name_);
msg.append(", required input port container is empty'");
msg.append(port);
msg.append(":Container'. Supported Ports:\n");
msg.append(":Multiple'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}
}

for (const auto& [port, container] : ports_.output_required)
for (const auto& [port, type] : ports_.output_required)
{
auto it = output_keys.find(port);
if (it == output_keys.end())
Expand All @@ -205,32 +205,32 @@ void TaskComposerNode::validatePorts() const
msg.append(", missing required output port '");
msg.append(port);
msg.append(":");
msg.append((container) ? "Multiple" : "Single");
msg.append((static_cast<bool>(type)) ? "Multiple" : "Single");
msg.append("'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}

if (static_cast<bool>(it->second.index()) != container)
if (it->second.index() != type)
{
std::string msg;
msg.append(name_);
msg.append(", required output port is wrong type'");
msg.append(port);
msg.append(":");
msg.append((container) ? "Multiple" : "Single");
msg.append((static_cast<bool>(type)) ? "Multiple" : "Single");
msg.append("'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}

if (container && std::get<std::vector<std::string>>(it->second).empty())
if (static_cast<bool>(type) && std::get<std::vector<std::string>>(it->second).empty())
{
std::string msg;
msg.append(name_);
msg.append(", required output port container is empty'");
msg.append(port);
msg.append(":Container'. Supported Ports:\n");
msg.append(":Multiple'. Supported Ports:\n");
msg.append(ports_.toString());
throw std::runtime_error(msg);
}
Expand All @@ -241,17 +241,16 @@ void TaskComposerNode::validatePorts() const
{
{
auto it = ports_.input_required.find(port);
if ((it != ports_.input_required.end()) &&
((key.index() == 0 && !it->second) || (key.index() == 1 && it->second)))
if ((it != ports_.input_required.end()) && (key.index() == it->second))
continue;
}

{
auto it = ports_.input_optional.find(port);
if ((it != ports_.input_optional.end()) &&
((key.index() == 0 && !it->second) || (key.index() == 1 && it->second)))
if ((it != ports_.input_optional.end()) && (key.index() == it->second))
{
if ((it != ports_.input_optional.end()) && it->second && std::get<std::vector<std::string>>(key).empty())
if ((it != ports_.input_optional.end()) && static_cast<bool>(it->second) &&
std::get<std::vector<std::string>>(key).empty())
{
std::string msg;
msg.append(name_);
Expand Down Expand Up @@ -281,17 +280,16 @@ void TaskComposerNode::validatePorts() const
{
{
auto it = ports_.output_required.find(port);
if ((it != ports_.output_required.end()) &&
((key.index() == 0 && !it->second) || (key.index() == 1 && it->second)))
if ((it != ports_.output_required.end()) && (key.index() == it->second))
continue;
}

{
auto it = ports_.output_optional.find(port);
if ((it != ports_.output_optional.end()) &&
((key.index() == 0 && !it->second) || (key.index() == 1 && it->second)))
if ((it != ports_.output_optional.end()) && (key.index() == it->second))
{
if ((it != ports_.output_optional.end()) && it->second && std::get<std::vector<std::string>>(key).empty())
if ((it != ports_.output_optional.end()) && static_cast<bool>(it->second) &&
std::get<std::vector<std::string>>(key).empty())
{
std::string msg;
msg.append(name_);
Expand Down
16 changes: 8 additions & 8 deletions tesseract_task_composer/core/src/task_composer_node_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ std::string TaskComposerNodePorts::toString() const
{
std::string temp = " required: [";
std::size_t cnt{ 0 };
for (const auto& [port, container] : input_required)
for (const auto& [port, type] : input_required)
{
std::string bool_str = (container) ? "Multiple" : "Single";
std::string bool_str = (static_cast<bool>(type)) ? "Multiple" : "Single";
temp.append(port);
temp.append(":");
temp.append(bool_str);
Expand All @@ -64,9 +64,9 @@ std::string TaskComposerNodePorts::toString() const
{
std::string temp = " optional: [";
std::size_t cnt{ 0 };
for (const auto& [port, container] : input_optional)
for (const auto& [port, type] : input_optional)
{
std::string bool_str = (container) ? "Multiple" : "Single";
std::string bool_str = (static_cast<bool>(type)) ? "Multiple" : "Single";
temp.append(port);
temp.append(":");
temp.append(bool_str);
Expand All @@ -89,9 +89,9 @@ std::string TaskComposerNodePorts::toString() const
{
std::string temp = " required: [";
std::size_t cnt{ 0 };
for (const auto& [port, container] : output_required)
for (const auto& [port, type] : output_required)
{
std::string bool_str = (container) ? "Multiple" : "Single";
std::string bool_str = (static_cast<bool>(type)) ? "Multiple" : "Single";
temp.append(port);
temp.append(":");
temp.append(bool_str);
Expand All @@ -113,9 +113,9 @@ std::string TaskComposerNodePorts::toString() const
{
std::string temp = " optional: [";
std::size_t cnt{ 0 };
for (const auto& [port, container] : output_optional)
for (const auto& [port, type] : output_optional)
{
std::string bool_str = (container) ? "Multiple" : "Single";
std::string bool_str = (static_cast<bool>(type)) ? "Multiple" : "Single";
temp.append(port);
temp.append(":");
temp.append(bool_str);
Expand Down
8 changes: 4 additions & 4 deletions tesseract_task_composer/core/src/test_suite/test_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ TestTask::TestTask(std::string name, const YAML::Node& config, const TaskCompose
TaskComposerNodePorts TestTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INOUT_PORT1_PORT] = false;
ports.input_required[INOUT_PORT2_PORT] = true;
ports.output_required[INOUT_PORT1_PORT] = false;
ports.output_required[INOUT_PORT2_PORT] = true;
ports.input_required[INOUT_PORT1_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INOUT_PORT2_PORT] = TaskComposerNodePorts::MULTIPLE;
ports.output_required[INOUT_PORT1_PORT] = TaskComposerNodePorts::SINGLE;
ports.output_required[INOUT_PORT2_PORT] = TaskComposerNodePorts::MULTIPLE;
return ports;
}

Expand Down
12 changes: 6 additions & 6 deletions tesseract_task_composer/examples/task_composer_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class AddTaskComposerNode : public TaskComposerTask
static TaskComposerNodePorts ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_LEFT_PORT] = false;
ports.input_required[INPUT_RIGHT_PORT] = false;
ports.output_required[OUTPUT_RESULT_PORT] = false;
ports.input_required[INPUT_LEFT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_RIGHT_PORT] = TaskComposerNodePorts::SINGLE;
ports.output_required[OUTPUT_RESULT_PORT] = TaskComposerNodePorts::SINGLE;
return ports;
}

Expand Down Expand Up @@ -76,9 +76,9 @@ class MultiplyTaskComposerNode : public TaskComposerTask
static TaskComposerNodePorts ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_LEFT_PORT] = false;
ports.input_required[INPUT_RIGHT_PORT] = false;
ports.output_required[OUTPUT_RESULT_PORT] = false;
ports.input_required[INPUT_LEFT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_RIGHT_PORT] = TaskComposerNodePorts::SINGLE;
ports.output_required[OUTPUT_RESULT_PORT] = TaskComposerNodePorts::SINGLE;
return ports;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ class MotionPlannerTask : public TaskComposerTask
static TaskComposerNodePorts ports()
{
TaskComposerNodePorts ports;
ports.input_required[INOUT_PROGRAM_PORT] = false;
ports.input_required[INPUT_ENVIRONMENT_PORT] = false;
ports.input_required[INPUT_PROFILES_PORT] = false;
ports.input_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_ENVIRONMENT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_PROFILES_PORT] = TaskComposerNodePorts::SINGLE;

ports.input_optional[INPUT_MANIP_INFO_PORT] = false;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MOVE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MANIP_INFO_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_MOVE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;

ports.output_required[INOUT_PROGRAM_PORT] = false;
ports.output_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
return ports;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ ContinuousContactCheckTask::ContinuousContactCheckTask(std::string name,
TaskComposerNodePorts ContinuousContactCheckTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_PROGRAM_PORT] = false;
ports.input_required[INPUT_ENVIRONMENT_PORT] = false;
ports.input_required[INPUT_PROFILES_PORT] = false;
ports.input_required[INPUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_ENVIRONMENT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_PROFILES_PORT] = TaskComposerNodePorts::SINGLE;

ports.input_optional[INPUT_MANIP_INFO_PORT] = false;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MANIP_INFO_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;
return ports;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ DiscreteContactCheckTask::DiscreteContactCheckTask(std::string name,
TaskComposerNodePorts DiscreteContactCheckTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_PROGRAM_PORT] = false;
ports.input_required[INPUT_ENVIRONMENT_PORT] = false;
ports.input_required[INPUT_PROFILES_PORT] = false;
ports.input_required[INPUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_ENVIRONMENT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_PROFILES_PORT] = TaskComposerNodePorts::SINGLE;

ports.input_optional[INPUT_MANIP_INFO_PORT] = false;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MANIP_INFO_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;
return ports;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ FixStateBoundsTask::FixStateBoundsTask(std::string name,
TaskComposerNodePorts FixStateBoundsTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INOUT_PROGRAM_PORT] = false;
ports.input_required[INPUT_ENVIRONMENT_PORT] = false;
ports.input_required[INPUT_PROFILES_PORT] = false;
ports.input_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_ENVIRONMENT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_PROFILES_PORT] = TaskComposerNodePorts::SINGLE;

ports.input_optional[INPUT_MANIP_INFO_PORT] = false;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MANIP_INFO_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;

ports.output_required[INOUT_PROGRAM_PORT] = false;
ports.output_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;

return ports;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ FixStateCollisionTask::FixStateCollisionTask(std::string name,
TaskComposerNodePorts FixStateCollisionTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INOUT_PROGRAM_PORT] = false;
ports.input_required[INPUT_ENVIRONMENT_PORT] = false;
ports.input_required[INPUT_PROFILES_PORT] = false;
ports.input_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_ENVIRONMENT_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_PROFILES_PORT] = TaskComposerNodePorts::SINGLE;

ports.input_optional[INPUT_MANIP_INFO_PORT] = false;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = false;
ports.input_optional[INPUT_MANIP_INFO_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_optional[INPUT_COMPOSITE_PROFILE_REMAPPING_PORT] = TaskComposerNodePorts::SINGLE;

ports.output_required[INOUT_PROGRAM_PORT] = false;
ports.output_required[INOUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;

return ports;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ FormatAsInputTask::FormatAsInputTask(std::string name,
TaskComposerNodePorts FormatAsInputTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INPUT_PRE_PLANNING_PROGRAM_PORT] = false;
ports.input_required[INPUT_POST_PLANNING_PROGRAM_PORT] = false;
ports.input_required[INPUT_PRE_PLANNING_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;
ports.input_required[INPUT_POST_PLANNING_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;

ports.output_required[OUTPUT_PROGRAM_PORT] = false;
ports.output_required[OUTPUT_PROGRAM_PORT] = TaskComposerNodePorts::SINGLE;

return ports;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ FormatAsResultTask::FormatAsResultTask(std::string name,
TaskComposerNodePorts FormatAsResultTask::ports()
{
TaskComposerNodePorts ports;
ports.input_required[INOUT_PROGRAMS_PORT] = true;
ports.output_required[INOUT_PROGRAMS_PORT] = true;
ports.input_required[INOUT_PROGRAMS_PORT] = TaskComposerNodePorts::MULTIPLE;
ports.output_required[INOUT_PROGRAMS_PORT] = TaskComposerNodePorts::MULTIPLE;
return ports;
}

Expand Down
Loading

0 comments on commit ddfa930

Please sign in to comment.