easy_costmap.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #include <global_planner_tests/easy_costmap.h>
00036 #include <global_planner_tests/util.h>
00037 #include <map_server/image_loader.h>
00038 #include <string>
00039 #include <vector>
00040 #include <algorithm>
00041 
00042 namespace global_planner_tests
00043 {
00044 
00045 EasyCostmap::EasyCostmap(const std::string& filename, const double resolution, const bool origin_at_center)
00046 {
00047   loadMapFromFile(filename, resolution, origin_at_center);
00048 }
00049 
00050 void EasyCostmap::loadMapFromFile(const std::string& filename, const double resolution, const bool origin_at_center)
00051 {
00052   double origin[3] = {0.0, 0.0, 0.0};
00053   nav_msgs::GetMap::Response map_resp;
00054   map_server::loadMapFromFile(&map_resp, resolve_filename(filename).c_str(), resolution, true, 0.0, 0.0, origin, RAW);
00055 
00056   if (origin_at_center)
00057   {
00058     map_resp.map.info.origin.position.x = map_resp.map.info.width * resolution / -2;
00059     map_resp.map.info.origin.position.y = map_resp.map.info.height * resolution / -2;
00060   }
00061   original_grid_ = map_resp.map;
00062   original_grid_.header.frame_id = "map";
00063   reset();
00064 }
00065 
00066 void EasyCostmap::reset()
00067 {
00068   nav_grid::NavGridInfo new_info;
00069   new_info.width = original_grid_.info.width;
00070   new_info.height = original_grid_.info.height;
00071   new_info.resolution = original_grid_.info.resolution;
00072   new_info.frame_id = original_grid_.header.frame_id;
00073   new_info.origin_x = original_grid_.info.origin.position.x;
00074   new_info.origin_y = original_grid_.info.origin.position.y;
00075 
00076   if (info_ != new_info)
00077   {
00078     info_ = new_info;
00079     data_.resize(info_.width * info_.height);
00080   }
00081   for (unsigned int i=0; i < data_.size(); i++)
00082   {
00083     data_[i] = static_cast<unsigned char>(original_grid_.data[i]);
00084   }
00085 }
00086 
00087 }  // namespace global_planner_tests


global_planner_tests
Author(s):
autogenerated on Wed Jun 26 2019 20:09:34