12 #include "mf_sensors_simulator/CameraOutput.h" 13 #include "mf_sensors_simulator/MultiPoses.h" 15 #include "mf_farm_simulator/Algae.h" 16 #include "reactphysics3d.h" 17 #include <tf2_ros/transform_listener.h> 18 #include <tf2/LinearMath/Vector3.h> 19 #include <tf2/LinearMath/Transform.h> 20 #include <geometry_msgs/TransformStamped.h> 21 #include <nodelet/nodelet.h> 84 virtual void notifyOverlap(rp3d::CollisionBody *body);
161 void main_cb(
const ros::TimerEvent &timer_event);
173 void algae_cb(
const mf_farm_simulator::AlgaeConstPtr
msg);
205 const std::vector<geometry_msgs::Pose> &poses,
206 rp3d::CollisionBody* body,
207 std::unique_ptr<rp3d::BoxShape> &shape,
208 ros::Time stamp = ros::Time(0)
217 bool ray_multi_cb(mf_sensors_simulator::MultiPoses::Request &req,
218 mf_sensors_simulator::MultiPoses::Response &res);
250 std::vector<float> &w_algae, std::vector<float> &h_algae,
251 std::vector<float> &inc_y3, std::vector<float> &inc_z3,
252 std::vector<geometry_msgs::TransformStamped> &tf_algae
267 tf2::Vector3
get_aim_pt(
int pxl_h,
int pxl_w,
int n_pixel_h = -1,
int n_pixel_w = -1);
274 inline rp3d::Vector3
tf2_to_rp3d(
const tf2::Vector3 vect);
284 inline geometry_msgs::TransformStamped
pose_to_tf(
const geometry_msgs::Pose &pose);
294 inline geometry_msgs::TransformStamped
inverse_tf(
295 const geometry_msgs::TransformStamped &transform);
304 const std::vector<geometry_msgs::TransformStamped> &transforms);
314 const geometry_msgs::TransformStamped &transform);
327 const tf2::Vector3 &aim_pt,
328 tf2::Vector3 &hit_pt,
330 const geometry_msgs::TransformStamped &fixed_camera_tf,
331 const tf2::Vector3 &origin = tf2::Vector3(0, 0, 0)
344 const tf2::Vector3 &aim_pt,
346 const geometry_msgs::TransformStamped &fixed_camera_tf,
347 const tf2::Vector3 &origin = tf2::Vector3(0, 0, 0)
376 const geometry_msgs::Pose &vp_pose,
377 int n_pxl_h,
int n_pxl_w,
378 mf_sensors_simulator::CameraOutput &pxl_output,
379 ros::Time stamp = ros::Time(0)
415 const tf2::Vector3 &p1,
const tf2::Vector3 &p2,
const tf2::Vector3 &p3,
const tf2::Vector3 &p4,
417 std::vector<float> &x_list, std::vector<float> &y_list, std::vector<float> &z_list
428 mf_sensors_simulator::CameraOutput &out_msg,
429 visualization_msgs::Marker &ray_marker,
430 visualization_msgs::Marker &pts_marker
443 const tf2::Vector3 &pt,
float color_r,
float color_g,
float color_b);
453 const tf2::Vector3 &pt1,
const tf2::Vector3 &pt2);
465 return rp3d::Vector3(vect.getX(), vect.getY(), vect.getZ());
470 const geometry_msgs::Pose &pose)
472 geometry_msgs::TransformStamped transf;
473 transf.transform.translation.x = pose.position.x;
474 transf.transform.translation.y = pose.position.y;
475 transf.transform.translation.z = pose.position.z;
476 transf.transform.rotation.x = pose.orientation.x;
477 transf.transform.rotation.y = pose.orientation.y;
478 transf.transform.rotation.z = pose.orientation.z;
479 transf.transform.rotation.w = pose.orientation.w;
486 const geometry_msgs::TransformStamped &transform)
488 tf2::Vector3 trans(transform.transform.translation.x,
489 transform.transform.translation.y,
490 transform.transform.translation.z);
491 tf2::Quaternion orient(transform.transform.rotation.x,
492 transform.transform.rotation.y,
493 transform.transform.rotation.z,
494 transform.transform.rotation.w);
496 tf2::Transform inverse = tf2::Transform(orient, trans).inverse();
497 trans = inverse.getOrigin();
498 orient = inverse.getRotation();
500 geometry_msgs::TransformStamped ret;
501 ret.transform.translation.x = trans.getX();
502 ret.transform.translation.y = trans.getY();
503 ret.transform.translation.z = trans.getZ();
504 ret.transform.rotation.x = orient.getX();
505 ret.transform.rotation.y = orient.getY();
506 ret.transform.rotation.z = orient.getZ();
507 ret.transform.rotation.w = orient.getW();
void get_ray_algae_carac(std::vector< float > &w_algae, std::vector< float > &h_algae, std::vector< float > &inc_y3, std::vector< float > &inc_z3, std::vector< geometry_msgs::TransformStamped > &tf_algae)
Gets position, dimension and axes of the algae for raycasting.
float noise_std_
Maximum standard deviation of the measurement noise.
std::vector< int > corr_algae_
Correspondance between the algae used for raytracing and all the others.
bool world_init_
Whether the collision world has been initialised.
bool algae_msg_received_
Whether an algae message has been received.
float focal_length_
Focal length of the camera.
void publish_output()
Publishes camera output.
void algae_cb(const mf_farm_simulator::AlgaeConstPtr msg)
Callback for the algae of the farm.
virtual rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo &info)
int n_pxl_width_
Nbr of pixels along sensor width.
static ros::Timer main_timer_
Timer callback for the main function.
ros::NodeHandle nh_
Node handler (for topics and services)
rp3d::CollisionWorld ray_world_
World with algae colliding with FOV.
void overlap_fov(rp3d::CollisionBody *body)
Selects algae that are in field of view of the camera.
rp3d::CollisionWorld coll_world_
World with all algae and camera FOV.
float camera_freq_
Frequency of the sensor.
std::vector< std::vector< std::vector< float > > > heatmaps_
Disease heatmatps for all the algae.
tf2::Vector3 apply_transform(const tf2::Vector3 &in_vector, const geometry_msgs::TransformStamped &transform)
Applies a transform to a vector.
box_shape_ptr fov_shape_
Collision shapes of the FOV body.
virtual void onInit()
Function called at beginning of nodelet execution.
Declaration of common Rviz display functions.
tf2::Vector3 hit_pt_
Hit point.
geometry_msgs::TransformStamped fixed_camera_tf_
Transform from fixed frame to camera.
ros::NodeHandle private_nh_
Private node handler (for parameters)
static sig_atomic_t volatile b_sigint_
Whether SIGINT signal has been received.
std::vector< box_shape_ptr > ray_shapes_
Collision shapes of algae for raycasting.
CameraNodelet * parent_
Parent CameraNodelet instance.
bool raycast_wall(const geometry_msgs::Pose &vp_pose, int n_pxl_h, int n_pxl_w, mf_sensors_simulator::CameraOutput &pxl_output, ros::Time stamp=ros::Time(0))
geometry_msgs::TransformStamped pose_to_tf(const geometry_msgs::Pose &pose)
Converts a pose to a transform.
void prepare_out_msgs(mf_sensors_simulator::CameraOutput &out_msg, visualization_msgs::Marker &ray_marker, visualization_msgs::Marker &pts_marker)
Prepares the ROS output messages.
tf2_ros::Buffer tf_buffer_
std::vector< float > fov_color_
Color of the camera field of view Rviz marker.
std::unique_ptr< rp3d::BoxShape > box_shape_ptr
void update_algae()
Updates algae in the collision world.
void init_coll_world()
Initialise the collision world.
float distance(const geometry_msgs::Point &p1, const geometry_msgs::Point &p2)
Computes the the euclidean distance between two positions.
void main_cb(const ros::TimerEvent &timer_event)
Main callback which is called by a timer.
float fov_distance_
Maximum distance detected by the camera.
rp3d::Vector3 tf2_to_rp3d(const tf2::Vector3 vect)
Converts a tf2 vector to a rp3d vector.
void add_pt_to_marker(visualization_msgs::Marker &marker, const tf2::Vector3 &pt, float color_r, float color_g, float color_b)
Add a point to a point marker.
std::string robot_frame_
Frame of the robot.
geometry_msgs::TransformStamped inverse_tf(const geometry_msgs::TransformStamped &transform)
Inverse a transform.
void interpolate_quadri(const tf2::Vector3 &p1, const tf2::Vector3 &p2, const tf2::Vector3 &p3, const tf2::Vector3 &p4, int n_h, int n_w, std::vector< float > &x_list, std::vector< float > &y_list, std::vector< float > &z_list)
Interpolates a 3D quadrilateral lying on a plane.
static void sigint_handler(int s)
SINGINT (Ctrl+C) callback to stop the nodelet properly.
float sensor_height_
Height of the camera sensor.
void add_line_to_marker(visualization_msgs::Marker &marker, const tf2::Vector3 &pt1, const tf2::Vector3 &pt2)
Add a point to a point marker.
rp3d::WorldSettings world_settings_
Collision world settings.
mf_farm_simulator::AlgaeConstPtr last_algae_msg_
Last algae message.
bool raycast_alga(const tf2::Vector3 &aim_pt, tf2::Vector3 &hit_pt, int &alga_idx, const geometry_msgs::TransformStamped &fixed_camera_tf, const tf2::Vector3 &origin=tf2::Vector3(0, 0, 0))
Casts a ray on algae and gets hit point.
Callback class for raycasting.
geometry_msgs::TransformStamped robot_camera_tf_
Transform from robot to camera frame.
std::string fixed_frame_
Frame in which the pose is expressed.
geometry_msgs::TransformStamped camera_robot_tf_
Transform from camera to robot frame.
std::mutex coll_mutex_
Mutex to control access to collision variables.
Callback class for overlap detection.
RaycastCallback(CameraNodelet *parent)
ros::Publisher rviz_pub_
Publisher for Rviz markers.
bool get_tf()
Gets tf transforms.
ros::Publisher out_pub_
Publisher for the camera output.
void update_fov_pose()
Updates pose of field of view body.
bool noise_meas_
Whether to noise measurements on disease heatmap.
std::vector< rp3d::CollisionBody * > ray_bodies_
Collision bodies for raycasting.
geometry_msgs::TransformStamped combine_transforms(const std::vector< geometry_msgs::TransformStamped > &transforms)
Combine transforms sequentially.
ros::ServiceServer ray_multi_serv_
Service for raycasting from several camera poses.
bool ray_multi_cb(mf_sensors_simulator::MultiPoses::Request &req, mf_sensors_simulator::MultiPoses::Response &res)
Service callback for raycasting from several camera poses.
RaycastCallback raycast_cb_
Callback instance for raycasting.
ros::Subscriber algae_sub_
Subscriber for the algae of the farm.
OverlapCallback overlap_cb_
tf2_ros::TransformListener tf_listener_
int alga_idx_
Index of the hit alga in the ray_bodies_ vector.
std::string camera_frame_
Frame of the camera.
void publish_rviz_fov()
Publishes a Rviz marker for the camera field of view.
std::vector< rp3d::CollisionBody * > algae_bodies_
Collision bodies of the algae.
int n_pxl_height_
Nbr of pixels along sensor height.
tf2::Vector3 get_aim_pt(int pxl_h, int pxl_w, int n_pixel_h=-1, int n_pixel_w=-1)
Gets an aim point from pixel coordinates for raycasting.
geometry_msgs::TransformStamped camera_fixed_tf_
Transform from camera to fixed frame.
bool alga_hit_
Whether an alga has been hit.
float sensor_width_
Width of the camera sensor.
CameraNodelet * parent_
Parent CameraNodelet instance.
Nodelet for a simulated camera.
std::vector< box_shape_ptr > algae_shapes_
Collision shapes of the algae bodies.
bool multi_fov_body(const std::vector< geometry_msgs::Pose > &poses, rp3d::CollisionBody *body, std::unique_ptr< rp3d::BoxShape > &shape, ros::Time stamp=ros::Time(0))
Fill a collision body for multi-pose FOV overlap.
rp3d::CollisionBody * fov_body_
Collision body of the camera FOV.