pathplanner/main.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <ros/subscriber.h>
3 #include <ros/publisher.h>
4 #include <sensor_msgs/PointCloud2.h>
5 #include <nav_msgs/Path.h>
6 #include <geometry_msgs/PoseStamped.h>
7 #include "GraphSearch.hpp"
8 #include "igvcsearchproblem.h"
9 #include <geometry_msgs/PoseStamped.h>
10 #include <tf/transform_datatypes.h>
11 #include <mutex>
12 #include <pcl_conversions/pcl_conversions.h>
13 #include <algorithm>
14 #include <igvc_msgs/action_path.h>
15 
16 using namespace std;
17 
18 ros::Publisher disp_path_pub;
19 
20 ros::Publisher act_path_pub;
21 
23 
25 
26 void map_callback(const sensor_msgs::PointCloud2ConstPtr &msg)
27 {
28  lock_guard<mutex> lock(planning_mutex);
29  pcl::fromROSMsg(*msg, *search_problem.Map);
30 }
31 
32 void position_callback(const geometry_msgs::PoseStampedConstPtr& msg)
33 {
34  lock_guard<mutex> lock(planning_mutex);
35  search_problem.Start.x = msg->pose.position.x;
36  search_problem.Start.y = msg->pose.position.y;
37  tf::Quaternion q;
38  tf::quaternionMsgToTF(msg->pose.orientation, q);
39  search_problem.Start.theta = tf::getYaw(q);
40 }
41 
42 void waypoint_callback(const geometry_msgs::PointStampedConstPtr& msg)
43 {
44  lock_guard<mutex> lock(planning_mutex);
45  search_problem.Goal.x = msg->point.x;
46  search_problem.Goal.y = msg->point.y;
47 }
48 
49 int main(int argc, char** argv)
50 {
51  ros::init(argc, argv, "pathplanner");
52 
53  ros::NodeHandle nh;
54 
55  ros::Subscriber map_sub = nh.subscribe("/map", 1, map_callback);
56 
57  ros::Subscriber pose_sub = nh.subscribe("/robot_pose_ekf/odom_combined", 1, position_callback);
58 
59  ros::Subscriber waypoint_sub = nh.subscribe("/waypoint", 1, waypoint_callback);
60 
61  disp_path_pub = nh.advertise<nav_msgs::Path>("/path_display", 1);
62 
63  act_path_pub = nh.advertise<igvc_msgs::action_path>("/path", 1);
64 
65  double baseline = 0.7275;
66 
67  search_problem.Map = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
69  search_problem.Threshold = 0.36375;
70  search_problem.Speed = 0.25;
71  search_problem.Baseline = baseline;
72  search_problem.DeltaT = 0.25;
73 
74  ros::Rate rate(3);
75  while(ros::ok())
76  {
77  ros::spinOnce();
78 
79  /* Do not attempt to plan a path if the path length would be greater than 100ft (~30m).
80  * This should only happen when we have received either a waypoint or position estimate, but not both.
81  * Long paths take forever to compute, and will freeze up this node.
82  */
84  continue;
85 
86  planning_mutex.lock();
87  // TODO only replan if needed.
89 
90  if(disp_path_pub.getNumSubscribers() > 0)
91  {
92  nav_msgs::Path disp_path_msg;
93  disp_path_msg.header.stamp = ros::Time::now();
94  disp_path_msg.header.frame_id = "map";
95  for(auto loc : *(path.getStates()))
96  {
97  geometry_msgs::PoseStamped pose;
98  pose.header.stamp = disp_path_msg.header.stamp;
99  pose.header.frame_id = disp_path_msg.header.frame_id;
100  pose.pose.position.x = loc.x;
101  pose.pose.position.y = loc.y;
102  disp_path_msg.poses.push_back(pose);
103  }
104  disp_path_pub.publish(disp_path_msg);
105 
106  igvc_msgs::action_path act_path_msg;
107  act_path_msg.header.stamp = ros::Time::now();
108  act_path_msg.header.frame_id = "map";
109  for(auto action : *(path.getActions()))
110  {
111  igvc_msgs::velocity_pair vels;
112  vels.header.stamp = act_path_msg.header.stamp;
113  vels.header.frame_id = act_path_msg.header.frame_id;
114  double radius = action.V / action.W;
115  vels.left_velocity = (radius - baseline/2.) * action.W;
116  vels.right_velocity = (radius + baseline/2.) * action.W;
117  vels.duration = action.DeltaT;
118  act_path_msg.actions.push_back(vels);
119  }
120  act_path_pub.publish(act_path_msg);
121  }
122 
123  planning_mutex.unlock();
124 
125  rate.sleep();
126  }
127 
128  return 0;
129 }
pcl::PointCloud< pcl::PointXYZ >::Ptr Map
ros::Publisher act_path_pub
action_pathConstPtr path
float distTo(SearchLocation other)
static Path< StateType, ActionType > AStar(SearchProblem< StateType, ActionType > &problem)
IGVCSearchProblem search_problem
SearchLocation Goal
mutex planning_mutex
void map_callback(const sensor_msgs::PointCloud2ConstPtr &msg)
SearchLocation Start
void position_callback(const geometry_msgs::PoseStampedConstPtr &msg)
int main(int argc, char **argv)
ros::Publisher disp_path_pub
void waypoint_callback(const geometry_msgs::PointStampedConstPtr &msg)


igvc
Author(s): Matthew Barulic , Al Chaussee
autogenerated on Sun May 10 2015 16:18:45