[ros-users] SICK LMS Subscriber Node

Morgan Quigley mquigley at cs.stanford.edu
Thu Jul 15 19:12:47 UTC 2010


The "rostopic echo" output will give a list of the fields, which are
the member variable names in the respective auto-generated c++ class.
A variable-length array in the message definition turns into a
std::vector in c++.

so, you can find out how many ranges there are with
size_t num_ranges = scan_msg->ranges.size();

and pick out an individual one with
float interesting_range = scan_msg->ranges[123];

Cheers(),
Morgan



On Thu, Jul 15, 2010 at 12:07 PM, Rishi Bedi <rbedi100 at gmail.com> wrote:
> Hi Morgan,
> Okay -- say I wanted to read in just the range values from sicklms -- how
> can I just grab those? When I use rostopic echo /scan, the ranges show up as
> a list within brackets - is there a way I can pick out data from a topic my
> node is subscribing to? Sorry if I'm being a bit dense -- I'm not well
> versed on handling data types in C++.
> Best,
> Rishi
>
> Rishi Bedi
> rbedi100 at gmail.com
>
>
> On Thu, Jul 15, 2010 at 3:00 PM, Morgan Quigley <mquigley at cs.stanford.edu>
> wrote:
>>
>> Hi Rishi,
>>
>> Since there are such a wide variety of data types in the system that
>> would need different useful string representations, the auto-generated
>> message types don't create a string-generation function. You'll need
>> to assemble a string yourself using stringstream or whatever.
>>
>> Cheers,
>> Morgan
>>
>>
>> On Thu, Jul 15, 2010 at 11:55 AM, Rishi Bedi <rbedi100 at gmail.com> wrote:
>> > Hi,
>> > I'm trying to write a node that subscribes to the "/scan" topic, which
>> > is
>> > published by sicktoolbox_wrapper. I tried to modify some of the code
>> > given
>> > in the "Writing a Simple Publisher/Subscriber" tutorial:
>> >
>> > #include <ros/ros.h>
>> > #include <std_msgs/String.h>
>> > #include <sensor_msgs/LaserScan.h>
>> >
>> > void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_msg)
>> >
>> > {
>> >   ROS_INFO("Received [%s]", scan_msg);
>> > }
>> >
>> > int main(int argc, char** argv)
>> > {
>> >   ros::init(argc, argv, "listener");
>> >   ros::NodeHandle n;
>> >   ros::Subscriber scan_sub = n.subscribe("scan", 100, scanCallback);
>> >   ros::spin();
>> > }
>> >
>> > The part where I think I'm getting tripped up is line 8 (the ROS_INFO
>> > command) -- how do I handle the unique data type LaserScan that
>> > sicktoolbox_wrapper uses to publish the scan data? I want to print the
>> > range
>> > values out, preferably as one long string -- what is the best way to
>> > convert
>> > the LaserScan type data into a string (or array)?
>> >
>> > Thanks a lot --
>> > Rishi
>> >
>> > Rishi Bedi
>> > rbedi100 at gmail.com
>> >
>> > _______________________________________________
>> > ros-users mailing list
>> > ros-users at code.ros.org
>> > https://code.ros.org/mailman/listinfo/ros-users
>> >
>> >
>> _______________________________________________
>> ros-users mailing list
>> ros-users at code.ros.org
>> https://code.ros.org/mailman/listinfo/ros-users
>
>
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
>



More information about the ros-users mailing list