11 #include <boost/filesystem.hpp>
20 if (start.pose.position.x != 0){
21 if (goal.pose.position.x != 0){
22 if (goal.pose.position.y != 0){
23 if (start.pose.position.y != 0){
33 for (
int i = 0; i <
MS_pIDs.size();i++){
34 ROS_DEBUG_STREAM(
"KILLING GP: "<<
GP_pIDs.at(i) );
43 return (stat (name.c_str(), &buffer) == 0);
47 pid_t tf_broadcaster_pID = fork();
48 if (tf_broadcaster_pID == 0)
50 ROS_DEBUG(
"starting tf_broadcaster_pID");
52 execl(
"/opt/ros/indigo/bin/rosrun",
"/opt/ros/indigo/bin/rosrun",
"tf",
"static_transform_publisher",
"0.066",
"1.7",
"0.54",
"0.49999984",
"0.49960184",
"0.49999984",
"0.50039816",
"map",
"base_link",
"100", (
char *)0);
54 else if (tf_broadcaster_pID < 0)
56 std::cout <<
"Failed to fork tf_broadcaster_pID" << std::endl;
69 pid_t map_server_pID = fork();
70 if (map_server_pID == 0)
72 ROS_DEBUG_STREAM(
"starting map_server node: "<< node_nr_str);
74 std:: string execute_param_1_string =
"__name:=map_server"+node_nr_str;
75 const char* execute_param_1 = execute_param_1_string.c_str();
76 ROS_DEBUG_STREAM(
"map_server name:\n" << node_nr_str );
79 std:: string execute_param_2_string = ros::package::getPath(
"rapp_map_server")+
"/maps/empty.yaml";
80 const char* execute_param_2 = execute_param_2_string.c_str();
82 std:: string execute_param_3_string =
"/map:=/map_server"+node_nr_str+
"/map";
83 const char* execute_param_3 = execute_param_3_string.c_str();
84 execl(
"/opt/ros/indigo/bin/rosrun",
"/opt/ros/indigo/bin/rosrun",
"rapp_map_server",
"rapp_map_server", execute_param_1, execute_param_2, execute_param_3, (
char *)0);
86 else if (map_server_pID < 0)
88 std::cout <<
"Failed to fork map_server node: "<<node_nr_str << std::endl;
99 const char* execute_command =
"/opt/ros/indigo/bin/rosparam";
100 pid_t load_configs_costmap_pID = fork();
101 if (load_configs_costmap_pID == 0)
103 ROS_DEBUG_STREAM(
"starting load_configs_costmap_pID for sequence: "<< node_nr_str);
105 std::string robot_type =
"NAO";
106 std::string costmap_file = robot_type+
".yaml";
107 std::string load_configs_pkg_path = ros::package::getPath(
"rapp_path_planning");
109 std:: string execute_param_1_string = load_configs_pkg_path+
"/cfg/costmap/"+costmap_file;
110 const char* execute_param_1 = execute_param_1_string.c_str();
111 ROS_DEBUG_STREAM(
"costmap file path:\n"<< execute_param_1_string);
114 std:: string execute_param_2_string =
"/global_planner"+node_nr_str+
"/costmap/";
115 const char* execute_param_2 = execute_param_2_string.c_str();
118 execl(execute_command,execute_command,
"load", execute_param_1,execute_param_2 , (
char *)0);
120 else if (load_configs_costmap_pID < 0)
122 std::cout <<
"Failed to fork load_configs" << std::endl;
128 pid_t load_configs_planner_pID = fork();
129 if (load_configs_planner_pID == 0)
131 ROS_DEBUG_STREAM(
"starting load_configs_planner_pID for sequence: "<< node_nr_str);
133 std::string algorithm =
"dijkstra";
134 std::string algorithm_file = algorithm+
".yaml";
135 std::string load_configs_pkg_path = ros::package::getPath(
"rapp_path_planning");
137 std:: string execute_param_1_string = load_configs_pkg_path+
"/cfg/planner/"+algorithm_file;
138 const char* execute_param_1 = execute_param_1_string.c_str();
140 std:: string execute_param_2_string =
"/global_planner"+node_nr_str+
"/planner/";
141 const char* execute_param_2 = execute_param_2_string.c_str();
142 execl(execute_command,execute_command,
"load", execute_param_1,execute_param_2 , (
char *)0);
144 else if (load_configs_planner_pID < 0)
146 ROS_ERROR(
"Failed to fork load_configs");
152 pid_t global_planner_pID = fork();
153 if (global_planner_pID == 0)
155 ROS_DEBUG_STREAM(
"starting global_planner node: "<< node_nr_str);
158 std:: string execute_param_1_string =
"__name:=global_planner"+node_nr_str;
159 const char* execute_param_1 = execute_param_1_string.c_str();
161 std:: string execute_param_2_string =
"/map:=/map_server"+node_nr_str+
"/map";
162 const char* execute_param_2 = execute_param_2_string.c_str();
164 execl(
"/opt/ros/indigo/bin/rosrun",
"/opt/ros/indigo/bin/rosrun",
"global_planner",
"planner", execute_param_1, execute_param_2, (
char *)0);
167 else if (global_planner_pID < 0)
169 ROS_ERROR(
"Failed to fork global_planner");
183 if ((
homedir = getenv(
"HOME")) == NULL) {
184 homedir = getpwuid(getuid())->pw_dir;
188 ROS_WARN(
"Path planning topic param does not exist. Setting to: /rapp/rapp_path_planning/plan_path");
193 ROS_WARN(
"Path planning threads param does not exist. Setting 5 threads.");
202 std::string node_nr_str = boost::lexical_cast<std::string>(node_nr);
213 std::string serv_node_name, serv_name;
214 ros::ServiceManager srv_manager;
218 serv_name =
"/global_planner"+threads_str+
"/make_plan";
219 bool serv_active = srv_manager.lookupService(serv_name.c_str() ,serv_node_name,serv_port);
221 while (!serv_active && i <= 20){
222 ROS_DEBUG_STREAM(
"Waiting for:"<<
" /global_planner"<<pathPlanningThreads_<<
"/make_plan" <<
" service ");
223 serv_active = srv_manager.lookupService(serv_name.c_str(),serv_node_name,serv_port);
224 ros::Duration(1).sleep();
230 ROS_WARN(
"Upload map topic param does not exist. Setting to: /rapp/rapp_path_planning/upload_map");
243 rapp_platform_ros_communications::MapServerUploadMapRosSrv::Response &res){
246 ros::ServiceClient upload_map_client =
nh_.serviceClient<rapp_platform_ros_communications::MapServerUploadMapRosSrv>(
"/map_server"+seq_nr_str+
"/upload_map");
247 rapp_platform_ros_communications::MapServerUploadMapRosSrv upload_map_srv;
248 upload_map_srv.request = req;
249 if(upload_map_client.call(upload_map_srv)){
250 res = upload_map_srv.response;
253 ROS_ERROR_STREAM(
"FAILED to call service:\n/map_server"<< seq_nr_str <<
"/upload_map");
259 std::vector<geometry_msgs::PoseStamped>
setPoseDist(
double pose_dist, std::vector<geometry_msgs::PoseStamped> input_path){
260 geometry_msgs::PoseStamped last_pose;
261 geometry_msgs::PoseStamped next_pose;
262 std::vector<geometry_msgs::PoseStamped> new_path;
265 last_pose.pose.position.x = input_path[0].pose.position.x;
266 last_pose.pose.position.y = input_path[0].pose.position.y;
267 new_path.push_back(input_path[0]);
270 for(
int i=0; i < (int) floor(input_path.size()/5) ; i+=1){
272 next_pose.pose.position.x = input_path[i*5].pose.position.x;
273 next_pose.pose.position.y = input_path[i*5].pose.position.y;
276 dist_now = sqrt((last_pose.pose.position.x - next_pose.pose.position.x)*(last_pose.pose.position.x - next_pose.pose.position.x)+(last_pose.pose.position.y - next_pose.pose.position.y)*(last_pose.pose.position.y - next_pose.pose.position.y));
278 if (dist_now >= pose_dist){
279 next_pose.pose.position.z = input_path[i*5].pose.position.z;
280 next_pose.pose.orientation.x = input_path[i*5].pose.orientation.x;
281 next_pose.pose.orientation.y = input_path[i*5].pose.orientation.y;
282 next_pose.pose.orientation.z = input_path[i*5].pose.orientation.z;
283 next_pose.pose.orientation.w = input_path[i*5].pose.orientation.w;
284 next_pose.header.seq = input_path[i*5].header.seq;
285 next_pose.header.stamp = input_path[i*5].header.stamp;
287 next_pose.header.frame_id = input_path[i*5].header.frame_id;
288 new_path.push_back(next_pose);
289 last_pose.pose.position.x = next_pose.pose.position.x;
290 last_pose.pose.position.y = next_pose.pose.position.y;
295 int nr_iter = (int) floor(input_path.size()/5);
296 if (nr_iter < input_path.size())
297 new_path.push_back(input_path[input_path.size()-1]);
303 rapp_platform_ros_communications::PathPlanningRosSrv::Request& req,
304 rapp_platform_ros_communications::PathPlanningRosSrv::Response& res)
306 std::string homedir_str =
homedir;
308 std::string map_path = homedir_str+
"/rapp_platform_files/maps/"+req.user_name+
"/"+req.map_name+
".yaml";
309 std::string costmap_file_path = ros::package::getPath(
"rapp_path_planning")+
"/cfg/costmap/"+req.robot_type+
".yaml";
310 std::string algorithm_file_path = ros::package::getPath(
"rapp_path_planning")+
"/cfg/planner/"+req.algorithm+
".yaml";
311 navfn::MakeNavPlanResponse response;
316 ROS_DEBUG(
"NEW <<Path_planning>> SERVICE STARTED");
318 ROS_DEBUG_STREAM(
"SEQ-NR is: " << seq_nr_str);
323 res.plan_found = response.plan_found;
325 res.error_message = response.error_message;
328 if (res.plan_found == 1){
329 nh_.param<
double>(
"rapp_path_planning_pose_distance",
pose_dist_, 0.15);
336 nh_.setParam(
"/rapp/rapp_path_planning/seq_"+seq_nr_str+
"/busy",
false);
339 res.error_message =
"Input map does not exist";
340 ROS_ERROR(
"Input map does not exist");
344 res.error_message =
"Input robot_type does not exist";
346 ROS_ERROR(
"Input robot_type does not exist");
351 res.error_message =
"Input algorithm does not exist";
353 ROS_ERROR(
"Input algorithm does not exist");
358 res.error_message =
"Robot pose can NOT be placed at the map border";
360 ROS_ERROR(
"Robot pose can NOT be placed at the map border");
std::vector< pid_t > GP_pIDs
std::string uploadMapTopic_
std::vector< geometry_msgs::PoseStamped > new_path
bool exists_file(const std::string &name)
std::string setSequenceNR(ros::NodeHandle &nh_, int pathPlanningThreads_)
Determines next planning seqence (which global_planner and map_server should be used) ...
bool pathPlanningCallback(rapp_platform_ros_communications::PathPlanningRosSrv::Request &req, rapp_platform_ros_communications::PathPlanningRosSrv::Response &res)
Determines next planning seqence (which global_planner and map_server should be used) ...
bool uploadMapCallback(rapp_platform_ros_communications::MapServerUploadMapRosSrv::Request &req, rapp_platform_ros_communications::MapServerUploadMapRosSrv::Response &res)
Upload map to RAPP Platform.
bool input_poses_correct(geometry_msgs::PoseStamped &start, geometry_msgs::PoseStamped &goal)
std::vector< geometry_msgs::PoseStamped > setPoseDist(double pose_dist, std::vector< geometry_msgs::PoseStamped > input_path)
pid_t start_global_planners(std::string node_nr_str)
pid_t start_map_servers(std::string node_nr_str)
std::string pathPlanningTopic_
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.
pid_t start_tf_publisher()
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.
PathPlanner path_planner_
ros::ServiceServer uploadMapService_
PathPlanning(void)
Default constructor.
std::vector< pid_t > MS_pIDs
ros::ServiceServer pathPlanningService_