Go to the documentation of this file.00001
00023 #include "testvstig/testvstig.h"
00024
00025
00026 PLUGINLIB_EXPORT_CLASS(testvstig::TestVstig, micros_swarm::Application)
00027
00028 namespace testvstig{
00029
00030 TestVstig::TestVstig() {}
00031
00032 TestVstig::~TestVstig() {}
00033
00034 void TestVstig::init() {}
00035
00036 void TestVstig::stop() {}
00037
00038 void TestVstig::loop_puts(const ros::TimerEvent&)
00039 {
00040 std::string robot_id_string = "robot_"+boost::lexical_cast<std::string>(get_id());
00041 static int count = 1;
00042 std_msgs::Int32 pval;
00043 pval.data = get_id() + count;
00044 vs.puts(robot_id_string, pval);
00045 count++;
00046 std::cout<<robot_id_string<<": "<<vs.size()<<std::endl;
00047
00048
00049
00050
00051
00052
00053
00054
00055 }
00056
00057 void TestVstig::loop_gets(const ros::TimerEvent&)
00058 {
00059
00060 std::string robot_id_string = "robot_" + boost::lexical_cast<std::string>(get_id());
00061 std_msgs::Int32 gval = vs.gets(robot_id_string);
00062 std::cout << robot_id_string << ": " << vs.size() << ", " << gval.data << std::endl;
00063
00064 }
00065
00066 void TestVstig::loop_put(const ros::TimerEvent&)
00067 {
00068 std::string robot_id_string = "robot_"+boost::lexical_cast<std::string>(get_id());
00069 static int count = 1;
00070 std_msgs::Int32 pval;
00071 pval.data = get_id() + count;
00072 vs.put(robot_id_string, pval);
00073 count++;
00074 std::cout<<robot_id_string<<": "<<vs.size()<<std::endl;
00075
00076 }
00077
00078 void TestVstig::loop_get(const ros::TimerEvent&)
00079 {
00080
00081 std::string robot_id_string = "robot_" + boost::lexical_cast<std::string>(get_id());
00082 std_msgs::Int32 gval = vs.get(robot_id_string);
00083 std::cout << robot_id_string << ": " << vs.size() << ", " << gval.data << std::endl;
00084
00085 }
00086
00087 void TestVstig::not_loop_put(const ros::TimerEvent&)
00088 {
00089 static int count = 1;
00090 std_msgs::Int32 pval;
00091 pval.data = get_id() + count;
00092
00093 std::string cur_string="robot_"+boost::lexical_cast<std::string>(get_id())+"/"+boost::lexical_cast<std::string>(count);
00094 std::string front_string="robot_"+boost::lexical_cast<std::string>(get_id())+"/"+boost::lexical_cast<std::string>(count-1);
00095 vs.put(cur_string, pval);
00096
00097
00098 std::cout<<cur_string<<": "<<vs.size()<<std::endl;
00099 count++;
00100 }
00101
00102 void TestVstig::not_loop_get(const ros::TimerEvent&)
00103 {
00104
00105 int i = micros_swarm::random_int(0, 2047);
00106 std::string cur_string = "tuple/" + boost::lexical_cast<std::string>(i);
00107 std_msgs::Int32 gval = vs.get(cur_string);
00108 std::cout << cur_string << ": " << vs.size() << ", " << gval.data << std::endl;
00109
00110 }
00111
00112 void TestVstig::baseCallback(const nav_msgs::Odometry& lmsg)
00113 {
00114 static int msg_count = 0;
00115 float x=lmsg.pose.pose.position.x;
00116 float y=lmsg.pose.pose.position.y;
00117
00118 float vx=lmsg.twist.twist.linear.x;
00119 float vy=lmsg.twist.twist.linear.y;
00120
00121 micros_swarm::Base l(x, y, 0, vx, vy, 0, 1);
00122 set_base(l);
00123
00124 msg_count++;
00125 if(msg_count >= 5) {
00126 std::cout<<"shutdown sub"<<std::endl;
00127 sub.shutdown();
00128 }
00129
00130 }
00131
00132 void TestVstig::start()
00133 {
00134 ros::NodeHandle nh;
00135 sub = nh.subscribe("base_pose_ground_truth", 1000, &TestVstig::baseCallback, this, ros::TransportHints().udp());
00136
00137
00138 vs=micros_swarm::VirtualStigmergy<std_msgs::Int32>(1);
00139 std_msgs::Int32 val;
00140 val.data = get_id();
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 for(int i = 0; i < 2048; i++){
00175 std::string cur_string="tuple/"+boost::lexical_cast<std::string>(i);
00176 std_msgs::Int32 pval;
00177 pval.data = i;
00178 vs.put(cur_string, pval);
00179 }
00180 ros::Duration(20).sleep();
00181 timer = nh.createTimer(ros::Duration(0.1), &TestVstig::not_loop_get, this);
00182 }
00183 };
00184