ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How can I use GetPlan service in Python ?

asked 2019-08-13 07:21:41 -0500

Dimi gravatar image

updated 2019-08-13 07:22:42 -0500

Hello!

I want to use make_plan service of move_base package in order to create a path towards a specified goal. How am i supposed to deal with this service in Python ?

    start = PoseStamped()
    start.header.seq = 0
    start.header.frame_id = "map"
    start.header.stamp = rospy.Time(0)
    start.pose.position.x = robot_x  #2.6
    start.pose.position.y = robot_y  #1.3

    Goal = PoseStamped()
    Goal.header.seq = 0
    Goal.header.frame_id = "map"
    Goal.header.stamp = rospy.Time(0)
    Goal.pose.position.x = goal_x  #-6.2
    Goal.pose.position.y = goal_y  #-3.0

    srv = GetPlan()
    srv.request.start = start
    srv.request.goal = Goal
    srv.request.tolerance = 1.5

I assume that in this way I can declare the robot's current position(start) and target's coordinates(goal) as presented here. In which way should I initialize the server so that i can obtain the path ? What's the crucial part that I have to add in my code?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-08-13 07:53:40 -0500

ct2034 gravatar image

updated 2019-08-13 10:50:32 -0500

you have to call the service:

get_plan = rospy.ServiceProxy('/move_base/make_plan', nav_msgs.GetPlan)
req = nav_msgs.GetPlan()
req.start = start
req.goal = Goal
req.tolerance = .5
resp = get_plan(req.start, req.goal, req.tolerance)
print(resp)
edit flag offensive delete link more

Comments

1

Thanks, indeed. Just to point out that I need to modify the last line :

resp = get_plan(req)

to :

resp = get_plan(req.start, req.goal, req.tolerance)

otherwise I get an error !

Dimi gravatar image Dimi  ( 2019-08-13 10:40:18 -0500 )edit

I followed ct2304's advice in ros kinetic and it worked also I had to import nav_msgs.srv

LukeBowersox gravatar image LukeBowersox  ( 2020-04-14 14:55:10 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-08-13 07:21:41 -0500

Seen: 1,298 times

Last updated: Aug 13 '19