Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible task definitions #39

Merged
merged 88 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
29f3b8c
Remove agv namespace and introduce CompositeData
mxgrey Sep 1, 2021
2ea66b5
Redesign State to be composable
mxgrey Sep 2, 2021
b181017
Defining task execution interfaces
mxgrey Sep 2, 2021
096ae8a
Adding a task logging interface
mxgrey Sep 3, 2021
86c3c13
Drafting the interfaces for phase sequence tasks
mxgrey Sep 3, 2021
e00b02c
Satisfy uncrustify
mxgrey Sep 3, 2021
7a7d7d3
Draft interface for Task Factory
mxgrey Sep 3, 2021
15aac52
Rework the design, improve consistency
mxgrey Sep 6, 2021
873693a
Satisfy uncrustify
mxgrey Sep 6, 2021
67f9398
Beginning to implement GoToPlace::Description
mxgrey Sep 6, 2021
68f2fda
Redesigning travel estimation cache
mxgrey Sep 7, 2021
1707f4f
Redesigning travel estimation
mxgrey Sep 7, 2021
45d62a6
Prototyping PickUp phase
mxgrey Sep 8, 2021
81380c8
Finish implementation of PickUp and begin API of DropOff
mxgrey Sep 9, 2021
21054b9
Implementing DropOff phase
mxgrey Sep 10, 2021
3b83b5d
Reorganizing
mxgrey Sep 10, 2021
7c31994
More reorganization
mxgrey Sep 10, 2021
9103c90
Gradually ironing out the transition to the reorganization
mxgrey Sep 10, 2021
66777a8
Continuing implementation of phase sequence task
mxgrey Sep 11, 2021
820cc33
Thinking about how to implement backups for phase sequence tasks
mxgrey Sep 13, 2021
5e14e82
Work reactive backup callbacks into the system
mxgrey Sep 13, 2021
e330d36
Creating minimal example of task activation
mxgrey Sep 13, 2021
d2911aa
Create minimal example of task restoring
mxgrey Sep 14, 2021
3505ac0
Use derived class implementation of backup
mxgrey Sep 14, 2021
724eb0a
Finish comment
mxgrey Sep 14, 2021
ecbe258
Creating an integration test to guide the implementation of backups
mxgrey Sep 14, 2021
37830d5
Move backups test into integration folder
mxgrey Sep 14, 2021
56c1f40
Continuing to implement backup and restore for phase sequence tasks
mxgrey Sep 23, 2021
ed651ae
Finished backup/restore implementation -- needs testing
mxgrey Sep 24, 2021
e1c2d51
Implementing phase activator
mxgrey Sep 24, 2021
3995281
Migrating to JSON and json-schema
mxgrey Oct 6, 2021
e2116b0
Fix header guards and begin schema header template
mxgrey Oct 6, 2021
8c2844f
Working on the generation of schema headers
mxgrey Oct 7, 2021
0615abf
Update transitive dependency
mxgrey Oct 7, 2021
973b387
Merge branch 'redesign_v2' of ssh://github.com/open-rmf/rmf_task into…
mxgrey Oct 7, 2021
05b4754
Able to generate schemas
mxgrey Oct 7, 2021
d730e02
Reimplement backups using json
mxgrey Oct 7, 2021
ae6c0c7
Include original message in error log
mxgrey Oct 11, 2021
d744b63
Put active phase snapshots into completed phases
mxgrey Oct 12, 2021
eab243b
Iterating on RestoreBackup phase
mxgrey Oct 13, 2021
cc329cf
Implement backup file manager (#41)
cnboonhan Oct 14, 2021
76ec880
Fix merge conflicts
mxgrey Oct 14, 2021
a7b3bc4
Rename Condition to Event
mxgrey Oct 14, 2021
7aee6bc
Introducing VersionedString and using it for event names + details
mxgrey Oct 15, 2021
fbb2160
Implementing the SimpleEvent class
mxgrey Oct 15, 2021
f1d3f62
Migrate to using the RestoreBackup phase
mxgrey Oct 18, 2021
6b46765
Abstracting Phase and Event interfaces into Activity
mxgrey Oct 18, 2021
cfb1e90
Finish refactoring to introduce Activity class namespace
mxgrey Oct 20, 2021
0611526
Remove the GoToPlace phase in favor of GoToPlace event
mxgrey Oct 20, 2021
d19c7ad
Remember to include <string>
mxgrey Oct 21, 2021
7d8db73
Use a const reference for pending tasks
mxgrey Oct 21, 2021
11831e0
Remember to include <string> pt. 2
mxgrey Oct 21, 2021
c720ffb
Refactoring Event to State, Standby, and Active, and implementing Eve…
mxgrey Nov 1, 2021
390f5a4
Implementing Event Sequence Standby
mxgrey Nov 1, 2021
54765af
Implementing the Event Sequence class
mxgrey Nov 3, 2021
036867b
Define the schema for event sequence backups
mxgrey Nov 3, 2021
eaf95ea
Finished implementing event sequence
mxgrey Nov 6, 2021
56ec2a2
Refactoring Sequence into a more generic Bundle
mxgrey Nov 6, 2021
cb5619c
Migrating schema header generation to rmf_api_msgs
mxgrey Nov 10, 2021
df57b7f
Add some conceptual sample schemas for task descriptions
mxgrey Nov 10, 2021
a0e39f7
Move schemas into subdirectory
mxgrey Nov 24, 2021
2108d42
Merge branch 'redesign_v2_task_schemas' into redesign_v2_Bundle
mxgrey Nov 24, 2021
3610da5
tweaks
mxgrey Nov 30, 2021
10fd78a
Refactor Sequence into Bundle
mxgrey Dec 7, 2021
2314e14
Filling in implementation gaps and beginning task sequence test
mxgrey Dec 8, 2021
1dd1659
Fix implementation bugs and begin unit tests for task sequences
mxgrey Dec 9, 2021
d11032e
Allow event bundles to be activated from a vector of Standbys
mxgrey Dec 14, 2021
cc8bf3d
Allow users to directly create Bundle Standbys, not Actives
mxgrey Dec 14, 2021
7420e52
Implement unfolding for tasks and events
mxgrey Dec 16, 2021
9842bd9
Remember to include implementation header
mxgrey Dec 16, 2021
0112e25
Make activate and restore const
mxgrey Dec 17, 2021
070e864
Add sequence numbers to logs and fix log iteration
mxgrey Dec 20, 2021
3aef75f
Add plain text info for task descriptions
mxgrey Dec 21, 2021
416503d
Handle cases with no ambient drain
mxgrey Dec 22, 2021
f05dda0
Create a Placeholder event to help eliminate boilerplate
mxgrey Dec 22, 2021
9fbd9d4
Fix circular reference
mxgrey Dec 31, 2021
113b671
Return more specific Clean Description
mxgrey Jan 9, 2022
c6b9ed4
fix empty itinerary duration
youliangtan Jan 18, 2022
c4d17fb
PerformAction Event Description (#49)
Yadunund Jan 20, 2022
dc4bbdb
nit rosdep json pkg name
youliangtan Jan 26, 2022
b783c18
Fix segfaults with PerformAction (#51)
Yadunund Jan 27, 2022
8195e4b
Use ament_uncrustify
Yadunund Jan 28, 2022
75b5f93
compile tests (#52)
xiyuoh Jan 28, 2022
ec67d50
Report the active phase's start time
mxgrey Feb 10, 2022
a895149
Merge branch 'main' into redesign_v2
mxgrey Feb 12, 2022
a8f63f0
Update repos
mxgrey Feb 12, 2022
a9b6ec6
Merge branch 'redesign_v2' of ssh://github.com/open-rmf/rmf_task into…
mxgrey Feb 12, 2022
956cf5b
Satisfy uncrustify
mxgrey Feb 12, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build
on:
on:
push:
pull_request:
schedule:
Expand All @@ -22,7 +22,7 @@ jobs:
package-name: |
rmf_task
vcs-repo-file-url: |
https://raw.githubusercontent.com/open-rmf/rmf/main/rmf.repos
https://raw.githubusercontent.com/open-rmf/rmf/redesign_v2/rmf.repos
colcon-defaults: |
{
"build": {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tsan.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tsan
on:
on:
pull_request:
schedule:
- cron: '31 0 * * *'
Expand All @@ -23,9 +23,9 @@ jobs:
target-ros2-distro: foxy
# build all packages listed in the meta package
package-name: |
rmf_task
rmf_task
vcs-repo-file-url: |
https://raw.githubusercontent.com/open-rmf/rmf/main/rmf.repos
https://raw.githubusercontent.com/open-rmf/rmf/redesign_v2/rmf.repos
colcon-defaults: |
{
"build": {
Expand Down
5 changes: 1 addition & 4 deletions rmf_task/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ find_package(ament_cmake_catch2 QUIET)
find_package(ament_cmake_uncrustify QUIET)

# ===== RMF Tasks library
file(GLOB lib_srcs
"src/rmf_task/agv/*.cpp"
"src/rmf_task/requests/*.cpp"
"src/rmf_task/requests/factory/*.cpp"
file(GLOB_RECURSE lib_srcs
"src/rmf_task/*.cpp"
)

Expand Down
183 changes: 183 additions & 0 deletions rmf_task/include/rmf_task/Activator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Copyright (C) 2021 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__ACTIVATOR_HPP
#define RMF_TASK__ACTIVATOR_HPP

#include <rmf_task/Request.hpp>

namespace rmf_task {

//==============================================================================
/// A factory for generating Task::Active instances from requests.
class Activator
{
public:

/// Construct an empty TaskFactory
Activator();

/// Signature for activating a task
///
/// \tparam Description
/// A class that implements the Task::Description interface
///
/// \param[in] get_state
/// A callback for retrieving the current state of the robot
///
/// \param[in] parameters
/// A reference to the parameters for the robot
///
/// \param[in] booking
/// An immutable reference to the booking information for the task
///
/// \param[in] description
/// The down-casted description of the task
///
/// \param[in] backup_state
/// The serialized backup state of the Task, if the Task is being restored
/// from a crash or disconnection. If the Task is not being restored, a
/// std::nullopt will be passed in here.
///
/// \param[in] update
Yadunund marked this conversation as resolved.
Show resolved Hide resolved
/// A callback that will be triggered when the task has a significant
/// update in its status.
///
/// \param[in] checkpoint
/// A callback that will be triggered when the task has reached a task
/// checkpoint whose state is worth backing up.
///
Copy link
Member

Choose a reason for hiding this comment

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

Missing documentation for phase_finished . Also \param below should be task_finished?

/// \param[in] finished
/// A callback that will be triggered when the task has finished.
///
/// \return an active, running instance of the requested task.
template<typename Description>
using Activate =
std::function<
Task::ActivePtr(
const std::function<State()>& get_state,
const ConstParametersPtr& parameters,
const Task::ConstBookingPtr& booking,
const Description& description,
std::optional<std::string> backup_state,
std::function<void(Phase::ConstSnapshotPtr)> update,
std::function<void(Task::Active::Backup)> checkpoint,
std::function<void(Phase::ConstCompletedPtr)> phase_finished,
std::function<void()> task_finished)
>;

/// Add a callback to convert from a Description into an active Task.
///
/// \tparam Description
/// A class that implements the Request::Description interface
///
/// \param[in] activator
/// A callback that activates a Task matching the Description
template<typename Description>
void add_activator(Activate<Description> activator);

/// Activate a Task object based on a Request.
///
/// \param[in] get_state
/// A callback for retrieving the current state of the robot
///
/// \param[in] parameters
/// A reference to the parameters for the robot
///
/// \param[in] request
/// The task request
///
/// \param[in] update
/// A callback that will be triggered when the task has a significant update
///
/// \param[in] checkpoint
/// A callback that will be triggered when the task has reached a task
/// checkpoint whose state is worth backing up.
///
/// \param[in] phase_finished
/// A callback that will be triggered whenever a task phase is finished
///
/// \param[in] task_finished
/// A callback that will be triggered when the task has finished
///
/// \return an active, running instance of the requested task.
Task::ActivePtr activate(
const std::function<State()>& get_state,
const ConstParametersPtr& parameters,
const Request& request,
std::function<void(Phase::ConstSnapshotPtr)> update,
std::function<void(Task::Active::Backup)> checkpoint,
std::function<void(Phase::ConstCompletedPtr)> phase_finished,
std::function<void()> task_finished) const;

/// Restore a Task that crashed or disconnected.
///
/// \param[in] get_state
/// A callback for retrieving the current state of the robot
///
/// \param[in] parameters
/// A reference to the parameters for the robot
///
/// \param[in] request
/// The task request
///
/// \param[in] backup_state
/// The serialized backup state of the Task
///
/// \param[in] update
/// A callback that will be triggered when the task has a significant update
///
/// \param[in] checkpoint
/// A callback that will be triggered when the task has reached a task
/// checkpoint whose state is worth backing up.
///
/// \param[in] phase_finished
/// A callback that will be triggered whenever a task phase is finished
///
/// \param[in] task_finished
/// A callback that will be triggered when the task has finished
///
/// \return an active, running instance of the requested task.
Task::ActivePtr restore(
const std::function<State()>& get_state,
const ConstParametersPtr& parameters,
const Request& request,
std::string backup_state,
std::function<void(Phase::ConstSnapshotPtr)> update,
std::function<void(Task::Active::Backup)> checkpoint,
std::function<void(Phase::ConstCompletedPtr)> phase_finished,
std::function<void()> task_finished) const;

class Implementation;
private:

/// \private
void _add_activator(
std::type_index type,
Activate<Task::Description> activator);

rmf_utils::impl_ptr<Implementation> _pimpl;
};

using ActivatorPtr = std::shared_ptr<Activator>;
using ConstActivatorPtr = std::shared_ptr<const Activator>;

} // namespace rmf_task

#include <rmf_task/detail/impl_Activator.hpp>

#endif // RMF_TASK__ACTIVATOR_HPP
109 changes: 109 additions & 0 deletions rmf_task/include/rmf_task/BackupFileManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2021 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__BACKUPFILEMANAGER_HPP
#define RMF_TASK__BACKUPFILEMANAGER_HPP

#include <rmf_task/Task.hpp>

#include <filesystem>

namespace rmf_task {

//==============================================================================
class BackupFileManager
{
public:

class Group;
class Robot;

/// Construct a BackupFileManager
///
/// \param[in] root_directory
/// Specify the root directory that the backup files should live in
BackupFileManager(std::filesystem::path root_directory,
std::function<void(std::string)> info_logger = nullptr,
std::function<void(std::string)> debug_logger = nullptr);

/// Set whether any previously existing backups should be cleared out on
/// startup. By default this behavior is turned OFF.
///
/// \param[in] value
/// True if the behavior should be turned on; false if it should be turned
/// off.
BackupFileManager& clear_on_startup(bool value = true);

/// Set whether any currently existing backups should be cleared out on
/// shutdown. By default this behavior is turned ON.
///
/// \param[in] value
/// True if the behavior should be turned on; false if it should be turned
/// off.
BackupFileManager& clear_on_shutdown(bool value = true);

/// Make a group (a.k.a. fleet) to back up.
std::shared_ptr<Group> make_group(std::string name);

class Implementation;
private:
rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};

//==============================================================================
class BackupFileManager::Group
{
public:

/// Make a handle to backup a robot for this group
///
/// \param[in] name
/// The unique name of the robot that's being backed up
std::shared_ptr<Robot> make_robot(std::string name);

// TODO(MXG): Add an API for saving the task assignments of the Group. When
// the Group is constructed/destructed, it should clear out those task
// assignments, according to the RAII settings of its parent BackupFileManager
// instance.

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

//==============================================================================
class BackupFileManager::Robot
{
public:

/// Read a backup state from file if a backup file exists for this robot.
/// If a backup does not exist, return a nullopt.
std::optional<std::string> read() const;

/// Write a backup to file
void write(const Task::Active::Backup& backup);

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

} // namespace rmf_task

#endif // RMF_TASK__BACKUPFILEMANAGER_HPP
Loading