Subscribe and Publish a arbitrary topic!
Hi
I would like to subscribe to the Laserscan data and process it and publish something. Unfortunately, I keep getting error. I appreciate if you help. here is my code:
#include <ros/ros.h>
#include <iostream>
#include <sensor_msgs/LaserScan.h>
#include <std_msgs/Float32.h>
std_msgs::Float32 minval;
void Callback_laser(const sensor_msgs::LaserScan::ConstPtr& scan)
{
minval = scan->ranges[0];
for(int i=0;i<scan->ranges.size();i++)
{
if(scan->ranges[i]<minval or minval!=minval)
minval=scan->ranges[i];
}
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "subscribing");
ros::NodeHandle n;
ros::Subscriber laser_subscriber = n.subscribe<sensor_msgs::LaserScan>("scan", 1000, Callback_laser);
ros::Publisher pub=n.advertise<std_msgs::Float32>("minval", 1000);
ros::Rate loop_rate(10);
while (ros::ok())
{
pub.publish(minval);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
Thanks in advance for your help.
Hi, it would be useful if you could attach any error logs.