00001 00023 #include <ros/ros.h> 00024 #include "micros_swarm/micros_swarm.h" 00025 00026 using namespace micros_swarm; 00027 00028 int main(int argc, char** argv) 00029 { 00030 ros::init(argc, argv, "micros_swarm_framework_main_node"); 00031 ros::NodeHandle nh; 00032 00033 RuntimeHandle rth; 00034 rth.setRobotID(1); 00035 00036 Base base(1,1,1,2,2,2,1); 00037 rth.setRobotBase(base); 00038 rth.printRobotBase(); 00039 std::cout<<std::endl; 00040 00041 rth.insertOrUpdateNeighbor(2, 0, 0, 0, 1, 1, 1,2, 2, 2); 00042 rth.insertOrUpdateNeighbor(3, 1, 2, 3, 2, 2, 2,3, 3, 3); 00043 rth.insertOrUpdateNeighbor(4, 2, 2, 2, 1, 2, 3,3, 3, 3); 00044 rth.printNeighbor(); 00045 std::cout<<"------"<<std::endl; 00046 rth.insertOrUpdateNeighbor(2, 1, 2, 3, 4, 5, 6,7, 8, 9); 00047 rth.deleteNeighbor(3); 00048 rth.deleteNeighbor(16); 00049 rth.printNeighbor(); 00050 std::cout<<std::endl; 00051 00052 rth.insertOrUpdateSwarm(1, true); 00053 rth.insertOrUpdateSwarm(2, false); 00054 rth.insertOrUpdateSwarm(3, true); 00055 rth.printSwarm(); 00056 std::cout<<"------"<<std::endl; 00057 rth.insertOrUpdateSwarm(2, true); 00058 rth.deleteSwarm(1); 00059 rth.deleteSwarm(16); 00060 rth.printSwarm(); 00061 std::cout<<rth.getSwarmFlag(1)<<std::endl; 00062 std::cout<<rth.getSwarmFlag(2)<<std::endl; 00063 std::cout<<std::endl; 00064 00065 std::vector<int> s1, s2; 00066 s1.push_back(1); s1.push_back(2); s1.push_back(3); 00067 s2.push_back(4); s2.push_back(5); s2.push_back(6); 00068 rth.insertOrRefreshNeighborSwarm(2, s1); 00069 rth.insertOrRefreshNeighborSwarm(3, s2); 00070 rth.printNeighborSwarm(); 00071 std::cout<<rth.inNeighborSwarm(2, 2)<<std::endl; 00072 std::cout<<rth.inNeighborSwarm(2, 4)<<std::endl; 00073 std::cout<<rth.inNeighborSwarm(3, 5)<<std::endl; 00074 std::cout<<rth.inNeighborSwarm(3, 1)<<std::endl; 00075 std::cout<<"------"<<std::endl; 00076 rth.joinNeighborSwarm(2, 4); 00077 rth.joinNeighborSwarm(2, 5); 00078 rth.leaveNeighborSwarm(2, 2); 00079 rth.leaveNeighborSwarm(2, 3); 00080 rth.leaveNeighborSwarm(2, 17); 00081 rth.printNeighborSwarm(); 00082 std::cout<<"------"<<std::endl; 00083 rth.deleteNeighborSwarm(2); 00084 rth.deleteNeighborSwarm(9); 00085 rth.printNeighborSwarm(); 00086 std::cout<<std::endl; 00087 00088 rth.createVirtualStigmergy(1); 00089 rth.createVirtualStigmergy(2); 00090 std::vector<uint8_t> val1; 00091 val1.push_back(1); 00092 rth.insertOrUpdateVirtualStigmergy(1, "key1", val1, 1, time(0), 0, 1); 00093 std::vector<uint8_t> val2; 00094 val2.push_back(2); 00095 rth.insertOrUpdateVirtualStigmergy(1, "key2", val2, 1, time(0), 0, 1); 00096 std::vector<uint8_t> val3; 00097 val3.push_back(3); 00098 rth.insertOrUpdateVirtualStigmergy(1, "key3", val3, 1, time(0), 0, 1); 00099 rth.printVirtualStigmergy(); 00100 VirtualStigmergyTuple vst1; 00101 rth.getVirtualStigmergyTuple(1, "key2", vst1); 00102 vst1.print(); 00103 VirtualStigmergyTuple vst2; 00104 rth.getVirtualStigmergyTuple(2, "key3", vst2); 00105 vst2.print(); 00106 std::cout<<rth.getVirtualStigmergySize(1)<<std::endl;; 00107 std::cout<<rth.getVirtualStigmergySize(2)<<std::endl; 00108 rth.deleteVirtualStigmergyValue(1, "key2"); 00109 rth.deleteVirtualStigmergyValue(1, "key6"); 00110 rth.deleteVirtualStigmergyValue(2, "key3"); 00111 rth.deleteVirtualStigmergyValue(5, "key7"); 00112 rth.printVirtualStigmergy(); 00113 VirtualStigmergyTuple vst3; 00114 rth.getVirtualStigmergyTuple(2, "key7", vst3); 00115 vst3.print(); 00116 VirtualStigmergyTuple vst4; 00117 rth.getVirtualStigmergyTuple(7, "key11", vst4); 00118 vst4.print(); 00119 rth.deleteVirtualStigmergy(2); 00120 rth.deleteVirtualStigmergy(5); 00121 rth.printVirtualStigmergy(); 00122 00123 ros::spin(); 00124 return 0; 00125 }