reading local costmap

asked 2022-01-04 04:04:48 -0500

dinesh gravatar image

I'm trying to read the cost of cells using only local costmap. For this i have used the layerdcostmap class but somehow i'm not getting the correct cost value from my code. /* * Segment 1: If global path is invalid, update the global path */

auto c_map = m_cost_map->getLayeredCostmap()->getCostmap();
for(auto pnt : local_plan) {
    double map_resolution = 0.05; // map resolution
    double robot_width = 0.1; // robot_width/2
    int invalid_gpath_count = 0;
    double pnt_dist = sqrt(pow(pnt.getOrigin().x()-local_pose.getOrigin().x(), 2) + pow(pnt.getOrigin().y()-local_pose.getOrigin().y(), 2));
    if(pnt_dist < local_costmap_height/2.0) {
        for(double x=pnt.getOrigin().x()-robot_width;x<=pnt.getOrigin().x()+robot_width;x+=map_resolution) {
            for(double y=pnt.getOrigin().y()-robot_width;y<=pnt.getOrigin().y()+robot_width;y+=map_resolution) {
                double dist = sqrt(pow(pnt.getOrigin().x()-x,2)+pow(pnt.getOrigin().y()-y,2));
                if(dist <= robot_width) {
                    geometry_msgs::Pose gp;
                    gp.position.x = x;
                    gp.position.y = y;
                    tf2::Transform p;
                    tf2::fromMsg(gp, p);
                    // double cost = get_cost(m_cost_map, p.getOrigin());
                    double cost = c_map->getCost(p.getOrigin().x(), p.getOrigin().y());
                    if(cost >= 200) {
                        invalid_gpath_count++;
                        if(invalid_gpath_count>3) {
                            ROS_INFO("cost: %f, m_max_cost: %f", cost, m_max_cost);
                            ROS_WARN("base_local_planner: invalid global path!");
                            // m_state = state_t::STATE_STUCK;
                            return false;   
                        }
                    }
                }
            }
        }
    }
}

What could be i doing the mistake.

edit retag flag offensive close merge delete