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

Victoria_W's profile - activity

2017-10-11 09:16:30 -0500 received badge  Taxonomist
2017-09-21 10:48:23 -0500 received badge  Nice Question (source)
2017-06-20 03:19:37 -0500 received badge  Student (source)
2017-04-24 00:40:57 -0500 received badge  Favorite Question (source)
2016-07-14 01:09:58 -0500 received badge  Famous Question (source)
2016-03-08 06:01:01 -0500 received badge  Famous Question (source)
2016-02-15 06:57:24 -0500 received badge  Notable Question (source)
2015-12-07 07:35:53 -0500 received badge  Notable Question (source)
2015-12-04 06:52:44 -0500 received badge  Popular Question (source)
2015-12-02 08:21:22 -0500 received badge  Supporter (source)
2015-12-02 08:09:51 -0500 received badge  Editor (source)
2015-12-02 08:07:09 -0500 asked a question UDP socket (publishing to topic)

Hello,

I would like to write an UDP socket in C++, which publishes packets (which have been sent to a certain port) to a ros topic. I already studied the ros::TransportUDP Class Reference, and found the function createIncoming(). There is kind of an example code in transport_udp.cpp (line 234-270), but since I am new to UDP and ROS, I am not sure how to create my own socket out of that (libraries I would have to include/initialization/how to adapt the code below/etc.).

Is there anyone who could help? Thanks a lot!

(something for TCP as an orientation would be okay to, but I would prefer UDP since I need to write it for the latter)


The code excerpt from transport_udp.cpp:

00234 bool TransportUDP::createIncoming(int port, bool is_server)
00235 {
00236   is_server_ = is_server;
00237 
00238   sock_ = socket(AF_INET, SOCK_DGRAM, 0);
00239 
00240   if (sock_ <= 0)
00241   {
00242     ROS_ERROR("socket() failed with error [%s]", last_socket_error_string());
00243     return false;
00244   }
00245 
00246   server_address_.sin_family = AF_INET;
00247   server_address_.sin_port = htons(port);
00248   server_address_.sin_addr.s_addr = isOnlyLocalhostAllowed() ? 
00249                                     htonl(INADDR_LOOPBACK) :
00250                                     INADDR_ANY;
00251   if (bind(sock_, (sockaddr *)&server_address_, sizeof(server_address_)) < 0)
00252   {
00253     ROS_ERROR("bind() failed with error [%s]",  last_socket_error_string());
00254     return false;
00255   }
00256 
00257   socklen_t len = sizeof(server_address_);
00258   getsockname(sock_, (sockaddr *)&server_address_, &len);
00259   server_port_ = ntohs(server_address_.sin_port);
00260   ROSCPP_LOG_DEBUG("UDPROS server listening on port [%d]", server_port_);
00261 
00262   if (!initializeSocket())
00263   {
00264     return false;
00265   }
00266 
00267   enableRead();
00268 
00269   return true;
00270 }
2015-12-02 05:27:56 -0500 received badge  Popular Question (source)
2015-12-01 07:59:56 -0500 asked a question Publish to topic from file

Hello,

I am quite new to ROS. I have a logfile (format: .pcapng) and I want to write a node which receives the logged udp-packets (as a simulation; later, the node should receive these packets from a CAN). My problem is the following: I know how to write a subscriber-node, but how can I make the file publishing the packets (as messages) to a topic?

I have read something about ROS bags, but I am not sure whether they are the way to go. I would prefer some kind of programm with which I could play the file, so that I simply had to write the subscriber node.

Thanks!

2015-12-01 07:59:56 -0500 asked a question Publish to topic from a file

Hello,

I am quite new to ROS. I have a logfile (format: .pcapng) and I want to write a node which receives the logged udp-packets (as a simulation; later, the node should receive these packets from a CAN). My problem is the following: I know how to write a subscriber-node, but how can I make the file publishing the packets (as messages) to a topic?

I have read something about ROS bags, but I am not sure whether they are the way to go. I would prefer some kind of programm with which I could play the file, so that I simply had to write the subscriber node.

Thanks!