29 #include <boost/function.hpp> 30 #include <boost/bind.hpp> 31 #include <boost/thread.hpp> 33 #include "std_msgs/String.h" 34 #include "nav_msgs/Odometry.h" 35 #include "geometry_msgs/Twist.h" 50 return sqrt((
self.x - nei.
x)*(
self.x - nei.
x) + (
self.y - nei.
y)*(
self.y - nei.
y));
56 void callback(
const nav_msgs::OdometryConstPtr &lmsg,
int r_id)
59 p.
x = lmsg->pose.pose.position.x;
60 p.
y = lmsg->pose.pose.position.y;
61 std::map<int, Position >::iterator pos_it;
67 pos_map.insert(std::pair<int, Position>(r_id, p));
98 std::map<int, Position >::iterator it;
112 std::map<int, std::vector<int> >::iterator it;
118 std::vector<int> nei;
137 for(
int j = 0; j < nei.size(); j++) {
158 std::vector<int> neis;
159 std::map<int, Position>::iterator it;
161 if (it->first == r_id) {
166 neis.push_back(it->first);
171 std::map < int, std::vector < int > > ::iterator nei_it;
174 nei_it->second = neis;
176 neighbor_map.insert(std::pair <
int, std::vector < int > > (r_id, neis));
183 int main(
int argc,
char** argv)
188 std::vector<ros::Subscriber> sub_vec;
193 ss<<
"/robot_"<<i<<
"/base_pose_ground_truth";
194 sub_vec[i] = nh.
subscribe<nav_msgs::Odometry>(ss.str(), 1000, boost::bind(
callback, _1, i));
199 boost::thread* process_thread_ =
new boost::thread(
process);
202 file.open(
"app3_statistic.txt");
207 std::cout<<step<<
" "<<err<<std::endl;
208 file<<step<<
" "<<err<<std::endl;
int main(int argc, char **argv)
std::map< int, std::vector< int > > neighbor_map
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::vector< int > get_neighbor(int r_id)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float pos_dis(Position self, Position nei)
std::map< int, Position > pos_map
void callback(const nav_msgs::OdometryConstPtr &lmsg, int r_id)
float nei_dis(int id1, int id2)
ROSCPP_DECL void spinOnce()
Position get_pos(int r_id)