24 #include "hector_uav_msgs/EnableMotors.h" 33 const double C = abs(
A-
B) / sqrt(4*
A*
B);
48 double _px,_py,_vx,
_vy;
59 _position=pair<double,double>(x,y);
60 _velocity=pair<double,double>(vx,vy);
70 pair<double,double>
get_vector(pair<double,double> start,pair<double,double> end)
72 pair<double,double> re=pair<double,double>(0,0);
73 re.first=end.first-start.first;
74 re.second=end.second-start.second;
80 double re =
EPSILON*(v.first*v.first+v.second*v.second);
91 pair<double,double> re = pair<double,double>(0,0);
92 double scale = 1+
EPSILON*(v.first*v.first+v.second*v.second);
94 re.first = v.first / scale;
95 re.second = v.second / scale;
101 return z / sqrt(1+z*z);
115 return 0.5*(1+cos(
PI*(z-
H)/(1-
H)));
125 pair<double,double> re = pair<double,double>(0,0);
136 double a_ij(pair<double,double> j_p)
143 pair<double,double> re = pair<double,double>(0,0);
147 re.first +=
a_ij((*i)->_position) * p_ij.first;
148 re.second +=
a_ij((*i)->_position) * p_ij.second;
154 pair<double,double>
p_r = pair<double,double>(3,0);
155 pair<double,double>
q_r = pair<double,double>(-40,-40);
158 pair<double,double> re = pair<double,double>(0,0);
172 GazeboFlocking::GazeboFlocking() {}
174 GazeboFlocking::~GazeboFlocking() {}
176 void GazeboFlocking::stop() {}
178 void GazeboFlocking::init()
189 float s = sqrt((a-x)*(a-x)+(b-y)*(b-y));
198 static double base_angle = 0;
202 double baseomega = 0;
203 double basespeed = 3;
235 if(time_count>=23*hz && time_count<=23*hz+10*hz)
236 baseomega =
PI/2.0/10;
237 else if(time_count >= 49.5*hz && time_count <= 49.5*hz+10*hz)
238 baseomega =
PI/2.0/10;
239 else if (time_count >= 76*hz && time_count<=76*hz+21*hz)
240 baseomega = (
PI-0.15)/2.0/10;
241 else if (time_count >=103*hz)
248 base_angle += baseomega /hz;
249 p_r.first = basespeed * cos(base_angle);
250 p_r.second = basespeed * sin(base_angle);
252 q_r.second += p_r.second *
interval;
254 geometry_msgs:: Twist msg;
257 typename std::map<int, micros_swarm::NeighborBase>::iterator it;
258 for(it=n.
data().begin();it!=n.
data().end();it++)
282 msg.linear.x +=p_r.first;
283 msg.linear.y +=p_r.second;
287 geometry_msgs::Twist sendmsg;
288 sendmsg.linear.x =msg.linear.x;
289 sendmsg.linear.y = msg.linear.y;
290 if(sendmsg.linear.x==0 && sendmsg.linear.y==0)
291 pub.publish(sendmsg);
294 if(sendmsg.linear.x!=0)
296 fi=atan(sendmsg.linear.y/sendmsg.linear.x);
297 if(sendmsg.linear.x<0&&sendmsg.linear.y>=0)
299 else if (sendmsg.linear.x<0 && sendmsg.linear.y<0)
302 else if (sendmsg.linear.y<0)
304 double v_scale = sqrt(sendmsg.linear.x*sendmsg.linear.x+sendmsg.linear.y*sendmsg.linear.y);
305 sendmsg.linear.x = v_scale*cos(fi-
my_theta);
306 sendmsg.linear.y = v_scale *sin(fi-
my_theta);
307 pub.publish(sendmsg);}
313 void GazeboFlocking::baseCallback(
const nav_msgs::Odometry& lmsg)
315 float x = lmsg.pose.pose.position.x;
316 float y = lmsg.pose.pose.position.y;
318 float vx = lmsg.twist.twist.linear.x;
319 float vy = lmsg.twist.twist.linear.y;
325 void GazeboFlocking::start()
331 hector_uav_msgs::EnableMotors srv;
332 srv.request.enable =
true;
333 if (client.
call(srv))
339 ROS_ERROR(
"Failed to call service enable_motors");
343 pub = nh.
advertise<geometry_msgs::Twist>(
"cmd_vel", 1000);
345 for(
int i = 0; i < 7*10; i++) {
346 geometry_msgs:: Twist upmsg;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
double phi_alpha(double z)
double a_ij(pair< double, double > j_p)
pair< double, double > get_vector(pair< double, double > start, pair< double, double > end)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static double getYaw(const Quaternion &bt_q)
bool call(MReq &req, MRes &res)
pair< double, double > my_velocity
TFSIMD_FORCE_INLINE const tfScalar & y() const
pair< double, double > q_r
pair< double, double > p_r
pair< double, double > segma_epsilon(pair< double, double > v)
pair< double, double > f_r()
pair< double, double > my_position
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
std::map< int, Type > & data()
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
pair< double, double > f_d()
pair< double, double > _velocity
NeighborHandle(int r_id, float x, float y, float vx, float vy)
pair< double, double > f_g()
static list< NeighborHandle * > neighbor_list
double segma_norm(pair< double, double > v)
bool test_location(float a, float b, float x, float y)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)