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::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)
 

Private Attributes

std::shared_ptr< tf2_ros::Buffer > listener
 
CpOdomTrackerodomTracker
 
std::optional< CbUndoPathBackwardsOptionsoptions_
 

Additional Inherited Members

- Protected Member Functions inherited from cl_nav2z::CbNav2ZClientBehaviorBase
void sendGoal (nav2_msgs::action::NavigateToPose::Goal &goal)
 
void cancelGoal ()
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationSucceeded (void(T::*callback)(const components::CpNav2ActionInterface::WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationAborted (void(T::*callback)(const components::CpNav2ActionInterface::WrappedResult &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onNavigationCancelled (void(T::*callback)(const components::CpNav2ActionInterface::WrappedResult &), T *object)
 
virtual void onNavigationResult (const components::CpNav2ActionInterface::WrappedResult &)
 
virtual void onNavigationActionSuccess (const components::CpNav2ActionInterface::WrappedResult &)
 
virtual void onNavigationActionAbort (const components::CpNav2ActionInterface::WrappedResult &)
 
- 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
 
smacc2::client_core_components::CpActionClient< nav2_msgs::action::NavigateToPose > * actionClient_ = nullptr
 
rclcpp_action::ResultCode navigationResult_
 

Detailed Description

Definition at line 40 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 listener = std::make_shared<tf2_ros::Buffer>(this->getNode()->get_clock());
42 requiresComponent(odomTracker, ComponentRequirement::HARD);
43
45
46 CpPlannerSwitcher * plannerSwitcher;
47 requiresComponent(plannerSwitcher, ComponentRequirement::HARD);
48
49 nav_msgs::msg::Path forwardpath = odomTracker->getPath();
50 // RCLCPP_INFO_STREAM(getLogger(),"[UndoPathBackward] Current path backwards: " << forwardpath);
51
52 odomTracker->setWorkingMode(WorkingMode::CLEAR_PATH);
53
54 nav2_msgs::action::NavigateToPose::Goal goal;
55
56 CpGoalCheckerSwitcher * goalCheckerSwitcher;
57 requiresComponent(goalCheckerSwitcher, ComponentRequirement::HARD);
58
59 if (forwardpath.poses.size() > 0)
60 {
61 goal.pose = forwardpath.poses.front();
62 goal.pose.header.stamp = rclcpp::Time(0);
63
64 if (options_ && options_->undoControllerName_)
65 {
66 plannerSwitcher->setUndoPathBackwardPlanner(false);
67 RCLCPP_INFO_STREAM(
68 getLogger(),
69 "[" << getName() << "] Undoing path with controller: " << *options_->undoControllerName_);
70 plannerSwitcher->setDesiredController(*options_->undoControllerName_);
71 plannerSwitcher->commitPublish();
72 }
73 else
74 {
75 plannerSwitcher->setUndoPathBackwardPlanner();
76 }
77
78 // WARNING: There might be some race condition with the remote undo global planner/controller were the global path was not
79 // received yet, thee goal switcher
80 // TODO: waiting notification from global planner that it is loaded
81
82 RCLCPP_ERROR_STREAM(
83 getLogger(), "[" << getName()
84 << "] Waiting for 5 seconds to get planer/controller and wait goal checker "
85 "ready");
86
87 RCLCPP_ERROR_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 sendGoal(nav2_msgs::action::NavigateToPose::Goal &goal)
std::shared_ptr< tf2_ros::Buffer > listener
void setWorkingMode(WorkingMode workingMode)
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References cl_nav2z::CpPlannerSwitcher::commitPublish(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), cl_nav2z::odom_tracker::CpOdomTracker::getPath(), listener, cl_nav2z::odom_tracker::CpOdomTracker::logStateString(), odomTracker, options_, smacc2::ISmaccClientBehavior::requiresComponent(), cl_nav2z::CbNav2ZClientBehaviorBase::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::ISmaccClientBehavior.

Definition at line 102 of file cb_undo_path_backwards.cpp.

103{
104 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Exiting: undo navigation ");
105
106 if (this->navigationResult_ == rclcpp_action::ResultCode::SUCCEEDED)
107 {
108 RCLCPP_INFO_STREAM(
109 getLogger(), getName() << " - [CbUndoPathBackwards] Exiting: undo navigation successful, "
110 "popping odom tracker path");
111
112 requiresComponent(odomTracker, ComponentRequirement::HARD);
114
116 }
117 else
118 {
119 RCLCPP_INFO_STREAM(
120 getLogger(), getName() << " - [CbUndoPathBackwards] Exiting: undo navigation abort, avoiding "
121 "popping current path");
122
123 requiresComponent(odomTracker, ComponentRequirement::HARD);
125 // navigation interrupted or aborted. The path may be not totally undone.
126 // We keep the odom tracker in its current state, probably in the middle of the undoing process.
127 // Could you try to repeat the behavior?
128 }
129}
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 smacc2::ISmaccClientBehavior::requiresComponent().

Here is the call graph for this function:

Member Data Documentation

◆ listener

std::shared_ptr<tf2_ros::Buffer> cl_nav2z::CbUndoPathBackwards::listener
private

Definition at line 50 of file cb_undo_path_backwards.hpp.

Referenced by onEntry().

◆ odomTracker

CpOdomTracker* cl_nav2z::CbUndoPathBackwards::odomTracker
private

Definition at line 52 of file cb_undo_path_backwards.hpp.

Referenced by onEntry(), and onExit().

◆ options_

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

Definition at line 54 of file cb_undo_path_backwards.hpp.

Referenced by CbUndoPathBackwards(), and onEntry().


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