how to display result just once after launching ,,, ros
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;
}
}
to add on i need to print the result of analyzeNewScan just once ,, !! please help
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?