Ask Your Question
1

How to read sensor from rosserial [closed]

asked 2013-12-24 09:51:26 -0600

richkappler gravatar image

updated 2013-12-26 16:06:11 -0600

tfoote gravatar image

I think this might be more of a publishing question, but here goes. I'm working through the ROS tutorials ( have done with almost all of them) and am attempting to work through the rosserial tutorials now, but modified for the equipment I have, to wit, and HCSR04 ultrasonic rangefinder attached to an Arduino Mega ADK. I know the board and sensor work, I can see the data in the Arduino serial monitor. I modified the Arduino code from this tutorial: IR Ranger Tutorial

to this:

[code] #include <ros.h> #include <ros time.h=""> #include <sensor_msgs range.h=""> #include <ultrasonic.h>

ros::NodeHandle nh;

sensor_msgs::Range range_msg; ros::Publisher pub_range( "range_data", &range_msg);

#define TRIGGER_PIN 48 #define ECHO_PIN 49

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

unsigned long range_timer;

char frameid[] = "/ultrasonic_ranger"; // creates a global variable for // sensors frame id string. It is // important to make this string // global so it will be alive for // as long as the message is in use

void setup() { nh.initNode(); nh.advertise(pub_range);

range_msg.radiation_type = sensor_msgs::Range::ULTRASOUND; range_msg.header.frame_id = frameid; range_msg.field_of_view = 0.2; range_msg.min_range = 0.0; range_msg.max_range = 10.0;

}

void loop() { float inMsec; long microsec = ultrasonic.timing();

inMsec = ultrasonic.convert(microsec, Ultrasonic::IN); // publish the range value every 50 milliseconds // since it takes that long for the sensor to stabilize if ( (millis()-range_timer) > 50){ range_msg.range = inMsec; range_msg.header.stamp = nh.now(); pub_range.publish(&range_msg); range_timer = millis() + 50; } nh.spinOnce(); } [/code]

It compiled and loaded fine. I'll admit, I'm pretty experienced at Arduino, reasonably proficient at code in general, particularly python, some C++.

My problem is I don't know what command to issue in ROS to read what this sensor is publishing to ROS. I think in particular I am still unclear about what the message name is that this is publishing. I've tried range_msg, pub_range, just not quite sure what I'm doing, still very new at ROS and would appreciate a nudge in the right direction.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by richkappler
close date 2013-12-28 08:06:48

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-12-24 17:17:53 -0600

You have to run the rosserial_python serial_node.py PORT and it will automatically start publishing the data which is called /range_data.

edit flag offensive delete link more

Comments

Yeah, got that part, did all that, roscore running, serial_node running. rqt_plot returns nothing.

richkappler gravatar imagerichkappler ( 2013-12-24 18:42:17 -0600 )edit
1

Did you try rostopic echo?

tonybaltovski gravatar imagetonybaltovski ( 2013-12-25 05:18:27 -0600 )edit

Yes, it's a buffer issue and it told me the topic hadn't published yet. Of note, it says the buffer size is 512 bytes and avr-size tells me I'm using close to 2500. Now I need to figure out how to change the buffer size. Digging through the archives now, thanks for the help!

richkappler gravatar imagerichkappler ( 2013-12-26 06:05:58 -0600 )edit
2

Sorry for patronizing you but it would of helped if you posted the errors you were getting. Do you have any delay between publishing? Constantly publishing without any delay will full up the buffer very quickly. You can change the buffer in ros.h but I do not recommend that since you will over full

tonybaltovski gravatar imagetonybaltovski ( 2013-12-26 10:02:38 -0600 )edit

Not patronizing at all. It turns out I was using the wrong file the wrong way if that made sense. I changed over to the sonar example, modified it for my equipment and everything worked like a champ. Thanks for trying to help, the error was simply a noob trying to figure things out.

richkappler gravatar imagerichkappler ( 2013-12-28 05:27:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-24 09:51:26 -0600

Seen: 1,486 times

Last updated: Dec 24 '13