how to call a service in the programme

asked 2017-04-11 09:05:45 -0500

zubair gravatar image

hi all

i have service which i giving me an integer when its being called , i want to add a condition in my program that only if that service is called i should start analyzing, else not.

        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;
        }


    }

}

fake_scan_pub.publish(newScan);
freeSpace = getFreeSpace();
if(freeSpace == -1){
    std::cout<<"NO FREE SPACES "<<std::endl;
}else{
    std::cout<<"The first free Area is: "<<freeSpace<<std::endl;
}

so, this above program should initiate only if service is called .. please help how can i do that .

edit retag flag offensive close merge delete

Comments

ros::ServiceServer service = nh.advertiseService("get_free_space", empty_place);

this is my service name

zubair gravatar image zubair  ( 2017-04-11 09:17:13 -0500 )edit