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

Rosserial/Arduino Publishers and Subscribers

asked 2011-07-19 06:47:58 -0600

UAV gravatar image

updated 2011-07-20 04:59:25 -0600

We have been working with arduino and rosserial, and we were wondering if it is possible to both send and receive information through the arduino so that it can communicate with the computer, instead of only sending information to or receiving information from the computer.

If so, does anyone have an example code we could see to point us in the right direction?


edit retag flag offensive close merge delete


Is there any way to have the publisher outside the void loop?

subarashi gravatar image subarashi  ( 2020-06-29 03:33:24 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2011-07-19 15:40:15 -0600

fergs gravatar image

updated 2011-07-20 05:28:50 -0600

Yes, you can have many publishers and subscribers at the same time -- the current implementation supports up to 25 of each on the Arduino (you'll probably run out of bandwidth before you hit that though).

The following can be found under ros_lib/examples folder as float64_test.pde:

 * rosserial::std_msgs::Float64 Test
 * Receives a Float64 input, subtracts 1.0, and publishes it

#include <ros.h>
#include <std_msgs/Float64.h>

float x; 

ros::NodeHandle nh;

ROS_CALLBACK(messageCb, std_msgs::Float64, msg)
  x = - 1.0;
  digitalWrite(13, HIGH-digitalRead(13));   // blink the led

std_msgs::Float64 test;
ros::Subscriber s("your_topic", &msg, &messageCb);
ros::Publisher p("my_topic", &test);

void setup()
  pinMode(13, OUTPUT);

void loop()
{ = x;
  p.publish( &test );

Here we subscribe to "your_topic", and publish to "my_topic". The publisher publishes at ~100hz, and the value is always the last message received - 1.0.

edit flag offensive delete link more


Thanks! This is very helpful! And on another note, apparently we were way over-thinking this...
UAV gravatar image UAV  ( 2011-07-20 05:37:53 -0600 )edit
Yep, we've tried to make this as easy as possible, while maintaining the feel of roscpp (as much as possible, some limitations on Arduino have forced things like the ROS_CALLBACK macro).
fergs gravatar image fergs  ( 2011-07-21 08:30:11 -0600 )edit

Question Tools

1 follower


Asked: 2011-07-19 06:47:58 -0600

Seen: 12,517 times

Last updated: Jun 29 '20