20 #include <pcl/filters/passthrough.h> 23 #include <visualization_msgs/Marker.h> 117 geometry_msgs::Point32 grid3d;
121 geometry_msgs::PoseArray msg;
132 ROS_INFO(
"pointcloudCallback open");
136 ROS_WARN(
"Odometry transform not received");
149 clock_t begin_filter = clock();
151 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
153 pcl::PassThrough<pcl::PointXYZ> pass;
154 pass.setInputCloud(cloud);
155 pass.setFilterFieldName(
"x");
156 pass.setFilterLimits(-2, 2);
157 pass.setNegative(
false);
158 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(
new pcl::PointCloud<pcl::PointXYZ>);
159 pass.filter(*cloud_filtered);
161 sensor_msgs::PointCloud2 passCloud;
164 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2(
new pcl::PointCloud<pcl::PointXYZ>);
166 pcl::PassThrough<pcl::PointXYZ> pass2;
167 pass2.setInputCloud(cloud2);
168 pass2.setFilterFieldName(
"y");
169 pass2.setFilterLimits(-2, 2);
170 pass2.setNegative(
false);
171 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered2(
new pcl::PointCloud<pcl::PointXYZ>);
172 pass2.filter(*cloud_filtered2);
174 sensor_msgs::PointCloud2 passCloud2;
179 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered_total(
new pcl::PointCloud<pcl::PointXYZ>);
180 sensor_msgs::PointCloud2 frustumCloudTotal;
181 *cloud_filtered_total = *cloud_filtered;
182 *cloud_filtered_total += *cloud_filtered2;
183 cloud_filtered_total->header = cloud->header;
187 clock_t end_filter = clock();
188 double elapsed_secs = double(end_filter - begin_filter) / CLOCKS_PER_SEC;
189 ROS_INFO(
"Filter time: [%lf] sec", elapsed_secs);
198 clock_t begin_predict = clock();
200 delta_x, delta_y, delta_z, delta_a);
201 clock_t end_predict = clock();
202 elapsed_secs = double(end_predict - begin_predict) / CLOCKS_PER_SEC;
203 ROS_INFO(
"Predict time: [%lf] sec", elapsed_secs);
206 const float sr = sin(0);
207 const float cr = cos(0);
208 const float sp = sin(0);
209 const float cp = cos(0);
210 float r00, r01, r02, r10, r11, r12, r20, r21, r22;
223 std::vector<pcl::PointXYZ> points;
224 points.resize(frustumCloudTotal.width);
225 for (uint32_t i = 0; i < frustumCloudTotal.width; ++i, ++iter_x, ++iter_y, ++iter_z)
227 points[i].x = *iter_x * r00 + *iter_y * r01 + *iter_z * r02;
228 points[i].y = *iter_x * r10 + *iter_y * r11 + *iter_z * r12;
229 points[i].z = *iter_x * r20 + *iter_y * r21 + *iter_z * r22;
233 clock_t begin_update = clock();
235 clock_t end_update = clock();
236 elapsed_secs = double(end_update - begin_update) / CLOCKS_PER_SEC;
237 ROS_INFO(
"Update time: [%lf] sec", elapsed_secs);
248 clock_t begin_resample = clock();
249 static int n_updates = 0;
255 clock_t end_resample = clock();
256 elapsed_secs = double(end_resample - begin_resample) / CLOCKS_PER_SEC;
257 ROS_INFO(
"Resample time: [%lf] sec", elapsed_secs);
262 ROS_INFO(
"pointcloudCallback close");
270 tf::Vector3(msg->transform.translation.x, msg->transform.translation.y, msg->transform.translation.z));
272 msg->transform.rotation.z, msg->transform.rotation.w));
277 ROS_WARN(
"Filter not initialized yet, waiting for initial pose.");
305 static bool has_takenoff =
false;
335 ROS_WARN(
"AMCL Jump detected in X");
340 ROS_WARN(
"AMCL Jump detected in Y");
345 ROS_WARN(
"AMCL Jump detected in Z");
350 ROS_WARN(
"AMCL Jump detected in Yaw");
356 geometry_msgs::Point32 grid3d;
382 geometry_msgs::TransformStamped odom_2_base_tf;
383 odom_2_base_tf.header.stamp = msg->header.stamp;
405 const int node = msg->destination_id;
407 geometry_msgs::Point32 grid3d;
410 geometry_msgs::Point anchor;
411 anchor.x = msg->position.x;
412 anchor.y = msg->position.y;
413 anchor.z = msg->position.z;
416 ax = msg->position.x - grid3d.x;
417 ay = msg->position.y - grid3d.y;
418 az = msg->position.z - grid3d.z;
420 range_data.push_back(
Range(static_cast<float>(msg->range), ax, ay, az));
422 geometry_msgs::Point uav;
427 rvizMarkerPublish(msg->destination_id, static_cast<float>(msg->range), uav, anchor);
449 double yaw, pitch, roll;
465 geometry_msgs::Point32 grid3d;
470 const float x_init = t.
x() - grid3d.x;
471 const float y_init = t.
y() - grid3d.y;
472 const float z_init = t.
z() - grid3d.z;
473 const float a_init =
static_cast<float>(
getYawFromTf(init_pose));
490 double yaw, pitch, roll;
497 const geometry_msgs::Point& anchor)
499 visualization_msgs::Marker marker;
502 marker.ns =
"amcl3d";
503 marker.id = anchor_id;
504 marker.type = visualization_msgs::Marker::LINE_STRIP;
505 marker.action = visualization_msgs::Marker::ADD;
506 marker.scale.x = 0.1;
509 marker.color.a = 0.5;
512 marker.color.r = 1.0;
513 marker.color.g = 1.0;
514 marker.color.b = 1.0;
521 marker.color.r = 0.0;
522 marker.color.g = 1.0;
523 marker.color.b = 0.0;
526 marker.color.r = 1.0;
527 marker.color.g = 0.0;
528 marker.color.b = 0.0;
531 marker.color.r = 0.0;
532 marker.color.g = 0.0;
533 marker.color.b = 1.0;
537 marker.points.clear();
538 marker.points.push_back(uav);
539 marker.points.push_back(anchor);
void odomCallback(const geometry_msgs::TransformStampedConstPtr &msg)
ros::Publisher odom_base_pub_
tf::StampedTransform grid_to_world_tf_
double publish_grid_slice_rate_
void publish(const boost::shared_ptr< M > &message) const
tf::Transform base_2_odom_tf_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
double publish_grid_tf_rate_
std::string base_frame_id_
sensor_msgs::PointCloud2 map_point_cloud_msg_
std::string odom_frame_id_
bool open(const std::string &map_path)
std::string global_frame_id_
std::string getName(void *handle)
ros::Timer grid_slice_pub_timer_
ros::Subscriber point_sub_
ROSCPP_DECL const std::string & getName()
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
TFSIMD_FORCE_INLINE const tfScalar & getW() const
void update(const Grid3d &grid3d, const std::vector< pcl::PointXYZ > &points, const std::vector< Range > &range_data, const double alpha, const double sigma)
Update Particles with a pointcloud update.
double getYawFromTf(const tf::Transform &tf)
Return yaw from a given TF.
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
Particle getMean() const
Get mean value from particles.
bool buildGridSliceMsg(const float z, nav_msgs::OccupancyGrid &msg) const
void publishGridSlice(const ros::TimerEvent &)
ros::Publisher cloud_filter_pub_
ros::Timer map_point_cloud_pub_timer_
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool checkUpdateThresholds()
Check motion and time thresholds for AMCL update.
ros::Publisher particles_pose_pub_
double publish_point_cloud_rate_
TFSIMD_FORCE_INLINE const tfScalar & z() const
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
ros::Subscriber range_sub_
std::vector< Range > range_data
TFSIMD_FORCE_INLINE const tfScalar & y() const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
void buildParticlesPoseMsg(const geometry_msgs::Point32 &offset, geometry_msgs::PoseArray &msg) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
tf::Transform lastupdatebase_2_odom_tf_
bool buildMapPointCloudMsg(sensor_msgs::PointCloud2 &msg) const
void predict(const double odom_x_mod, const double odom_y_mod, const double odom_z_mod, const double odom_a_mod, const double delta_x, const double delta_y, const double delta_z, const double delta_a)
tf::Transform lastbase_2_world_tf_
tf::Transform amcl_out_lastbase_2_odom_tf_
tf::Transform lastodom_2_world_tf_
void rvizMarkerPublish(const uint32_t anchor_id, const float r, const geometry_msgs::Point &uav, const geometry_msgs::Point &anchor)
To show range sensors in Rviz.
void buildGrid3d2WorldTf(const std::string &global_frame_id, tf::StampedTransform &tf) const
ros::Publisher range_markers_pub_
bool isInitialized() const
ros::Publisher map_point_cloud_pub_
void setInitialPose(const tf::Transform &init_pose, const float x_dev, const float y_dev, const float z_dev, const float a_dev)
Set the initial pose of the particle filter.
void publishGridTf(const ros::TimerEvent &)
void getMinOctomap(float &x, float &y, float &z) const
ros::Time nextupdate_time_
tf::Transform initodom_2_world_tf_
void publishMapPointCloud(const ros::TimerEvent &)
void init(const int num_particles, const float x_init, const float y_init, const float z_init, const float a_init, const float x_dev, const float y_dev, const float z_dev, const float a_dev)
Set the initial pose of the particle filter.
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
void resample()
Resample the set of particles using low-variance sampling.
TFSIMD_FORCE_INLINE const tfScalar & getX() const
nav_msgs::OccupancyGrid grid_slice_msg_
tf::Transform odom_increment_tf
ros::Subscriber odom_sub_
ROSCPP_DECL void spinOnce()
Struct that contains the data concerning one range meaurement.
ros::Publisher grid_slice_pub_
void pointcloudCallback(const sensor_msgs::PointCloud2ConstPtr &msg)
void rangeCallback(const rosinrange_msg::range_poseConstPtr &msg)
TFSIMD_FORCE_INLINE tfScalar length() const
ros::Timer grid_to_world_tf_timer_