12 #include "mf_sensors_simulator/MultiPoses.h" 13 #include "mf_mapping/UpdateGP.h" 14 #include "mf_common/Float32Array.h" 15 #include "mf_common/Array2D.h" 16 #include "mf_common/Float32Array.h" 17 #include <geometry_msgs/TransformStamped.h> 18 #include <geometry_msgs/PoseArray.h> 19 #include <geometry_msgs/Point.h> 20 #include <visualization_msgs/Marker.h> 21 #include <std_srvs/Empty.h> 22 #include <pluginlib/class_list_macros.h> 37 sig_atomic_t
volatile PlanningNodelet::b_sigint_ = 0;
38 ros::Timer PlanningNodelet::main_timer_ = ros::Timer();
43 PlanningNodelet::PlanningNodelet():
44 tf_listener_(tf_buffer_)
55 nh_ = getNodeHandle();
59 struct sigaction sigIntHandler;
61 sigemptyset(&sigIntHandler.sa_mask);
62 sigIntHandler.sa_flags = 0;
63 sigaction(SIGINT, &sigIntHandler, NULL);
66 vector<double> model_csts;
67 vector<double> bnd_input;
68 bool initially_disabled;
76 private_nh_.param<
bool>(
"initially_disabled", initially_disabled,
false);
79 private_nh_.param<vector<double>>(
"model_constants", model_csts, vector<double>(11, 0.0));
80 private_nh_.param<vector<double>>(
"bnd_input", bnd_input, vector<double>(4, 0.0));
105 wall_orientation_ = fabs(wall_orientation_);
108 bnd_pitch_ *= M_PI / 180.0;
111 lattice_size_vert_ = 0;
113 lattice_size_horiz_ = 0;
127 path_.poses.resize(0);
137 lattice_pub_ =
nh_.advertise<visualization_msgs::Marker>(
"wp_lattice", 0);
157 if (!ros::ok() || ros::isShuttingDown() ||
b_sigint_)
169 clock_t start = clock();
170 cout <<
"\n=== Starting plannning... ===" << endl;
174 cout <<
"Ellapsed time: " << (clock() - start) / (
double)CLOCKS_PER_SEC << endl;
198 geometry_msgs::Point pos_wall;
199 geometry_msgs::Point pos_ocean =
waypoints_.back().position;
203 if ((pos_wall.z > 0 && pos_wall.y >=
length_wall_) || (pos_wall.z < 0 && pos_wall.y <= 0))
217 visualization_msgs::Marker marker;
218 marker.header.stamp = ros::Time::now();
220 marker.ns =
"lattice";
221 marker.pose.orientation.w = 1.0;
222 marker.color.r = 0.0;
223 marker.color.g = 1.0;
224 marker.color.b = 0.0;
225 marker.color.a = 1.0;
226 marker.type = visualization_msgs::Marker::POINTS;
227 marker.action = visualization_msgs::Marker::ADD;
228 marker.scale.x = 0.05;
229 marker.scale.y = 0.05;
230 marker.points.resize(n);
231 marker.colors.resize(n);
234 for (
unsigned int k = 0; k <
n; k++) {
235 marker.points[k].x =
lattice_[k].position.x;
236 marker.points[k].y =
lattice_[k].position.y;
237 marker.points[k].z =
lattice_[k].position.z;
239 marker.colors[k].r = 0.0;
240 marker.colors[k].g = 0.0;
241 marker.colors[k].b = 1.0;
242 marker.colors[k].a = 1.0;
248 geometry_msgs::PoseArray
msg;
254 marker.ns =
"selected_vp";
263 marker.colors[k].r = 0.0;
264 marker.colors[k].g = 1.0;
265 marker.colors[k].b = 0.0;
266 marker.colors[k].a = 1.0;
272 marker.ns =
"hitpoints";
274 marker.color.r = 0.0;
275 marker.color.g = 1.0;
276 marker.color.b = 1.0;
277 marker.color.a = 1.0;
280 marker.points.resize(n_pts);
281 for (
unsigned int k = 0; k < n_pts; k++) {
293 geometry_msgs::TransformStamped t1, t2, t3, t4, t5, t6, t7;
304 catch (tf2::TransformException &ex) {
305 NODELET_WARN(
"[planning_nodelet] %s", ex.what());
340 std_srvs::Empty::Request &req,
341 std_srvs::Empty::Response &res)
343 ROS_INFO(
"[planning_nodelet] Planner disabled");
346 path_.poses.resize(0);
354 std_srvs::Empty::Request &req,
355 std_srvs::Empty::Response &res)
357 ROS_INFO(
"[planning_nodelet] Planner enabled");
int nbr_lattices_
Number of lattices for multi-lattices planning.
float plan_horizon_
Horizon (m) of the planning (for each lattice)
static void sigint_handler(int s)
SINGINT (Ctrl+C) callback to stop the nodelet properly.
std::vector< float > x_hit_pt_sel_
X coordinates of the hit points for the selected viewpoint (in ocean frame)
bool vert_motion_
Whether to allow motion in the vertical plane.
geometry_msgs::TransformStamped robot_ocean_tf_
Transform from robot to ocean frames.
ros::Subscriber state_sub_
Subscriber for the state of the robot.
Declaration of physical underwater robot model.
float path_res_
Spatial resolution (m) of the planned trajectory.
geometry_msgs::TransformStamped wall_ocean_tf_
Transform from wall to ocean frames.
ros::Subscriber gp_mean_sub_
Subscriber for the mean of the Gaussian Process.
float wall_orientation_
Orientation of the wall (absolute value)
float lattice_res_
Resolution (m) of the waypoints lattice.
bool enable_cb(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Service server callback to enable planning.
tf2_ros::Buffer tf_buffer_
Buffer for tf2.
std::string camera_frame_
Camera frame.
int camera_width_
Number of pixels of the camera along width (-1 for actual camera size)
ros::NodeHandle nh_
Node handler (for topics and services)
geometry_msgs::TransformStamped ocean_camera_tf_
Transform from ocean to camera frames.
bool disable_cb(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Service server callback to disable planning.
std::vector< std::vector< float > > array_to_vector2D(const std::vector< mf_common::Float32Array > &array)
Converts a custom ROS array to a 2D std vector.
std::vector< float > last_gp_mean_
Last mean of the Gaussian Process.
nav_msgs::Path path_
Interpolated path between the waypoints (in ocean frame)
void state_cb(const mf_common::Float32Array msg)
Callback for the state of the robot.
float main_freq_
Frequency of the main loop.
ros::Publisher path_pub_
Publisher for the path.
geometry_msgs::TransformStamped robot_wall_tf_
Transform from robot to wall frames.
ros::NodeHandle private_nh_
Private node handler (for parameters)
std::vector< geometry_msgs::Pose > lattice_
Lattice of possible waypoints in ocean frame.
geometry_msgs::TransformStamped ocean_wall_tf_
Transform from ocean to wall frames.
bool plan_trajectory()
Main function to compute a trajectory plan.
std::vector< double > state_type
Data type of the state.
void gp_mean_cb(const mf_common::Float32ArrayConstPtr msg)
Callback for Gaussian Process mean.
void pub_lattice_markers()
Publishes the waypoints lattice markers.
ros::ServiceClient update_gp_client_
Service client for updating the Gaussian Process.
std::vector< geometry_msgs::Pose > waypoints_
Waypoints to follow (in ocean frame)
ros::Subscriber gp_cov_sub_
Subscriber for the covariance of the Gaussian Process.
std::vector< std::vector< float > > last_gp_cov_
Last covariance of the Gaussian Process.
RobotModel::state_type state_
State of the robot (in ocean frame)
bool cart_lattice_
Whether to create a cartesian lattice, or use motion model instead.
std::vector< geometry_msgs::Pose > selected_vp_
Selected view points in the lattice (in ocean frame)
bool check_planning_needed()
Checks whether planning is needed or not.
bool horiz_motion_
Whether to allow motion in the horizontal plane.
std::vector< float > bnd_depth_
Bounds on the depth (in wall frame) for waypoint selection.
std::vector< float > z_hit_pt_sel_
Z coordinates of the hit points for the selected viewpoint (in ocean frame)
std::vector< float > y_hit_pt_sel_
Y coordinates of the hit points for the selected viewpoint (in ocean frame)
std::string ocean_frame_
Ocean frame.
Class defining the robot model.
float max_elev_rudder_
Maximum angle of the elevation rudder.
ros::ServiceClient ray_multi_client_
Service client for raycasting at several camera poses.
static sig_atomic_t volatile b_sigint_
Whether SIGINT signal has been received.
virtual void onInit()
Function called at beginning of nodelet execution.
geometry_msgs::TransformStamped wall_robot_tf_
Transform from wall to robot frames.
static ros::Timer main_timer_
Timer callback for the main function.
RobotModel robot_model_
Robot model.
int lattice_size_vert_
Size of the lattice in the vertical direction (half size when single-lattice planning) ...
int lattice_size_horiz_
Size of the lattice in the horizontal direction (half size when single-lattice planning) ...
std::string wall_frame_
Wall frame.
bool linear_path_
Whether to create a linear path, or a spline one.
int camera_height_
Number of pixels of the camera along height (-1 for actual camera size)
float plan_speed_
Planned speed (m/s) of the robot.
std::string robot_frame_
Robot frame.
float max_lat_rudder_
Maximum angle of the lateral rudder.
bool get_tf()
Gets tf transforms.
bool planner_enabled_
Whether the planner should run.
bool replan_
Whether to replan from the current robot pose, or to plan from the last planned pose.
ros::ServiceServer disable_serv_
Service server to disable planning.
bool state_received_
Whether the state of the robot has been received.
Declaration of a nodelet for path plannning of an underwater robot surveying a marine farm...
ros::Publisher lattice_pub_
Publisher for the waypoints lattice.
bool mult_lattices_
Whether to use multi-lattices planning.
geometry_msgs::TransformStamped ocean_robot_tf_
Transform from ocean to robot frames.
Nodelet for path planning of an underwater robot surveying a marine farm.
void main_cb(const ros::TimerEvent &timer_event)
Main callback which is called by a timer.
ros::ServiceServer enable_serv_
Service server to enable planning.
void gp_cov_cb(const mf_common::Array2DConstPtr msg)
Callback for Gaussian Process covariance.
ros::Publisher lattice_pose_pub_
Publisher for the waypoints lattice poses.
std::vector< float > bnd_wall_dist_
Bounds on the distance to the wall for waypoint selection.