Skip to content

Commit

Permalink
Pimplify PhoneNumber. Reuse WaitFor model
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <yadunund@openrobotics.org>
  • Loading branch information
Yadunund committed Jan 5, 2022
2 parents 0be7812 + 9fbd9d4 commit fb34755
Show file tree
Hide file tree
Showing 89 changed files with 4,450 additions and 740 deletions.
20 changes: 11 additions & 9 deletions rmf_task/include/rmf_task/Activator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class Activator
/// Signature for activating a task
///
/// \tparam Description
/// A class that implements the Request::Description interface
/// 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 roboth
/// A reference to the parameters for the robot
///
/// \param[in] booking
/// An immutable reference to the booking information for the task
Expand Down Expand Up @@ -69,7 +69,7 @@ class Activator
using Activate =
std::function<
Task::ActivePtr(
std::function<State()> get_state,
const std::function<State()>& get_state,
const ConstParametersPtr& parameters,
const Task::ConstBookingPtr& booking,
const Description& description,
Expand All @@ -80,7 +80,7 @@ class Activator
std::function<void()> task_finished)
>;

/// Add a callback to convert from a Request into an active Task.
/// Add a callback to convert from a Description into an active Task.
///
/// \tparam Description
/// A class that implements the Request::Description interface
Expand All @@ -90,7 +90,7 @@ class Activator
template<typename Description>
void add_activator(Activate<Description> activator);

/// Activate a Task object based on a Request::Description.
/// Activate a Task object based on a Request.
///
/// \param[in] get_state
/// A callback for retrieving the current state of the robot
Expand All @@ -116,13 +116,13 @@ class Activator
///
/// \return an active, running instance of the requested task.
Task::ActivePtr activate(
std::function<State()> get_state,
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);
std::function<void()> task_finished) const;

/// Restore a Task that crashed or disconnected.
///
Expand Down Expand Up @@ -153,14 +153,14 @@ class Activator
///
/// \return an active, running instance of the requested task.
Task::ActivePtr restore(
std::function<State()> get_state,
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);
std::function<void()> task_finished) const;

class Implementation;
private:
Expand All @@ -173,6 +173,8 @@ class Activator
rmf_utils::impl_ptr<Implementation> _pimpl;
};

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

} // namespace rmf_task

Expand Down
85 changes: 59 additions & 26 deletions rmf_task/include/rmf_task/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ class Event
/// that should not generally be used.
Uninitialized = 0,

/// The event is underway but it has been blocked. The blockage may
/// require manual intervention to fix.
Blocked,

/// An error has occurred that the Task implementation does not know how to
/// deal with. Manual intervention is needed to get the task back on track.
Error,

/// The event cannot ever finish correctly, even with manual intervention.
/// This may mean that the Task cannot be completed if it does not have
/// an automated way to recover from this failure state.
Failed,

/// The event is on standby. It cannot be started yet, and that is its
/// expected status.
Standby,
Expand All @@ -55,14 +68,6 @@ class Event
/// The event is underway but it has been temporarily delayed.
Delayed,

/// The event is underway but it has been blocked. The blockage may
/// require manual intervention to fix.
Blocked,

/// An error has occurred that the Task implementation does not know how to
/// deal with. Manual intervention is needed to get the task back on track.
Error,

/// An operator has instructed this event to be skipped
Skipped,

Expand All @@ -72,37 +77,42 @@ class Event
/// An operator has instructed this event to be killed
Killed,

/// The event cannot ever finish correctly, even with manual intervention.
/// This may mean that the Task cannot be completed if it does not have
/// an automated way to recover from this failure state.
Failed,

/// The event is finished.
Finished
/// The event has completed.
Completed,
};

class Active;
using ConstActivePtr = std::shared_ptr<const Active>;
/// Given the status of two events that are in sequence with each other,
/// return the overall status of the sequence.
static Status sequence_status(Status earlier, Status later);

class State;
using ConstStatePtr = std::shared_ptr<const State>;

class Snapshot;
using ConstSnapshotPtr = std::shared_ptr<const Snapshot>;

class AssignID;
using AssignIDPtr = std::shared_ptr<const AssignID>;
};

//==============================================================================
/// The interface to an active event.
class Event::Active
class Event::State
{
public:

using Status = Event::Status;
using ConstActivePtr = Event::ConstActivePtr;
using ConstStatePtr = Event::ConstStatePtr;

/// The ID of this event, which is unique within its phase
virtual uint64_t id() const = 0;

/// The current Status of this event
virtual Status status() const = 0;

/// Simple wrapper for identifying when an event is finished
inline bool finished() const { return status() == Status::Finished; }
/// A convenience function which returns true if the event's status is any of
/// Skipped, Canceled, Killed, or Completed.
bool finished() const;

/// The "name" of this event. Ideally a short, simple piece of text that
/// helps a human being intuit what this event is expecting at a glance.
Expand All @@ -115,23 +125,26 @@ class Event::Active
virtual Log::View log() const = 0;

/// Get more granular dependencies of this event, if any exist.
virtual std::vector<ConstActivePtr> dependencies() const = 0;
virtual std::vector<ConstStatePtr> dependencies() const = 0;

// Virtual destructor
virtual ~Active() = default;
virtual ~State() = default;
};

//==============================================================================
/// A snapshot of the state of an event. This snapshot can be read while the
/// original event is arbitrarily changed, and there is no risk of a race
/// condition, as long as the snapshot is not being created while the event
/// is changing.
class Event::Snapshot : public Event::Active
class Event::Snapshot : public Event::State
{
public:

/// Make a snapshot of the current state of an Event
static ConstSnapshotPtr make(const Active& other);
static ConstSnapshotPtr make(const State& other);

// Documentation inherited
uint64_t id() const final;

// Documentation inherited
Status status() const final;
Expand All @@ -146,14 +159,34 @@ class Event::Snapshot : public Event::Active
Log::View log() const final;

// Documentation inherited
std::vector<ConstActivePtr> dependencies() const final;
std::vector<ConstStatePtr> dependencies() const final;

class Implementation;
private:
Snapshot();
rmf_utils::impl_ptr<Implementation> _pimpl;
};

//==============================================================================
/// A utility class that helps to assign unique IDs to events
class Event::AssignID
{
public:

/// Make a shared_ptr<AssignID>
static AssignIDPtr make();

/// Constructor
AssignID();

/// Get a new unique ID
uint64_t assign() const;

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

} // namespace rmf_task

#endif // RMF_TASK__EVENT_HPP
6 changes: 6 additions & 0 deletions rmf_task/include/rmf_task/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define RMF_TASK__HEADER_HPP

#include <rmf_traffic/Time.hpp>
#include <rmf_traffic/agv/Graph.hpp>

#include <rmf_utils/impl_ptr.hpp>

Expand Down Expand Up @@ -60,6 +61,11 @@ class Header
rmf_utils::impl_ptr<Implementation> _pimpl;
};

//==============================================================================
std::string standard_waypoint_name(
const rmf_traffic::agv::Graph& graph,
std::size_t waypoint);

} // namespace rmf_task

#endif // RMF_TASK__HEADER_HPP
14 changes: 11 additions & 3 deletions rmf_task/include/rmf_task/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

#include <rmf_utils/impl_ptr.hpp>

#include <chrono>
#include <functional>
#include <memory>
#include <string>

#include <rmf_traffic/Time.hpp>

namespace rmf_task {

class Log;
Expand All @@ -44,7 +45,7 @@ class Log
/// \param[in] clock
/// Specify a clock for this log to use. If nullptr is given, then
/// std::chrono::system_clock::now() will be used.
Log(std::function<std::chrono::system_clock::time_point()> clock = nullptr);
Log(std::function<rmf_traffic::Time()> clock = nullptr);

// TODO(MXG): Should we have a debug log option?

Expand Down Expand Up @@ -96,8 +97,12 @@ class Log::Entry
/// What was the tier of this entry.
Tier tier() const;

/// Sequence number for this log entry. This increments once for each new
/// log entry, until overflowing and wrapping around to 0.
uint32_t seq() const;

/// What was the timestamp of this entry.
std::chrono::system_clock::time_point time() const;
rmf_traffic::Time time() const;

/// What was the text of this entry.
const std::string& text() const;
Expand Down Expand Up @@ -202,6 +207,9 @@ class Log::Reader::Iterable::iterator
/// Equality comparison operator
bool operator==(const iterator& other) const;

/// Inequality comparison operator
bool operator!=(const iterator& other) const;

class Implementation;
private:
iterator();
Expand Down
8 changes: 4 additions & 4 deletions rmf_task/include/rmf_task/Phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ class Phase::Active
virtual ConstTagPtr tag() const = 0;

/// The Event that needs to finish for this phase to be complete
virtual Event::ConstActivePtr final_event() const = 0;
virtual Event::ConstStatePtr final_event() const = 0;

/// The estimated finish time for this phase
virtual rmf_traffic::Time estimate_finish_time() const = 0;
virtual rmf_traffic::Duration estimate_remaining_time() const = 0;

// Virtual destructor
virtual ~Active() = default;
Expand All @@ -136,10 +136,10 @@ class Phase::Snapshot : public Phase::Active
ConstTagPtr tag() const final;

// Documentation inherited
Event::ConstActivePtr final_event() const final;
Event::ConstStatePtr final_event() const final;

// Documentation inherited
rmf_traffic::Time estimate_finish_time() const final;
rmf_traffic::Duration estimate_remaining_time() const final;

class Implementation;
private:
Expand Down
23 changes: 22 additions & 1 deletion rmf_task/include/rmf_task/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ class Task::Description
rmf_traffic::Time earliest_start_time,
const Parameters& parameters) const = 0;

struct Info
{
std::string category;
std::string detail;
};

/// Generate a plain text info description for the task, given the predicted
/// initial state and the task planning parameters.
///
/// \param[in] initial_state
/// The predicted initial state for the task
///
/// \param[in] parameters
/// The task planning parameters
virtual Info generate_info(
const State& initial_state,
const Parameters& parameters) const = 0;

// Virtual destructor
virtual ~Description() = default;
};
Expand All @@ -180,6 +198,9 @@ class Task::Active
/// with the highest sequence number will be kept.
using Backup = detail::Backup;

/// Get a quick overview status of how the task is going
virtual Event::Status status_overview() const = 0;

/// Descriptions of the phases that have been completed
virtual const std::vector<Phase::ConstCompletedPtr>&
completed_phases() const = 0;
Expand All @@ -194,7 +215,7 @@ class Task::Active
virtual const ConstTagPtr& tag() const = 0;

/// Estimate the overall finishing time of the task
virtual rmf_traffic::Time estimate_finish_time() const = 0;
virtual rmf_traffic::Duration estimate_remaining_time() const = 0;

/// Get a backup for this Task
virtual Backup backup() const = 0;
Expand Down
6 changes: 6 additions & 0 deletions rmf_task/include/rmf_task/detail/Resume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <rmf_utils/impl_ptr.hpp>

#include <functional>

namespace rmf_task {
namespace detail {

Expand All @@ -28,6 +30,10 @@ class Resume
{
public:

/// Make a Resume object. The callback will be triggered when the user
/// triggers the Resume.
static Resume make(std::function<void()> callback);

/// Call this object to tell the Task to resume.
void operator()() const;

Expand Down
Loading

0 comments on commit fb34755

Please sign in to comment.