Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6f2dc14
prototyping a minimal dispatcher with new task_msgs
youliangtan Aug 21, 2020
32dca9d
add new exec
youliangtan Aug 21, 2020
7737e4f
Merge branch 'master' into feature/task-dispatcher
youliangtan Aug 21, 2020
e6b013d
skeleton for bidder and nomination
youliangtan Aug 24, 2020
b747ed6
further complete bidder and dispatcher
youliangtan Aug 25, 2020
855828b
create simple test exec with bidding pipeline
youliangtan Aug 26, 2020
10cd9ec
Merge branch 'master' into feature/task-dispatcher
youliangtan Sep 15, 2020
af124c8
first version restructuring of new bidding mechanism
youliangtan Sep 24, 2020
537e9d4
preliminary test run of bidder and dispatcher nodes
youliangtan Sep 25, 2020
68a72af
update codes
youliangtan Sep 25, 2020
812f88c
redesign task action interfaces and test out task action interactions
youliangtan Sep 28, 2020
48eb4c5
restructure rmf tasks dir and enhance task tracking on dispatcher
youliangtan Sep 29, 2020
b68163a
add simple test on bidding
youliangtan Sep 30, 2020
b02c521
refactor and define dispatchernode api
youliangtan Oct 5, 2020
287d909
halfway game thru restructuring of code
youliangtan Oct 8, 2020
07cebb3
expose dispatcher api and change action msg fields
youliangtan Oct 9, 2020
b69f467
dispatcher lib api
youliangtan Oct 12, 2020
59b65dc
continuation of work on restucturing dispatcher api
youliangtan Oct 13, 2020
9bc1955
update msg definitions and apis
youliangtan Oct 14, 2020
edef66e
Merge branch 'master' into feature/task-dispatcher
youliangtan Oct 14, 2020
f80cff9
adding srv msg, basic integration test
youliangtan Oct 14, 2020
39956fe
cleanups and further complete dispatcher node
youliangtan Oct 16, 2020
ad30deb
lint, use TaskSummary as TaskStatus
youliangtan Oct 16, 2020
dde6db9
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Oct 16, 2020
dd5d47d
minor changes based on comments
youliangtan Oct 19, 2020
0d02040
update msgs for dispatcher
youliangtan Oct 19, 2020
b1fecd1
code refactoring
youliangtan Oct 20, 2020
236a3d3
Update dispatcher api
youliangtan Oct 21, 2020
eaa1100
extend impl for dispatcher, and add dockerfile
youliangtan Oct 23, 2020
1d8cc4a
sequential bidding and further refactoring, then test
youliangtan Oct 26, 2020
2717a35
templated action and refine dispatcher for gui
youliangtan Oct 28, 2020
4694dfe
latest minor fix on UB
youliangtan Nov 3, 2020
4aec625
merge with new msgs
youliangtan Nov 5, 2020
5d959ec
ensure tasksummary msg is compliant
youliangtan Nov 11, 2020
16d411e
cleanup diff
youliangtan Nov 11, 2020
d7fcf1e
add loop type
youliangtan Nov 16, 2020
997ecea
merge
youliangtan Nov 16, 2020
32ac381
receiving stray task summarry msg
youliangtan Nov 23, 2020
a2e4645
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Nov 23, 2020
4ea5bc2
Merge branch 'master' of github.com:osrf/rmf_core into feature/task-d…
youliangtan Nov 23, 2020
3c541ef
merge with dispatcher-demo and rm charging task from cache on every r…
youliangtan Nov 24, 2020
e2417dd
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Nov 24, 2020
ff3113b
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Dec 7, 2020
9dd8ca7
Merge branch 'develop/dispatcher_demo_traffic_light_merged' into feat…
youliangtan Dec 9, 2020
9798763
merge latest master on traffic light
youliangtan Dec 9, 2020
a1b90f8
refactoring actino task templates
youliangtan Dec 11, 2020
33109ff
refactor and cleanups again
youliangtan Dec 11, 2020
d1120cd
remove charge battery id gen
youliangtan Dec 14, 2020
ae85ecd
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Dec 16, 2020
0883ddf
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Dec 21, 2020
cdee853
first review cleanup iteration
youliangtan Dec 21, 2020
cc72624
more cleanups
youliangtan Dec 22, 2020
210cda3
remove template action
youliangtan Dec 22, 2020
71cb106
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Dec 22, 2020
ec4e943
further refactoring
youliangtan Dec 22, 2020
a8f4569
fix compilations
youliangtan Dec 22, 2020
01dc181
con't refactor
youliangtan Dec 23, 2020
a82ec9d
create TaskDescription.Msg in TaskProfile
youliangtan Dec 23, 2020
e35831e
Merge branch 'develop/dispatcher_demo' into feature/task-dispatcher
youliangtan Dec 23, 2020
8a00de7
append task_description and update task_id gen
youliangtan Dec 23, 2020
4825e2b
reorg apis and add internal_Auctioneer
youliangtan Dec 23, 2020
25b80d3
fix issue on ignoring stray taskstatus
youliangtan Dec 24, 2020
d4edc5c
change default eval and update cancel task impl
youliangtan Dec 29, 2020
88dce51
switch to std::optional
youliangtan Dec 29, 2020
fd33a08
remove max limit terminated tasks according to submission time
youliangtan Dec 30, 2020
e09468b
refactor headers
youliangtan Dec 31, 2020
98b379f
fix bug on unusual short bid duration
youliangtan Jan 4, 2021
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
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG TAG="foxy-ros-base-focal"
FROM ros:$TAG

ENV HOME /home/ws_rmf/

RUN apt-get update && apt-get install -y g++-8 \
ros-foxy-rmw-cyclonedds-cpp
RUN mkdir -p /home/ws_rmf

WORKDIR /home/ws_rmf/
COPY . src
RUN rosdep update
RUN rosdep install --from-paths src --ignore-src --rosdistro foxy -yr

RUN /ros_entrypoint.sh \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=RELEASE && \
sed -i '$isource "/home/ws_rmf/install/setup.bash"' /ros_entrypoint.sh && \
rm -rf build devel src

# todo: should have a multistage build

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
2 changes: 1 addition & 1 deletion rmf_fleet_adapter/src/full_control/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ std::shared_ptr<Connections> make_fleet(
connections->fleet->accept_task_requests(
[task_types](const rmf_task_msgs::msg::TaskProfile& msg)
{
if (task_types.find(msg.task_type.type) != task_types.end())
if (task_types.find(msg.description.task_type.type) != task_types.end())
return true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion rmf_fleet_adapter/src/rmf_fleet_adapter/TaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void TaskManager::set_queue(
msg.state = msg.STATE_QUEUED;
msg.robot_name = _context->name();
msg.fleet_name = _context->description().owner();
msg.task_profile.task_type = task_type_msg;
msg.task_profile.description.task_type = task_type_msg;
msg.start_time = rmf_traffic_ros2::convert(
_queue.back()->deployment_time());
msg.start_time = rmf_traffic_ros2::convert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ void FleetUpdateHandle::Implementation::bid_notice_cb(
// Determine task type and convert to request pointer
rmf_task::ConstRequestPtr new_request = nullptr;
const auto& task_profile = msg->task_profile;
const auto& task_type = task_profile.task_type;
const rmf_traffic::Time start_time = rmf_traffic_ros2::convert(task_profile.start_time);
const auto& task_type = task_profile.description.task_type;
const rmf_traffic::Time start_time =
rmf_traffic_ros2::convert(task_profile.description.start_time);
// TODO (YV) get rid of ID field in RequestPtr
std::string id = msg->task_profile.task_id;
const auto& graph = planner->get_configuration().graph();

// Process Cleaning task
if (task_type.type == rmf_task_msgs::msg::TaskType::TYPE_CLEAN)
{
if (task_profile.clean.start_waypoint.empty())
if (task_profile.description.clean.start_waypoint.empty())
{
RCLCPP_ERROR(
node->get_logger(),
Expand All @@ -166,7 +167,8 @@ void FleetUpdateHandle::Implementation::bid_notice_cb(
}

// Check for valid start waypoint
const std::string start_wp_name = task_profile.clean.start_waypoint;
const std::string start_wp_name =
task_profile.description.clean.start_waypoint;
const auto start_wp = graph.find_waypoint(start_wp_name);
if (!start_wp)
{
Expand Down Expand Up @@ -245,7 +247,7 @@ void FleetUpdateHandle::Implementation::bid_notice_cb(

else if (task_type.type == rmf_task_msgs::msg::TaskType::TYPE_DELIVERY)
{
const auto& delivery = task_profile.delivery;
const auto& delivery = task_profile.description.delivery;
if (delivery.pickup_place_name.empty())
{
RCLCPP_ERROR(
Expand Down Expand Up @@ -340,7 +342,7 @@ void FleetUpdateHandle::Implementation::bid_notice_cb(
}
else if (task_type.type == rmf_task_msgs::msg::TaskType::TYPE_LOOP)
{
const auto& loop = task_profile.loop;
const auto& loop = task_profile.description.loop;
if (loop.start_name.empty())
{
RCLCPP_ERROR(
Expand Down
1 change: 1 addition & 0 deletions rmf_task_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(msg_files
"msg/Behavior.msg"
"msg/BehaviorParameter.msg"
"msg/Station.msg"
"msg/TaskDescription.msg"
"msg/TaskSummary.msg"
"msg/Tasks.msg"
"msg/Loop.msg"
Expand Down
13 changes: 13 additions & 0 deletions rmf_task_msgs/msg/TaskDescription.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Desired start time of a task
builtin_interfaces/Time start_time

# Task type
TaskType task_type

# Task definitions
Station station
Loop loop
Delivery delivery
# Charge charge
Clean clean
# Patrol patrol
15 changes: 1 addition & 14 deletions rmf_task_msgs/msg/TaskProfile.msg
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,4 @@ string task_id
# Task submission time
builtin_interfaces/Time submission_time

# Desired start time of a task
builtin_interfaces/Time start_time

# Task type
TaskType task_type

# Task definitions
Station station
Loop loop
Delivery delivery
# Charge charge
Clean clean
# Patrol patrol

TaskDescription description
12 changes: 2 additions & 10 deletions rmf_task_msgs/srv/SubmitTask.srv
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ string requester
# Desired start time of a task
builtin_interfaces/Time start_time

# Task type
TaskType task_type

# Task definitions
Station station
Loop loop
Delivery delivery
# Charge charge
Clean clean
# Patrol patrol
# desciption of task
TaskDescription description

# fleet selection evaluator
uint8 evaluator
Expand Down
95 changes: 95 additions & 0 deletions rmf_task_ros2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 3.5)

project(rmf_task_ros2)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# we dont use add_compile_options with pedantic in message packages
# because the Python C extensions dont comply with it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

include(GNUInstallDirs)

find_package(ament_cmake REQUIRED)
find_package(rmf_traffic REQUIRED)
find_package(rmf_traffic_ros2 REQUIRED)
find_package(rmf_task_msgs REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(rclcpp REQUIRED)

file(GLOB_RECURSE core_lib_srcs "src/rmf_task_ros2/*.cpp")
add_library(rmf_task_ros2 SHARED ${core_lib_srcs})

target_link_libraries(rmf_task_ros2
PUBLIC
rmf_traffic::rmf_traffic
rmf_traffic_ros2::rmf_traffic_ros2
${rmf_task_msgs_LIBRARIES}
${rclcpp_LIBRARIES}
)

target_include_directories(rmf_task_ros2
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${rmf_traffic_ros2_INCLUDE_DIRS}
${rmf_task_msgs_INCLUDE_DIRS}
${rclcpp_INCLUDE_DIRS}
)

ament_export_targets(rmf_task_ros2 HAS_LIBRARY_TARGET)
ament_export_dependencies(rmf_traffic rmf_task_msgs rclcpp)

#===============================================================================

find_package(ament_cmake_catch2 QUIET)
if(BUILD_TESTING AND ament_cmake_catch2_FOUND)
file(GLOB_RECURSE unit_test_srcs "test/*.cpp")

ament_add_catch2(
test_rmf_task_ros2 test/main.cpp ${unit_test_srcs}
TIMEOUT 300)
target_link_libraries(test_rmf_task_ros2
rmf_task_ros2
rmf_traffic::rmf_traffic
rmf_traffic_ros2::rmf_traffic_ros2
)

target_include_directories(test_rmf_task_ros2
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/>
)
endif()

#===============================================================================

add_executable(rmf_bidder_node
src/mock_bidder/main.cpp
)
target_link_libraries(rmf_bidder_node PUBLIC rmf_task_ros2)

#===============================================================================

add_executable(rmf_task_dispatcher
src/dispatcher_node/main.cpp
)
target_link_libraries(rmf_task_dispatcher PUBLIC rmf_task_ros2)

#===============================================================================
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
TARGETS rmf_task_ros2 rmf_task_dispatcher rmf_bidder_node
EXPORT rmf_task_ros2
RUNTIME DESTINATION lib/rmf_task_ros2
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

ament_package()
141 changes: 141 additions & 0 deletions rmf_task_ros2/include/rmf_task_ros2/Dispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2020 Open Source Robotics Foundation
*
* 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
*
* 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 RMF_TASK_ROS2__DISPATCHER_HPP
#define RMF_TASK_ROS2__DISPATCHER_HPP

#include <rclcpp/node.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rmf_utils/impl_ptr.hpp>
#include <rmf_utils/optional.hpp>

#include <rmf_task_ros2/bidding/Auctioneer.hpp>
#include <rmf_task_ros2/TaskStatus.hpp>


namespace rmf_task_ros2 {

//==============================================================================
/// This dispatcher class holds an instance which handles the dispatching of
/// tasks to all downstream RMF fleet adapters.
class Dispatcher : public std::enable_shared_from_this<Dispatcher>
{
public:
using DispatchTasks = std::unordered_map<TaskID, TaskStatusPtr>;
using TaskDescription = rmf_task_msgs::msg::TaskDescription;

/// Initialize an rclcpp context and make an dispatcher instance. This will
/// instantiate an rclcpp::Node, a task dispatcher node. Dispatcher node will
/// allow you to dispatch submitted task to the best fleet/robot within RMF.
///
/// \param[in] dispatcher_node_name
/// The ROS 2 node to manage the Dispatching of Task
///
/// \sa init_and_make_node()
static std::shared_ptr<Dispatcher> init_and_make_node(
const std::string dispatcher_node_name);

/// Similarly this will init the dispatcher, but you will also need to init
/// rclcpp via rclcpp::init(~).
///
/// \param[in] dispatcher_node_name
/// The ROS 2 node to manage the Dispatching of Task
///
/// \sa make_node()
static std::shared_ptr<Dispatcher> make_node(
const std::string dispatcher_node_name);

/// Create a dispatcher by providing the ros2 node
///
/// \param[in] node
/// ROS 2 node instance
///
/// \sa make()
static std::shared_ptr<Dispatcher> make(
const std::shared_ptr<rclcpp::Node>& node);

/// Submit task to dispatcher node. Calling this function will immediately
/// trigger the bidding process, then the task "action". Once submmitted,
/// Task State will be in 'Pending' State, till the task is awarded to a fleet
/// then the state will turn to 'Queued'
///
/// \param [in] task_description
/// Submit a task to dispatch
///
/// \return task_id
/// self-generated task_id, nullopt is submit task failed
std::optional<TaskID> submit_task(
const TaskDescription& task_description);

/// Cancel an active task which was previously submitted to Dispatcher. This
/// will terminate the task with a State of: `Canceled`. If a task is
/// `Queued` or `Executing`, this function will send a cancel req to
/// the respective fleet adapter. It is the responsibility of the fleet adapter
/// to make sure it cancels the task internally.
///
/// \param [in] task_id
/// Task to cancel
///
/// \return true if success
bool cancel_task(const TaskID& task_id);

/// Check the state of a submited task. It can be either active or terminated
///
/// \param [in] task_id
/// task_id obtained from `submit_task()`
///
/// \return State of the task, nullopt if task is not available
const rmf_utils::optional<TaskStatus::State> get_task_state(
const TaskID& task_id) const;

/// Get a mutable ref of active tasks map list handled by dispatcher
const DispatchTasks& active_tasks() const;

/// Get a mutable ref of terminated tasks map list
const DispatchTasks& terminated_tasks() const;

using StatusCallback = std::function<void(const TaskStatusPtr status)>;

/// Trigger this callback when a task status is changed. This will return the
/// Changed task status.
///
/// \param [in] callback function
void on_change(StatusCallback on_change_fn);

/// Change the default evaluator to a custom evaluator, which is used by
/// bidding auctioneer. Default evaluator is: `LeastFleetDiffCostEvaluator`
///
/// \param [in] evaluator
/// evaluator used to select the best bid from fleets
void evaluator(std::shared_ptr<bidding::Auctioneer::Evaluator> evaluator);

/// Get the rclcpp::Node that this dispatcher will be using for communication.
std::shared_ptr<rclcpp::Node> node();

/// spin dispatcher node
void spin();

class Implementation;

private:
Dispatcher();
rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};

} // namespace rmf_task_ros2

#endif // RMF_TASK_ROS2__DISPATCHER_HPP
Loading