How to read sensor from rosserial [closed]
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.