ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

how to display result just once after launching ,,, ros

asked 2017-04-12 06:05:33 -0600

zubair gravatar image

updated 2018-07-15 02:27:22 -0600

jayess gravatar image

this is my code which keep on giving me the first free area , i need to print that just once when i launch the file,, how can i do that please ??

void analyzeNewScan()
{
    if(analyzeEmptySpace)
    {
    //              listener->lookupTransform("map", "agv1/base_link", ros::Time::now(), transform);

        if(to_transform)
        {

            int space;

            int n_leituras = 0;

            for (int i=0; i<palletdrop.size();i++)
            {
                palletdrop[i].isFree = true;
            }


            for(int i=0; i<newScan.ranges.size()-1; i++)
            {
                double closest_angle;

                closest_angle = ((double)(i*newScan.angle_increment) + newScan.angle_min)+3.14/2;
                double next_angle = ((double)((i+1)*newScan.angle_increment) + newScan.angle_min) +3.14/2;

                double true_angle = ((double)(i*newScan.angle_increment) + newScan.angle_min);
                double true_x = newScan.ranges[i] * cos(true_angle);
                double true_y = newScan.ranges[i] * sin(true_angle);

                double x_obs = newScan.ranges[i] * cos(closest_angle);
                double y_obs = newScan.ranges[i] * sin(closest_angle);

                double x_next_obs = newScan.ranges[i+1] * cos(next_angle);
                double y_next_obs = newScan.ranges[i+1] * sin(next_angle);


                geometry_msgs::PointStamped bll;
                bll.header.frame_id = "/agv1/front_laser";
                bll.header.stamp = curr_time;
                bll.point.x = true_x;
                bll.point.y = true_y;      
                bll.point.z = 0.0;
                geometry_msgs::PointStamped m;
                listener->transformPoint("map", bll,m);


                if(m.point.x > startx -3  && m.point.x < startx + h && m.point.y < starty && m.point.y > starty - npallets * h )
                {    
                    for (int i=0; i<palletdrop.size();i++)
                    {

                        if(palletdrop[i].isInside(m.point.x,m.point.y))
                        {
                            palletdrop[i].setOccupied();
                        }
                    }
                }
                else
                {
                    newScan.ranges[i] = 0;
                }
            }
        }
        freeSpace = getFreeSpace();


        fake_scan_pub.publish(newScan);
        if(freeSpace == -1)
        {
            std::cout<<"NO FREE SPACES "<<std::endl;
        }
        else
        {
            std::cout<<"The first free Area is: "<<freeSpace<<std::endl;
        }
        //analyzeEmptySpace = false;
    }
}
edit retag flag offensive close merge delete

Comments

to add on i need to print the result of analyzeNewScan just once ,, !! please help

zubair gravatar image zubair  ( 2017-04-12 06:06:47 -0600 )edit

It looks like the analyzeNewScan() function is called multiple times then. Can you provide the code where it is called (or bound as a ros callback)? By the way, the formatting of your posted code is broken at the top. Mind fixing it?

cellard0or gravatar image cellard0or  ( 2017-04-12 06:50:05 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-04-12 08:20:17 -0600

zubair gravatar image

updated 2017-04-12 08:20:45 -0600

i got it working well,, thanks a lot guys,, and i need to call that analyzenewscan function again in main program after the service is being called ..

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-12 06:05:33 -0600

Seen: 133 times

Last updated: Jul 15 '18