SMACC
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cl_move_base_z::PlannerSwitcher Class Reference

#include <planner_switcher.h>

Inheritance diagram for cl_move_base_z::PlannerSwitcher:
Inheritance graph
Collaboration diagram for cl_move_base_z::PlannerSwitcher:
Collaboration graph

Public Member Functions

 PlannerSwitcher ()
 
void setBackwardPlanner ()
 
void setUndoPathBackwardsPlannerConfiguration ()
 
void setUndoPathPureSpinningPlannerConfiguration ()
 
void setForwardPlanner ()
 
void setPureSpinningPlanner ()
 
virtual void onInitialize () override
 
void setDefaultPlanners ()
 
- Public Member Functions inherited from smacc::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Private Member Functions

void updatePlanners (bool subscribecallback=true)
 
void dynreconfCallback (const dynamic_reconfigure::Config::ConstPtr &configuration_update)
 

Private Attributes

std::string desired_global_planner_
 
std::string desired_local_planner_
 
ros::Subscriber dynrecofSub_
 
bool set_planners_mode_flag
 

Additional Inherited Members

- Protected Member Functions inherited from smacc::ISmaccComponent
virtual void initialize (ISmaccClient *owner)
 
void setStateMachine (ISmaccStateMachine *stateMachine)
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
virtual void onInitialize ()
 
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)
 
- Protected Attributes inherited from smacc::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Definition at line 19 of file planner_switcher.h.

Constructor & Destructor Documentation

◆ PlannerSwitcher()

cl_move_base_z::PlannerSwitcher::PlannerSwitcher ( )

Definition at line 12 of file planner_switcher.cpp.

13{
14}

Member Function Documentation

◆ dynreconfCallback()

void cl_move_base_z::PlannerSwitcher::dynreconfCallback ( const dynamic_reconfigure::Config::ConstPtr &  configuration_update)
private

Definition at line 118 of file planner_switcher.cpp.

119{
120 auto gp = std::find_if(configuration_update->strs.begin(), configuration_update->strs.begin(),
121 [&](const dynamic_reconfigure::StrParameter &p) {
122 return p.name == "base_global_planner" && p.value == desired_global_planner_;
123 });
124
125 auto lp = std::find_if(configuration_update->strs.begin(), configuration_update->strs.begin(),
126 [&](const dynamic_reconfigure::StrParameter &p) {
127 return p.name == "base_local_planner" && p.value == desired_local_planner_;
128 });
129
130 if (gp == configuration_update->strs.end() || lp == configuration_update->strs.end())
131 {
132 ROS_INFO("[PlannerSwitcher] After planner update it is noticed an incorrect move_base planner configuration. Resending request.");
134 updatePlanners(false);
135 }
136 else
137 {
138 ROS_INFO("[PlannerSwitcher] Planners correctly configured according to parameter update callback");
140 }
141}
void updatePlanners(bool subscribecallback=true)

References set_planners_mode_flag, and updatePlanners().

Referenced by onInitialize().

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

◆ onInitialize()

void cl_move_base_z::PlannerSwitcher::onInitialize ( )
overridevirtual

Reimplemented from smacc::ISmaccComponent.

Definition at line 16 of file planner_switcher.cpp.

17{
18 auto client_ = dynamic_cast<ClMoveBaseZ *>(owner_);
19 ros::NodeHandle nh(client_->name_);
20 dynrecofSub_ = nh.subscribe<dynamic_reconfigure::Config>("/move_base/parameter_updates", 1, boost::bind(&PlannerSwitcher::dynreconfCallback, this, _1));
21}
void dynreconfCallback(const dynamic_reconfigure::Config::ConstPtr &configuration_update)
ISmaccClient * owner_
Definition: component.h:57

References dynrecofSub_, dynreconfCallback(), and smacc::ISmaccComponent::owner_.

Here is the call graph for this function:

◆ setBackwardPlanner()

void cl_move_base_z::PlannerSwitcher::setBackwardPlanner ( )

Definition at line 39 of file planner_switcher.cpp.

40{
41 ROS_INFO("[PlannerSwitcher] Planner Switcher: Trying to set BackwardPlanner");
42 desired_global_planner_ = "backward_global_planner/BackwardGlobalPlanner";
43 desired_local_planner_ = "backward_local_planner/BackwardLocalPlanner";
45}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Referenced by cl_move_base_z::CbNavigateBackwards::onEntry().

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

◆ setDefaultPlanners()

void cl_move_base_z::PlannerSwitcher::setDefaultPlanners ( )

Definition at line 64 of file planner_switcher.cpp.

65{
66 desired_global_planner_ = "navfn/NavfnROS";
67 desired_local_planner_ = "base_local_planner/TrajectoryPlannerROS";
69}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Referenced by cl_move_base_z::CbNavigateGlobalPosition::onEntry(), cl_move_base_z::CbRotate::onEntry(), and cl_move_base_z::WaypointNavigator::sendNextGoal().

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

◆ setForwardPlanner()

void cl_move_base_z::PlannerSwitcher::setForwardPlanner ( )

Definition at line 47 of file planner_switcher.cpp.

48{
49 ROS_INFO("[PlannerSwitcher] Planner Switcher: Trying to set ForwardPlanner");
50 desired_global_planner_ = "forward_global_planner/ForwardGlobalPlanner";
51 desired_local_planner_ = "forward_local_planner/ForwardLocalPlanner";
53}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Referenced by cl_move_base_z::CbNavigateForward::onEntry().

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

◆ setPureSpinningPlanner()

void cl_move_base_z::PlannerSwitcher::setPureSpinningPlanner ( )

Definition at line 56 of file planner_switcher.cpp.

57{
58 ROS_INFO("[PlannerSwitcher] Planner Switcher: Trying to set PureSpinningPlanner");
59 desired_global_planner_ = "forward_global_planner/ForwardGlobalPlanner";
60 desired_local_planner_ = "pure_spinning_local_planner/PureSpinningLocalPlanner";
62}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Referenced by cl_move_base_z::CbAbsoluteRotate::onEntry().

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

◆ setUndoPathBackwardsPlannerConfiguration()

void cl_move_base_z::PlannerSwitcher::setUndoPathBackwardsPlannerConfiguration ( )

Definition at line 23 of file planner_switcher.cpp.

24{
25 ROS_INFO("[PlannerSwitcher] Planner Switcher: Trying to set BackwardPlanner");
26 desired_global_planner_ = "undo_path_global_planner/UndoPathGlobalPlanner";
27 desired_local_planner_ = "backward_local_planner/BackwardLocalPlanner";
29}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Here is the call graph for this function:

◆ setUndoPathPureSpinningPlannerConfiguration()

void cl_move_base_z::PlannerSwitcher::setUndoPathPureSpinningPlannerConfiguration ( )

Definition at line 31 of file planner_switcher.cpp.

32{
33 ROS_INFO("[PlannerSwitcher] Planner Switcher: Trying to set BackwardPlanner");
34 desired_global_planner_ = "undo_path_global_planner/UndoPathGlobalPlanner";
35 desired_local_planner_ = "pure_spinning_local_planner/PureSpinningLocalPlanner";
37}

References desired_global_planner_, desired_local_planner_, and updatePlanners().

Here is the call graph for this function:

◆ updatePlanners()

void cl_move_base_z::PlannerSwitcher::updatePlanners ( bool  subscribecallback = true)
private

Definition at line 71 of file planner_switcher.cpp.

72{
73 ROS_INFO_STREAM("[PlannerSwitcher] Setting global planner: " << desired_global_planner_);
74 ROS_INFO_STREAM("[PlannerSwitcher] Setting local planner: " << desired_local_planner_);
75
76 dynamic_reconfigure::ReconfigureRequest srv_req;
77 dynamic_reconfigure::ReconfigureResponse srv_resp;
78 dynamic_reconfigure::StrParameter local_planner, global_planner;
79 dynamic_reconfigure::Config conf;
80
81 local_planner.name = "base_local_planner";
82 local_planner.value = desired_local_planner_;
83 conf.strs.push_back(local_planner);
84
85 global_planner.name = "base_global_planner";
86 global_planner.value = desired_global_planner_;
87 conf.strs.push_back(global_planner);
88
89 srv_req.config = conf;
90 ROS_INFO("setting values of the dynamic reconfigure server");
91 bool error;
92 do
93 {
94 bool res = ros::service::call("/move_base/set_parameters", srv_req, srv_resp);
95 ros::spinOnce();
96 ros::Duration(0.5).sleep();
97
98 error = false;
99 auto baselocalPlannerIt = std::find_if(srv_resp.config.strs.begin(), srv_resp.config.strs.end(), [](auto sp){return sp.name == "base_local_planner";});
100 auto baseglobalPlannerIt = std::find_if(srv_resp.config.strs.begin(), srv_resp.config.strs.end(), [](auto sp){return sp.name == "base_global_planner";});
101
102 auto updatedLocalPlanner = baselocalPlannerIt->value;
103 auto updatedGlobalPlanner = baseglobalPlannerIt->value;
104 ROS_INFO_STREAM("[PlannerSwitcher] Selected base local planner: " << updatedLocalPlanner);
105 ROS_INFO_STREAM("[PlannerSwitcher] Selected base global planner: " << updatedGlobalPlanner);
106
107 if(updatedGlobalPlanner != desired_global_planner_ || updatedLocalPlanner!= desired_local_planner_)
108 {
109 ROS_WARN("[PlannerSwitcher] Planners not correctly configured. Waiting 1 second and retrying...");
110 ROS_INFO_STREAM("[PlannerSwitcher] Response: " << srv_resp);
111 error = true;
112 }
113
114 }while(error);
115
116}

References desired_global_planner_, and desired_local_planner_.

Referenced by dynreconfCallback(), setBackwardPlanner(), setDefaultPlanners(), setForwardPlanner(), setPureSpinningPlanner(), setUndoPathBackwardsPlannerConfiguration(), and setUndoPathPureSpinningPlannerConfiguration().

Here is the caller graph for this function:

Member Data Documentation

◆ desired_global_planner_

std::string cl_move_base_z::PlannerSwitcher::desired_global_planner_
private

◆ desired_local_planner_

std::string cl_move_base_z::PlannerSwitcher::desired_local_planner_
private

◆ dynrecofSub_

ros::Subscriber cl_move_base_z::PlannerSwitcher::dynrecofSub_
private

Definition at line 38 of file planner_switcher.h.

Referenced by onInitialize().

◆ set_planners_mode_flag

bool cl_move_base_z::PlannerSwitcher::set_planners_mode_flag
private

Definition at line 39 of file planner_switcher.h.

Referenced by dynreconfCallback().


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