move_base_legacy_relay.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @author Jorge Santos
4 # License: 3-Clause BSD
5 
6 import actionlib
7 import copy
8 
9 import rospy
10 import nav_msgs.srv as nav_srvs
11 import mbf_msgs.msg as mbf_msgs
12 import move_base_msgs.msg as mb_msgs
13 from dynamic_reconfigure.client import Client
14 from dynamic_reconfigure.server import Server
15 from geometry_msgs.msg import PoseStamped
16 from move_base.cfg import MoveBaseConfig
17 
18 
19 """
20 move_base legacy relay node:
21 Relays old move_base actions to the new mbf move_base action, similar but with richer result and feedback.
22 We also relay the simple goal topic published by RViz, the make_plan service and dynamic reconfiguration
23 calls (note that some parameters have changed names; see http://wiki.ros.org/move_base_flex for details)
24 """
25 
26 # keep configured base local and global planners to send to MBF
27 bgp = None
28 blp = None
29 
30 
31 def simple_goal_cb(msg):
32  mbf_mb_ac.send_goal(mbf_msgs.MoveBaseGoal(target_pose=msg, planner=bgp, controller=blp))
33  rospy.logdebug("Relaying move_base_simple/goal pose to mbf")
34 
35 
36 def mb_execute_cb(msg):
37  mbf_mb_ac.send_goal(mbf_msgs.MoveBaseGoal(target_pose=msg.target_pose, planner=bgp, controller=blp),
38  feedback_cb=mbf_feedback_cb)
39  rospy.logdebug("Relaying legacy move_base goal to mbf")
40  mbf_mb_ac.wait_for_result()
41 
42  status = mbf_mb_ac.get_state()
43  result = mbf_mb_ac.get_result()
44 
45  rospy.logdebug("MBF execution completed with result [%d]: %s", result.outcome, result.message)
46  if result.outcome == mbf_msgs.MoveBaseResult.SUCCESS:
47  mb_as.set_succeeded(mb_msgs.MoveBaseResult(), "Goal reached.")
48  else:
49  mb_as.set_aborted(mb_msgs.MoveBaseResult(), result.message)
50 
51 
52 def make_plan_cb(request):
53  mbf_gp_ac.send_goal(mbf_msgs.GetPathGoal(start_pose=request.start, target_pose=request.goal,
54  use_start_pose=bool(request.start.header.frame_id),
55  planner=bgp, tolerance=request.tolerance))
56  rospy.logdebug("Relaying legacy make_plan service to mbf get_path action server")
57  mbf_gp_ac.wait_for_result()
58 
59  status = mbf_gp_ac.get_state()
60  result = mbf_gp_ac.get_result()
61 
62  rospy.logdebug("MBF get_path execution completed with result [%d]: %s", result.outcome, result.message)
63  if result.outcome == mbf_msgs.GetPathResult.SUCCESS:
64  return nav_srvs.GetPlanResponse(plan=result.path)
65 
66 
67 def mbf_feedback_cb(feedback):
68  mb_as.publish_feedback(mb_msgs.MoveBaseFeedback(base_position=feedback.current_pose))
69 
70 
71 def mb_reconf_cb(config, level):
72  rospy.logdebug("Relaying legacy move_base reconfigure request to mbf")
73 
74  if not hasattr(mb_reconf_cb, "default_config"):
75  mb_reconf_cb.default_config = copy.deepcopy(config)
76 
77  if config.get('restore_defaults'):
78  config = mb_reconf_cb.default_config
79 
80  mbf_config = copy.deepcopy(config)
81 
82  # Map move_base legacy parameters to new mbf ones, and drop those not supported
83  # mbf doesn't allow changing plugins dynamically, but we can provide them in the
84  # action goal, so we keep both base_local_planner and base_global_planner
85  if 'base_local_planner' in mbf_config:
86  global blp
87  blp = mbf_config.pop('base_local_planner')
88  if 'controller_frequency' in mbf_config:
89  mbf_config['controller_frequency'] = mbf_config.pop('controller_frequency')
90  if 'controller_patience' in mbf_config:
91  mbf_config['controller_patience'] = mbf_config.pop('controller_patience')
92  if 'max_controller_retries' in mbf_config:
93  mbf_config['controller_max_retries'] = mbf_config.pop('max_controller_retries')
94  if 'base_global_planner' in mbf_config:
95  global bgp
96  bgp = mbf_config.pop('base_global_planner')
97  if 'planner_frequency' in mbf_config:
98  mbf_config['planner_frequency'] = mbf_config.pop('planner_frequency')
99  if 'planner_patience' in mbf_config:
100  mbf_config['planner_patience'] = mbf_config.pop('planner_patience')
101  if 'max_planning_retries' in mbf_config:
102  mbf_config['planner_max_retries'] = mbf_config.pop('max_planning_retries')
103  if 'recovery_behavior_enabled' in mbf_config:
104  mbf_config['recovery_enabled'] = mbf_config.pop('recovery_behavior_enabled')
105  if 'conservative_reset_dist' in mbf_config:
106  mbf_config.pop('conservative_reset_dist') # no mbf equivalent for this!
107  if 'clearing_rotation_allowed' in mbf_config:
108  mbf_config.pop('clearing_rotation_allowed') # no mbf equivalent for this!
109  if 'make_plan_add_unreachable_goal' in mbf_config:
110  mbf_config.pop('make_plan_add_unreachable_goal') # no mbf equivalent for this!
111  if 'make_plan_clear_costmap' in mbf_config:
112  mbf_config.pop('make_plan_clear_costmap') # no mbf equivalent for this!
113  mbf_drc.update_configuration(mbf_config)
114  return config
115 
116 
117 if __name__ == '__main__':
118  rospy.init_node("move_base")
119 
120  # TODO what happens with malformed target goal??? FAILURE or INVALID_POSE
121  # txt must be: "Aborting on goal because it was sent with an invalid quaternion"
122 
123  # move_base_flex get_path and move_base action clients
124  mbf_mb_ac = actionlib.SimpleActionClient("move_base_flex/move_base", mbf_msgs.MoveBaseAction)
125  mbf_gp_ac = actionlib.SimpleActionClient("move_base_flex/get_path", mbf_msgs.GetPathAction)
126  mbf_mb_ac.wait_for_server(rospy.Duration(20))
127  mbf_gp_ac.wait_for_server(rospy.Duration(10))
128 
129  # move_base_flex dynamic reconfigure client
130  mbf_drc = Client("move_base_flex", timeout=10)
131 
132  # move_base simple topic and action server
133  mb_sg = rospy.Subscriber('move_base_simple/goal', PoseStamped, simple_goal_cb)
134  mb_as = actionlib.SimpleActionServer('move_base', mb_msgs.MoveBaseAction, mb_execute_cb, auto_start=False)
135  mb_as.start()
136 
137  # move_base make_plan service
138  mb_mps = rospy.Service('~make_plan', nav_srvs.GetPlan, make_plan_cb)
139 
140  # move_base dynamic reconfigure server
141  mb_drs = Server(MoveBaseConfig, mb_reconf_cb)
142 
143  rospy.spin()
def mb_reconf_cb(config, level)


mbf_costmap_nav
Author(s): Sebastian Pütz
autogenerated on Fri Nov 6 2020 03:56:29