Ask Your Question
0

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
1

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 imageDimi ( 2019-08-13 10:40:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 19 times

Last updated: Aug 13