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

#include <cp_waypoints_navigator.hpp>

Inheritance diagram for cl_nav2z::CpWaypointNavigator:
Inheritance graph
Collaboration diagram for cl_nav2z::CpWaypointNavigator:
Collaboration graph

Public Member Functions

 CpWaypointNavigator ()
 
void onInitialize () override
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
std::optional< std::shared_future< std::shared_ptr< rclcpp_action::ClientGoalHandle< nav2_msgs::action::NavigateToPose > > > > sendNextGoal (std::optional< NavigateNextWaypointOptions > options=std::nullopt)
 
void stopWaitingResult ()
 
- Public Member Functions inherited from cl_nav2z::CpWaypointNavigatorBase
 CpWaypointNavigatorBase ()
 
 ~CpWaypointNavigatorBase () override
 
void onInitialize () override
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
bool loadWayPointsFromFile (std::string filepath)
 
bool loadWayPointsFromFile2 (std::string filepath)
 
void setWaypoints (const std::vector< geometry_msgs::msg::Pose > &waypoints)
 
void setWaypoints (const std::vector< Pose2D > &waypoints)
 
const std::vector< geometry_msgs::msg::Pose > & getWaypoints () const
 
const std::vector< std::string > & getWaypointNames () const
 
std::optional< geometry_msgs::msg::Pose > getNamedPose (std::string name) const
 
geometry_msgs::msg::Pose getPose (int index) const
 
geometry_msgs::msg::Pose getCurrentPose () const
 
long getCurrentWaypointIndex () const
 
std::optional< std::string > getCurrentWaypointName () const
 
void rewind (int count)
 
void forward (int count)
 
bool seekName (std::string name)
 
bool loadWaypointsFromYamlParameter (std::string parameter_name, std::string yaml_file_package_name)
 
void notifyGoalReached ()
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
virtual std::string getName () const
 

Public Attributes

ClNav2Z * client_ = nullptr
 
components::CpNav2ActionInterface * nav2ActionInterface_ = nullptr
 
smacc2::SmaccSignal< void()> onNavigationRequestSucceeded_
 
smacc2::SmaccSignal< void()> onNavigationRequestAborted_
 
smacc2::SmaccSignal< void()> onNavigationRequestCancelled_
 
- Public Attributes inherited from cl_nav2z::CpWaypointNavigatorBase
WaypointEventDispatcher waypointsEventDispatcher
 
long currentWaypoint_
 

Private Member Functions

void onNavigationResult (const components::CpNav2ActionInterface::WrappedResult &r)
 
void onGoalReached (const components::CpNav2ActionInterface::WrappedResult &res)
 
void onGoalCancelled (const components::CpNav2ActionInterface::WrappedResult &)
 
void onGoalAborted (const components::CpNav2ActionInterface::WrappedResult &)
 

Private Attributes

smacc2::SmaccSignalConnection succeededNav2ZClientConnection_
 
smacc2::SmaccSignalConnection abortedNav2ZClientConnection_
 
smacc2::SmaccSignalConnection cancelledNav2ZClientConnection_
 

Additional Inherited Members

- Protected Member Functions inherited from cl_nav2z::CpWaypointNavigatorBase
void insertWaypoint (int index, geometry_msgs::msg::Pose &newpose)
 
void removeWaypoint (int index)
 
- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (const std::string &name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Attributes inherited from cl_nav2z::CpWaypointNavigatorBase
std::vector< geometry_msgs::msg::Pose > waypoints_
 
std::vector< std::string > waypointsNames_
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

Detailed Description

Definition at line 48 of file cp_waypoints_navigator.hpp.

Constructor & Destructor Documentation

◆ CpWaypointNavigator()

cl_nav2z::CpWaypointNavigator::CpWaypointNavigator ( )

Definition at line 45 of file cp_waypoints_navigator.cpp.

45{}

Member Function Documentation

◆ onGoalAborted()

void cl_nav2z::CpWaypointNavigator::onGoalAborted ( const components::CpNav2ActionInterface::WrappedResult & )
private

Definition at line 62 of file cp_waypoints_navigator.cpp.

References onNavigationRequestAborted_, and stopWaitingResult().

Referenced by onNavigationResult(), and sendNextGoal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onGoalCancelled()

void cl_nav2z::CpWaypointNavigator::onGoalCancelled ( const components::CpNav2ActionInterface::WrappedResult & )
private

Definition at line 54 of file cp_waypoints_navigator.cpp.

56{
58
60}
smacc2::SmaccSignal< void()> onNavigationRequestCancelled_

References onNavigationRequestCancelled_, and stopWaitingResult().

Referenced by onNavigationResult(), and sendNextGoal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onGoalReached()

void cl_nav2z::CpWaypointNavigator::onGoalReached ( const components::CpNav2ActionInterface::WrappedResult & res)
private

Definition at line 70 of file cp_waypoints_navigator.cpp.

72{
74 // asks whether the waypoint just reached is the last one, so before the index moves on
75 this->notifyGoalReached();
77 RCLCPP_WARN(
78 getLogger(), "[CpWaypointNavigator] Goal result received, incrementing waypoint index: %ld",
81
83}
smacc2::SmaccSignal< void()> onNavigationRequestSucceeded_
rclcpp::Logger getLogger() const

References cl_nav2z::CpWaypointNavigatorBase::currentWaypoint_, smacc2::ISmaccComponent::getLogger(), cl_nav2z::CpWaypointNavigatorBase::notifyGoalReached(), onNavigationRequestSucceeded_, WaypointEventDispatcher::postWaypointEvent(), stopWaitingResult(), and cl_nav2z::CpWaypointNavigatorBase::waypointsEventDispatcher.

Referenced by onNavigationResult(), and sendNextGoal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

void cl_nav2z::CpWaypointNavigator::onInitialize ( )
overridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 49 of file cp_waypoints_navigator.cpp.

50{
51 this->requiresComponent(nav2ActionInterface_, ComponentRequirement::HARD);
52}
components::CpNav2ActionInterface * nav2ActionInterface_
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References nav2ActionInterface_, and smacc2::ISmaccComponent::requiresComponent().

Here is the call graph for this function:

◆ onNavigationResult()

void cl_nav2z::CpWaypointNavigator::onNavigationResult ( const components::CpNav2ActionInterface::WrappedResult & r)
private

Definition at line 296 of file cp_waypoints_navigator.cpp.

298{
299 if (r.code == rclcpp_action::ResultCode::SUCCEEDED)
300 {
301 this->onGoalReached(r);
302 }
303 else if (r.code == rclcpp_action::ResultCode::CANCELED)
304 {
305 this->onGoalCancelled(r);
306 }
307 else
308 {
309 // ABORTED, and UNKNOWN treated the same way.
310 this->onGoalAborted(r);
311 }
312}
void onGoalReached(const components::CpNav2ActionInterface::WrappedResult &res)
void onGoalAborted(const components::CpNav2ActionInterface::WrappedResult &)
void onGoalCancelled(const components::CpNav2ActionInterface::WrappedResult &)

References onGoalAborted(), onGoalCancelled(), and onGoalReached().

Here is the call graph for this function:

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void cl_nav2z::CpWaypointNavigator::onStateOrthogonalAllocation ( )
inline

Definition at line 59 of file cp_waypoints_navigator.hpp.

60 {
61 client_ = dynamic_cast<ClNav2Z *>(owner_);
62 waypointsEventDispatcher.initialize<TSourceObject, TOrthogonal>(client_);
63 this->requiresComponent(nav2ActionInterface_, ComponentRequirement::HARD);
64 }
ISmaccClient * owner_
Definition component.hpp:96
namespace cl_nav2z class ClNav2Z

References client_, WaypointEventDispatcher::initialize(), smacc2::ISmaccComponent::owner_, smacc2::ISmaccComponent::requiresComponent(), and cl_nav2z::CpWaypointNavigatorBase::waypointsEventDispatcher.

Here is the call graph for this function:

◆ sendNextGoal()

std::optional< std::shared_future< std::shared_ptr< rclcpp_action::ClientGoalHandle< nav2_msgs::action::NavigateToPose > > > > cl_nav2z::CpWaypointNavigator::sendNextGoal ( std::optional< NavigateNextWaypointOptions > options = std::nullopt)

Definition at line 178 of file cp_waypoints_navigator.cpp.

179{
180 if (currentWaypoint_ >= 0 && currentWaypoint_ < (int)waypoints_.size())
181 {
182 const auto & next = waypoints_[currentWaypoint_];
183
184 const std::string & nextName = waypointsNames_[currentWaypoint_];
185 if (!nextName.empty())
186 {
187 RCLCPP_INFO(
188 getLogger(), "[CpWaypointNavigator] sending goal, waypoint: %s", nextName.c_str());
189 }
190 else
191 {
192 RCLCPP_INFO(
193 getLogger(), "[CpWaypointNavigator] sending goal, waypoint: %ld", currentWaypoint_);
194 }
195
196 nav2_msgs::action::NavigateToPose::Goal goal;
197 CpPose * p = nullptr;
198 this->requiresComponent(p, ComponentRequirement::HARD);
199
200 // configuring goal
201 goal.pose.header.frame_id = p->getReferenceFrame();
202 goal.pose.pose = next;
203
204 cl_nav2z::CpPlannerSwitcher * plannerSwitcher = nullptr;
205 this->requiresComponent(plannerSwitcher, ComponentRequirement::HARD);
206
207 plannerSwitcher->setDefaultPlanners(false);
208 if (options && options->controllerName_)
209 {
210 RCLCPP_WARN(
211 getLogger(), "[WaypointsNavigator] override controller: %s",
212 options->controllerName_->c_str());
213
214 plannerSwitcher->setDesiredController(*options->controllerName_);
215 }
216 else
217 {
218 RCLCPP_WARN(getLogger(), "[WaypointsNavigator] Configuring default planners");
219 }
220
221 cl_nav2z::CpGoalCheckerSwitcher * goalCheckerSwitcher = nullptr;
222 this->requiresComponent(goalCheckerSwitcher, ComponentRequirement::SOFT);
223
224 if (goalCheckerSwitcher == nullptr)
225 {
226 RCLCPP_WARN(
227 getLogger(), "[WaypointsNavigator] no CpGoalCheckerSwitcher; goal checker left as is");
228 }
229 else if (options && options->goalCheckerName_)
230 {
231 RCLCPP_WARN(
232 getLogger(), "[WaypointsNavigator] override goal checker: %s",
233 options->goalCheckerName_->c_str());
234
235 goalCheckerSwitcher->setGoalCheckerId(*options->goalCheckerName_);
236 }
237 else
238 {
239 RCLCPP_WARN(getLogger(), "[WaypointsNavigator] Configuring default goal checker");
240 goalCheckerSwitcher->setGoalCheckerId("goal_checker");
241 }
242
243 plannerSwitcher->commitPublish();
244
245 RCLCPP_INFO(getLogger(), "[WaypointsNavigator] Getting odom tracker");
246
247 cl_nav2z::odom_tracker::CpOdomTracker * odomTracker = nullptr;
248 requiresComponent(odomTracker, ComponentRequirement::SOFT);
249
250 if (odomTracker != nullptr)
251 {
252 RCLCPP_INFO(getLogger(), "[WaypointsNavigator] Storing path in odom tracker");
253
254 auto pathname = this->owner_->getStateMachine()->getCurrentState()->getName() + " - " +
255 getName() + " - " + nextName;
256 odomTracker->pushPath(pathname);
257 // Stamped pose: the bare-Pose overload would mislabel these map-frame
258 // coordinates with the odom frame (see cb_navigate_global_position.cpp)
259 odomTracker->setStartPoint(p->toPoseStampedMsg());
261 }
262
263 // Set up navigation result handling
264 if (!succeededNav2ZClientConnection_.connected())
265 {
272 }
273
274 return nav2ActionInterface_->sendGoal(goal);
275 }
276 else
277 {
278 RCLCPP_WARN(
279 getLogger(),
280 "[CpWaypointsNavigator] All waypoints were consumed. There is no more waypoints available.");
281 }
282
283 return std::nullopt;
284}
void setGoalCheckerId(std::string goal_checker_id)
void setDefaultPlanners(bool commit=true)
std::vector< geometry_msgs::msg::Pose > waypoints_
smacc2::SmaccSignalConnection succeededNav2ZClientConnection_
smacc2::SmaccSignalConnection cancelledNav2ZClientConnection_
smacc2::SmaccSignalConnection abortedNav2ZClientConnection_
smacc2::SmaccSignalConnection onNavigationSucceeded(void(T::*callback)(const WrappedResult &), T *object)
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal)
smacc2::SmaccSignalConnection onNavigationAborted(void(T::*callback)(const WrappedResult &), T *object)
smacc2::SmaccSignalConnection onNavigationCancelled(void(T::*callback)(const WrappedResult &), T *object)
void setWorkingMode(WorkingMode workingMode)
void setStartPoint(const geometry_msgs::msg::PoseStamped &pose)
ISmaccStateMachine * getStateMachine()
virtual std::string getName() const
virtual std::string getName()=0

References abortedNav2ZClientConnection_, cancelledNav2ZClientConnection_, cl_nav2z::CpPlannerSwitcher::commitPublish(), cl_nav2z::CpWaypointNavigatorBase::currentWaypoint_, smacc2::ISmaccStateMachine::getCurrentState(), smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::ISmaccState::getName(), cl_nav2z::CpPose::getReferenceFrame(), smacc2::ISmaccClient::getStateMachine(), nav2ActionInterface_, onGoalAborted(), onGoalCancelled(), onGoalReached(), cl_nav2z::components::CpNav2ActionInterface::onNavigationAborted(), cl_nav2z::components::CpNav2ActionInterface::onNavigationCancelled(), cl_nav2z::components::CpNav2ActionInterface::onNavigationSucceeded(), smacc2::ISmaccComponent::owner_, cl_nav2z::odom_tracker::CpOdomTracker::pushPath(), cl_nav2z::odom_tracker::RECORD_PATH, smacc2::ISmaccComponent::requiresComponent(), cl_nav2z::components::CpNav2ActionInterface::sendGoal(), cl_nav2z::CpPlannerSwitcher::setDefaultPlanners(), cl_nav2z::CpPlannerSwitcher::setDesiredController(), cl_nav2z::CpGoalCheckerSwitcher::setGoalCheckerId(), cl_nav2z::odom_tracker::CpOdomTracker::setStartPoint(), cl_nav2z::odom_tracker::CpOdomTracker::setWorkingMode(), succeededNav2ZClientConnection_, cl_nav2z::CpPose::toPoseStampedMsg(), cl_nav2z::CpWaypointNavigatorBase::waypoints_, and cl_nav2z::CpWaypointNavigatorBase::waypointsNames_.

Referenced by cl_nav2z::CbNavigateNextWaypoint::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopWaitingResult()

void cl_nav2z::CpWaypointNavigator::stopWaitingResult ( )

Definition at line 166 of file cp_waypoints_navigator.cpp.

167{
168 if (succeededNav2ZClientConnection_.connected())
169 {
170 this->succeededNav2ZClientConnection_.disconnect();
171 this->cancelledNav2ZClientConnection_.disconnect();
172 this->abortedNav2ZClientConnection_.disconnect();
173 }
174}

References abortedNav2ZClientConnection_, cancelledNav2ZClientConnection_, and succeededNav2ZClientConnection_.

Referenced by cl_nav2z::CbNavigateNextWaypoint::onExit(), onGoalAborted(), onGoalCancelled(), and onGoalReached().

Here is the caller graph for this function:

Member Data Documentation

◆ abortedNav2ZClientConnection_

smacc2::SmaccSignalConnection cl_nav2z::CpWaypointNavigator::abortedNav2ZClientConnection_
private

Definition at line 84 of file cp_waypoints_navigator.hpp.

Referenced by sendNextGoal(), and stopWaitingResult().

◆ cancelledNav2ZClientConnection_

smacc2::SmaccSignalConnection cl_nav2z::CpWaypointNavigator::cancelledNav2ZClientConnection_
private

Definition at line 85 of file cp_waypoints_navigator.hpp.

Referenced by sendNextGoal(), and stopWaitingResult().

◆ client_

ClNav2Z* cl_nav2z::CpWaypointNavigator::client_ = nullptr

Definition at line 51 of file cp_waypoints_navigator.hpp.

Referenced by onStateOrthogonalAllocation().

◆ nav2ActionInterface_

components::CpNav2ActionInterface* cl_nav2z::CpWaypointNavigator::nav2ActionInterface_ = nullptr

Definition at line 52 of file cp_waypoints_navigator.hpp.

Referenced by onInitialize(), and sendNextGoal().

◆ onNavigationRequestAborted_

smacc2::SmaccSignal<void()> cl_nav2z::CpWaypointNavigator::onNavigationRequestAborted_

Definition at line 73 of file cp_waypoints_navigator.hpp.

Referenced by onGoalAborted().

◆ onNavigationRequestCancelled_

smacc2::SmaccSignal<void()> cl_nav2z::CpWaypointNavigator::onNavigationRequestCancelled_

Definition at line 74 of file cp_waypoints_navigator.hpp.

Referenced by onGoalCancelled().

◆ onNavigationRequestSucceeded_

smacc2::SmaccSignal<void()> cl_nav2z::CpWaypointNavigator::onNavigationRequestSucceeded_

Definition at line 72 of file cp_waypoints_navigator.hpp.

Referenced by onGoalReached().

◆ succeededNav2ZClientConnection_

smacc2::SmaccSignalConnection cl_nav2z::CpWaypointNavigator::succeededNav2ZClientConnection_
private

Definition at line 83 of file cp_waypoints_navigator.hpp.

Referenced by sendNextGoal(), and stopWaitingResult().


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