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

How to define new topic in UWSIM?

asked 2015-04-13 08:41:41 -0500

User_810 gravatar image

I want to add a topic through which two vehicles can communicate with each other. Currently, the vehicles communicate to ROS and vice-versa. I want the vehicles to communicate with each other. I tried to create my own example code and put it along other examples present, but I was not able to compile it. I just want to pass timestamp from one vehicle to another. Can someone please tell me where should I start? I saw timestamp information is already included in standard message header. But I don’t know where to define my topic. Should it be in RosInterface.cpp? And how do I add my own cpp code for testing?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-04-13 09:02:08 -0500

aak2166 gravatar image

ROS is designed so that communication between nodes, regardless of where they are running, happens through the ROS master.

I'm not familiar with UWSIM, but if it's a sim that just has ROS plugins the following architecture is pretty standard: You can write your nodes so that each robot has a publisher and subscriber.

When you initialize a publisher or subscriber with a topic:

ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

That topic is created and the ROS master handles all communication to it. In this case the topic is called chatter. Aside from writing the publisher/subscriber nodes there are no additional steps to take when you want a topic created.

So, for each simulated robot you would have a node that handles outbound communication through a publisher and inbound through a subscriber. If your robots are called rob_one and rob_two, then their publishers can publish on topics: rob_one_timestamp and rob_two_timestamp, respectively. Then rob_one's subscriber can subscribe to rob_two_timestamp and vice versa.

It's a bit tough without seeing some of your code, and your CMakeLists.txt to understand why it isn't compiling.

edit flag offensive delete link more

answered 2015-04-13 09:47:37 -0500

Javier Perez gravatar image


as aak21566 said, you just need to create a publisher and subscriber between the two robots. You don't need to modify UWSim at all, as UWSim uses ROS as middleware to publish sensor readings and subscribe to orders. So I guess what you need is to create your own ROS nodes for each vehicle which can communicate with UWSim and between them.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-13 08:41:41 -0500

Seen: 259 times

Last updated: Apr 13 '15