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

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

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

Liuche gravatar image

updated 2022-03-04 06:26:10 -0500

lucasw gravatar image

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
5

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

jayess gravatar image

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

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".

Update:

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
    path.poses.append(pose)
    path_pub.publish(path)

rospy.init_node('path_node')

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

if __name__ == '__main__':
    rospy.spin()
edit flag offensive delete link more

Comments

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 image Liuche  ( 2018-01-03 05:23:19 -0500 )edit

Well, this did answer your original question.

jayess gravatar image jayess  ( 2018-01-03 11:01:13 -0500 )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 image Liuche  ( 2018-01-03 18:58:16 -0500 )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 image jayess  ( 2018-01-03 19:03:54 -0500 )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 image Liuche  ( 2018-01-03 19:19:53 -0500 )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 image Liuche  ( 2018-01-03 19:21:34 -0500 )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 image Liuche  ( 2018-01-03 19:23:44 -0500 )edit

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

jayess gravatar image jayess  ( 2018-01-03 19:27:01 -0500 )edit

Actually, No. I only want to show robot's route. I already visualize my robot, now I try to visualize its Walking route

There is no way to add pictures here. No way to express the problem well. (Sad)

Liuche gravatar image Liuche  ( 2018-01-03 19:30:12 -0500 )edit

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

Liuche gravatar image Liuche  ( 2018-01-03 19:44:21 -0500 )edit

@jayess YES!!!!!
That's what I want. But rospy.init_node('path_node') should put a little in front,or it's will show ERROR message Just the line is too thin.

it's thank you so much. !!! This made me learn more.

Liuche gravatar image Liuche  ( 2018-01-04 01:32:24 -0500 )edit
1

@Liuche: it's good to know how things work. You might also be interested in the answer(s) to #q209224, especially hector_trajectory_server.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-04 02:10:20 -0500 )edit

@gvdhoom I did see this article. But because I'm not using Hector. So I did not quite understand how it worked. jayess's method helped me a lot.

Liuche gravatar image Liuche  ( 2018-01-04 03:01:34 -0500 )edit

The pkg can be used completely stand-alone.

As I wrote: it's good to first know how things work, but in the end you might want to use an already existing solution (for the obvious reasons).

gvdhoorn gravatar image gvdhoorn  ( 2018-01-04 03:03:10 -0500 )edit

This is, at best, a toy example just to learn how it works and not something that you'd want to use for anything serious. But, as @gvdhoorn stated, there are preexisting packages that you can use.

jayess gravatar image jayess  ( 2018-01-04 03:17:19 -0500 )edit

It has helped me a lot, though it looks simple, thank you all!!!!

Liuche gravatar image Liuche  ( 2018-01-04 05:49:29 -0500 )edit

Sorry to bring it up again. I saw your youtube video tutorial. It's helpful.But is there any way to set the path on once I startup the rviz, (just like the /odom or /map, are already there once I startup, no need to add extra topic)

CHIN gravatar image CHIN  ( 2019-01-30 22:57:10 -0500 )edit
1

I didn't make a video, but to save a configuration in RViz click on "File" then "Save Config" or just press Ctrl+s. See the RViz user guide for more information.

jayess gravatar image jayess  ( 2019-01-30 23:12:59 -0500 )edit

Opps ,sorry about that,(embarassed) But thank you very much for answering it!

CHIN gravatar image CHIN  ( 2019-02-01 00:33:38 -0500 )edit

Nothing to be embarrassed about

jayess gravatar image jayess  ( 2019-02-01 00:48:42 -0500 )edit
1

Thanks, this really helps.

lochlomond gravatar image lochlomond  ( 2019-08-20 22:42:23 -0500 )edit
0

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

RDaneelOlivaw gravatar image

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

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

Comments

2

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 image gvdhoorn  ( 2018-01-03 06:39:48 -0500 )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 image RDaneelOlivaw  ( 2018-01-03 06:51:10 -0500 )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 image Liuche  ( 2018-01-03 06:52:07 -0500 )edit
1

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 image gvdhoorn  ( 2018-01-03 06:53:18 -0500 )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 image RDaneelOlivaw  ( 2018-01-03 07:01:03 -0500 )edit
1

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 image gvdhoorn  ( 2018-01-03 08:35:41 -0500 )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.

Thanks!!

Liuche gravatar image Liuche  ( 2018-01-03 08:36:08 -0500 )edit
2

@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 image gvdhoorn  ( 2018-01-03 08:42:00 -0500 )edit

Question Tools

6 followers

Stats

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

Seen: 17,284 times

Last updated: Jan 04 '18