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

Feature: Backup and Restore Fleet Adapters #161

Open
wants to merge 89 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
5944a22
Added skeleton for broadcast client
Yadunund Dec 6, 2021
ae176b5
wip
Yadunund Dec 6, 2021
6231519
Implemented make
Yadunund Dec 7, 2021
43db070
Initialize broadcast client
Yadunund Dec 7, 2021
fb32c33
Debugging
Yadunund Dec 7, 2021
0591869
Cleanup
Yadunund Dec 8, 2021
bfd85a0
Publish fleet_state message
Yadunund Dec 8, 2021
e4bf907
Store broadcast_client within TaskManager
Yadunund Dec 8, 2021
c8e0517
Changes to support rmf_task/redesign_v2
Yadunund Dec 8, 2021
c89e534
Schema validator loader uses internal dictionary
Yadunund Dec 9, 2021
aaf008e
Fixed fleet_state message
Yadunund Dec 9, 2021
a8f6592
Merge branch 'main' into feature/websocket_client
Yadunund Dec 9, 2021
46fe559
Update python binding
Yadunund Dec 9, 2021
129f66b
Publish _update jsons
Yadunund Dec 9, 2021
a274b49
Add helper functions to validate and publish task updates
Yadunund Dec 9, 2021
5becba1
Uncrustify
Yadunund Dec 9, 2021
03de72a
Creating a shim to migrate the legacy task phases to the new system
mxgrey Dec 10, 2021
d62e94c
Implementing the GoToPlace event
mxgrey Dec 14, 2021
1e0bfb9
Finish implementation of GoToPlace and EmergencyPullover
mxgrey Dec 15, 2021
31c095a
Implement delivery
mxgrey Dec 16, 2021
a072869
Finished refactoring to new task system -- need to finish comms imple…
mxgrey Dec 17, 2021
7664c76
Publish task states
mxgrey Dec 20, 2021
0cd4cc0
Continue implementing json updates, fix a subtle bug
mxgrey Dec 21, 2021
2ca24c3
Support battery charging tasks
mxgrey Dec 22, 2021
eea945c
Fix battery charging and deliveries
mxgrey Dec 22, 2021
2855b26
Use Placeholder event instead of WaitFor event
mxgrey Dec 22, 2021
96cc725
Implemented json message handling -- need to finish task change imple…
mxgrey Dec 24, 2021
1d37028
Implemented interrupt and resume -- just a few more commands missing
mxgrey Dec 24, 2021
15f548b
Finished implementation of all task manipulation requests -- needs te…
mxgrey Dec 24, 2021
8c51312
Beginning API for json deserialization
mxgrey Dec 29, 2021
c340558
Remove redundant comparison function
mxgrey Dec 29, 2021
07b8e96
Merged in the latest changes
mxgrey Dec 29, 2021
f854943
Merge branch 'json_deserialize' into redesign_v2
mxgrey Dec 29, 2021
19b93e1
Adding the ability to deserialize json task requests
mxgrey Dec 30, 2021
5ff66e3
Implement deserialization of JSON for task descriptions
mxgrey Dec 31, 2021
42a826e
Finish implementations for delivery and loop
mxgrey Dec 31, 2021
e6e75b4
Fix validator instantiation
mxgrey Dec 31, 2021
e379d8d
Merge branch 'redesign_v2' into json_deserialization
mxgrey Dec 31, 2021
18078c4
Finish implementation of task description deserialization
mxgrey Jan 3, 2022
12ba598
Add a task description schema for Clean
mxgrey Jan 3, 2022
6eb7c29
Remember to publish task log updates
mxgrey Jan 3, 2022
943f62f
Fix websocket fleet state updates
mxgrey Jan 3, 2022
d1ddea3
Merge branch 'redesign_v2' into json_deserialization
mxgrey Jan 3, 2022
7cfff09
Reworking the dispatcher to reduce responsibilities and eliminate cruft
mxgrey Jan 4, 2022
4f43046
Remember to put task_id into task log update
mxgrey Jan 4, 2022
dbbd8df
Merge branch 'redesign_v2' into json_deserialization
mxgrey Jan 5, 2022
750699e
Refactoring dispatch node -- finished Dispatcher class
mxgrey Jan 6, 2022
8eba8cc
Finished migrating the dispatch system -- needs testing
mxgrey Jan 7, 2022
bab1e34
Creating new API for letting users accept tasks
mxgrey Jan 8, 2022
abf79bf
Migrating to new bid notice system
mxgrey Jan 9, 2022
36a2cc2
Finished critical parts of migration -- needs testing
mxgrey Jan 9, 2022
765ed0d
Fixing subtle bugs
mxgrey Jan 9, 2022
1bb3bed
Implement support for composed tasks
mxgrey Jan 10, 2022
acf6aff
Removing support for adding custom tasks -- wait until we can work mo…
mxgrey Jan 10, 2022
3ca614b
Fix stray comma
mxgrey Jan 10, 2022
8ca867a
fix breaking add_fleet() py api change
youliangtan Jan 11, 2022
06a3447
Remove url reserved characters from task_id fields
mxgrey Jan 12, 2022
4baf4f8
Change the task_id format to something a bit nicer
mxgrey Jan 12, 2022
ce8bb9a
Remember to fill in event states
mxgrey Jan 12, 2022
a4fab05
Fix the usage of nlohmann::json
mxgrey Jan 13, 2022
067d8e2
fix json key check error
youliangtan Jan 13, 2022
26f4b39
Fix the use of nlohmann::json
mxgrey Jan 13, 2022
fffb5d6
Merge branch 'redesign_v2' of ssh://github.com/open-rmf/rmf_ros2 into…
mxgrey Jan 13, 2022
cac1959
Adding debug printouts to dispatcher
mxgrey Jan 13, 2022
ede8b53
Desperate debug
mxgrey Jan 13, 2022
acca4ae
Fix usage of json
mxgrey Jan 13, 2022
707aba1
Fix category for legacy clean
Yadunund Jan 13, 2022
50c5982
Wrap json parse in try-catch blocks
Yadunund Jan 13, 2022
d3c4938
Remove debugging cruft
mxgrey Jan 14, 2022
bf03846
Fix merge
mxgrey Jan 14, 2022
6d174d2
fix empty itinerary gotoplace error
youliangtan Jan 20, 2022
d054c32
fix compilation on foxy
youliangtan Jan 21, 2022
10c9a51
Support PerformAction event in composed tasks (#155)
Yadunund Jan 24, 2022
2f41a93
Fix Compose Tasks (#159)
Yadunund Jan 27, 2022
1c33ab9
Add sqlite3 dependency
Yadunund Jan 28, 2022
0a6193c
Fix dispatch response
Yadunund Jan 28, 2022
53b257e
check priority json keys
youliangtan Jan 28, 2022
946e0d7
Merge branch 'redesign_v2' of https://github.com/open-rmf/rmf_ros2 in…
youliangtan Jan 28, 2022
012d51f
WIP
Yadunund Jan 28, 2022
c94b0ad
Update json dependency (#160)
Yadunund Jan 28, 2022
b9e4a70
Added skeleton for DatabaseLogger
Yadunund Jan 28, 2022
1efd68c
Cleanup
Yadunund Jan 31, 2022
7efc506
Feature: Direct Task Assignment (#158)
Yadunund Jan 31, 2022
ed53fe5
Merge branch 'redesign_v2' into backup_and_restore
Yadunund Jan 31, 2022
02475b7
Backup active task
Yadunund Jan 31, 2022
681e416
Tested logging active task and task logs
Yadunund Jan 31, 2022
0947106
Backup dispatch and direct queues
Yadunund Jan 31, 2022
060e88f
Backup task queues
Yadunund Jan 31, 2022
4f0e58c
Update task queue table
Yadunund Jan 31, 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
43 changes: 33 additions & 10 deletions rmf_fleet_adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ set(dep_pkgs
rmf_task_msgs
rmf_traffic
rmf_traffic_ros2
rmf_task_ros2
rmf_battery
rmf_task
rmf_task_sequence
std_msgs
rmf_api_msgs
websocketpp
nlohmann_json
nlohmann_json_schema_validator_vendor
SQLite3
)
foreach(pkg ${dep_pkgs})
find_package(${pkg} REQUIRED)
Expand Down Expand Up @@ -70,21 +77,29 @@ target_link_libraries(rmf_fleet_adapter
rmf_traffic_ros2::rmf_traffic_ros2
rmf_battery::rmf_battery
rmf_task::rmf_task
rmf_task_sequence::rmf_task_sequence
rmf_task_ros2::rmf_task_ros2
yaml-cpp
${rmf_fleet_msgs_LIBRARIES}
${rclcpp_LIBRARIES}
${rmf_task_msgs_LIBRARIES}
PRIVATE
rmf_rxcpp
nlohmann_json::nlohmann_json
rmf_api_msgs::rmf_api_msgs
${rmf_door_msgs_LIBRARIES}
${rmf_lift_msgs_LIBRARIES}
${rmf_dispenser_msgs_LIBRARIES}
${rmf_ingestor_msgs_LIBRARIES}
${websocketpp_LIBRARIES}
nlohmann_json_schema_validator
${SQLite3_LIBRARIES}
)

target_include_directories(rmf_fleet_adapter
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/rmf_api_generate_schema_headers/include> # for auto-generated schema headers
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${rmf_traffic_ros2_INCLUDE_DIRS}
${rmf_fleet_msgs_INCLUDE_DIRS}
Expand All @@ -96,6 +111,10 @@ target_include_directories(rmf_fleet_adapter
${rmf_lift_msgs_INCLUDE_DIRS}
${rmf_dispenser_msgs_INCLUDE_DIRS}
${rmf_ingestor_msgs_INCLUDE_DIRS}
${rmf_api_msgs_INCLUDE_DIRS}
${WEBSOCKETPP_INCLUDE_DIR}
${nlohmann_json_schema_validator_INCLUDE_DIRS}
${SQLite3_INCLUDE_DIRS}
)

if (BUILD_TESTING)
Expand Down Expand Up @@ -130,7 +149,10 @@ if (BUILD_TESTING)
${rmf_lift_msgs_INCLUDE_DIRS}
${rmf_dispenser_msgs_INCLUDE_DIRS}
${rmf_ingestor_msgs_INCLUDE_DIRS}
${rmf_api_msgs_INCLUDE_DIRS}
${std_msgs_INCLUDE_DIRS}
${WEBSOCKETPP_INCLUDE_DIR}
${nlohmann_json_schema_validator_INCLUDE_DIRS}
)
target_link_libraries(test_rmf_fleet_adapter
PRIVATE
Expand All @@ -143,7 +165,10 @@ if (BUILD_TESTING)
${rmf_ingestor_msgs_LIBRARIES}
rmf_fleet_adapter
rmf_utils::rmf_utils
rmf_api_msgs::rmf_api_msgs
${std_msgs_LIBRARIES}
${websocketpp_LIBRARIES}
nlohmann_json_schema_validator
)

target_compile_definitions(test_rmf_fleet_adapter
Expand Down Expand Up @@ -453,17 +478,16 @@ target_include_directories(close_lanes

# -----------------------------------------------------------------------------

ament_export_targets(rmf_fleet_adapter HAS_LIBRARY_TARGET)
ament_export_dependencies(
rmf_task
rmf_traffic_ros2
rmf_fleet_msgs
rmf_door_msgs
rmf_lift_msgs
rmf_ingestor_msgs
rmf_dispenser_msgs
rmf_api_generate_schema_headers(
PACKAGE rmf_fleet_adapter
SCHEMAS_DIR ${CMAKE_CURRENT_LIST_DIR}/schemas
)

# -----------------------------------------------------------------------------

ament_export_targets(rmf_fleet_adapter HAS_LIBRARY_TARGET)
ament_export_dependencies(${dep_pkgs})

install(
TARGETS
rmf_fleet_adapter
Expand Down Expand Up @@ -499,4 +523,3 @@ install(
)

ament_package()

3 changes: 3 additions & 0 deletions rmf_fleet_adapter/include/rmf_fleet_adapter/StandardNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const std::string DockSummaryTopicName = "dock_summary";
const std::string LaneClosureRequestTopicName = "lane_closure_requests";
const std::string ClosedLaneTopicName = "closed_lanes";

const std::string TaskApiRequests = "task_api_requests";
const std::string TaskApiResponses = "task_api_responses";

} // namespace rmf_fleet_adapter

#endif // RMF_FLEET_ADAPTER__STANDARDNAMES_HPP
19 changes: 18 additions & 1 deletion rmf_fleet_adapter/include/rmf_fleet_adapter/agv/Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,27 @@ class Adapter : public std::enable_shared_from_this<Adapter>
///
/// \param[in] navigation_graph
/// Specify the navigation graph used by the vehicles in this fleet.
///
/// \param[in] server_uri
/// Specify the URI for the websocket server that receives updates on tasks
/// and states. If nullopt, data will not be published.
///
/// \param[in] backup_file_path
/// Loads and logs backup data to the specified file. If the file already,
/// exists the fleet handle will be restored to the last backup state. If
/// the file does not exist, a new one will be created.
/// If nullopt, the fleet adapter will not perform any backup/restore.
///
/// TODO(YV): Add this param
/// \param[in] restore_from_backup
/// If true, fleet adapter will be restored to last known backup state.
/// [Not implemented yet]
std::shared_ptr<FleetUpdateHandle> add_fleet(
const std::string& fleet_name,
rmf_traffic::agv::VehicleTraits traits,
rmf_traffic::agv::Graph navigation_graph);
rmf_traffic::agv::Graph navigation_graph,
std::optional<std::string> server_uri = std::nullopt,
std::optional<std::string> backup_file_path = std::nullopt);

/// Create a traffic light to help manage robots that can only support pause
/// and resume commands.
Expand Down
154 changes: 152 additions & 2 deletions rmf_fleet_adapter/include/rmf_fleet_adapter/agv/FleetUpdateHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

#include <rmf_task/RequestFactory.hpp>

#include <nlohmann/json.hpp>
#include <rmf_task/Activator.hpp>
#include <rmf_task_sequence/Phase.hpp>
#include <rmf_task_sequence/Event.hpp>

namespace rmf_fleet_adapter {
namespace agv {

Expand Down Expand Up @@ -70,6 +75,131 @@ class FleetUpdateHandle : public std::enable_shared_from_this<FleetUpdateHandle>
rmf_traffic::agv::Plan::StartSet start,
std::function<void(std::shared_ptr<RobotUpdateHandle> handle)> handle_cb);

/// Confirmation is a class used by the task acceptance callbacks to decide if
/// a task description should be accepted.
class Confirmation
{
public:

/// Constructor
Confirmation();

/// Call this function to decide that you want to accept the task request.
/// If this function is never called, it will be assumed that the task is
/// rejected.
Confirmation& accept();

/// Check whether
bool is_accepted() const;

/// Call this function to bring attention to errors related to the task
/// request. Each call to this function will overwrite any past calls, so
/// it is recommended to only call it once.
Confirmation& errors(std::vector<std::string> error_messages);

/// Call this function to add errors instead of overwriting the ones that
/// were already there.
Confirmation& add_errors(std::vector<std::string> error_messages);

/// Check the errors that have been given to this confirmation.
const std::vector<std::string>& errors() const;

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

/// Signature for a callback that decides whether to accept a specific
/// category of task request.
///
/// \param[in] description
/// A description of the task that is being considered
///
/// \param[in] confirm
/// Use this object to decide if you want to accept the task
using ConsiderRequest =
std::function<void(
const nlohmann::json& description,
Confirmation& confirm)
>;

/// Allow this fleet adapter to consider delivery requests.
///
/// Pass in nullptrs to disable delivery requests.
///
/// By default, delivery requests are not accepted until you provide these
/// callbacks.
///
/// The FleetUpdateHandle will ensure that the requests are feasible for the
/// robots before triggering these callbacks.
///
/// \param[in] consider_pickup
/// Decide whether to accept a pickup request. The description will satisfy
/// the event_description_PickUp.json schema of rmf_fleet_adapter.
///
/// \param[in] consider_dropoff
/// Decide whether to accept a dropoff request. The description will satisfy
/// the event_description_DropOff.json schema of rmf_fleet_adapter.
FleetUpdateHandle& consider_delivery_requests(
ConsiderRequest consider_pickup,
ConsiderRequest consider_dropoff);

/// Allow this fleet adapter to consider cleaning requests.
///
/// Pass in a nullptr to disable cleaning requests.
///
/// By default, cleaning requests are not accepted until you provide this
/// callback.
///
/// \param[in] consider
/// Decide whether to accept a cleaning request. The description will
/// satisfy the event_description_Clean.json schema of rmf_fleet_adapter.
/// The FleetUpdateHandle will ensure that the request is feasible for the
/// robots before triggering this callback.
FleetUpdateHandle& consider_cleaning_requests(ConsiderRequest consider);

/// Allow this fleet adapter to consider patrol requests.
///
/// Pass in a nullptr to disable patrol requests.
///
/// By default, patrol requests are always accepted.
///
/// \param[in] consider
/// Decide whether to accept a patrol request. The description will satisfy
/// the task_description_Patrol.json schema of rmf_fleet_adapter. The
/// FleetUpdateHandle will ensure that the request is feasible for the
/// robots before triggering this callback.
FleetUpdateHandle& consider_patrol_requests(ConsiderRequest consider);

/// Allow this fleet adapter to consider composed requests.
///
/// Pass in a nullptr to disable composed requests.
///
/// By default, composed requests are always accepted, as long as the events
/// that they are composed of are accepted.
///
/// \param[in] consider
/// Decide whether to accept a composed request. The description will
/// satisfy the task_description_Compose.json schema of rmf_fleet_adapter.
/// The FleetUpdateHandle will ensure that the request is feasible for the
/// robots before triggering this callback.
FleetUpdateHandle& consider_composed_requests(ConsiderRequest consider);

/// Allow this fleet adapter to execute a PerformAction activity of specified
/// category which may be present in sequence event.
///
/// \param[in] category
/// A string that categorizes the action. This value should be used when
/// filling out the category field in event_description_PerformAction.json
/// schema.
///
/// \param[in] consider
/// Decide whether to accept the action based on the description field in
/// event_description_PerformAction.json schema.
FleetUpdateHandle& add_performable_action(
const std::string& category,
ConsiderRequest consider);

/// Specify a set of lanes that should be closed.
void close_lanes(std::vector<std::size_t> lane_indices);

Expand Down Expand Up @@ -142,6 +272,7 @@ class FleetUpdateHandle : public std::enable_shared_from_this<FleetUpdateHandle>
/// compatible with the requested payload, pickup, and dropoff behavior
/// settings. The path planning feasibility will be taken care of by the
/// adapter internally.
[[deprecated("Use the consider_..._requests functions instead")]]
FleetUpdateHandle& accept_task_requests(AcceptTaskRequest check);

/// A callback function that evaluates whether a fleet will accept a delivery
Expand All @@ -164,7 +295,7 @@ class FleetUpdateHandle : public std::enable_shared_from_this<FleetUpdateHandle>
/// compatible with the requested payload, pickup, and dropoff behavior
/// settings. The path planning feasibility will be taken care of by the
/// adapter internally.
[[deprecated("Use accept_task_requests() instead")]]
[[deprecated("Use consider_delivery_requests() instead")]]
FleetUpdateHandle& accept_delivery_requests(AcceptDeliveryRequest check);

/// Specify the default value for how high the delay of the current itinerary
Expand All @@ -176,12 +307,31 @@ class FleetUpdateHandle : public std::enable_shared_from_this<FleetUpdateHandle>
/// Get the default value for the maximum acceptable delay.
std::optional<rmf_traffic::Duration> default_maximum_delay() const;

/// The behavior is identical to fleet_state_topic_publish_period
[[deprecated("Use fleet_state_topic_publish_period instead")]]
FleetUpdateHandle& fleet_state_publish_period(
std::optional<rmf_traffic::Duration> value);

/// Specify a period for how often the fleet state message is published for
/// this fleet. Passing in std::nullopt will disable the fleet state message
/// publishing. The default value is 1s.
FleetUpdateHandle& fleet_state_publish_period(
FleetUpdateHandle& fleet_state_topic_publish_period(
std::optional<rmf_traffic::Duration> value);

/// Specify a period for how often the fleet state is updated in the database
/// and to the API server. This is separate from publishing the fleet state
/// over the ROS2 fleet state topic. Passing in std::nullopt will disable
/// the updating, but this is not recommended unless you intend to provide the
/// API server with the fleet states through some other means.
///
/// The default value is 1s.
FleetUpdateHandle& fleet_state_update_period(
std::optional<rmf_traffic::Duration> value);

// Do not allow moving
FleetUpdateHandle(FleetUpdateHandle&&) = delete;
FleetUpdateHandle& operator=(FleetUpdateHandle&&) = delete;

class Implementation;
private:
FleetUpdateHandle();
Expand Down
Loading