Ask Your Question
0

Time issue when publishing laser scan message

asked 2011-12-16 18:53:01 -0500

alfa_80 gravatar image

updated 2011-12-16 19:03:55 -0500

I am publishing a laser message. However, I got confused whether I should use scan_time = ros::Time::now(); like in the tutorial or should I use the time read from a file. Is there any pitfall in order to control time later on, for both ways. Which way give me a better choice where time control is very important. Please also check the way I code and publish the laser scan message. I feel like something is wrong somewhere.

The code snippet is as below:

    void PointCloud::publishLaser()
    {
        int num_laser_readings;
        double laser_frequency;

        num_laser_readings = 1080;

        laser_frequency = 40; //20 could be


        ros::Rate r(1.0);


        int t = 0;


        while (n.ok() && (t < num_row))
        {
            sensor_msgs::LaserScan scan;

               //data_set[t][1]/1000) is time from dataset, reading row by row
            ros::Time scan_time( double(data_set[t][1]/1000));



            for (int i = 0; i < num_row; i++)
            {
                scan.header.stamp =  scan_time;
            }

            scan.header.frame_id = "laser_frame";
            scan.angle_min = - 270 / 2 * M_PI / 180; // -xx degree
            scan.angle_max = 270 / 2 * M_PI / 180;   // xx degree

            scan.angle_increment = (scan.angle_max-scan.angle_min)/num_laser_readings;

            scan.time_increment = (1 / laser_frequency) / (num_laser_readings);
            scan.range_min = 0.0;
            scan.range_max = 100.0;

            scan.set_ranges_size(num_laser_readings);

            for(int i = 0; i < num_laser_readings; ++i)
            {
//              Laser scanner data reside in column 10th to 1080th
                scan.ranges[i] = data_set[t][i+9] / 1000.0;
            }


            scan_pub.publish(scan);
            ++count;
            ++t;

            r.sleep();
        }
    }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-12-17 06:28:59 -0500

dornhege gravatar image

I you have some dataset you should use the original time as that matches the other data.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-12-16 18:53:01 -0500

Seen: 423 times

Last updated: Dec 17 '11