Skip to content

Commit

Permalink
Move ProcessInfo into ProcessInterface for outside access (#514)
Browse files Browse the repository at this point in the history
* Move ProcessInfo into ProcessInterface for outside access

* Rename Process to Task for generators and associated types

ProcessGenerator -> TaskGenerator
ProcessInterface -> TaskflowInterface
ProcessInfo -> TaskInfo
ProcessInfoContainer -> TaskInfoContainer
ProcessInput -> TaskInput

* Fix remaining changes

Co-authored-by: Levi Armstrong <levi.armstrong@swri.org>
  • Loading branch information
2 people authored and Levi-Armstrong committed Jan 7, 2021
1 parent e815b0c commit 79a37e5
Show file tree
Hide file tree
Showing 67 changed files with 1,049 additions and 1,018 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ include(GenerateExportHeader)

# Create interface
add_library(${PROJECT_NAME}
src/core/process_input.cpp
src/core/task_input.cpp
src/core/debug_observer.cpp
src/core/process_generator.cpp
src/core/task_generator.cpp
src/core/process_planning_future.cpp
src/core/process_planning_server.cpp
src/core/process_environment_cache.cpp
src/core/process_interface.cpp
src/core/process_info.cpp
src/core/taskflow_interface.cpp
src/core/task_info.cpp
src/core/default_process_planners.cpp
src/core/taskflow_container.cpp
src/core/utils.cpp
src/process_generators/continuous_contact_check_process_generator.cpp
src/process_generators/discrete_contact_check_process_generator.cpp
src/process_generators/fix_state_bounds_process_generator.cpp
src/process_generators/fix_state_collision_process_generator.cpp
src/process_generators/iterative_spline_parameterization_process_generator.cpp
src/process_generators/motion_planner_process_generator.cpp
src/process_generators/profile_switch_process_generator.cpp
src/process_generators/seed_min_length_process_generator.cpp
src/task_generators/continuous_contact_check_task_generator.cpp
src/task_generators/discrete_contact_check_task_generator.cpp
src/task_generators/fix_state_bounds_task_generator.cpp
src/task_generators/fix_state_collision_task_generator.cpp
src/task_generators/iterative_spline_parameterization_task_generator.cpp
src/task_generators/motion_planner_task_generator.cpp
src/task_generators/profile_switch_task_generator.cpp
src/task_generators/seed_min_length_task_generator.cpp
src/taskflow_generators/graph_taskflow.cpp
src/taskflow_generators/raster_taskflow.cpp
src/taskflow_generators/raster_global_taskflow.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This package contains process managers for Tesseract. Examples include
* Raster strip planning manager

## Overview
### ProcessInput
This package uses [Taskflow](https://github.com/taskflow/taskflow) to organize and perform robotics tasks. Each of the tasks in the system will take a ProcessInput which is just a Tesseract::ConstPtr and references to instructions and the seed.
### TaskInput
This package uses [Taskflow](https://github.com/taskflow/taskflow) to organize and perform robotics tasks. Each of the tasks in the system will take a TaskInput which is just a Tesseract::ConstPtr and references to instructions and the seed.

Each Task will operate on the instructions and the results will get stored in the seed. The ProcessInput does not own the instructions in order to keep it lightweight and able to be segmented into sub-ProcessInputs (see [] operator). Therefore, the instructions and seed passed into the ProcessInput must be kept alive by the user.
Each Task will operate on the instructions and the results will get stored in the seed. The TaskInput does not own the instructions in order to keep it lightweight and able to be segmented into sub-TaskInputs (see [] operator). Therefore, the instructions and seed passed into the TaskInput must be kept alive by the user.

It is also worth noting that ProcessInput is not inherently thread-safe. Since taskflow will attempt to execute as many tasks in parallel as possible, it is the responsibility of the user to ensure that Tasks that use the same portions of the ProcessInput are not running at the same time. In practice, this shouldn't be difficult as many of the planning operations currently implemented have a clear order. However, you should not, for example, try to plan the same segment using two different planners at the same time without first making a copy of the inputs to the ProcessInput for each Task.
It is also worth noting that TaskInput is not inherently thread-safe. Since taskflow will attempt to execute as many tasks in parallel as possible, it is the responsibility of the user to ensure that Tasks that use the same portions of the TaskInput are not running at the same time. In practice, this shouldn't be difficult as many of the planning operations currently implemented have a clear order. However, you should not, for example, try to plan the same segment using two different planners at the same time without first making a copy of the inputs to the TaskInput for each Task.

### Class Structure
The package is divided into several types of classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <taskflow/taskflow.hpp>
#include <tesseract_common/utils.h>

struct ProcessInput
struct TaskInput
{
int* cnt;
};
Expand All @@ -18,7 +18,7 @@ int main(int /*argc*/, char** /*argv*/)
tf::Taskflow taskflow;

int num_subtaskflows = 1;
ProcessInput input;
TaskInput input;
input.cnt = &num_subtaskflows;

tf::Task t = taskflow.placeholder();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <taskflow/taskflow.hpp>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_process_managers/core/process_interface.h>
#include <tesseract_process_managers/core/taskflow_interface.h>
#include <tesseract_process_managers/core/taskflow_generator.h>

#include <tesseract_motion_planners/core/types.h>
Expand All @@ -60,7 +60,7 @@ struct ProcessPlanningFuture
std::future<void> process_future;

/** @brief This is used to abort the associated process and check if the process was successful */
ProcessInterface::Ptr interface;
TaskflowInterface::Ptr interface;

#ifndef SWIG
/** @brief The stored input to the process */
Expand All @@ -77,6 +77,7 @@ struct ProcessPlanningFuture

/** @brief The stored composite profile remapping */
std::unique_ptr<const PlannerProfileRemapping> composite_profile_remapping;

#else
// clang-format off
%extend {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file process_generator.h
* @file task_generator.h
* @brief Process generator
*
* @author Matthew Powelson
Expand All @@ -23,8 +23,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TESSERACT_PROCESS_MANAGERS_PROCESS_GENERATOR_H
#define TESSERACT_PROCESS_MANAGERS_PROCESS_GENERATOR_H
#ifndef TESSERACT_PROCESS_MANAGERS_TASK_GENERATOR_H
#define TESSERACT_PROCESS_MANAGERS_TASK_GENERATOR_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Expand All @@ -33,28 +33,28 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <taskflow/taskflow.hpp>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_process_managers/core/process_input.h>
#include <tesseract_process_managers/core/task_input.h>

namespace tesseract_planning
{
/**
* @brief This is a base class for generating instances of processes as tasks such that they may be executed in
* parallel. A typical workflow would be task t = process_generator.generateTask(input, taskflow)
* parallel. A typical workflow would be task t = task_generator.generateTask(input, taskflow)
*
* Only unique pointers should be used because of the ability to abort the process. With recent changes this may no
* longer be valid but need to investigate.
*/
class ProcessGenerator
class TaskGenerator
{
public:
using UPtr = std::unique_ptr<ProcessGenerator>;
using UPtr = std::unique_ptr<TaskGenerator>;

ProcessGenerator(std::string name = "");
virtual ~ProcessGenerator() = default;
ProcessGenerator(const ProcessGenerator&) = delete;
ProcessGenerator& operator=(const ProcessGenerator&) = delete;
ProcessGenerator(ProcessGenerator&&) = delete;
ProcessGenerator& operator=(ProcessGenerator&&) = delete;
TaskGenerator(std::string name = "");
virtual ~TaskGenerator() = default;
TaskGenerator(const TaskGenerator&) = delete;
TaskGenerator& operator=(const TaskGenerator&) = delete;
TaskGenerator(TaskGenerator&&) = delete;
TaskGenerator& operator=(TaskGenerator&&) = delete;

/**
* @brief Get the task name
Expand All @@ -68,29 +68,29 @@ class ProcessGenerator
* @param taskflow The taskflow to associate the task with
* @return Task
*/
virtual tf::Task generateTask(ProcessInput input, tf::Taskflow& taskflow);
virtual tf::Task generateTask(TaskInput input, tf::Taskflow& taskflow);

/**
* @brief Assign work to the provided task
* @param input The process input
* @param task The task to assign the work to
*/
virtual void assignTask(ProcessInput input, tf::Task& task);
virtual void assignTask(TaskInput input, tf::Task& task);

/**
* @brief Generated a Task
* @param input The process input
* @param taskflow The taskflow to associate the task with
* @return Conditional Task
*/
virtual tf::Task generateConditionalTask(ProcessInput input, tf::Taskflow& taskflow);
virtual tf::Task generateConditionalTask(TaskInput input, tf::Taskflow& taskflow);

/**
* @brief Assign work to the provided task
* @param input The process input
* @param task The task to assign the work to
*/
virtual void assignConditionalTask(ProcessInput input, tf::Task& task);
virtual void assignConditionalTask(TaskInput input, tf::Task& task);

protected:
/** @brief The name of the process */
Expand All @@ -101,14 +101,14 @@ class ProcessGenerator
* @param input The process input
* @return Task
*/
virtual void process(ProcessInput input, std::size_t unique_id) const = 0;
virtual void process(TaskInput input, std::size_t unique_id) const = 0;

/**
* @brief Generate Conditional Task
* @param input The process input
* @return Conditional Task
*/
virtual int conditionalProcess(ProcessInput input, std::size_t unique_id) const = 0;
virtual int conditionalProcess(TaskInput input, std::size_t unique_id) const = 0;
};

} // namespace tesseract_planning
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @file task_info.h
* @brief Process Info
*
* @author Matthew Powelson
* @date July 15. 2020
* @version TODO
* @bug No known bugs
*
* @copyright Copyright (c) 2020, Southwest Research Institute
*
* @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_PROCESS_MANAGERS_task_info_H
#define TESSERACT_PROCESS_MANAGERS_task_info_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <memory>
#include <shared_mutex>
#include <map>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#ifdef SWIG
%shared_ptr(tesseract_planning::TaskInfo)
%template(TaskInfoMap) std::map<std::size_t, std::shared_ptr<const tesseract_planning::TaskInfo>>;
%shared_ptr(tesseract_planning::TaskInfoContainer)
#endif // SWIG

namespace tesseract_planning
{
/** Stores information about a Task */
class TaskInfo
{
public:
using Ptr = std::shared_ptr<TaskInfo>;
using ConstPtr = std::shared_ptr<const TaskInfo>;

TaskInfo(std::size_t unique_id, std::string name = "");
virtual ~TaskInfo() = default;
TaskInfo(const TaskInfo&) = default;
TaskInfo& operator=(const TaskInfo&) = default;
TaskInfo(TaskInfo&&) = default;
TaskInfo& operator=(TaskInfo&&) = default;

/** @brief Value returned from the Task on completion */
int return_value;

/** @brief Unique ID generated for the Task by Taskflow */
std::size_t unique_id;

std::string task_name;

std::string message;
};

/** @brief A threadsafe container for TaskInfos */
struct TaskInfoContainer
{
using Ptr = std::shared_ptr<TaskInfoContainer>;
using ConstPtr = std::shared_ptr<const TaskInfoContainer>;

void addTaskInfo(TaskInfo::ConstPtr task_info);

TaskInfo::ConstPtr operator[](std::size_t index) const;

/** @brief Get a copy of the task_info_map_ in case it gets resized*/
std::map<std::size_t, TaskInfo::ConstPtr> getTaskInfoMap() const;

private:
mutable std::shared_mutex mutex_;
std::map<std::size_t, TaskInfo::ConstPtr> task_info_map_;
};
} // namespace tesseract_planning

#endif // TESSERACT_PROCESS_MANAGERS_task_info_H
Loading

0 comments on commit 79a37e5

Please sign in to comment.