How to read sensor from rosserial
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
include
include
include
ros::NodeHandle nh;
sensormsgs::Range rangemsg; ros::Publisher pubrange( "rangedata", &range_msg);
define TRIGGER_PIN 48
define ECHO_PIN 49
Ultrasonic ultrasonic(TRIGGERPIN, ECHOPIN);
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);
rangemsg.radiationtype = sensormsgs::Range::ULTRASOUND; rangemsg.header.frameid = frameid; rangemsg.fieldofview = 0.2; rangemsg.minrange = 0.0; rangemsg.maxrange = 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()-rangetimer) > 50){ rangemsg.range = inMsec; rangemsg.header.stamp = nh.now(); pubrange.publish(&rangemsg); rangetimer = 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 rangemsg, pubrange, just not quite sure what I'm doing, still very new at ROS and would appreciate a nudge in the right direction.
Asked by richkappler on 2013-12-24 10:51:26 UTC
Answers
You have to run the rosserial_python serial_node.py PORT
and it will automatically start publishing the data which is called /range_data.
Asked by tonybaltovski on 2013-12-24 18:17:53 UTC
Comments
Yeah, got that part, did all that, roscore running, serial_node running. rqt_plot returns nothing.
Asked by richkappler on 2013-12-24 19:42:17 UTC
Did you try rostopic echo?
Asked by tonybaltovski on 2013-12-25 06:18:27 UTC
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!
Asked by richkappler on 2013-12-26 07:05:58 UTC
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
Asked by tonybaltovski on 2013-12-26 11:02:38 UTC
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.
Asked by richkappler on 2013-12-28 06:27:44 UTC
Comments