i need some an example how to wrtie a node, wich is subscribing and publishing at the same time. I want to publish a message when i got i message, beacuse of that i try to publish in the Callback function, but it doesn't work.
My code is following:
void pointCallback(const nxt_msgs::Range &msg)
{
sensor_msgs::LaserScan pub;
ros::NodeHandle r;
ros::Publisher laser_scan_pub = r.advertise<sensor_msgs::LaserScan>("laser_scan", 50);
laser_scan_pub.publish(pub);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "range_to_laser");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("point_cloud", 50, pointCallback);
ros::spin();
return 0;
}
Originally posted by tfoote on ROS Answers with karma: 58457 on 2011-03-08
Post score: 10
Original comments
Comment by tfoote on 2011-03-08:
from ros-users mail
Comment by ctguell on 2013-10-02:
@tfoote could you solve this after all? Im trying to do the same and im having trouble accomplishing it, any help would be great , thanks
Comment by Dirk Thomas on 2013-10-02:
Please see accepted answer from tfoote below. It perfectly describes why the above code does not work and also how it should be modified.