30 #include <nav_msgs/OccupancyGrid.h> 32 #include <boost/functional/hash.hpp> 33 #include "yaml-cpp/yaml.h" 35 int main(
int argc,
char **argv)
38 ros::init(argc, argv,
"segment to graph");
83 std::vector<double> start_x = (waypoints_yaml[
"start_x"].as<std::vector<double>>());
84 std::vector<double> start_y = (waypoints_yaml[
"start_y"].as<std::vector<double>>());
85 std::vector<double> end_x = (waypoints_yaml[
"end_x"].as<std::vector<double>>());
86 std::vector<double> end_y = (waypoints_yaml[
"end_y"].as<std::vector<double>>());
87 std::vector<double> path_space = (waypoints_yaml[
"space"].as<std::vector<double>>());
88 double origin_x = (waypoints_yaml[
"origin_x"].as<
double>());
89 double origin_y = (waypoints_yaml[
"origin_y"].as<
double>());
90 double resolution = (waypoints_yaml[
"resolution"].as<
double>());
92 std::vector<PathSeg> graph;
94 for (uint32_t i = 0; i < start_x.size(); i++)
96 Eigen::Vector2d start((start_x[i] + origin_x) / resolution, (start_y[i] + origin_y) / resolution);
97 Eigen::Vector2d end((end_x[i] + origin_x) / resolution, (end_y[i] + origin_y) / resolution);
98 graph.emplace_back(start, end, path_space[i]);
111 for (uint32_t i = 0; i < graph.size(); i++)
113 tuw_multi_robot_msgs::Vertex v;
116 v.weight = (graph[i].start - graph[i].end).norm();
117 v.width = graph[i].width / resolution;
119 geometry_msgs::Point start;
120 start.x = graph[i].start[0];
121 start.y = graph[i].start[1];
123 geometry_msgs::Point end;
124 end.x = graph[i].end[0];
125 end.y = graph[i].end[1];
128 v.path.push_back(start);
129 v.path.push_back(end);
131 std::vector<int> pred =
findNeighbors(graph, graph[i].start, i);
135 v.predecessors.push_back(pr);
138 std::vector<int> succ =
findNeighbors(graph, graph[i].end, i);
142 v.successors.push_back(sr);
153 std::vector<int32_t> n;
155 for (uint32_t i = 0; i < _graph.size(); i++)
159 if ((_graph[i].start - _point).norm() < 0.1 || (_graph[i].end - _point).norm() < 0.1)
SegmentToGraphNode(ros::NodeHandle &n)
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher pubSegments_
std::vector< int32_t > findNeighbors(std::vector< PathSeg > &_graph, Eigen::Vector2d _point, uint32_t _segment)
std::string segment_file_
tuw_multi_robot_msgs::Graph current_graph_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle n_param_
Node handler to the current node.
ROSCPP_DECL void spinOnce()
std::string segment_topic_