10 #ifndef GP_NODELET_HPP 11 #define GP_NODELET_HPP 13 #include "mf_mapping/UpdateGP.h" 14 #include "mf_mapping/LoadGP.h" 15 #include "mf_sensors_simulator/CameraOutput.h" 16 #include <tf2_ros/transform_listener.h> 17 #include <nodelet/nodelet.h> 19 #include <eigen3/Eigen/Dense> 59 typedef std::vector<float>
vec_f;
133 void main_cb(
const ros::TimerEvent &timer_event);
152 void camera_cb(
const mf_sensors_simulator::CameraOutputConstPtr &
msg);
158 mf_mapping::UpdateGP::Response &res);
163 bool load_gp_cb(mf_mapping::LoadGP::Request &req,
164 mf_mapping::LoadGP::Response &res);
180 bool transform_points(
const vec_f &x_in,
const vec_f &y_in,
const vec_f &z_in,
181 vec_f &x_out, vec_f &y_out, vec_f &z_out,
182 std::string frame_in, std::string frame_out);
197 bool transform_points(
const vec_f &x_in,
const vec_f &y_in,
const vec_f &z_in,
198 vec_f &x_out, vec_f &y_out, vec_f &z_out,
199 const geometry_msgs::TransformStamped &transform);
225 inline double matern_kernel(
double x1,
double y1,
double x2,
double y2)
const;
243 unsigned int size_obs,
unsigned int size_nobs,
245 std::vector<unsigned int> &idx_obs, std::vector<unsigned int> &idx_nobs
273 const std::vector<unsigned int> &idx_obs,
274 const std::vector<unsigned int> &idx_nobs,
275 Eigen::VectorXf &mu, Eigen::VectorXf &mu_obs,
276 Eigen::MatrixXf &
P, Eigen::MatrixXf &P_obs, Eigen::MatrixXf &B,
277 Eigen::MatrixXf &C_obs, Eigen::MatrixXf &C_obs_inv,
278 Eigen::VectorXf &x_coord, Eigen::VectorXf &y_coord
292 const std::vector<unsigned int> &idx_obs,
293 const std::vector<unsigned int> &idx_nobs,
294 const Eigen::VectorXf &mu,
const Eigen::MatrixXf &
P,
295 Eigen::VectorXf &gp_mean, Eigen::MatrixXf &gp_cov
313 const vec_f &x_meas,
const vec_f &y_meas,
const vec_f &z_meas,
314 const vec_f &distances,
const vec_f &values,
315 Eigen::VectorXf &gp_mean, Eigen::MatrixXf &gp_cov,
316 std::vector<unsigned int> &idx_obs,
318 bool update_mean =
true 331 const std::vector<unsigned int> &idx_obs,
332 const Eigen::VectorXf &gp_mean,
333 Eigen::VectorXf &x_obs, Eigen::VectorXf &y_obs,
349 const Eigen::VectorXf &x_obs,
const Eigen::VectorXf &y_obs,
350 const Eigen::VectorXf &W
378 double lambert_w0(
double z,
double precision=0.01,
double init_w=1.0)
const;
396 double lambert_wm1(
double z,
double precision=0.01,
double init_w=-2.0)
const;
411 double lambert_w(
double z,
double precision,
double init_w)
const;
424 double d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
tf2_ros::Buffer tf_buffer_
Tf2 buffer for getting tf transforms.
ros::Publisher cov_img_pub_
Publisher for an image of the GP covariance.
void prepare_eval(const std::vector< unsigned int > &idx_obs, const Eigen::VectorXf &gp_mean, Eigen::VectorXf &x_obs, Eigen::VectorXf &y_obs, Eigen::VectorXf &W) const
Prepares objects needed for Gaussian Process evaluation.
geometry_msgs::TransformStamped wall_camera_tf_
tf2_ros::TransformListener tf_listener_
Tf2 listener for getting tf transforms.
float size_wall_x_
Size (m) of the algae wall in the x direction.
ros::Publisher gp_mean_pub_
Publisher for the GP mean.
float main_freq_
Frequency of the main loop.
void camera_cb(const mf_sensors_simulator::CameraOutputConstPtr &msg)
Callback for the camera output.
static ros::Timer main_timer_
Timer callback for the main function.
float gp_noise_var_
Noise variance of the Gaussian Process.
double lambert_w(double z, double precision, double init_w) const
Applies Netwton's method to evaluate Lambert W function.
bool update_gp_cb(mf_mapping::UpdateGP::Request &req, mf_mapping::UpdateGP::Response &res)
Service to update the Gaussian Process for several sets of measurements.
ros::Subscriber camera_sub_
Subscriber for the camera.
float delta_y_
Increment (m) in the y direction.
float gp_init_mean_
Initial mean values of the Gaussian Process.
Eigen::MatrixXf gp_C_
Covariance of the values of the mean of the GP.
double lambert_w0(double z, double precision=0.01, double init_w=1.0) const
Evaluates the Lambert W (0 branch) function.
float matern_thresh_
Threshold to consider that the kernel value is 0.
Eigen::VectorXf gp_mean_
Mean of the Gaussian Process.
ros::NodeHandle nh_
Node handler (for topics and services)
void build_Kalman_objects(const std::vector< unsigned int > &idx_obs, const std::vector< unsigned int > &idx_nobs, Eigen::VectorXf &mu, Eigen::VectorXf &mu_obs, Eigen::MatrixXf &P, Eigen::MatrixXf &P_obs, Eigen::MatrixXf &B, Eigen::MatrixXf &C_obs, Eigen::MatrixXf &C_obs_inv, Eigen::VectorXf &x_coord, Eigen::VectorXf &y_coord) const
Builds vectors and matrices needed during Kalman update.
float camera_var_
Max variance on camera measurements.
unsigned int size_gp_
Total size of the Gaussian Process.
ros::ServiceServer update_gp_serv_
Service server for updating the GP.
Eigen::MatrixXf gp_C_inv_
Inverse of gp_C_.
int size_img_x_
Size of the output image in the x direction.
std::vector< bool > changed_pxl_
Whether an output pixel has been updated.
unsigned int size_img_
Total size of the image.
ros::Publisher wall_img_pub_
Publisher for an image of the wall GP.
bool gp_initialised_
Whether the Gaussian Process is initialised.
void pop_reordered_idx(unsigned int size_obs, unsigned int size_nobs, unsigned int min_x, unsigned int max_x, unsigned int min_y, unsigned int max_y, std::vector< unsigned int > &idx_obs, std::vector< unsigned int > &idx_nobs) const
Populates indices correspondance for reordered states.
double lambert_wm1(double z, double precision=0.01, double init_w=-2.0) const
Evaluates the Lambert W (-1 branch) function.
virtual void onInit()
Function called at beginning of nodelet execution.
float distance(const geometry_msgs::Point &p1, const geometry_msgs::Point &p2)
Computes the the euclidean distance between two positions.
float size_wall_y_
Size (m) of the algae wall in the y direction.
static void sigint_handler(int s)
SINGINT (Ctrl+C) callback to stop the nodelet properly.
ros::Publisher gp_eval_pub_
Publisher for the evaluated GP over the wall.
float matern_var_
Signal variance of the Matern kernel.
double matern_kernel(double x1, double y1, double x2, double y2) const
Matern 3/2 kernel function.
void init_gp()
Initialises the Gaussian Process.
static sig_atomic_t volatile b_sigint_
Whether SIGINT signal has been received.
float eval_gp(float x, float y, const Eigen::VectorXf &x_obs, const Eigen::VectorXf &y_obs, const Eigen::VectorXf &W) const
Evaluates the Gaussian Process at a given point.
float delta_x_
Increment (m) in the x direction.
bool tf_got_
Whether transforms have been retrieved.
bool load_gp_cb(mf_mapping::LoadGP::Request &req, mf_mapping::LoadGP::Response &res)
Service to load the Gaussian Process mean.
void update_reordered_gp(const std::vector< unsigned int > &idx_obs, const std::vector< unsigned int > &idx_nobs, const Eigen::VectorXf &mu, const Eigen::MatrixXf &P, Eigen::VectorXf &gp_mean, Eigen::MatrixXf &gp_cov) const
Fills GP mean and covariance from reordered objects.
std::string wall_frame_
Name of the wall frame.
Nodelet for a Gaussian Process mapping an algae wall.
std::vector< unsigned int > idx_obs_
Array of corresponding indices for observed states.
std::vector< float > out_values_
Output values of the Gaussian Process.
Eigen::VectorXf y_coord_
Y coordinates of the state on the wall.
float camera_noise(float distance) const
Camera sensor noise model.
bool gp_loaded_
Whether the GP has been loaded from an external source.
void update_gp(const vec_f &x_meas, const vec_f &y_meas, const vec_f &z_meas, const vec_f &distances, const vec_f &values, Eigen::VectorXf &gp_mean, Eigen::MatrixXf &gp_cov, std::vector< unsigned int > &idx_obs, RectArea &obs_coord, bool update_mean=true) const
Updates the Gaussian Process given measured data points.
Eigen::MatrixXf gp_cov_
Covariance of the Gaussian Process.
void publish_gp_state()
Publishes mean and covariance of the Gaussian Process.
float radius_obs_
Radius of influence of an observation on the GP.
void main_cb(const ros::TimerEvent &timer_event)
Main callback which is called by a timer.
Eigen::VectorXf x_coord_
X coordinates of the state on the wall.
void notif_changing_pxls(const RectArea &coord)
Notifies changing pixels during GP update.
void publish_gp_eval()
Publishes the evaluated GP and its covariance.
bool get_tf()
Gets necessary tf transforms.
std::vector< float > vec_f
ros::ServiceServer load_gp_serv_
Service server for loading the GP.
mf_sensors_simulator::CameraOutput::ConstPtr camera_msg_
Last camera message.
ros::NodeHandle private_nh_
Private node handler (for parameters)
ros::Publisher gp_cov_pub_
Publisher for the GP covariance.
float matern_length_
Lengthscale of the Matern kernel.
int size_gp_x_
Size of the Gaussian Process mean in the x direction.
bool camera_msg_available_
Whether a new camera message is available.
bool transform_points(const vec_f &x_in, const vec_f &y_in, const vec_f &z_in, vec_f &x_out, vec_f &y_out, vec_f &z_out, std::string frame_in, std::string frame_out)
Transforms points from one frame to another.
float gp_cov_thresh_
Threshold to consider a value as 0 in the covariance.
float camera_decay_
Exponential decay rate on camera measurements.
std::string camera_frame_
Name of the camera frame.
int size_gp_y_
Size of the Gaussian Process mean in the y direction.