Ask Your Question
2

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?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
7

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 = msg.data - 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);
  nh.initNode();
  nh.advertise(p);
  nh.subscribe(s);
}

void loop()
{
  test.data = x;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

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

Comments

Thanks! This is very helpful! And on another note, apparently we were way over-thinking this...
UAV gravatar imageUAV ( 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 imagefergs ( 2011-07-21 08:30:11 -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

1 follower

Stats

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

Seen: 9,117 times

Last updated: Jul 20 '11