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 ()
 
virtual ~CpWaypointNavigatorBase ()
 
void onInitialize () override
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
void loadWayPointsFromFile (std::string filepath)
 
void 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)
 
void seekName (std::string name)
 
void loadWaypointsFromYamlParameter (std::string parameter_name, std::string yaml_file_package_name)
 
void notifyGoalReached ()
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Public Attributes

ClNav2Zclient_
 
components::CpNav2ActionInterfacenav2ActionInterface_ = nullptr
 
smacc2::SmaccSignal< void()> onNavigationRequestSucceded
 
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

boost::signals2::connection succeddedNav2ZClientConnection_
 
boost::signals2::connection abortedNav2ZClientConnection_
 
boost::signals2::connection 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 (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 (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachinegetStateMachine ()
 
- 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
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Definition at line 48 of file cp_waypoints_navigator.hpp.

Constructor & Destructor Documentation

◆ CpWaypointNavigator()

cl_nav2z::CpWaypointNavigator::CpWaypointNavigator ( )

Definition at line 44 of file cp_waypoints_navigator.cpp.

44{}

Member Function Documentation

◆ onGoalAborted()

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

Definition at line 61 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 53 of file cp_waypoints_navigator.cpp.

55{
57
59}
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 69 of file cp_waypoints_navigator.cpp.

71{
74 RCLCPP_WARN(
75 getLogger(), "[CpWaypointNavigator] Goal result received, incrementing waypoint index: %ld",
78
79 this->notifyGoalReached();
80
82}
smacc2::SmaccSignal< void()> onNavigationRequestSucceded
rclcpp::Logger getLogger() const

References cl_nav2z::CpWaypointNavigatorBase::currentWaypoint_, smacc2::ISmaccComponent::getLogger(), cl_nav2z::CpWaypointNavigatorBase::notifyGoalReached(), onNavigationRequestSucceded, 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 48 of file cp_waypoints_navigator.cpp.

49{
50 this->requiresComponent(nav2ActionInterface_, ComponentRequirement::HARD);
51}
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 329 of file cp_waypoints_navigator.cpp.

331{
332 if (r.code == rclcpp_action::ResultCode::SUCCEEDED)
333 {
334 this->onGoalReached(r);
335 }
336 else if (r.code == rclcpp_action::ResultCode::ABORTED)
337 {
338 this->onGoalAborted(r);
339 }
340 else if (r.code == rclcpp_action::ResultCode::CANCELED)
341 {
342 this->onGoalCancelled(r);
343 }
344 else
345 {
346 this->onGoalAborted(r);
347 }
348}
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:88
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 200 of file cp_waypoints_navigator.cpp.

201{
202 if (currentWaypoint_ >= 0 && currentWaypoint_ < (int)waypoints_.size())
203 {
204 auto & next = waypoints_[currentWaypoint_];
205
206 std::string nextName;
207 if ((long)waypointsNames_.size() > currentWaypoint_)
208 {
210 RCLCPP_INFO(
211 getLogger(), "[CpWaypointNavigator] sending goal, waypoint: %s", nextName.c_str());
212 }
213 else
214 {
215 RCLCPP_INFO(
216 getLogger(), "[CpWaypointNavigator] sending goal, waypoint: %ld", currentWaypoint_);
217 }
218
219 nav2_msgs::action::NavigateToPose::Goal goal;
220 CpPose * p;
221 this->requiresComponent(p, ComponentRequirement::HARD);
222 auto pose = p->toPoseMsg();
223
224 // configuring goal
225 goal.pose.header.frame_id = p->getReferenceFrame();
226 //goal.pose.header.stamp = getNode()->now();
227 goal.pose.pose = next;
228
229 cl_nav2z::CpPlannerSwitcher * plannerSwitcher;
230 this->requiresComponent(plannerSwitcher, ComponentRequirement::HARD);
231
232 plannerSwitcher->setDefaultPlanners(false);
233 if (options && options->controllerName_)
234 {
235 RCLCPP_WARN(
236 getLogger(), "[WaypointsNavigator] override controller: %s",
237 options->controllerName_->c_str());
238
239 plannerSwitcher->setDesiredController(*options->controllerName_);
240 }
241 else
242 {
243 RCLCPP_WARN(getLogger(), "[WaypointsNavigator] Configuring default planners");
244 }
245
246 cl_nav2z::CpGoalCheckerSwitcher * goalCheckerSwitcher;
247 // this->requiresComponent(goalCheckerSwitcher, ComponentRequirement::HARD);
248 this->requiresComponent(goalCheckerSwitcher, ComponentRequirement::SOFT);
249
250 if (options && options->goalCheckerName_)
251 {
252 RCLCPP_WARN(
253 getLogger(), "[WaypointsNavigator] override goal checker: %s",
254 options->goalCheckerName_->c_str());
255
256 goalCheckerSwitcher->setGoalCheckerId(*options->goalCheckerName_);
257 }
258 else
259 {
260 RCLCPP_WARN(getLogger(), "[WaypointsNavigator] Configuring default goal checker");
261 goalCheckerSwitcher->setGoalCheckerId("goal_checker");
262 }
263
264 plannerSwitcher->commitPublish();
265
266 // publish stuff
267 // rclcpp::sleep_for(5s);
268
269 RCLCPP_INFO(getLogger(), "[WaypointsNavigator] Getting odom tracker");
270
272 requiresComponent(odomTracker, ComponentRequirement::SOFT);
273
274 if (odomTracker != nullptr)
275 {
276 RCLCPP_INFO(getLogger(), "[WaypointsNavigator] Storing path in odom tracker");
277
278 auto pathname = this->owner_->getStateMachine()->getCurrentState()->getName() + " - " +
279 getName() + " - " + nextName;
280 odomTracker->pushPath(pathname);
281 odomTracker->setStartPoint(pose);
283 }
284
285 // SEND GOAL
286 // if (!succeddedNav2ZClientConnection_.connected())
287 // {
288 // this->succeddedNav2ZClientConnection_ =
289 // client_->onSucceeded(&WaypointNavigator::onGoalReached, this);
290 // this->cancelledNav2ZClientConnection_ =
291 // client_->onAborted(&WaypointNavigator::onGoalCancelled, this);
292 // this->abortedNav2ZClientConnection_ =
293 // client_->onCancelled(&WaypointNavigator::onGoalAborted, this);
294 // }
295
296 // Set up navigation result handling
297 if (!succeddedNav2ZClientConnection_.connected())
298 {
305 }
306
307 return nav2ActionInterface_->sendGoal(goal);
308 }
309 else
310 {
311 RCLCPP_WARN(
312 getLogger(),
313 "[CpWaypointsNavigator] All waypoints were consumed. There is no more waypoints available.");
314 }
315
316 return std::nullopt;
317}
void setGoalCheckerId(std::string goal_checker_id)
void setDefaultPlanners(bool commit=true)
std::vector< geometry_msgs::msg::Pose > waypoints_
boost::signals2::connection succeddedNav2ZClientConnection_
boost::signals2::connection abortedNav2ZClientConnection_
boost::signals2::connection cancelledNav2ZClientConnection_
boost::signals2::connection onNavigationCancelled(void(T::*callback)(const WrappedResult &), T *object)
boost::signals2::connection onNavigationSucceeded(void(T::*callback)(const WrappedResult &), T *object)
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal)
boost::signals2::connection onNavigationAborted(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(), succeddedNav2ZClientConnection_, cl_nav2z::CpPose::toPoseMsg(), 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 188 of file cp_waypoints_navigator.cpp.

189{
190 if (succeddedNav2ZClientConnection_.connected())
191 {
192 this->succeddedNav2ZClientConnection_.disconnect();
193 this->cancelledNav2ZClientConnection_.disconnect();
194 this->abortedNav2ZClientConnection_.disconnect();
195 }
196}

References abortedNav2ZClientConnection_, cancelledNav2ZClientConnection_, and succeddedNav2ZClientConnection_.

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

Here is the caller graph for this function:

Member Data Documentation

◆ abortedNav2ZClientConnection_

boost::signals2::connection cl_nav2z::CpWaypointNavigator::abortedNav2ZClientConnection_
private

Definition at line 84 of file cp_waypoints_navigator.hpp.

Referenced by sendNextGoal(), and stopWaitingResult().

◆ cancelledNav2ZClientConnection_

boost::signals2::connection 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_

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().

◆ onNavigationRequestSucceded

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

Definition at line 72 of file cp_waypoints_navigator.hpp.

Referenced by onGoalReached().

◆ succeddedNav2ZClientConnection_

boost::signals2::connection cl_nav2z::CpWaypointNavigator::succeddedNav2ZClientConnection_
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: