34 #include <boost/algorithm/string.hpp>    37 #include "nav_msgs/GetMap.h"    38 #include "std_msgs/String.h"    39 #include "geometry_msgs/Quaternion.h"    41 #include <Eigen/Geometry>    43 #include <QtGui/QApplication>    50 #include <hector_nav_msgs/GetRobotTrajectory.h>    63     : geotiff_writer_(false)
    66     , running_saved_map_num_(0)
    68     pn_.param(
"map_file_path", p_map_file_path_, std::string(
"."));
    69     geotiff_writer_.setMapFilePath(p_map_file_path_);
    70     geotiff_writer_.setUseUtcTimeSuffix(
true);
    72     pn_.param(
"map_file_base_name", p_map_file_base_name_, std::string());
    74     pn_.param(
"draw_background_checkerboard", p_draw_background_checkerboard_, 
true);
    75     pn_.param(
"draw_free_space_grid", p_draw_free_space_grid_, 
true);
    77     sys_cmd_sub_ = n_.subscribe(
"syscommand", 1, &MapGenerator::sysCmdCallback, 
this);
    79     map_service_client_ = n_.serviceClient<nav_msgs::GetMap>(
"map");
    81     path_service_client_ = n_.serviceClient<hector_nav_msgs::GetRobotTrajectory>(
"trajectory");
    84     double p_geotiff_save_period = 0.0;
    85     pn_.param(
"geotiff_save_period", p_geotiff_save_period, 0.0);
    87     if(p_geotiff_save_period > 0.0){
    90       map_save_timer_ = pn_.createTimer(
ros::Duration(p_geotiff_save_period), &MapGenerator::timerSaveGeotiffCallback, 
this, 
false );
    94     pn_.param(
"plugins", p_plugin_list_, std::string(
""));
    96     std::vector<std::string> plugin_list;
    97     boost::algorithm::split(plugin_list, p_plugin_list_, boost::is_any_of(
"\t "));
   100     if ((plugin_list.size() > 0) && (plugin_list[0].length() > 0)){
   103       for (
size_t i = 0; i < plugin_list.size(); ++i){
   107           tmp->initialize(plugin_loader_->getName(plugin_list[i]));
   108           plugin_vector_.push_back(tmp);
   112           ROS_ERROR(
"The plugin failed to load for some reason. Error: %s", ex.what());
   116       ROS_INFO(
"No plugins loaded for geotiff node");
   125       delete plugin_loader_;
   133     std::stringstream ssStream;
   135     nav_msgs::GetMap srv_map;
   136     if (map_service_client_.call(srv_map))
   138       ROS_INFO(
"GeotiffNode: Map service called successfully");
   139       const nav_msgs::OccupancyGrid& map (srv_map.response.map);
   141       std::string map_file_name = p_map_file_base_name_;
   142       std::string competition_name;
   143       std::string team_name;
   144       std::string mission_name;
   146       if (n_.getParamCached(
"/competition", competition_name) && !competition_name.empty()) map_file_name = map_file_name + 
"_" + competition_name;
   147       if (n_.getParamCached(
"/team", team_name)               && !team_name.empty())        map_file_name = map_file_name + 
"_" + team_name;
   148       if (n_.getParamCached(
"/mission", mission_name)         && !mission_name.empty())     map_file_name = map_file_name + 
"_" + mission_name;
   149       if (pn_.getParamCached(
"map_file_postfix", postfix)     && !postfix.empty())          map_file_name = map_file_name + 
"_" + postfix;
   150       if (map_file_name.substr(0, 1) == 
"_") map_file_name = map_file_name.substr(1);
   151       if (map_file_name.empty()) map_file_name = 
"GeoTiffMap";
   152       geotiff_writer_.setMapFileName(map_file_name);
   153       bool transformSuccess = geotiff_writer_.setupTransforms(map);
   155       if(!transformSuccess){
   156         ROS_INFO(
"Couldn't set map transform");
   160       geotiff_writer_.setupImageSize();
   162       if (p_draw_background_checkerboard_){
   163         geotiff_writer_.drawBackgroundCheckerboard();
   166       geotiff_writer_.drawMap(map, p_draw_free_space_grid_);
   167       geotiff_writer_.drawCoords();
   177     for (
size_t i = 0; i < plugin_vector_.size(); ++i){
   178       plugin_vector_[i]->draw(&geotiff_writer_);
   247     geotiff_writer_.writeGeotiffImage();
   248     running_saved_map_num_++;
   252     ROS_INFO(
"GeoTiff created in %f seconds", elapsed_time.
toSec());
   257     this->writeGeotiff();
   262     if ( !(sys_cmd.data == 
"savegeotiff")){
   266     this->writeGeotiff();
   288   std::vector<boost::shared_ptr<hector_geotiff::MapWriterPluginInterface> > 
plugin_vector_;
   299 int main(
int argc, 
char** argv)
 
void sysCmdCallback(const std_msgs::String &sys_cmd)
ros::Timer map_save_timer_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber sys_cmd_sub_
ros::ServiceClient map_service_client_
int main(int argc, char **argv)
std::vector< boost::shared_ptr< hector_geotiff::MapWriterPluginInterface > > plugin_vector_
void timerSaveGeotiffCallback(const ros::TimerEvent &e)
std::string p_map_file_path_
ros::ServiceClient object_service_client_
bool p_draw_background_checkerboard_
bool p_draw_free_space_grid_
unsigned int running_saved_map_num_
std::string p_map_file_base_name_
std::string p_plugin_list_
ros::ServiceClient path_service_client_
GeotiffWriter geotiff_writer_
pluginlib::ClassLoader< hector_geotiff::MapWriterPluginInterface > * plugin_loader_