test_nav_planning_scene.cpp
Go to the documentation of this file.
00001 /*
00002  * test_nav_sbpl.cpp
00003  *
00004  *  Created on: 2 Jul 2012
00005  *      Author: andreas
00006  */
00007 
00008 #include <planner_modules_pr2/navstack_planning_scene_module.h>
00009 #include <planner_modules_pr2/navstack_module.h>
00010 #include <planner_modules_pr2/module_param_cache.h>
00011 #include "tidyup_utils/planning_scene_interface.h"
00012 #include "tidyup_utils/stringutil.h"
00013 #include <nav_msgs/GetPlan.h>
00014 #include <geometry_msgs/PoseStamped.h>
00015 #include <map>
00016 #include <utility>
00017 using std::pair; using std::make_pair;
00018 #include <boost/foreach.hpp>
00019 #ifdef __CDT_PARSER__
00020     #define forEach(a, b) for(a : b)
00021 #else
00022     #define forEach BOOST_FOREACH
00023 #endif
00024 #include <sys/times.h>
00025 #include <ios>
00026 #include <string>
00027 #include <hardcoded_facts/geometryPoses.h>
00028 
00029 using std::map;
00030 using namespace std;
00031 
00032 int main(int argc, char* argv[])
00033 {
00034     if(argc != 3)
00035     {
00036         ROS_WARN("usage: plan_to_location_planning_scene <location_file> <location_name>");
00037         exit(0);
00038     }
00039 
00040     // init module code and services
00041     ros::init(argc, argv, "test_nav_planning_scene", ros::init_options::AnonymousName);
00042 
00043     char* fake_argv[4];
00044     fake_argv[0] = "bla";
00045     fake_argv[1] = "/map";
00046     fake_argv[2] = "0.05";
00047     fake_argv[3] = "1";
00048     ROS_ASSERT_MSG(ros::param::has("/continual_planning_executive/door_location_file"), "Door location parameter missing: /continual_planning_executive/door_location_file");
00049 
00050     planning_scene_navstack_init(4, fake_argv);
00051 
00052     // load location file
00053     string locationsFile = argv[1];
00054     string goalLocationName = argv[2];
00055     GeometryPoses locations = GeometryPoses();
00056     if (!locations.load(locationsFile))
00057     {
00058         ROS_ERROR("Could not load locations from \"%s\".", locationsFile.c_str());
00059         return -1;
00060     }
00061     const geometry_msgs::PoseStamped* poseStampedPtr = NULL;
00062     forEach(const GeometryPoses::NamedPose & np, locations.getPoses())
00063     {
00064         if(np.first == goalLocationName)
00065         {
00066             poseStampedPtr = &(np.second);
00067             break;
00068         }
00069     }
00070     if (poseStampedPtr == NULL)
00071     {
00072         ROS_ERROR("specified location \"%s\" not found in location file.", goalLocationName.c_str());
00073         return -1;
00074     }
00075 
00076     // set planning scene
00077     PlanningSceneInterface::instance()->resetPlanningScene();
00078 //    const vector<arm_navigation_msgs::CollisionObject>& objectList = PlanningSceneInterface::instance()->getCollisionObjects();
00079 //    vector<arm_navigation_msgs::CollisionObject>::const_iterator objectIterator = objectList.begin();
00080 //    for ( ; objectIterator != objectList.end(); objectIterator++)
00081 //    {
00082 //        // move door +2m in z direction (aka hack open)
00083 //        if (StringUtil::startsWith(objectIterator->id, "door"))
00084 //        {
00085 //            geometry_msgs::Pose pose = objectIterator->poses[0];
00086 //            pose.position.z += 2;
00087 //            PlanningSceneInterface::instance()->updateObject(objectIterator->id, pose);
00088 //        }
00089 //    }
00090 //    PlanningSceneInterface::instance()->sendDiff();
00091 
00092     double cost = 0;
00093 //    string cacheKey = computePathCacheKey("current_location", goalLocationName);
00094 //    if (!g_PathCostCache.get(cacheKey, cost))
00095     {
00096         // send make_plan request
00097         nav_msgs::GetPlan srv;
00098         srv.request.goal = *poseStampedPtr;
00099         bool serviceCallSuccessful = false;
00100         cost = callPlanningService(srv, "current_location", goalLocationName, serviceCallSuccessful);
00101         if (serviceCallSuccessful)
00102         { // only cache real computed paths (including INFINITE_COST)
00103 //            g_PathCostCache.set(cacheKey, cost);
00104         }
00105     }
00106     if (cost < INFINITE_COST)
00107         ROS_INFO("Test SUCCESSFUL: found plan to location \"%s\". length: %0.2f", goalLocationName.c_str(), cost);
00108     else
00109         ROS_ERROR("Test FAILED: no plan to location \"%s\".", goalLocationName.c_str());
00110 }
00111 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


tidyup_tools
Author(s): Andreas Hertle, Christian Dornhege
autogenerated on Wed Dec 26 2012 15:50:57