costmap_services.cpp
Go to the documentation of this file.
00001 #include <costmap_services/costmap_services.h>
00002 
00003 namespace costmap_services {
00004   CostmapServices::CostmapServices( std::string name ) : costmap_ros_("costmap", tf_) {
00005     ros::NodeHandle private_nh( "~/" + name );
00006 
00007     // Initialization.
00008     private_nh.param("controller_frequency", controller_frequency_, 10.0);
00009     private_nh.param("num_th_samples", num_th_samples_, 20);
00010     private_nh.param("num_x_samples", num_x_samples_, 10);
00011     private_nh.param("theta_range", theta_range_, 0.7);
00012     planner_.initialize("planner", &tf_, &costmap_ros_);
00013 
00014     // Setup ROS services.
00015     if (! ros::service::exists("~costmap_getcost", false)){  // Avoid doublely advertizing if multiple instances of this library
00016         costmap_srv_ = private_nh.advertiseService("costmap_getcost", &CostmapServices::getCost, this );
00017     }
00018     if (! ros::service::exists("~costmap_scoretraj", false)){  // Avoid doublely advertizing if multiple instances of this library
00019         scoreTraj_srv_ = private_nh.advertiseService("costmap_scoretraj", &CostmapServices::scoreTraj, this );
00020     }
00021   }
00022 
00023 
00024   CostmapServices::~CostmapServices(){
00025     return;
00026   }
00027 
00028 
00029   bool CostmapServices::getCost( costmap_services::GetCost::Request  &req,
00030                                  costmap_services::GetCost::Response &res ){
00031     // Get a copy of the current costmap to test. (threadsafe)
00032     costmap_2d::Costmap2D costmap;
00033     costmap_ros_.getCostmapCopy( costmap ); 
00034 
00035     // Coordinate transform.
00036     unsigned int cell_x, cell_y;
00037     if( !costmap.worldToMap( req.x, req.y, cell_x, cell_y )){
00038       res.cost = -1.0;
00039       return false;
00040     }
00041 
00042     res.cost = double( costmap.getCost( cell_x, cell_y ));
00043     return true;
00044   }
00045 
00046 
00047   bool CostmapServices::scoreTraj( costmap_services::ScoreTraj::Request  &req,
00048                                    costmap_services::ScoreTraj::Response &res ){
00049     res.cost = planner_.scoreTrajectory( req.vx, req.vy, req.vtheta, true ); // also updates map.
00050     return true;
00051   } 
00052 
00053 
00054 };
00055 
00056 
00057 int main(int argc, char** argv){
00058   ros::init(argc, argv, "costmap_services");
00059   costmap_services::CostmapServices at( "cs" );
00060   ros::spin();
00061   return 0;
00062 }


costmap_services
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 11:49:08