Advertisement
Guest User

laser_scan_matcher_odom.h

a guest
Jan 29th, 2012
1,401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.28 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2011, Ivan Dryanovski, William Morris
  3.  * All rights reserved.
  4.  *
  5.  * *** Modified also to publish horizontal velocities:                       ***
  6.  * *** WARNING: This is not the original laser_scan_matcher from CCNY,       ***
  7.  * *** it's been slightly modified in a dirty fashion.                       ***
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions are met:
  11.  *
  12.  *     * Redistributions of source code must retain the above copyright
  13.  *       notice, this list of conditions and the following disclaimer.
  14.  *     * Redistributions in binary form must reproduce the above copyright
  15.  *       notice, this list of conditions and the following disclaimer in the
  16.  *       documentation and/or other materials provided with the distribution.
  17.  *     * Neither the name of the CCNY Robotics Lab nor the names of its
  18.  *       contributors may be used to endorse or promote products derived from
  19.  *       this software without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31.  * POSSIBILITY OF SUCH DAMAGE.
  32.  */
  33.  
  34. /*  This package uses Canonical Scan Matcher [1], written by
  35.  *  Andrea Censi
  36.  *
  37.  *  [1] A. Censi, "An ICP variant using a point-to-line metric"
  38.  *  Proceedings of the IEEE International Conference
  39.  *  on Robotics and Automation (ICRA), 2008
  40.  */
  41.  
  42. #ifndef LASER_SCAN_MATCHER_LASER_SCAN_MATCHER_H
  43. #define LASER_SCAN_MATCHER_LASER_SCAN_MATCHER_H
  44.  
  45. #include <ros/ros.h>
  46. #include <sensor_msgs/Imu.h>
  47. #include <sensor_msgs/LaserScan.h>
  48. #include <geometry_msgs/Pose2D.h>
  49. #include <geometry_msgs/Twist.h>
  50. #include <nav_msgs/Odometry.h>
  51. #include <tf/transform_datatypes.h>
  52. #include <tf/transform_listener.h>
  53. #include <tf/transform_broadcaster.h>
  54.  
  55. #include <pcl/point_types.h>
  56. #include <pcl/point_cloud.h>
  57. #include <pcl_ros/point_cloud.h>
  58.  
  59. #include <csm/csm_all.h>  // csm defines min and max, but Eigen complains
  60. #undef min
  61. #undef max
  62.  
  63. namespace scan_tools
  64. {
  65.  
  66. // inputs
  67. const std::string scan_topic_  = "scan";
  68. const std::string cloud_topic_ = "cloud";
  69. const std::string odom_topic_  = "odom";
  70. const std::string imu_topic_   = "imu";
  71.  
  72. // outputs
  73. const std::string pose_topic_ = "pose2D";
  74.  
  75. typedef pcl::PointXYZ           PointT;
  76. typedef pcl::PointCloud<PointT> PointCloudT;
  77.  
  78. class LaserScanMatcher
  79. {
  80.   private:
  81.  
  82.     // **** ros  
  83.  
  84.     ros::NodeHandle nh_;
  85.     ros::NodeHandle nh_private_;
  86.  
  87.     ros::Subscriber scan_subscriber_;
  88.     ros::Subscriber cloud_subscriber_;
  89.     ros::Subscriber odom_subscriber_;
  90.     ros::Subscriber imu_subscriber_;
  91.  
  92.     tf::TransformListener    tf_listener_;
  93.     tf::TransformBroadcaster tf_broadcaster_;
  94.  
  95.     tf::Transform base_to_laser_;
  96.     tf::Transform laser_to_base_;
  97.  
  98.     ros::Publisher  test_pub_;
  99.     ros::Publisher  pose_publisher_;
  100.     ros::Publisher  vel_publisher_;
  101.  
  102.     // **** parameters
  103.  
  104.     std::string base_frame_;
  105.     std::string fixed_frame_;
  106.     double cloud_range_min_;
  107.     double cloud_range_max_;
  108.     bool publish_tf_;
  109.     bool publish_pose_;
  110.     bool publish_vel_;
  111.  
  112.     bool use_cloud_input_;
  113.  
  114.     // **** What predictions are available to speed up the ICP?
  115.     // 1) imu - [theta] from imu yaw angle - /odom topic
  116.     // 2) odom - [x, y, theta] from wheel odometry - /imu topic
  117.     // 3) alpha_beta - [x, y, theta] from simple tracking filter - no topic req.
  118.     // If more than one is enabled, priority is imu > odom > alpha_beta
  119.  
  120.     bool use_imu_;
  121.     bool use_odom_;
  122.     bool use_alpha_beta_;
  123.  
  124.     double alpha_;
  125.     double beta_;
  126.  
  127.     // **** state variables
  128.  
  129.     bool initialized_;
  130.  
  131.     bool received_imu_;
  132.     bool received_odom_;
  133.  
  134.     boost::mutex mutex_;
  135.  
  136.     tf::Transform w2b_; // world-to-base tf (pose of base frame)
  137.  
  138.     double v_x_;  // velocity estimated by the alpha-beta tracker
  139.     double v_y_;  
  140.     double v_a_;
  141.  
  142.     double vel_x_, vel_y_, vel_a_;  // simple velocity estimates
  143.     double last_vel_x_, last_vel_y_, last_vel_a_;
  144.  
  145.     ros::Time last_icp_time_;
  146.  
  147.     double latest_imu_yaw_;
  148.     double last_imu_yaw_;
  149.  
  150.     nav_msgs::Odometry latest_odom_;
  151.     nav_msgs::Odometry last_odom_;
  152.     nav_msgs::Odometry vel_msg_;
  153.  
  154.     std::vector<double> a_cos_;
  155.     std::vector<double> a_sin_;
  156.  
  157.     sm_params input_;
  158.     sm_result output_;
  159.     LDP prev_ldp_scan_;
  160.  
  161.     // **** methods
  162.  
  163.     void processScan(LDP& curr_ldp_scan, const ros::Time& time);
  164.  
  165.     void laserScanToLDP(const sensor_msgs::LaserScan::ConstPtr& scan_msg,
  166.                               LDP& ldp);
  167.     void PointCloudToLDP(const PointCloudT::ConstPtr& cloud,
  168.                                LDP& ldp);
  169.  
  170.     void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_msg);
  171.     void cloudCallback (const PointCloudT::ConstPtr& cloud);
  172.  
  173.     void odomCallback (const nav_msgs::Odometry::ConstPtr& odom_msg);
  174.     void imuCallback (const sensor_msgs::ImuPtr& imu_msg);
  175.  
  176.     void createCache (const sensor_msgs::LaserScan::ConstPtr& scan_msg);
  177.     bool getBaseToLaserTf (const std::string& frame_id);
  178.     void initParams();
  179.  
  180.     void getPrediction(double& pr_ch_x, double& pr_ch_y,
  181.                        double& pr_ch_a, double dt);
  182.  
  183.     double getYawFromQuaternion(const geometry_msgs::Quaternion& quaternion);
  184.     double getYawFromQuaternion(const tf::Quaternion& quaternion);
  185.     void createTfFromXYTheta(double x, double y, double theta, tf::Transform& t);
  186.  
  187.   public:
  188.  
  189.     LaserScanMatcher(ros::NodeHandle nh, ros::NodeHandle nh_private);
  190.     ~LaserScanMatcher();
  191. };
  192.  
  193. } //namespace
  194.  
  195. #endif // LASER_SCAN_MATCHER_LASER_SCAN_MATCHER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement