Ask Your Question

How to create a Publisher about trajectory path, then show it in rviz?

asked 2018-01-03 02:29:20 -0600

Liuche gravatar image

updated 2018-01-03 21:10:19 -0600

Hi, thank you for your attention.

I am running gmapping_demo with turtlebot.

I want to know how to create a Publisher of the (robot) trajectory path in rviz.

And then I could show it in rviz.

It is not path planning. It's just wnat a line will show after the robot walk through.

Is there any tutorial can teach me?

I actually want to know robot's trajectory (create a Publisher nav_msg/Path topic <--- I'm not sure).

There is a video (Just like the red trajectory path).

I want to do is to show Every time robots walk past

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-01-03 04:28:20 -0600

jayess gravatar image

updated 2018-01-04 03:14:42 -0600

Check out the wiki. It shows you how to add topics to visualize with rviz and much more.

In short, in rviz:

  1. Click "Add" towards the bottom of the "Displays" window.
  2. A new window will pop up with two tabs, click on the tab labeled "By topic".
  3. You will see all the topics that rviz can visualize. Find the topic that you want to visualize, click on it
  4. Click "OK".


So, if I understand your question correctly you want to display the path that your robot is taking. A way to do this is by subscribing to the robot's odometry topic (/odom?) and then take the robot's pose and republish them as a path. Here's a simple script that should be a decent starting point for you.

#!/usr/bin/env python
import rospy

from nav_msgs.msg import Path
from nav_msgs.msg import Odometry
from geometry_msgs.msg import PoseStamped

path = Path()

def odom_cb(data):
    global path
    path.header = data.header
    pose = PoseStamped()
    pose.header = data.header
    pose.pose = data.pose.pose


odom_sub = rospy.Subscriber('/odom', Odometry, odom_cb)
path_pub = rospy.Publisher('/path', Path, queue_size=10)

if __name__ == '__main__':
edit flag offensive delete link more


Thank you for answering!

But I actually want to know how to draw the robot's trajectory (create a topic).

I have not created a topic about trajectory(Path), so I can't subscribe and show it.

Liuche gravatar imageLiuche ( 2018-01-03 05:23:19 -0600 )edit

Well, this did answer your original question.

jayess gravatar imagejayess ( 2018-01-03 11:01:13 -0600 )edit

Yes, but still i don't even have a publisher, so i can't "add" "By topic". I have been looking for a long time. I haven't seen this tutorial yet (sad)

Liuche gravatar imageLiuche ( 2018-01-03 18:58:16 -0600 )edit

What are you trying to? Create an actual path for the robot to navigate a map or just create some arbitrary path to visualize in rviz? We can only give answers that address the information given in a question.

jayess gravatar imagejayess ( 2018-01-03 19:03:54 -0600 )edit

Is such that. Now I using the gmapping_demo package. I can let the robot move around. But I want to record the robot's trajectory. And displayed on Rviz. This is what I want to achieve.

Liuche gravatar imageLiuche ( 2018-01-03 19:19:53 -0600 )edit

In other words, I want to create a topic can record Path message. Then I can subscribe and display it on Rviz.

Liuche gravatar imageLiuche ( 2018-01-03 19:21:34 -0600 )edit

Just like this video show.

Or not to use Nav_msg / Path ?? I'm sorry to bother you, Beginners always have problems

Liuche gravatar imageLiuche ( 2018-01-03 19:23:44 -0600 )edit

So, this not path planning related? You want to visualize where your robot has been using rviz?

jayess gravatar imagejayess ( 2018-01-03 19:27:01 -0600 )edit

answered 2018-01-03 06:32:42 -0600

RDaneelOlivaw gravatar image

updated 2018-01-03 06:34:18 -0600

To complete the answer given , I posted this video tutorial on how to add it and what you should see VIDEO TUTORIAL

Its essentially launching RVIZ, click add , select a Path element , click Add and then fill in the element data. The most important data to fill is the nav_msgs/Path topic. If you have one publishing already it should apear in the drop down menu. Then selet the colour and thats quite it.

Its highly advisable that you add one for the local path planning and another for the global.

Hope it helped.

edit flag offensive delete link more



The OP states that he doesn't even have a publisher for nav_msgs/Path, so this answer (as well as @jayess answer) doesn't answer the question.

Additionally: a new answer + a video of similar steps that @jayess already posted? Was that necessary?

gvdhoorn gravatar imagegvdhoorn ( 2018-01-03 06:39:48 -0600 )edit

Do I remove it then? Though a video showing the process would be interesting, but if it doesnt have any relevance, I'll remove the post, no problem there. Just want best user experience. I'll be waiting for your decision.

RDaneelOlivaw gravatar imageRDaneelOlivaw ( 2018-01-03 06:51:10 -0600 )edit

Yes, just like @gvdhoorn said. I don't even have a publisher for nav_msg/Path.

Until now I still just follow Turtlebot's tutorial. I haven't written a topic by myself about nav_msg / Path.

Hope there is a tutorial can teach me.

Liuche gravatar imageLiuche ( 2018-01-03 06:52:07 -0600 )edit

I'll be waiting for your decision.

It's not my decision. I just wanted to know what your motivation was for posting a new answer + creating an entire video. Which are both essentially duplicates of @jayess' answer. And don't take the feedback from the OP into account.

gvdhoorn gravatar imagegvdhoorn ( 2018-01-03 06:53:18 -0600 )edit

Oh, I just feel that it helps to have a visual tutorial of a question a part from a text based answer. It gives more details.

RDaneelOlivaw gravatar imageRDaneelOlivaw ( 2018-01-03 07:01:03 -0600 )edit

Even then, a comment would have been more appropriate in that case. As-is, your duplicate, incorrect post will be seen first by future readers, simply because it was posted later.

I would recommend you repost the link to your video as a comment, or remove it completely.

gvdhoorn gravatar imagegvdhoorn ( 2018-01-03 08:35:41 -0600 )edit

You are right, the visual tutorial is more helpful for me. It doesn't matter, you don't need to delete it.

But if you have a visual tutorial about create a publisher for nav_msg/Path , it will more helpful.


Liuche gravatar imageLiuche ( 2018-01-03 08:36:08 -0600 )edit

@Liuche: to rectify this situation, please edit your original post to more clearly state what it is that you want to do. Both @jayess and @RDaneelOlivaw's answers are the result of them misunderstanding what you're after.

gvdhoorn gravatar imagegvdhoorn ( 2018-01-03 08:42:00 -0600 )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



Asked: 2018-01-03 02:29:20 -0600

Seen: 6,080 times

Last updated: Jan 04 '18