testscdspso.cpp
Go to the documentation of this file.
1 
24 
25 #define PI 3.1415926
26 
27 // Register the application
29 
30 namespace testscdspso{
31 
32  TestSCDSPSO::TestSCDSPSO() {}
33 
34  TestSCDSPSO::~TestSCDSPSO() {}
35 
36  void TestSCDSPSO::init() {}
37 
38  void TestSCDSPSO::stop() {}
39 
40  void TestSCDSPSO::loop(const ros::TimerEvent&)
41  {
42  static int i=0;
43  if(i<50)
44  i++;
46  data.val = get_id() + i;
47  tuple.put("test_scds_pso", data);
48 
49  micros_swarm::SCDSPSODataTuple best = tuple.get("test_scds_pso");
50  std::cout<<"robot: "<<get_id()<<", best: "<<best.val<<std::endl;
51  }
52 
53  void TestSCDSPSO::baseCallback(const nav_msgs::Odometry& lmsg)
54  {
55  float x=lmsg.pose.pose.position.x;
56  float y=lmsg.pose.pose.position.y;
57 
58  float vx=lmsg.twist.twist.linear.x;
59  float vy=lmsg.twist.twist.linear.y;
60 
61  micros_swarm::Base l(x, y, 0, vx, vy, 0, 1);
62  set_base(l);
63  }
64 
65  float TestSCDSPSO::fitness(const std::vector<float>& vec)
66  {
67  float x = vec[0];
68  float y = vec[1];
69  float fitness = -(20+x*x+y*y-10*cos(2*PI*x)-10*cos(2*PI*y));
70  return fitness;
71  }
72 
73  void TestSCDSPSO::start()
74  {
75  agent.set_param(1, 1.49445, 1.49445);
76  agent.set_dim(2);
77  agent.set_fitness(boost::bind(&TestSCDSPSO::fitness, this, _1));
78 
79  std::vector<float> max_pos;
80  max_pos.resize(2);
81  max_pos[0] = 5.12;
82  max_pos[1] = 5.12;
83  agent.set_max_pos(max_pos);
84 
85  std::vector<float> min_pos;
86  min_pos.resize(2);
87  min_pos[0] = -5.12;
88  min_pos[1] = -5.12;
89  agent.set_min_pos(min_pos);
90 
91  std::vector<float> max_vel;
92  max_vel.resize(2);
93  max_vel[0] = 1;
94  max_vel[1] = 1;
95  agent.set_max_vel(max_vel);
96 
97  std::vector<float> min_vel;
98  min_vel.resize(2);
99  min_vel[0] = -1;
100  min_vel[1] = -1;
101  agent.set_min_vel(min_vel);
102 
103  agent.rand_init();
104  agent.start(1500);
105  }
106 };
107 
#define PI
Definition: testscdspso.cpp:25
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


testscdspso
Author(s):
autogenerated on Mon Jun 10 2019 14:02:35