SMACC2
Loading...
Searching...
No Matches
cl_nav2z::CbUndoPathBackwards Class Reference

#include <cb_undo_path_backwards.hpp>

Inheritance diagram for cl_nav2z::CbUndoPathBackwards:
Inheritance graph
Collaboration diagram for cl_nav2z::CbUndoPathBackwards:
Collaboration graph

Public Member Functions

 CbUndoPathBackwards (std::optional< CbUndoPathBackwardsOptions > options=std::nullopt)
 
void onEntry () override
 
void onExit () override
 
- Public Member Functions inherited from cl_nav2z::CbNav2ZClientBehaviorBase
virtual ~CbNav2ZClientBehaviorBase ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
- Public Member Functions inherited from smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >
void onStateOrthogonalAllocation ()
 
virtual ~CbActionClientBehaviorBase ()
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 

Private Attributes

CpOdomTrackerodomTracker
 
std::optional< CbUndoPathBackwardsOptionsoptions_
 

Additional Inherited Members

- Public Types inherited from smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >
using Goal
 
using GoalHandle
 
using WrappedResult
 
using Feedback
 
using ActionClientComponent
 
- Protected Member Functions inherited from cl_nav2z::CbNav2ZClientBehaviorBase
virtual void onNavigationActionSuccess (const components::CpNav2ActionInterface::WrappedResult &)
 
virtual void onNavigationActionAbort (const components::CpNav2ActionInterface::WrappedResult &)
 
void onActionSuccess (const WrappedResult &result) override
 
void onActionAbort (const WrappedResult &result) override
 
- Protected Member Functions inherited from smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >
bool sendGoal (Goal &goal)
 
void cancelGoal ()
 
virtual void onActionSuccess (const WrappedResult &result)
 
virtual void onActionAbort (const WrappedResult &result)
 
virtual void onActionFeedback (const Feedback &)
 
void setActionClientName (std::string name)
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
- Protected Attributes inherited from cl_nav2z::CbNav2ZClientBehaviorBase
components::CpNav2ActionInterfacenav2ActionInterface_ = nullptr
 
rclcpp_action::ResultCode navigationResult_ = rclcpp_action::ResultCode::UNKNOWN
 
- Protected Attributes inherited from smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >
ActionClientComponentactionClient_
 
std::string actionClientName_
 
rclcpp_action::ResultCode actionResult_
 
std::chrono::milliseconds goalResponseTimeout_
 

Detailed Description

Definition at line 38 of file cb_undo_path_backwards.hpp.

Constructor & Destructor Documentation

◆ CbUndoPathBackwards()

cl_nav2z::CbUndoPathBackwards::CbUndoPathBackwards ( std::optional< CbUndoPathBackwardsOptions > options = std::nullopt)

Definition at line 34 of file cb_undo_path_backwards.cpp.

35{
36 options_ = options;
37}
std::optional< CbUndoPathBackwardsOptions > options_

References options_.

Member Function Documentation

◆ onEntry()

void cl_nav2z::CbUndoPathBackwards::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 39 of file cb_undo_path_backwards.cpp.

40{
41 requiresComponent(odomTracker, ComponentRequirement::HARD);
42
44
45 CpPlannerSwitcher * plannerSwitcher;
46 requiresComponent(plannerSwitcher, ComponentRequirement::HARD);
47
48 nav_msgs::msg::Path forwardpath = odomTracker->getPath();
49 // RCLCPP_INFO_STREAM(getLogger(),"[UndoPathBackward] Current path backwards: " << forwardpath);
50
51 odomTracker->setWorkingMode(WorkingMode::CLEAR_PATH);
52
53 nav2_msgs::action::NavigateToPose::Goal goal;
54
55 CpGoalCheckerSwitcher * goalCheckerSwitcher;
56 requiresComponent(goalCheckerSwitcher, ComponentRequirement::HARD);
57
58 if (forwardpath.poses.size() > 0)
59 {
60 goal.pose = forwardpath.poses.front();
61 goal.pose.header.stamp = rclcpp::Time(0);
62
63 if (options_ && options_->undoControllerName_)
64 {
65 plannerSwitcher->setUndoPathBackwardPlanner(false);
66 RCLCPP_INFO_STREAM(
67 getLogger(),
68 "[" << getName() << "] Undoing path with controller: " << *options_->undoControllerName_);
69 plannerSwitcher->setDesiredController(*options_->undoControllerName_);
70 plannerSwitcher->commitPublish();
71 }
72 else
73 {
74 plannerSwitcher->setUndoPathBackwardPlanner();
75 }
76
77 // The remote UndoPathGlobalPlanner receives the recorded trail via the
78 // odom_tracker_path topic. Right after a popPath (chained undo) its cache may
79 // still hold the previous, fully-consumed trail - a few poses under the robot -
80 // which would make the goal checker succeed instantly without moving. The
81 // tracker republishes at odom rate (~20-30 Hz), so a short settle guarantees
82 // the planner sees the restored trail before the goal is accepted.
83 // (This runs in the asynchronous onEntry thread: it does not block the state
84 // machine. TODO: replace with an explicit ready handshake from the planner.)
85 rclcpp::sleep_for(std::chrono::milliseconds(500));
86
87 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] activating undo navigation planner");
88
89 if (options_ && options_->goalCheckerId_)
90 {
91 goalCheckerSwitcher->setGoalCheckerId(*options_->goalCheckerId_);
92 }
93 else
94 {
95 goalCheckerSwitcher->setGoalCheckerId("undo_path_backwards_goal_checker");
96 }
97
98 this->sendGoal(goal);
99 }
100}
void setWorkingMode(WorkingMode workingMode)
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References cl_nav2z::CpPlannerSwitcher::commitPublish(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_nav2z::odom_tracker::CpOdomTracker::getPath(), cl_nav2z::odom_tracker::CpOdomTracker::logStateString(), odomTracker, options_, smacc2::ISmaccClientBehavior::requiresComponent(), smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >::sendGoal(), cl_nav2z::CpPlannerSwitcher::setDesiredController(), cl_nav2z::CpGoalCheckerSwitcher::setGoalCheckerId(), cl_nav2z::CpPlannerSwitcher::setUndoPathBackwardPlanner(), and cl_nav2z::odom_tracker::CpOdomTracker::setWorkingMode().

Here is the call graph for this function:

◆ onExit()

void cl_nav2z::CbUndoPathBackwards::onExit ( )
overridevirtual

Reimplemented from smacc2::client_behavior_bases::CbActionClientBehaviorBase< nav2_msgs::action::NavigateToPose >.

Definition at line 102 of file cb_undo_path_backwards.cpp.

103{
104 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Exiting: undo navigation ");
105
106 // NOTE: odomTracker was resolved in onEntry. Do NOT call requiresComponent here:
107 // this method runs in the asynchronous onExit thread while the state machine
108 // thread holds m_mutex_ during state disposal and joins this thread - a
109 // requiresComponent lookup (which locks m_mutex_) deadlocks the state machine.
110 if (this->navigationResult_ == rclcpp_action::ResultCode::SUCCEEDED)
111 {
112 RCLCPP_INFO_STREAM(
113 getLogger(), getName() << " - [CbUndoPathBackwards] Exiting: undo navigation successful, "
114 "popping odom tracker path");
115
118 }
119 else
120 {
121 RCLCPP_INFO_STREAM(
122 getLogger(), getName() << " - [CbUndoPathBackwards] Exiting: undo navigation abort, avoiding "
123 "popping current path");
124
126 // navigation interrupted or aborted. The path may be not totally undone.
127 // We keep the odom tracker in its current state, probably in the middle of the undoing process.
128 // Could you try to repeat the behavior?
129 }
130
131 // Stop consuming the recorded path once the behavior is over: CLEAR_PATH must not
132 // outlive this behavior, otherwise the tracker keeps eating paths recorded by
133 // subsequent behaviors.
134 odomTracker->setWorkingMode(WorkingMode::IDLE);
135}
void popPath(int pathCount=1, bool keepPreviousPath=false)

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_nav2z::odom_tracker::CpOdomTracker::logStateString(), cl_nav2z::CbNav2ZClientBehaviorBase::navigationResult_, odomTracker, cl_nav2z::odom_tracker::CpOdomTracker::popPath(), and cl_nav2z::odom_tracker::CpOdomTracker::setWorkingMode().

Here is the call graph for this function:

Member Data Documentation

◆ odomTracker

CpOdomTracker* cl_nav2z::CbUndoPathBackwards::odomTracker
private

Definition at line 48 of file cb_undo_path_backwards.hpp.

Referenced by onEntry(), and onExit().

◆ options_

std::optional<CbUndoPathBackwardsOptions> cl_nav2z::CbUndoPathBackwards::options_
private

Definition at line 50 of file cb_undo_path_backwards.hpp.

Referenced by CbUndoPathBackwards(), and onEntry().


The documentation for this class was generated from the following files: