11 std::string seq_nr_str;
12 if (nh_.hasParam(
"/rapp/rapp_path_planning/last_seq")){
13 nh_.getParam(
"/rapp/rapp_path_planning/last_seq", seq_nr_int);
16 if (seq_nr_int > pathPlanningThreads_)
20 seq_nr_str = boost::lexical_cast<std::string>(seq_nr_int);
21 nh_.setParam(
"/rapp/rapp_path_planning/last_seq", seq_nr_int);
28 nh_.setParam(
"/map_server"+seq_nr+
"/setMap", map_path);
29 ros::ServiceClient get_map_client = nh_.serviceClient<rapp_platform_ros_communications::MapServerGetMapRosSrv>(
"map_server"+seq_nr+
"/get_map");
30 ros::ServiceClient set_costmap_client = nh_.serviceClient<rapp_platform_ros_communications::Costmap2dRosSrv>(
"/global_planner"+seq_nr+
"/costmap_map_update");
32 rapp_platform_ros_communications::MapServerGetMapRosSrv get_map_srv;
33 rapp_platform_ros_communications::Costmap2dRosSrv set_costmap_srv;
34 get_map_srv.request.map_path = map_path;
36 std::string serv_node_name, serv_name;
37 ros::ServiceManager srv_manager;
38 bool serv_active = srv_manager.lookupService(
"map_server"+seq_nr+
"/get_map",serv_node_name,serv_port);
41 ROS_DEBUG_STREAM(
"Waiting for:"<<
" map_server"<<seq_nr<<
"/get_map" <<
" service ");
42 serv_active = srv_manager.lookupService(
"map_server"+seq_nr+
"/get_map",serv_node_name,serv_port);
43 ros::Duration(1).sleep();
47 if (get_map_client.call(get_map_srv))
49 set_costmap_srv.request.map = get_map_srv.response.map;
51 if (set_costmap_client.call(set_costmap_srv))
53 ROS_INFO_STREAM(
"Costmap update for SEQ: " << seq_nr);
56 ROS_ERROR_STREAM(
"Costmap update error for SEQ: " << seq_nr <<
"\n path planner cannot set new costmap");
61 ROS_ERROR_STREAM(
"Costmap update error for SEQ: " << seq_nr <<
"\n path planner cannot get map from map server");
64 const char* execute_command =
"/opt/ros/indigo/bin/rosparam";
65 pid_t load_configs_costmap_pID = fork();
66 if (load_configs_costmap_pID == 0)
68 ROS_DEBUG_STREAM(
"starting load_configs_costmap_pID for sequence: "<< seq_nr);
71 std::string costmap_file = robot_type+
".yaml";
72 std::string load_configs_pkg_path = ros::package::getPath(
"rapp_path_planning");
74 std:: string execute_param_1_string = load_configs_pkg_path+
"/cfg/costmap/"+costmap_file;
75 const char* execute_param_1 = execute_param_1_string.c_str();
76 ROS_DEBUG_STREAM(
"costmap file path:\n"<< execute_param_1_string);
79 std:: string execute_param_2_string =
"/global_planner"+seq_nr+
"/costmap/";
80 const char* execute_param_2 = execute_param_2_string.c_str();
81 nh_.setParam(
"/global_planner"+seq_nr+
"/costmap/map_service",
"/map_server"+seq_nr+
"/getMap");
83 execl(execute_command,execute_command,
"load", execute_param_1,execute_param_2 , (
char *)0);
85 else if (load_configs_costmap_pID < 0)
87 std::cout <<
"Failed to fork load_configs" << std::endl;
93 pid_t load_configs_planner_pID = fork();
94 if (load_configs_planner_pID == 0)
96 ROS_DEBUG_STREAM(
"starting load_configs_planner_pID for sequence: "<< seq_nr);
99 std::string algorithm_file = algorithm+
".yaml";
100 std::string load_configs_pkg_path = ros::package::getPath(
"rapp_path_planning");
102 std:: string execute_param_1_string = load_configs_pkg_path+
"/cfg/planner/"+algorithm_file;
103 const char* execute_param_1 = execute_param_1_string.c_str();
105 std:: string execute_param_2_string =
"/global_planner"+seq_nr+
"/planner/";
106 const char* execute_param_2 = execute_param_2_string.c_str();
107 execl(execute_command,execute_command,
"load", execute_param_1,execute_param_2 , (
char *)0);
109 else if (load_configs_planner_pID < 0)
111 ROS_ERROR(
"Failed to fork load_configs");
118 std:: string costmap_param_name =
"/global_planner"+seq_nr+
"/costmap/map_topic";
120 std:: string planner_param_name =
"/global_planner"+seq_nr+
"/planner/use_dijkstra";
121 ros::Time time_start = ros::Time::now();
124 while (!nh_.hasParam(costmap_param_name) && !nh_.hasParam(planner_param_name)){
125 ros::Duration(0.1).sleep();
126 time_now = ros::Time::now();
127 if (time_now > time_start + ros::Duration(5))
137 navfn::MakeNavPlanResponse
PathPlanner::startSequence(std::string seq_nr, geometry_msgs::PoseStamped request_start, geometry_msgs::PoseStamped request_goal, ros::NodeHandle &nh_){
138 navfn::MakeNavPlanResponse planned_path;
140 std::string serv_node_name, serv_name;
141 serv_name =
"/global_planner"+seq_nr+
"/make_plan";
142 ros::ServiceManager srv_manager;
143 bool serv_active = srv_manager.lookupService(serv_name,serv_node_name,serv_port);
145 ros::Duration(1.5).sleep();
147 while (!serv_active){
148 ROS_ERROR(
"Can't find service make_plan");
149 serv_active = srv_manager.lookupService(serv_name,serv_node_name,serv_port);
150 ros::Duration(1).sleep();
152 ROS_DEBUG_STREAM(
"HOST name:\n" << serv_node_name <<
"service port:\n" << serv_port);
154 ros::ServiceClient client = nh_.serviceClient<navfn::MakeNavPlan>(
"/global_planner"+seq_nr+
"/make_plan");
155 navfn::MakeNavPlan srv;
156 srv.request.start = request_start;
157 srv.request.goal = request_goal;
159 if (client.call(srv))
161 navfn::MakeNavPlanResponse planned_path;
162 planned_path = srv.response;
163 ROS_DEBUG(
"Path planning service ended");
170 ROS_ERROR(
"Failed to call service make_plan");
std::string setSequenceNR(ros::NodeHandle &nh_, int pathPlanningThreads_)
Determines next planning seqence (which global_planner and map_server should be used) ...
bool configureSequence(std::string seq_nr, std::string map_path, std::string robot_type, std::string algorithm, ros::NodeHandle &nh_)
Configures sequence. Sets map, approprate costmap parameters for specified robot type, sets global_planner to use detemined algorithm.
PathPlanner(void)
Default constructor.
navfn::MakeNavPlanResponse startSequence(std::string seq_nr, geometry_msgs::PoseStamped request_start, geometry_msgs::PoseStamped request_goal, ros::NodeHandle &nh_)
Starts planning service of determined planning sequence.