maximum distance (point) to obstacle [closed]

asked 2012-08-06 14:36:58 -0500

Astronaut gravatar image


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 = 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())




return 0;


edit retag flag offensive reopen merge delete

Closed for the following reason Question does not follow our guidelines for questions. Please see: for more details. by tfoote
close date 2012-08-06 15:49:45


This does not appear to be a question please see the support guidelines.

tfoote gravatar image tfoote  ( 2012-08-06 15:49:31 -0500 )edit