Ask Your Question
0

How to subscribe to ros_arduino_msgs?

asked 2017-03-08 18:38:12 -0600

mrtechnology1312 gravatar image

I'm using the ROSArduinoBridge to connect an ODROID to an Arduino and I'd like to subscribe to a digital sensor topic that the ROSArduinoBridge is publishing. I can't figure out the C++ syntax to be able to do this. Has anyone ever done this before and would be able to help me figure this out? I've checked the basic ROS Subscriber tutorials and tried to #include "ros_arduino_msgs/Digital.h", but the compiler says it can't find that file and I don't know what it should be. Any help would be appreciated, thanks!

edit retag flag offensive close merge delete

Comments

This should be no different than subscribing to any other topic, provided you have all the right includes set up and your dependencies declared correctly.

Please include your CMakeLists.txt and package.xml and a snippet of code showing your #includes and Subscriber.

gvdhoorn gravatar imagegvdhoorn ( 2017-03-09 01:36:17 -0600 )edit

Thanks for the help! Looks like I had set up the dependencies wrong and I found the correct way after a little searching. I'll post how I did it as an answer.

mrtechnology1312 gravatar imagemrtechnology1312 ( 2017-03-09 11:58:24 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-03-09 12:18:25 -0600

mrtechnology1312 gravatar image

For anyone else who might need to do this:

In CMakeLists.txt I had (among other things):

find_package(catkin REQUIRED COMPONENTS    
  ros_arduino_msgs    
)

In package.xml I added:

<build_depend>ros_arduino_msgs</build_depend>

and

<run_depend>ros_arduino_msgs</run_depend>

And in my C++ file I had (among other things):

#include "ros_arduino_msgs/Digital.h"

int start_val = 0;

void start(const ros_arduino_msgs::DigitalConstPtr& msg) {
    start_val = msg->value;
}

int main(int argc, char * argv[]) {
    ros::init(argc, argv, "test_node");

    ros::NodeHandle nh;
    ros::Subscriber start_sub = nh.subscribe("/arduino/sensor/start_led",1,start);

    while(start_val==0) {
        ros::spinOnce();
    }

    //do other things
}

I was just using this within another program to make sure it didn't start until one of my LED values was 1.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-03-08 18:38:12 -0600

Seen: 132 times

Last updated: Mar 09 '17