8 nh.
param(this_node::getName() +
"/margin",
margin, 0.5);
12 nh.
param<
int>(
"/rng_seed", seed, 0);
78 cpswarm_msgs::GetPoints area;
81 vector<geometry_msgs::Point> coords = area.response.points;
84 for (
int i = 0; i < coords.size(); ++i) {
85 geometry_msgs::Point v1;
86 v1.x =
goal.position.x - coords[i].x;
87 v1.y =
goal.position.y - coords[i].y;
89 geometry_msgs::Point v2;
90 v2.x = coords[(i+1)%coords.size()].x - coords[i].x;
91 v2.y = coords[(i+1)%coords.size()].y - coords[i].y;
93 geometry_msgs::Point v3;
97 double dot1 = v1.x*v3.x + v1.y*v3.y;
98 double dot2 = v2.x*v3.x + v2.y*v3.y;
99 double cross = v2.x*v1.y - v1.x*v2.y;
101 double t1 = cross / dot2;
102 double t2 = dot1 / dot2;
104 if (t1 >= 0.0 && t2 >= 0.0 && t2 <= 1.0) {
123 cpswarm_msgs::GetSector clear;
129 ROS_DEBUG(
"Clear [%.2f, %.2f] size %.2f", clear.response.min, clear.response.max, clear.response.max - clear.response.min);
132 geometry_msgs::Pose
goal;
136 ROS_DEBUG_THROTTLE(1,
"Checking goal [%.2f, %.2f, %.2f] in direction %.2f...", goal.position.x, goal.position.y, goal.position.z,
direction);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
~uav_random_direction()
Destructor that deletes the private member objects.
bool move(geometry_msgs::Pose pose)
#define ROS_DEBUG_THROTTLE(rate,...)
behavior_state_t
An enumeration for the state of the behavior algorithm.
bool call(MReq &req, MRes &res)
random_numbers::RandomNumberGenerator * rng
The random number generator used for selecting a random direction.
bool occupied(geometry_msgs::Pose pose)
double margin
The distance in meter to keep to the environment boundary.
ServiceClient area_client
Service client to get the area polygon.
position pos
A helper object for position related tasks.
bool select_goal()
Compute goal position from direction.
double direction
The direction in which the drone is travling. It is measured in radian, clockwise starting from north...
geometry_msgs::Pose get_pose() const
bool new_direction()
Compute new direction using rng.
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
uav_random_direction(double altitude)
Constructor that initializes the private member variables.
double uniformReal(double lower_bound, double upper_bound)
behavior_state_t step()
Move the swarm member to a new position.
geometry_msgs::Pose goal
The current goal.
bool out_of_bounds(geometry_msgs::Pose pose)
ServiceClient clear_sector_client
Service client for determining the sector clear of obstacles.
ROSCPP_DECL void spinOnce()