7 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 5.0);
8 rate =
new Rate(loop_rate);
10 nh.param(this_node::getName() +
"/queue_size", queue_size, 1);
11 nh.param(this_node::getName() +
"/goal_timeout",
goal_timeout, 30.0);
23 pose_pub =
nh.advertise<geometry_msgs::PoseStamped>(
"pos_controller/goal_position", queue_size,
true);
27 ROS_DEBUG_ONCE(
"Waiting for valid pose...");
40 double b = remainder(atan2(p.position.y -
pose.position.y, p.position.x -
pose.position.x) -
get_yaw(), 2*M_PI);
53 geometry_msgs::Pose goal;
56 goal.position.x = start.position.x + distance * cos(direction);
57 goal.position.y = start.position.y + distance * sin(direction);
58 goal.position.z = start.position.z;
61 tf2::Quaternion orientation;
62 orientation.setRPY(0, 0, direction);
63 goal.orientation = tf2::toMsg(orientation);
75 return hypot(p1.position.x - p2.position.x, p1.position.y - p2.position.y);
92 ROS_ERROR(
"Cannot move to (%.2f,%.2f) because it is out of bounds!", goal.position.x, goal.position.y);
97 geometry_msgs::PoseStamped goal_pose;
98 goal_pose.header.stamp = Time::now();
99 goal_pose.pose = goal;
104 ROS_INFO(
"Move to (%.2f,%.2f)", goal.position.x, goal.position.y);
107 Time start = Time::now();
118 ROS_WARN(
"Failed to reach goal (%.2f,%.2f) in timeout %.2fs!", goal.position.x, goal.position.y,
goal_timeout);
128 cpswarm_msgs::GetSector ocs;
131 if (ocs.response.min == ocs.response.max)
134 ROS_ERROR(
"Goal %.2f in occupied sector [%.2f,%.2f]?",
bearing(pose), ocs.response.min, ocs.response.max);
137 if (ocs.response.max > 2*M_PI &&
bearing(pose) < M_PI)
138 return ocs.response.min <=
bearing(pose) + 2*M_PI &&
bearing(pose) + 2*M_PI <= ocs.response.max;
140 return ocs.response.min <=
bearing(pose) &&
bearing(pose) <= ocs.response.max;
143 ROS_ERROR(
"Failed to check if goal is occupied");
150 cpswarm_msgs::OutOfBounds oob;
151 oob.request.pose =
pose;
153 return oob.response.out;
156 ROS_ERROR(
"Failed to check if goal is out of bounds");
163 tf2::Quaternion orientation;
164 tf2::fromMsg(pose.orientation, orientation);
165 return tf2::getYaw(orientation);
171 ROS_DEBUG(
"Pose (%.2f,%.2f) --> (%.2f,%.2f)",
pose.position.x,
pose.position.y, goal.position.x, goal.position.y);
181 if (msg->header.stamp.isValid())
187 ROS_DEBUG_THROTTLE(1,
"Yaw %.2f",
get_yaw());
188 ROS_DEBUG_THROTTLE(1,
"Pose [%.2f, %.2f, %.2f]",
pose.position.x,
pose.position.y,
pose.position.z);
double goal_timeout
The time in seconds that the CPS is given time to reach a destination before giving up...
bool move(geometry_msgs::Pose pose)
Move the CPS to the given pose.
NodeHandle nh
A node handle for the main ROS node.
double dist(geometry_msgs::Pose p) const
Compute the straight-line distance from the current position to the given position.
Rate * rate
The loop rate object for running the behavior control loops at a specific frequency.
~position()
Destructor that deletes the private member objects.
bool pose_valid
Whether a valid position has been received.
double bearing(geometry_msgs::Pose p) const
Compute the bearing from the current pose of the CPS to a given pose.
position()
Constructor that initializes the private member variables.
bool occupied(geometry_msgs::Pose pose)
Check whether there is an obstacle in the direction of the given pose.
geometry_msgs::Pose pose
Current position of the CPS.
double goal_tolerance
The distance that the CPS can be away from a goal while still being considered to have reached that g...
void pose_callback(const geometry_msgs::PoseStamped::ConstPtr &msg)
Callback function for position updates.
geometry_msgs::Pose compute_goal(double distance, double direction) const
Compute the goal coordinates relative to the current position.
Publisher pose_pub
Publisher for sending the goal position of the CPS to the position controller in the abstraction libr...
ServiceClient occupied_sector_client
Service client for determining the sector occupied by obstacles.
bool out_of_bounds(geometry_msgs::Pose pose)
Check whether a given pose is out of the mission area boundaries.
Subscriber pose_sub
Subscriber for the position of the CPS.
bool reached(geometry_msgs::Pose goal)
Check whether the CPS has reached a given pose.
double get_yaw() const
Get the current yaw orientation of the CPS.
ServiceClient out_of_bounds_client
Service client for determining whether the goal is out of the area bounds.
geometry_msgs::Pose get_pose() const
Get the current pose of the CPS.