maximum distance (point) to obstacle [closed]
Hello
Im trying to write a callback function than gives me the maximal distance to the obstacle based on laser range finder. I have the callback function for the closest point. Its look like this. This is the code of the callback function for the closest point. Im using ROS Fuerte, and A Hokuyo UTM-30LX/LN scanning laser range finder, able to measure distance to objects between {0.1m -30m} in a semicircular field of 270 . Any help?
include "ros/ros.h"
include "std_msgs/String.h"
include "sensor_msgs/LaserScan.h"
include <vector>
sensor_msgs::LaserScan laser_scan; float min_range;
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg) {
std::vector<float> laser;
laser = msg->ranges;
int size_laser = laser.size();
for (int i=0;i<size_laser;i++){
if (laser[i] < 0.01){
laser[i] = 99999;
}
if (laser[i] > 45){
laser[i] = 99999;
}
}
min_range = 2;
int index_min;
for (int i=0;i<size_laser;i++){
if (laser[i] < min_range){
min_range = laser[i];
index_min = i;
ROS_INFO("Minimum Range = %f", min_range);
}
}
for (int j=0;j<size_laser;j++){
if (laser[j] > min_range + 0.5){
laser[j] = 0;
}
}
laser_scan = *msg;
laser_scan.ranges.clear();
laser_scan.ranges = laser;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "object_node");
ros::NodeHandle n;
ROS_INFO("Minimum Range = %f", min_range);
ros::Subscriber sub = n.subscribe("scan", 1000, scanCallback);
ros::Publisher laser_pub = n.advertise<sensor_msgs::LaserScan>("closest_points", 100);
ros::Rate loop_rate(10);
while (ros::ok())
{
laser_pub.publish(laser_scan);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
This does not appear to be a question please see the support guidelines. www.ros.org/wiki/Support